pyiem.iemre module#

Support library for the IEM Reanalysis code.

pyiem.iemre.d2l(val)[source]#

Convert a domain label to a string used within filenames.

Return type:

str

pyiem.iemre.get_table(valid)[source]#

Figure out which table should be used for given valid.

Parameters:

valid (datetime or date) – which time is of interest

Returns:

str tablename

pyiem.iemre.set_grids(valid, ds, table=None, domain='conus')[source]#

Update the database with a given xarray.Dataset.

Parameters:
  • valid (datetime or date) – If datetime, save hourly, if date, save daily

  • ds (xarray.Dataset) – The xarray dataset to save

  • table (str,optional) – hard coded database table to use to set the data on. Usually dynamically computed.

  • domain (str,optional) – IEMRE domain to save data to

pyiem.iemre.get_grids(valid, varnames=None, cursor=None, table=None, domain='conus')[source]#

Fetch grid(s) from the database, returning xarray.

Parameters:
  • valid (datetime or date) – If datetime, load hourly, if date, load daily

  • varnames (str or list,optional) – Which variables to fetch from database, defaults to all available

  • cursor (database cursor,optional) – cursor to use for query

  • table (str,optional) – Hard coded table to fetch data from, useful in the case of forecast data.

  • domain (str,optional) – IEMRE domain to fetch data from

Returns:

xarray.Dataset

pyiem.iemre.get_dailyc_ncname(domain='conus')[source]#

Return the filename of the daily climatology netcdf file

Parameters:

domain (str)

Return type:

str

pyiem.iemre.get_daily_ncname(year, domain='conus')[source]#

Get the daily netcdf filename for the given year

Parameters:

domain (str)

Return type:

str

pyiem.iemre.get_dailyc_mrms_ncname()[source]#

Get the MRMS daily climatology filename

pyiem.iemre.get_daily_mrms_ncname(year)[source]#

Get the daily netcdf MRMS filename for the given year

pyiem.iemre.get_hourly_ncname(year, domain='conus')[source]#

Get the daily netcdf filename for the given year

Parameters:

domain (str)

Return type:

str

pyiem.iemre.daily_offset(ts)[source]#

Compute the timestamp index in the netcdf file

pyiem.iemre.hourly_offset(dtobj)[source]#

Return time index for given timestamp

Parameters:

dtobj (datetime) – datetime, if no tzinfo, we assume it is UTC

Returns:

int time index in the netcdf file

pyiem.iemre.find_ij(lon, lat, domain='conus')[source]#

Return the i, j grid indices (based 0) for given lat/lon.

Parameters:
Return type:

Tuple[int | None, int | None]

pyiem.iemre.get_domain(lon, lat)[source]#

Compute the domain that contains the given point.

Parameters:
Return type:

str | None

pyiem.iemre.get_gid(lon, lat, domain='conus')[source]#

Compute the grid id for the given location.

Parameters:

domain (str)

Return type:

int | None

pyiem.iemre.grb2iemre(grb, resampling=None, domain='conus')[source]#

Reproject a grib message onto the IEMRE grid.

A helper frontend to reproject2iemre.

Parameters:
  • grb (pygrib.gribmessage) – single message to reproject

  • resampling (rasterio.warp.Resampling,optional) – defaults to nearest

  • domain (str) – IEMRE domain to reproject onto

Returns:

numpy.ma.array of reprojected grid oriented S to N like IEMRE

Return type:

ndarray

pyiem.iemre.reproject2iemre(grid, affine_in, crs_in, resampling=None, domain='conus')[source]#

Reproject the given grid to IEMRE grid, returning S to N oriented grid.

Note: If the affine_in is dy > 0 then the grid is assumed to be S to N.

Parameters:
  • grid (numpy.array) – 2D grid to reproject

  • affine_in (affine.Affine) – affine transform of input grid

  • crs_in (pyproj.Proj) – projection of input grid

  • resampling (rasterio.warp.Resampling,optional) – defaults to nearest

  • domain (str) – IEMRE domain to reproject onto

Returns:

numpy.ma.array of reprojected grid oriented S to N like IEMRE