hagelslag.data package

Submodules

hagelslag.data.HRRRModelGrid module

class hagelslag.data.HRRRModelGrid.HRRRModelGrid(run_date, variable, start_date, end_date, path, frequency='1H')

Bases: hagelslag.data.ModelGrid.ModelGrid

hagelslag.data.HailForecastGrid module

class hagelslag.data.HailForecastGrid.HailForecastGrid(run_date, start_date, end_date, ensemble_name, ml_model, members, variable, message_number, path)

Bases: object

HailForecastGrid loads and stores gridded machine learning hail forecasts from GRIB2 files. It can load an arbitrary number of members and timesteps at once.

run_date

Date of the initial time of the model run

Type:datetime.datetime
start_date

Date of the initial forecast time being loaded

Type:datetime.datetime
end_date

Date of the final forecast time being loaded

Type:datetime.datetime
forecast_dates

All forecast times

Type:pandas.DatetimeIndex
ensemble_name

Name of the NWP ensemble being used

Type:str
ml_model

Name of the machine learning model being loaded

Type:str
variable

Name of the machine learning model variable being forecast

Type:str
message_number

Field in the GRIB2 file to load. The first field in the file has message number 1.

Type:int
path

Path to top-level GRIB2 directory. Assumes files are stored in directories by run_date

Type:str
data

Hail forecast data with dimensions (member, time, y, x)

Type:ndarray
lon

2D array of longitudes

Type:ndarray
lat

2D array of latitudes

Type:ndarray
x

2d array of x-coordinate values in km

Type:ndarray
y

2d array of y-coordinate values in km

Type:ndarray
i

2d array of row indices

Type:ndarray
j

2d array of column indices

Type:ndarray
dx

distance between grid points

Type:float
proj

a pyproj projection object used for converting lat-lon points to x-y coordinate values

Type:Proj
projparams

PROJ4 parameters describing map projection

Type:dict
load_data()
period_neighborhood_probability(radius, smoothing, threshold, stride, start_time, end_time)

Calculate the neighborhood probability over the full period of the forecast

Parameters:
  • radius – circular radius from each point in km
  • smoothing – width of Gaussian smoother in km
  • threshold – intensity of exceedance
  • stride – number of grid points to skip for reduced neighborhood grid
Returns:

(neighborhood probabilities)

hagelslag.data.MRMSGrid module

class hagelslag.data.MRMSGrid.MRMSGrid(start_date, end_date, variable, path, freq='1H')

Bases: object

An interface to the NOAA National Severe Storms Lab Multi-Radar Multi-Sensor (MRMS) dataset.

MRMSGrid assumes that the data are in netCDF format and have been interpolated to match the grid being used for forecasting.

Parameters:
  • start_date (datetime.datetime or time str) – Date of first time step to be loaded.
  • end_date (datetime.datetime or str in timestamp format) – Date of last time step to be loaded.
  • variable (str) – MRMS variable name
  • path (str) – Path to the directory containing MRMS files.
  • freq (str, optional (default="1H")) – Time frequency of the data being loaded. Uses pandas time syntax.
start_date

Date of first time step to be loaded.

Type:datetime.datetime or time str
end_date

Date of last time step to be loaded.

Type:datetime.datetime or str in timestamp format
variable

MRMS variable name

Type:str
path

Path to the directory containing MRMS files.

Type:str
freq

Time frequency of the data being loaded. Uses pandas time syntax.

Type:str, optional (default=”1H”)
all_dates

pandas.DatetimeIndex

List of dates being loaded
data

Array of gridded observations after load_data is called. None otherwise.

Type:ndarray or None
valid_dates

Contains the dates where data loaded successfully.

Type:ndarray
load_data()

Loads data files and stores the output in the data attribute.

period_neighborhood_probability(radius, smoothing, threshold, stride, x, y, dx)

Calculate the neighborhood probability over the full period of the forecast

Parameters:
  • radius – circular radius from each point in km
  • smoothing – width of Gaussian smoother in km
  • threshold – intensity of exceedance
  • stride – number of grid points to skip for reduced neighborhood grid
  • x – x-coordinate array in km
  • y – y-coordinate array in km
  • dx – distance between grid points in km
Returns:

neighborhood probablities

hagelslag.data.ModelGrid module

class hagelslag.data.ModelGrid.ModelGrid(filenames, run_date, start_date, end_date, variable, frequency='1H')

Bases: object

Base class for reading 2D model output grids from netCDF files.

Given a list of file names, loads the values of a single variable from a model run. Supports model output in netCDF format.

filenames

List of netCDF files containing model output

Type:list of str
run_date

Date of the initialization time of the model run.

Type:ISO date string or datetime.datetime object
start_date

Date of the first timestep extracted.

Type:ISO date string or datetime.datetime object
end_date

Date of the last timestep extracted.

Type:ISO date string or datetime.datetime object
freqency

spacing between model time steps.

Type:str
valid_dates

DatetimeIndex of all model timesteps

forecast_hours

array of all hours in the forecast

file_objects

List of the file objects for each model time step

Type:list
close()

Close links to all open file objects and delete the objects.

static format_var_name(variable, var_list)

Searches var list for variable name, checks other variable name format options.

Parameters:
  • variable (str) – Variable being loaded
  • var_list (list) – List of variables in file.
Returns:

Name of variable in file containing relevant data, and index of variable z-level if multiple variables contained in same array in file.

load_data()

Load data from netCDF file objects or list of netCDF file objects. Handles special variable name formats.

Returns:Array of data loaded from files in (time, y, x) dimensions, Units
load_data_old()

Loads time series of 2D data grids from each opened file. The code handles loading a full time series from one file or individual time steps from multiple files. Missing files are supported.

hagelslag.data.ModelOutput module

hagelslag.data.NCARModelGrid module

class hagelslag.data.NCARModelGrid.NCARModelGrid(member, run_date, variable, start_date, end_date, path, single_step=False)

Bases: hagelslag.data.ModelGrid.ModelGrid

Extension of the ModelGrid class for interfacing with the NCAR ensemble.

Parameters:
  • member (str) – Name of the ensemble member
  • run_date (datetime.datetime object) – Date of the initial step of the ensemble run
  • start_date (datetime.datetime object) – First time step extracted.
  • end_date (datetime.datetime object) – Last time step extracted.
  • path (str) – Path to model output files.
  • single_step (boolean (default=False)) – Whether variable information is stored with each time step in a separate file or one file containing all timesteps.

hagelslag.data.SSEFModelGrid module

class hagelslag.data.SSEFModelGrid.SSEFModelGrid(member, run_date, variable, start_date, end_date, path, single_step=False)

Bases: hagelslag.data.ModelGrid.ModelGrid

Extension of ModelGrid to the CAPS Storm-Scale Ensemble Forecast system.

Parameters:
  • member (str) – Name of the ensemble member
  • run_date (datetime.datetime object) – Date of the initial step of the ensemble run
  • start_date (datetime.datetime object) – First time step extracted.
  • end_date (datetime.datetime object) – Last time step extracted.
  • path (str) – Path to model output files.
  • single_step (boolean (default=False)) – Whether variable information is stored with each time step in a separate file or one file containing all timesteps.

hagelslag.data.WRFModelGrid module

class hagelslag.data.WRFModelGrid.WRFModelGrid(forecast_date, variable, domain, path, nocolons=False)

Bases: object

Load data from raw WRF model output files.

get_global_attributes()
load_full_grid()
load_time_var(time_var='XTIME')

Module contents