def getPressureLevels(self): total_ele37 = [ 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000 ] # flip max and min because 1000 is the bottom and 0 is the top elevationMax = pressure_from_elevation(self.elevation['min']) elevationMin = pressure_from_elevation(self.elevation['max']) minNum = min(total_ele37, key=lambda x: abs(x - elevationMin)) maxNum = min(total_ele37, key=lambda x: abs(x - elevationMax)) if (minNum > elevationMin and total_ele37.index(minNum) > 0): elevationMinRange = total_ele37.index(minNum) - 1 else: elevationMinRange = total_ele37.index(minNum) if (maxNum < elevationMin and total_ele37.index(maxNum) < 36): elevationMaxRange = total_ele37.index(maxNum) - 1 else: elevationMaxRange = total_ele37.index(maxNum) elevation = [] for e in range(elevationMinRange, elevationMaxRange + 1): elevation.append(total_ele37[e]) elevation = [str(ele) for ele in elevation] elevation = '/'.join(elevation) return elevation
def getPressureLevels(self, elevation): """Restrict list of ERA5 pressure levels to be downloaded""" Pmax = pressure_from_elevation(elevation['min']) + 55 Pmin = pressure_from_elevation(elevation['max']) - 55 levs = np.array([ 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000 ]) mask = (levs >= Pmin) * (levs <= Pmax) # select levs = [str(levi) for levi in levs[mask]] return levs
def era5_pressure_levels(elev_min: float, elev_max: float) -> "list[str]": """Restrict list of ERA5 pressure levels to be downloaded""" Pmax = pressure_from_elevation( elev_min) + 55 # Pressure inversely correlated Pmin = pressure_from_elevation(elev_max) - 55 levs = np.array([ 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000 ]) mask = (levs >= Pmin) * (levs <= Pmax) # select levs = [str(levi) for levi in levs[mask]] return levs
def elevation_corrected_sw(zenith, grid_sw, lat, lon, time, grid_elevation, sub_elevation) -> "tuple": grid_pressure = pressure_from_elevation(grid_elevation) sub_pressure = pressure_from_elevation(sub_elevation) # atmospheric properties if zenith is None: zenith = solar_zenith(lat=lat, lon=lon, time=time) else: zenith = np.atleast_1d(zenith) toa = sw_toa(zenith=zenith) if (toa < grid_sw).any(): warnings.warn( "Calculated top-of-atmosphere radiation is less than grid-level radiation " f"(max difference = {(toa-grid_sw).min()} W m2). This could be because " "grid-level radiation is the average of an accumulation over an interval but TOA is calculated instantaneously " "at either the beginning or end of the interval.") """ try averaging out the TOA """ toa[toa < grid_sw] = grid_sw[ toa < grid_sw] # a workaround: just bump up the TOA a bit mr = relative_optical_airmass(zenith_angle=zenith) # grid grid_local_airmass = local_condition_airmass(mr=mr, p=grid_pressure) # kt = clearness_index(grid_sw, toa) diffuse, direct = sw_partition(grid_sw, toa) k = broadband_attenuation(sw_d=grid_sw * direct, toa=toa, m=grid_local_airmass) # subgrid site sub_local_airmass = local_condition_airmass(mr=mr, p=sub_pressure) sw_dir_sub = np.where(toa == 0, 0, beer_lambert(toa, k, sub_local_airmass)) # print(f"grid p {grid_pressure} \nsub_pressure {sub_pressure}\nzenith {zenith}\ntoa {toa}\nmr {mr}\nk {k}\ngrid_local = {grid_local_airmass}\nsub local {sub_local_airmass}") diffuse = grid_sw * diffuse return diffuse, sw_dir_sub
def subset_lev(self, elev_min, elev_max): Pmax = pressure_from_elevation(elev_min) + 55 Pmin = pressure_from_elevation(elev_max) - 55 indices = np.where((self.LEVS >= Pmin) & (self.LEVS <= Pmax)) return "[{}:{}]".format(np.min(indices), np.max(indices))
def test_array(self): self.assertEqual( 4, len(met.pressure_from_elevation(np.array([10, 150, 300, 1000]))))
def test_zero(self): self.assertAlmostEqual(met.pressure_from_elevation(0), 1013.25)