def compute_rtma_bounds(bbox): """ Compute bounds from RTMA data even when RTMA data is not available from terrain static data :param bbox: the bounding box of the data :return: a tuple containing bound coordinates (min_lon,max_lon,min_lat,max_lat) """ lats, lons = GribFile('static/ds.terrainh.bin')[1].latlons() i1, i2, j1, j2 = find_region_indices(lats, lons, bbox[0], bbox[2], bbox[1], bbox[3]) lats, lons = lats[i1:i2, j1:j2], lons[i1:i2, j1:j2] return (lons.min(), lons.max(), lats.min(), lats.max())
def load_rtma_data(rtma_data, bbox): """ Load relevant RTMA fields and return them :param rtma_data: a dictionary mapping variable names to local paths :param bbox: the bounding box of the data :return: a tuple containing t2, rh, lats, lons """ gf = GribFile(rtma_data['temp'])[1] lats, lons = gf.latlons() # bbox format: minlat, minlon, maxlat, maxlon i1, i2, j1, j2 = find_region_indices(lats, lons, bbox[0], bbox[2], bbox[1], bbox[3]) t2 = np.ma.array(gf.values())[i1:i2, j1:j2] # temperature at 2m in K td = np.ma.array(GribFile( rtma_data['td'])[1].values())[i1:i2, j1:j2] # dew point in K precipa = np.ma.array(GribFile( rtma_data['precipa'])[1].values())[i1:i2, j1:j2] # precipitation hgt = np.ma.array(GribFile('static/ds.terrainh.bin')[1].values())[i1:i2, j1:j2] logging.info('t2 min %s max %s' % (np.min(t2), np.max(t2))) logging.info('td min %s max %s' % (np.min(td), np.max(td))) logging.info('precipa min %s max %s' % (np.min(precipa), np.max(precipa))) logging.info('hgt min %s max %s' % (np.min(hgt), np.max(hgt))) # compute relative humidity rh = 100 * np.exp(17.625 * 243.04 * (td - t2) / (243.04 + t2 - 273.15) / (243.0 + td - 273.15)) return td, t2, rh, precipa, hgt, lats[i1:i2, j1:j2], lons[i1:i2, j1:j2]
def load_rtma_data(rtma_data, bbox): """ Load relevant RTMA fields and return them :param rtma_data: a dictionary mapping variable names to local paths :param bbox: the bounding box of the data :return: a tuple containing t2, rh, lats, lons """ gf = GribFile(rtma_data['temp'])[1] lats, lons = gf.latlons() # bbox format: minlat, minlon, maxlat, maxlon i1, i2, j1, j2 = find_region_indices(lats, lons, bbox[0], bbox[2], bbox[1], bbox[3]) t2 = gf.values()[i1:i2,j1:j2] # temperature at 2m in K td = GribFile(rtma_data['td'])[1].values()[i1:i2,j1:j2] # dew point in K rain = GribFile(rtma_data['precipa'])[1].values()[i1:i2,j1:j2] # precipitation hgt = GribFile('static/ds.terrainh.bin')[1].values()[i1:i2,j1:j2] # compute relative humidity rh = 100*np.exp(17.625*243.04*(td - t2) / (243.04 + t2 - 273.15) / (243.0 + td - 273.15)) return t2, rh, rain, hgt, lats[i1:i2,j1:j2], lons[i1:i2,j1:j2]