def get_bathymetry(lat, lon, resolution="5min"): """Interpolate bathymetry from ETOPO For a given (lat, lon), interpolates the bathymetry from ETOPO """ assert np.shape(lat) == np.shape(lon), "Lat & Lon shape mismatch" db = oceansdb.ETOPO(resolution=resolution) etopo = db["topography"].track(var="height", lat=lat, lon=lon) return {"bathymetry": -etopo["height"].astype("i")}
def location_at_sea(data, cfg=None): """ Evaluate if location is at sea. Interpolate the depth from ETOPO for the data position. If local "height" is negative, means lower than sea level, hence at sea. FIXME: It must allow to check Lat/Lon from data to work with TSGs, i.e. one location for each measurement. Double check other branches, I thought I had already done this before. """ try: flag_bad = cfg['flag_bad'] except: flag_bad = 3 assert hasattr(data, 'attributes'), "Missing attributes" # Temporary solution while migrating to OceanSites variables syntax if ('LATITUDE' not in data.attributes) and \ ('latitude' in data.attributes): print("Deprecated. In the future it will not accept latitude anymore. It'll must be LATITUDE") data.attributes['LATITUDE'] = data.attributes['latitude'] if ('LONGITUDE' not in data.attributes) and \ ('longitude' in data.attributes): print("Deprecated. In the future it will not accept longitude anymore. It'll must be LONGITUDE") data.attributes['LONGITUDE'] = data.attributes['longitude'] if ('LATITUDE' not in data.attributes) or \ ('LONGITUDE' not in data.attributes): print("Missing geolocation (lat/lon)") return 0 ETOPO = oceansdb.ETOPO() try: etopo = ETOPO.extract( var='elevation', lat=data.attributes['LATITUDE'], lon=data.attributes['LONGITUDE']) if etopo['elevation'] <= 0: return 1 elif etopo['elevation'] > 0: return flag_bad except: return 0
def location_at_sea(data, cfg=None): """ Evaluate if location is at sea. Interpolate the depth from ETOPO for the data position. If local "height" is negative, means lower than sea level, hence at sea. FIXME: It must allow to check Lat/Lon from data to work with TSGs, i.e. one location for each measurement. Double check other branches, I thought I had already done this before. ATTENTION: This is old code that was completely replaced by LocationAtSea and it will be removed. """ try: flag_good = cfg["flag_good"] except: flag_good = 1 try: flag_bad = cfg["flag_bad"] except: flag_bad = 3 assert hasattr(data, "attrs"), "Missing attributes" # Temporary solution while migrating to OceanSites variables syntax if ("LATITUDE" not in data.attrs) and ("latitude" in data.attrs): module_logger.debug( "Deprecated. In the future it will not accept latitude anymore. It'll must be LATITUDE" ) data.attrs["LATITUDE"] = data.attrs["latitude"] if ("LONGITUDE" not in data.attrs) and ("longitude" in data.attrs): module_logger.debug( "Deprecated. In the future it will not accept longitude anymore. It'll must be LONGITUDE" ) data.attrs["LONGITUDE"] = data.attrs["longitude"] if ( ("LATITUDE" not in data.attrs) or (data.attrs["LATITUDE"] == None) or ("LONGITUDE" not in data.attrs) or (data.attrs["LONGITUDE"] == None) ): module_logger.debug("Missing geolocation (lat/lon)") return 0 if ( (data.attrs["LATITUDE"] > 90) or (data.attrs["LATITUDE"] < -90) or (data.attrs["LONGITUDE"] > 360) or (data.attrs["LONGITUDE"] < -180) ): return flag_bad try: ETOPO = oceansdb.ETOPO() etopo = ETOPO["topography"].extract( var="height", lat=data.attrs["LATITUDE"], lon=data.attrs["LONGITUDE"] ) h = etopo["height"] flag = np.zeros(h.shape, dtype="i1") flag[np.nonzero(h <= 0)] = flag_good flag[np.nonzero(h > 0)] = flag_bad return flag except: return 0
def find_depth(latitude, longitude): db = oceansdb.ETOPO() return db.extract(lat=latitude, lon=longitude)['elevation'][0]
def find_depth(latitude, longitude): db = oceansdb.ETOPO() return db['topography'].extract(lat=latitude, lon=longitude)['height'][0]
def location_at_sea(data, cfg=None): """ Evaluate if location is at sea. Interpolate the depth from ETOPO for the data position. If local "height" is negative, means lower than sea level, hence at sea. FIXME: It must allow to check Lat/Lon from data to work with TSGs, i.e. one location for each measurement. Double check other branches, I thought I had already done this before. """ try: flag_good = cfg['flag_good'] except: flag_good = 1 try: flag_bad = cfg['flag_bad'] except: flag_bad = 3 assert hasattr(data, 'attrs'), "Missing attributes" # Temporary solution while migrating to OceanSites variables syntax if ('LATITUDE' not in data.attrs) and ('latitude' in data.attrs): module_logger.debug( "Deprecated. In the future it will not accept latitude anymore. It'll must be LATITUDE" ) data.attrs['LATITUDE'] = data.attrs['latitude'] if ('LONGITUDE' not in data.attrs) and ('longitude' in data.attrs): module_logger.debug( "Deprecated. In the future it will not accept longitude anymore. It'll must be LONGITUDE" ) data.attrs['LONGITUDE'] = data.attrs['longitude'] if ('LATITUDE' not in data.attrs) or \ (data.attrs['LATITUDE'] == None) or \ ('LONGITUDE' not in data.attrs) or \ (data.attrs['LONGITUDE'] == None): module_logger.debug("Missing geolocation (lat/lon)") return 0 if (data.attrs['LATITUDE'] > 90) or \ (data.attrs['LATITUDE'] < -90) or \ (data.attrs['LONGITUDE'] > 360) or \ (data.attrs['LONGITUDE'] < -180): return flag_bad try: ETOPO = oceansdb.ETOPO() etopo = ETOPO['topography'].extract(var='height', lat=data.attrs['LATITUDE'], lon=data.attrs['LONGITUDE']) h = etopo['height'] flag = np.zeros(h.shape, dtype='i1') flag[np.nonzero(h <= 0)] = flag_good flag[np.nonzero(h > 0)] = flag_bad return flag except: return 0