def from_nexus_point(nexus_point, tile=None, parameter='sst'): point = DomsPoint() point.data_id = "%s[%s]" % (tile.tile_id, nexus_point.index) # TODO Not an ideal solution; but it works for now. if parameter == 'sst': point.sst = nexus_point.data_val.item() elif parameter == 'sss': point.sss = nexus_point.data_val.item() elif parameter == 'wind': point.wind_u = nexus_point.data_val.item() try: point.wind_v = tile.meta_data['wind_v'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass try: point.wind_direction = tile.meta_data['wind_dir'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass try: point.wind_speed = tile.meta_data['wind_speed'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass else: raise NotImplementedError( '%s not supported. Only sst, sss, and wind parameters are supported.' % parameter) point.longitude = nexus_point.longitude.item() point.latitude = nexus_point.latitude.item() point.time = datetime.utcfromtimestamp( nexus_point.time).strftime('%Y-%m-%dT%H:%M:%SZ') try: point.depth = nexus_point.depth except KeyError: # No depth associated with this measurement pass point.sst_depth = 0 point.source = tile.dataset point.file_url = tile.granule # TODO device should change based on the satellite making the observations. point.platform = 9 point.device = 5 return point
def from_nexus_point(nexus_point, tile=None): point = DomsPoint() point.data_id = "%s[%s]" % (tile.tile_id, nexus_point.index) # Get the name of the satellite variable from the source NetCDF satellite_var_name = tile.var_name point.satellite_var_name = satellite_var_name point.satellite_var_value = nexus_point.data_val.item() try: point.wind_v = tile.meta_data['wind_v'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass try: point.wind_direction = tile.meta_data['wind_dir'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass try: point.wind_speed = tile.meta_data['wind_speed'][tuple( nexus_point.index)].item() except (KeyError, IndexError): pass point.longitude = nexus_point.longitude.item() point.latitude = nexus_point.latitude.item() point.time = datetime.utcfromtimestamp( nexus_point.time).strftime('%Y-%m-%dT%H:%M:%SZ') try: point.depth = nexus_point.depth except KeyError: # No depth associated with this measurement pass point.sst_depth = 0 point.source = tile.dataset point.file_url = tile.granule # TODO device should change based on the satellite making the observations. point.platform = 9 point.device = 5 return point
def from_edge_point(edge_point): point = DomsPoint() try: x, y = wkt.loads(edge_point['point']).coords[0] except ReadingError: try: x, y = Point( *[float(c) for c in edge_point['point'].split(' ')]).coords[0] except ValueError: y, x = Point( *[float(c) for c in edge_point['point'].split(',')]).coords[0] point.longitude = x point.latitude = y point.time = edge_point['time'] point.wind_u = edge_point.get('eastward_wind') point.wind_v = edge_point.get('northward_wind') point.wind_direction = edge_point.get('wind_direction') point.wind_speed = edge_point.get('wind_speed') point.sst = edge_point.get('sea_water_temperature') point.sst_depth = edge_point.get('sea_water_temperature_depth') point.sss = edge_point.get('sea_water_salinity') point.sss_depth = edge_point.get('sea_water_salinity_depth') point.source = edge_point.get('source') point.platform = edge_point.get('platform') point.device = edge_point.get('device') point.file_url = edge_point.get('fileurl') try: point.data_id = unicode(edge_point['id']) except KeyError: point.data_id = "%s:%s:%s" % (point.time, point.longitude, point.latitude) return point