HRRR output to GSSHA input (HRRRtoGSSHA)

http://rapidrefresh.noaa.gov/

HRRRtoGSSHA

class gsshapy.grid.HRRRtoGSSHA(gssha_project_folder, gssha_project_file_name, lsm_input_folder_path, lsm_search_card, lsm_lat_var='gridlat_0', lsm_lon_var='gridlon_0', lsm_time_var='time', lsm_lat_dim='ygrid_0', lsm_lon_dim='xgrid_0', lsm_time_dim='time', output_timezone=None)[source]

Bases: gsshapy.grid.grid_to_gssha.GRIDtoGSSHA

This class converts the HRRR output data to GSSHA formatted input. This class inheris from class:GRIDtoGSSHA.

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_search_card

str – Glob search pattern for LSM files. Ex. “*.grib2”.

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 UTC. This option does NOT currently work for NetCDF output.

Example:

from gsshapy.grid import HRRRtoGSSHA

l2g = HRRRtoGSSHA(gssha_project_folder='E:\GSSHA',
                  gssha_project_file_name='gssha.prj',
                  lsm_input_folder_path='E:\GSSHA\hrrr-data',
                  lsm_search_card="*.grib2",
                  )

# example data var map
data_var_map_array = [
                       ['precipitation_rate', 'PRATE_P0_L1_GLC0'],
                       ['pressure', 'PRES_P0_L1_GLC0'],
                       ['relative_humidity', 'RH_P0_L103_GLC0'],
                       ['wind_speed', ['UGRD_P0_L103_GLC0', 'VGRD_P0_L103_GLC0']],
                       ['direct_radiation_cc', ['DSWRF_P0_L1_GLC0', 'TCDC_P0_L10_GLC0']],
                       ['diffusive_radiation_cc', ['DSWRF_P0_L1_GLC0', 'TCDC_P0_L10_GLC0']],
                       ['temperature', 'TMP_P0_L1_GLC0'],
                       ['cloud_cover_pc', 'TCDC_P0_L10_GLC0'],
                      ]
lsm_data_to_arc_ascii(data_var_map_array, main_output_folder='')

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:
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)

Writes extracted data to the NetCDF file format

Warning

The NetCDF GSSHA file is only supported in GSSHA 7 or greater.

Note

GSSHA CARDS:
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)
lsm_precip_to_gssha_precip_gage(out_gage_file, lsm_data_var, precip_type='RADAR')

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')

Download HRRR

gsshapy.grid.hrrr_to_gssha.download_hrrr_for_gssha(main_directory, forecast_start_date_string, forecast_start_hour_string, leftlon=-180, rightlon=180, toplat=90, bottomlat=-90)[source]

Function to download HRRR data for GSSHA

URL:
http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl
Parameters:
  • main_directory (str) – Location of the output for the forecast data.
  • forecast_start_date_string (str) – String for day of forecast. Ex. ‘20160913’
  • forecast_start_hour_string (str) – String for hour of forecast start. Ex. ‘02’
  • leftlon (Optional[double,int]) – Left bound for longitude. Default is -180.
  • rightlon (Optional[double,int]) – Right bound for longitude. Default is 180.
  • toplat (Optional[double,int]) – Top bound for latitude. Default is 90.
  • bottomlat (Optional[double,int]) – Bottom bound for latitude. Default is -90.
Returns:

List of paths to downloaded files.

Return type:

downloaded_file_list(list)

Example:

from gsshapy.grid.hrrr_to_gssha import download_hrrr_for_gssha

hrrr_folder = '/HRRR'
leftlon = -95
rightlon = -75
toplat = 35
bottomlat = 30
downloaded_file_list = download_hrrr_for_gssha(hrrr_folder,'20160914','01',
                                               leftlon,rightlon,toplat,bottomlat)