fgreg commented on a change in pull request #61: SDAP-105 DOMS matchup netcdf 
and csv generation
URL: 
https://github.com/apache/incubator-sdap-nexus/pull/61#discussion_r243469680
 
 

 ##########
 File path: analysis/webservice/algorithms/doms/BaseDomsHandler.py
 ##########
 @@ -560,165 +392,245 @@ def __addNetCDFConstants(dataset):
         dataset.publisher_name = "NASA PO.DAAC"
         dataset.publisher_email = "[email protected]"
         dataset.publisher_url = "https://podaac.jpl.nasa.gov";
-        dataset.acknowledgment = "DOMS is a NASA/AIST-funded project.  Grant 
number ####."
-
-
-class DomsNetCDFFormatterAlt:
-    @staticmethod
-    def create(executionId, results, params, details):
-        t = tempfile.mkstemp(prefix="doms_", suffix=".nc")
-        tempFileName = t[1]
-
-        dataset = Dataset(tempFileName, "w", format="NETCDF4")
-
-        dataset.matchID = executionId
-        dataset.Matchup_TimeWindow = params["timeTolerance"]
-        dataset.Matchup_TimeWindow_Units = "hours"
-
-        dataset.time_coverage_start = 
datetime.fromtimestamp(params["startTime"] / 1000).strftime('%Y%m%d %H:%M:%S')
-        dataset.time_coverage_end = datetime.fromtimestamp(params["endTime"] / 
1000).strftime('%Y%m%d %H:%M:%S')
-        dataset.depth_min = params["depthMin"]
-        dataset.depth_max = params["depthMax"]
-        dataset.platforms = params["platforms"]
-
-        dataset.Matchup_SearchRadius = params["radiusTolerance"]
-        dataset.Matchup_SearchRadius_Units = "m"
-
-        dataset.bounding_box = params["bbox"]
-        dataset.primary = params["primary"]
-        dataset.secondary = ",".join(params["matchup"])
-
-        dataset.Matchup_ParameterPrimary = params["parameter"] if "parameter" 
in params else ""
-
-        dataset.time_coverage_resolution = "point"
-
-        bbox = geo.BoundingBox(asString=params["bbox"])
-        dataset.geospatial_lat_max = bbox.north
-        dataset.geospatial_lat_min = bbox.south
-        dataset.geospatial_lon_max = bbox.east
-        dataset.geospatial_lon_min = bbox.west
-        dataset.geospatial_lat_resolution = "point"
-        dataset.geospatial_lon_resolution = "point"
-        dataset.geospatial_lat_units = "degrees_north"
-        dataset.geospatial_lon_units = "degrees_east"
-        dataset.geospatial_vertical_min = 0.0
-        dataset.geospatial_vertical_max = params["radiusTolerance"]
-        dataset.geospatial_vertical_units = "m"
-        dataset.geospatial_vertical_resolution = "point"
-        dataset.geospatial_vertical_positive = "down"
-
-        dataset.time_to_complete = details["timeToComplete"]
-        dataset.num_insitu_matched = details["numInSituMatched"]
-        dataset.num_gridded_checked = details["numGriddedChecked"]
-        dataset.num_gridded_matched = details["numGriddedMatched"]
-        dataset.num_insitu_checked = details["numInSituChecked"]
-
-        dataset.date_modified = datetime.now().strftime('%Y%m%d %H:%M:%S')
-        dataset.date_created = datetime.now().strftime('%Y%m%d %H:%M:%S')
-
-        DomsNetCDFFormatterAlt.__addNetCDFConstants(dataset)
-
-        satelliteGroup = dataset.createGroup("SatelliteData")
-        satelliteWriter = DomsNetCDFValueWriter(satelliteGroup)
-
-        insituGroup = dataset.createGroup("InsituData")
-        insituWriter = DomsNetCDFValueWriter(insituGroup)
-
-        matches = DomsNetCDFFormatterAlt.__writeResults(results, 
satelliteWriter, insituWriter)
-
-        satelliteWriter.commit()
-        insituWriter.commit()
-
-        satDim = dataset.createDimension("satellite_ids", size=None)
-        satVar = dataset.createVariable("satellite_ids", "i4", 
("satellite_ids",), chunksizes=(2048,),
-                                        fill_value=-32767)
-
-        satVar[:] = [f[0] for f in matches]
-
-        insituDim = dataset.createDimension("insitu_ids", size=None)
-        insituVar = dataset.createVariable("insitu_ids", "i4", 
("insitu_ids",), chunksizes=(2048,),
-                                           fill_value=-32767)
-        insituVar[:] = [f[1] for f in matches]
-
-        dataset.close()
-
-        f = open(tempFileName, "rb")
-        data = f.read()
-        f.close()
-        os.unlink(tempFileName)
-        return data
+        dataset.acknowledgment = "DOMS is a NASA/AIST-funded project. NRA 
NNH14ZDA001N."
 
     @staticmethod
     def __writeResults(results, satelliteWriter, insituWriter):
         ids = {}
         matches = []
-
         insituIndex = 0
 
         for r in range(0, len(results)):
             result = results[r]
-            satelliteWriter.write(result)
+            satelliteWriter.addData(result)
             for match in result["matches"]:
                 if match["id"] not in ids:
                     ids[match["id"]] = insituIndex
                     insituIndex += 1
-                    insituWriter.write(match)
+                    insituWriter.addData(match)
 
                 matches.append((r, ids[match["id"]]))
 
-        return matches
+        satelliteWriter.writeGroup()
+        insituWriter.writeGroup()
 
-    @staticmethod
-    def __addNetCDFConstants(dataset):
-        dataset.bnds = 2
-        dataset.Conventions = "CF-1.6, ACDD-1.3"
-        dataset.title = "DOMS satellite-insitu machup output file"
-        dataset.history = "Processing_Version = V1.0, Software_Name = DOMS, 
Software_Version = 1.03"
-        dataset.institution = "JPL, FSU, NCAR"
-        dataset.source = "doms.jpl.nasa.gov"
-        dataset.standard_name_vocabulary = "CF Standard Name Table v27", "BODC 
controlled vocabulary"
-        dataset.cdm_data_type = "Point/Profile, Swath/Grid"
-        dataset.processing_level = "4"
-        dataset.platform = "Endeavor"
-        dataset.instrument = "Endeavor on-board sea-bird SBE 9/11 CTD"
-        dataset.project = "Distributed Oceanographic Matchup System (DOMS)"
-        dataset.keywords_vocabulary = "NASA Global Change Master Directory 
(GCMD) Science Keywords"
-        dataset.keywords = "Salinity, Upper Ocean, SPURS, CTD, Endeavor, 
Atlantic Ocean"
-        dataset.creator_name = "NASA PO.DAAC"
-        dataset.creator_email = "[email protected]"
-        dataset.creator_url = "https://podaac.jpl.nasa.gov/";
-        dataset.publisher_name = "NASA PO.DAAC"
-        dataset.publisher_email = "[email protected]"
-        dataset.publisher_url = "https://podaac.jpl.nasa.gov";
-        dataset.acknowledgment = "DOMS is a NASA/AIST-funded project.  Grant 
number ####."
+        return matches
 
 
 class DomsNetCDFValueWriter:
     def __init__(self, group):
-        self.latVar = DomsNetCDFValueWriter.__createDimension(group, "lat", 
"f4")
-        self.lonVar = DomsNetCDFValueWriter.__createDimension(group, "lon", 
"f4")
-        self.sstVar = DomsNetCDFValueWriter.__createDimension(group, 
"sea_water_temperature", "f4")
-        self.timeVar = DomsNetCDFValueWriter.__createDimension(group, "time", 
"f4")
+        group.createDimension("dim", size=None)
+        self.group = group
 
         self.lat = []
         self.lon = []
-        self.sst = []
         self.time = []
+        self.sea_water_salinity = []
+        self.wind_speed = []
+        self.wind_u = []
+        self.wind_v = []
+        self.wind_direction = []
+        self.sea_water_temperature = []
+        self.depth = []
+
+    def addData(self, value):
+        self.lat.append(value.get("y", None))
+        self.lon.append(value.get("x", None))
+        self.time.append(time.mktime(value.get("time").timetuple()))
+        self.sea_water_salinity.append(value.get("sea_water_salinity", None))
+        self.wind_speed.append(value.get("wind_speed", None))
+        self.wind_u.append(value.get("wind_u", None))
+        self.wind_v.append(value.get("wind_v", None))
+        self.wind_direction.append(value.get("wind_direction", None))
+        self.sea_water_temperature.append(value.get("sea_water_temperature", 
None))
+
+        #
+        # Compress multiple depth variables into one depth array
+        #
+        if value.get("sea_water_temperature_depth") is not None:
+            self.depth.append(value.get("sea_water_temperature_depth"))
+        elif value.get("sea_water_salinity_depth") is not None:
+            self.depth.append(value.get("sea_water_salinity_depth"))
+        else:
+            self.depth.append(None)
+
+    def writeGroup(self):
+        #
+        # Create variables, enrich with attributes, and add data
+        #
+        lonVar = self.group.createVariable("lon", "f4", ("dim",), 
fill_value=-32767.0)
+        latVar = self.group.createVariable("lat", "f4", ("dim",), 
fill_value=-32767.0)
+        timeVar = self.group.createVariable("time", "f4", ("dim",), 
fill_value=-32767.0)
+
+        self.__enrichLon(lonVar, min(self.lon), max(self.lon))
+        self.__enrichLat(latVar, min(self.lat), max(self.lat))
+        self.__enrichTime(timeVar)
+
+        latVar[:] = self.lat
+        lonVar[:] = self.lon
+        timeVar[:] = self.time
+
+        if self.sea_water_salinity.count(None) != len(self.sea_water_salinity):
+            if self.group.name == "SatelliteData":
 
 Review comment:
   Check against a variable instead of a string

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to