@@ -1120,6 +1120,7 @@ def set_atmospheric_model( # pylint: disable=too-many-statements
11201120 temperature = None ,
11211121 wind_u = 0 ,
11221122 wind_v = 0 ,
1123+ pressure_conversion_factor = "Pa" ,
11231124 ):
11241125 """Define the atmospheric model for this Environment.
11251126
@@ -1216,6 +1217,12 @@ def set_atmospheric_model( # pylint: disable=too-many-statements
12161217 m/s). Finally, a callable or function is also accepted. The function
12171218 should take one argument, the height above sea level in meters and
12181219 return a corresponding wind-v in m/s.
1220+ pressure_conversion_factor : string, int, float
1221+ This defines the pressure conversion factor to Pa when type is
1222+ ``forecast`` or ``reanalysis``. The pressure unit from the data may
1223+ not be in Pascal, so the correction is necessary. Valid strings are
1224+ ("mbar", "hPa", "Pa"), or a strictly positive number if using a
1225+ custom pressure unit.
12191226
12201227 Returns
12211228 -------
@@ -1265,6 +1272,28 @@ def set_atmospheric_model( # pylint: disable=too-many-statements
12651272 case "windy" :
12661273 self .process_windy_atmosphere (file )
12671274 case "forecast" | "reanalysis" | "ensemble" :
1275+ conversion_factor = 1
1276+ if not isinstance (pressure_conversion_factor , (float , int , str )):
1277+ raise ValueError (
1278+ "Argument 'pressure_conversion_factor' must be numeric or a standard pressure unit ('mbar', 'hPa', 'Pa')!"
1279+ )
1280+ if isinstance (pressure_conversion_factor , (float , int )):
1281+ if pressure_conversion_factor <= 0 :
1282+ raise ValueError (
1283+ "Argument 'pressure_conversion_factor' must be strictly positive!"
1284+ )
1285+ else :
1286+ conversion_factor = pressure_conversion_factor
1287+ if isinstance (pressure_conversion_factor , str ):
1288+ if pressure_conversion_factor .lower () in ("mbar" , "hpa" ):
1289+ conversion_factor = 100
1290+ elif pressure_conversion_factor .lower () == "pa" :
1291+ conversion_factor = 1
1292+ else :
1293+ raise ValueError (
1294+ "Argument 'pressure_conversion_factor' unit must be a standard pressure unit ('mbar', 'hPa', 'Pa')!"
1295+ )
1296+
12681297 if isinstance (file , str ):
12691298 shortcut_map = self .__atm_type_file_to_function_map .get (type , {})
12701299 matching_shortcut = next (
@@ -1305,9 +1334,11 @@ def set_atmospheric_model( # pylint: disable=too-many-statements
13051334 dataset = fetch_function () if fetch_function is not None else file
13061335
13071336 if type in ["forecast" , "reanalysis" ]:
1308- self .process_forecast_reanalysis (dataset , dictionary )
1337+ self .process_forecast_reanalysis (
1338+ dataset , dictionary , conversion_factor = conversion_factor
1339+ )
13091340 else :
1310- self .process_ensemble (dataset , dictionary )
1341+ self .process_ensemble (dataset , dictionary , conversion_factor )
13111342 case _: # pragma: no cover
13121343 raise ValueError (f"Unknown model type '{ type } '." )
13131344
@@ -1686,7 +1717,7 @@ def process_wyoming_sounding(self, file): # pylint: disable=too-many-statements
16861717 # Save maximum expected height
16871718 self ._max_expected_height = data_array [- 1 , 1 ]
16881719
1689- def process_forecast_reanalysis (self , file , dictionary ): # pylint: disable=too-many-locals,too-many-statements
1720+ def process_forecast_reanalysis (self , file , dictionary , conversion_factor ): # pylint: disable=too-many-locals,too-many-statements
16901721 """Import and process atmospheric data from weather forecasts
16911722 and reanalysis given as ``netCDF`` or ``OPeNDAP`` files.
16921723 Sets pressure, temperature, wind-u and wind-v
@@ -1738,6 +1769,9 @@ def process_forecast_reanalysis(self, file, dictionary): # pylint: disable=too-
17381769 "u_wind": "ugrdprs",
17391770 "v_wind": "vgrdprs",
17401771 }
1772+ conversion_factor : float, int
1773+ Specifies the factor by which the pressure will be multiplied
1774+ in order to transform it to Pascal.
17411775
17421776 Returns
17431777 -------
@@ -1790,7 +1824,7 @@ def process_forecast_reanalysis(self, file, dictionary): # pylint: disable=too-
17901824 _ , lat_index = find_latitude_index (target_lat , lat_array )
17911825
17921826 # Get pressure level data from file
1793- levels = get_pressure_levels_from_file (data , dictionary )
1827+ levels = get_pressure_levels_from_file (data , dictionary , conversion_factor )
17941828
17951829 # Get geopotential data from file
17961830 try :
@@ -1991,7 +2025,7 @@ def process_forecast_reanalysis(self, file, dictionary): # pylint: disable=too-
19912025 # Close weather data
19922026 data .close ()
19932027
1994- def process_ensemble (self , file , dictionary ): # pylint: disable=too-many-locals,too-many-statements
2028+ def process_ensemble (self , file , dictionary , conversion_factor ): # pylint: disable=too-many-locals,too-many-statements
19952029 """Import and process atmospheric data from weather ensembles
19962030 given as ``netCDF`` or ``OPeNDAP`` files. Sets pressure, temperature,
19972031 wind-u and wind-v profiles and surface elevation obtained from a weather
@@ -2042,6 +2076,9 @@ def process_ensemble(self, file, dictionary): # pylint: disable=too-many-locals
20422076 "u_wind": "ugrdprs",
20432077 "v_wind": "vgrdprs",
20442078 }
2079+ conversion_factor : float, int
2080+ Specifies the factor by which the pressure will be multiplied
2081+ in order to transform it to Pascal.
20452082
20462083 See also
20472084 --------
@@ -2106,7 +2143,7 @@ class for some dictionary examples.
21062143 num_members = 1
21072144
21082145 # Get pressure level data from file
2109- levels = get_pressure_levels_from_file (data , dictionary )
2146+ levels = get_pressure_levels_from_file (data , dictionary , conversion_factor )
21102147
21112148 inverse_dictionary = {v : k for k , v in dictionary .items ()}
21122149 param_dictionary = {
0 commit comments