Land Surface Model output to GSSHA input (GRIDtoGSSHA)¶
GRIDtoGSSHA¶
-
class
gsshapy.grid.
GRIDtoGSSHA
(gssha_project_folder, gssha_project_file_name, lsm_input_folder_path, lsm_search_card, lsm_lat_var='lat', lsm_lon_var='lon', lsm_time_var='time', lsm_lat_dim='lat', lsm_lon_dim='lon', lsm_time_dim='time', output_timezone=None, pangaea_loader=None)[source]¶ Bases:
object
This class converts the LSM output data to GSSHA formatted input.
-
gssha_project_folder
¶ str
– Path to the GSSHA project folder
-
gssha_project_file_name
¶ str
– Name of the GSSHA elevation grid file.
-
lsm_input_folder_path
¶ str
– Path to the input folder for the LSM files.
-
lsm_lat_var
¶ Optional[
str
] – Name of the latitude variable in the LSM netCDF files. Defaults to ‘lat’.
-
lsm_lon_var
¶ Optional[
str
] – Name of the longitude variable in the LSM netCDF files. Defaults to ‘lon’.
-
lsm_time_var
¶ Optional[
str
] – Name of the time variable in the LSM netCDF files. Defaults to ‘time’.
-
lsm_lat_dim
¶ Optional[
str
] – Name of the latitude dimension in the LSM netCDF files. Defaults to ‘lat’.
-
lsm_lon_dim
¶ Optional[
str
] – Name of the longitude dimension in the LSM netCDF files. Defaults to ‘lon’.
-
lsm_time_dim
¶ Optional[
str
] – Name of the time dimension in the LSM netCDF files. Defaults to ‘time’.
-
output_timezone
¶ Optional[
tzinfo
] – This is the timezone to output the dates for the data. Default is the timezone of your GSSHA model. This option does NOT currently work for NetCDF output.
-
pangaea_loader
¶ Optional[
str
] – String to define loader used when opening pangaea dataset (Ex. ‘hrrr’). Default is None.
Example:
from gsshapy.grid import GRIDtoGSSHA g2g = GRIDtoGSSHA(gssha_project_folder='E:/GSSHA', gssha_project_file_name='gssha.prj', lsm_input_folder_path='E:/GSSHA/lsm-data', lsm_search_card="*.nc", )
-
lsm_precip_to_gssha_precip_gage
(out_gage_file, lsm_data_var, precip_type='RADAR')[source]¶ This function takes array data and writes out a GSSHA precip gage file. See: http://www.gsshawiki.com/Precipitation:Spatially_and_Temporally_Varied_Precipitation
Note
- GSSHA CARDS:
- PRECIP_FILE card with path to gage file
- RAIN_INV_DISTANCE or RAIN_THIESSEN
Parameters: - out_gage_file (str) – Location of gage file to generate.
- lsm_data_var (str or list) – This is the variable name for precipitation in the LSM files. If there is a string, it assumes a single variable. If it is a list, then it assumes the first element is the variable name for RAINC and the second is for RAINNC (see: http://www.meteo.unican.es/wiki/cordexwrf/OutputVariables).
- precip_type (Optional[str]) – This tells if the data is the ACCUM, RADAR, or GAGES data type. Default is ‘RADAR’.
GRIDtoGSSHA Example:
from gsshapy.grid import GRIDtoGSSHA #STEP 1: Initialize class g2g = GRIDtoGSSHA(gssha_project_folder='/path/to/gssha_project', gssha_project_file_name='gssha_project.prj', lsm_input_folder_path='/path/to/wrf-data', lsm_search_card='*.nc', lsm_lat_var='XLAT', lsm_lon_var='XLONG', lsm_time_var='Times', lsm_lat_dim='south_north', lsm_lon_dim='west_east', lsm_time_dim='Time', ) #STEP 2: Generate GAGE data (from WRF) g2g.lsm_precip_to_gssha_precip_gage(out_gage_file="E:/GSSHA/wrf_gage_1.gag", lsm_data_var=['RAINC', 'RAINNC'], precip_type='ACCUM')
HRRRtoGSSHA Example:
from gsshapy.grid import HRRRtoGSSHA #STEP 1: Initialize class h2g = HRRRtoGSSHA( #YOUR INIT PARAMETERS HERE ) #STEP 2: Generate GAGE data g2g.lsm_precip_to_gssha_precip_gage(out_gage_file="E:/GSSHA/hrrr_gage_1.gag", lsm_data_var='prate', precip_type='RADAR')
-
lsm_data_to_arc_ascii
(data_var_map_array, main_output_folder='')[source]¶ Writes extracted data to Arc ASCII file format into folder to be read in by GSSHA. Also generates the HMET_ASCII card file for GSSHA in the folder named ‘hmet_file_list.txt’.
Warning
For GSSHA 6 Versions, for GSSHA 7 or greater, use lsm_data_to_subset_netcdf.
Note
- GSSHA CARDS:
- HMET_ASCII pointing to the hmet_file_list.txt
- LONG_TERM (see: http://www.gsshawiki.com/Long-term_Simulations:Global_parameters)
Parameters: - data_var_map_array (list) – Array to map the variables in the LSM file to the matching required GSSHA data.
- main_output_folder (Optional[str]) – This is the path to place the generated ASCII files. If not included, it defaults to os.path.join(self.gssha_project_folder, “hmet_ascii_data”).
GRIDtoGSSHA Example:
from gsshapy.grid import GRIDtoGSSHA #STEP 1: Initialize class g2g = GRIDtoGSSHA(gssha_project_folder='/path/to/gssha_project', gssha_project_file_name='gssha_project.prj', lsm_input_folder_path='/path/to/wrf-data', lsm_search_card='*.nc', lsm_lat_var='XLAT', lsm_lon_var='XLONG', lsm_time_var='Times', lsm_lat_dim='south_north', lsm_lon_dim='west_east', lsm_time_dim='Time', ) #STEP 2: Generate ASCII DATA #SEE: http://www.meteo.unican.es/wiki/cordexwrf/OutputVariables #EXAMPLE DATA ARRAY 1: WRF GRID DATA BASED data_var_map_array = [ ['precipitation_acc', ['RAINC', 'RAINNC']], ['pressure', 'PSFC'], ['relative_humidity', ['Q2', 'PSFC', 'T2']], #MUST BE IN ORDER: ['SPECIFIC HUMIDITY', 'PRESSURE', 'TEMPERATURE'] ['wind_speed', ['U10', 'V10']], #['U_VELOCITY', 'V_VELOCITY'] ['direct_radiation', ['SWDOWN', 'DIFFUSE_FRAC']], #MUST BE IN ORDER: ['GLOBAL RADIATION', 'DIFFUSIVE FRACTION'] ['diffusive_radiation', ['SWDOWN', 'DIFFUSE_FRAC']], #MUST BE IN ORDER: ['GLOBAL RADIATION', 'DIFFUSIVE FRACTION'] ['temperature', 'T2'], ['cloud_cover' , 'CLDFRA'], #'CLOUD_FRACTION' ] g2g.lsm_data_to_arc_ascii(data_var_map_array)
HRRRtoGSSHA Example:
from gsshapy.grid import HRRRtoGSSHA #STEP 1: Initialize class h2g = HRRRtoGSSHA( #YOUR INIT PARAMETERS HERE ) #STEP 2: Generate ASCII DATA #EXAMPLE DATA ARRAY 1: HRRR GRID DATA BASED data_var_map_array = [ ['precipitation_rate', 'prate'], ['pressure', 'sp'], ['relative_humidity', '2r'], ['wind_speed', ['10u', '10v']], ['direct_radiation_cc', ['dswrf', 'tcc']], ['diffusive_radiation_cc', ['dswrf', 'tcc']], ['temperature', 't'], ['cloud_cover_pc' , 'tcc'], ] h2g.lsm_data_to_arc_ascii(data_var_map_array)
-
lsm_data_to_subset_netcdf
(netcdf_file_path, data_var_map_array, resample_method=None)[source]¶ Writes extracted data to the NetCDF file format
Warning
The NetCDF GSSHA file is only supported in GSSHA 7 or greater.
Note
- GSSHA CARDS:
- HMET_NETCDF pointing to the netcdf_file_path
- LONG_TERM (see: http://www.gsshawiki.com/Long-term_Simulations:Global_parameters)
Parameters: - netcdf_file_path (string) – Path to output the NetCDF file for GSSHA.
- data_var_map_array (list) – Array to map the variables in the LSM file to the matching required GSSHA data.
- resample_method (Optional[gdalconst]) – Resample input method to match hmet data to GSSHA grid for NetCDF output. Default is None.
GRIDtoGSSHA Example:
from gsshapy.grid import GRIDtoGSSHA #STEP 1: Initialize class g2g = GRIDtoGSSHA(gssha_project_folder='/path/to/gssha_project', gssha_project_file_name='gssha_project.prj', lsm_input_folder_path='/path/to/wrf-data', lsm_search_card='*.nc', lsm_lat_var='XLAT', lsm_lon_var='XLONG', lsm_time_var='Times', lsm_lat_dim='south_north', lsm_lon_dim='west_east', lsm_time_dim='Time', ) #STEP 2: Generate NetCDF DATA #EXAMPLE DATA ARRAY 1: WRF GRID DATA BASED #SEE: http://www.meteo.unican.es/wiki/cordexwrf/OutputVariables data_var_map_array = [ ['precipitation_acc', ['RAINC', 'RAINNC']], ['pressure', 'PSFC'], ['relative_humidity', ['Q2', 'PSFC', 'T2']], #MUST BE IN ORDER: ['SPECIFIC HUMIDITY', 'PRESSURE', 'TEMPERATURE'] ['wind_speed', ['U10', 'V10']], #['U_VELOCITY', 'V_VELOCITY'] ['direct_radiation', ['SWDOWN', 'DIFFUSE_FRAC']], #MUST BE IN ORDER: ['GLOBAL RADIATION', 'DIFFUSIVE FRACTION'] ['diffusive_radiation', ['SWDOWN', 'DIFFUSE_FRAC']], #MUST BE IN ORDER: ['GLOBAL RADIATION', 'DIFFUSIVE FRACTION'] ['temperature', 'T2'], ['cloud_cover' , 'CLDFRA'], #'CLOUD_FRACTION' ] g2g.lsm_data_to_subset_netcdf("E/GSSHA/gssha_wrf_data.nc", data_var_map_array)
HRRRtoGSSHA Example:
from gsshapy.grid import HRRRtoGSSHA #STEP 1: Initialize class h2g = HRRRtoGSSHA( #YOUR INIT PARAMETERS HERE ) #STEP 2: Generate NetCDF DATA #EXAMPLE DATA ARRAY 2: HRRR GRID DATA BASED data_var_map_array = [ ['precipitation_rate', 'prate'], ['pressure', 'sp'], ['relative_humidity', '2r'], ['wind_speed', ['10u', '10v']], ['direct_radiation_cc', ['dswrf', 'tcc']], ['diffusive_radiation_cc', ['dswrf', 'tcc']], ['temperature', 't'], ['cloud_cover_pc' , 'tcc'], ] h2g.lsm_data_to_subset_netcdf("E:/GSSHA/gssha_wrf_data.nc", data_var_map_array)
-
HMET ASCII UPDATE¶
-
gsshapy.grid.grid_to_gssha.
update_hmet_card_file
(hmet_card_file_path, new_hmet_data_path)[source]¶ This function updates the paths in the HMET card file to the new location of the HMET data. This is necessary because the file paths are absolute and will need to be updated if moved.
Parameters: - hmet_card_file_path (str) – Location of the file used for the HMET_ASCII card.
- new_hmet_data_path (str) – Location where the HMET ASCII files are currently.
Example:
new_hmet_data_path = "E:\GSSHA\new_hmet_directory" hmet_card_file_path = "E:\GSSHA\hmet_card_file.txt" update_hmet_card_file(hmet_card_file_path, new_hmet_data_path)