ravenpy.extractors package

Submodules

ravenpy.extractors.forecasts module

ravenpy.extractors.forecasts.get_CASPAR_dataset(climate_model: str, date: datetime, thredds: str = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/', directory: str = 'dodsC/birdhouse/disk2/caspar/daily/') Tuple[Dataset, List[DatetimeIndex | Series | Timestamp | Any]][source]

Return CASPAR dataset.

Parameters:
  • climate_model (str) – Type of climate model, for now only “GEPS” is supported.

  • date (dt.datetime) – The date of the forecast.

  • thredds (str) – The thredds server url. Default: “https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/

  • directory (str) – The directory on the thredds server where the data is stored. Default: “dodsC/birdhouse/disk2/caspar/daily/”

Returns:

The forecast dataset.

Return type:

xr.Dataset

ravenpy.extractors.forecasts.get_ECCC_dataset(climate_model: str, thredds: str = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/', directory: str = 'dodsC/datasets/forecasts/eccc_geps/') Tuple[Dataset, List[DatetimeIndex | Series | Timestamp | Any]][source]

Return latest GEPS forecast dataset.

Parameters:
  • climate_model (str) – Type of climate model, for now only “GEPS” is supported.

  • thredds (str) – The thredds server url. Default: “https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/

  • directory (str) – The directory on the thredds server where the data is stored. Default: “dodsC/datasets/forecasts/eccc_geps/”

Returns:

The forecast dataset.

Return type:

xr.Dataset

ravenpy.extractors.forecasts.get_hindcast_day(region_coll: fiona.Collection, date, climate_model='GEPS')[source]

Generate a forecast dataset that can be used to run raven.

Data comes from the CASPAR archive and must be aggregated such that each file contains forecast data for a single day, but for all forecast timesteps and all members.

The code takes the region shapefile, the forecast date required, and the climate_model to use, here GEPS by default, but eventually could be GEPS, GDPS, REPS or RDPS.

ravenpy.extractors.forecasts.get_recent_ECCC_forecast(region_coll: fiona.Collection, climate_model: str = 'GEPS') Dataset[source]

Generate a forecast dataset that can be used to run raven.

Data comes from the ECCC datamart and collected daily. It is aggregated such that each file contains forecast data for a single day, but for all forecast timesteps and all members.

The code takes the region shapefile and the climate_model to use, here GEPS by default, but eventually could be GEPS, GDPS, REPS or RDPS.

Parameters:
  • region_coll (fiona.Collection) – The region vectors.

  • climate_model (str) – Type of climate model, for now only “GEPS” is supported.

Returns:

The forecast dataset.

Return type:

xr.Dataset

ravenpy.extractors.forecasts.get_subsetted_forecast(region_coll: fiona.Collection, ds: Dataset, times: datetime | DataArray, is_caspar: bool) Dataset[source]

Get Subsetted Forecast.

This function takes a dataset, a region and the time sampling array and returns the subsetted values for the given region and times.

Parameters:
  • region_coll (fiona.Collection) – The region vectors.

  • ds (xr.Dataset) – The dataset containing the raw, worldwide forecast data

  • times (dt.datetime or xr.DataArray) – The array of times required to do the forecast.

  • is_caspar (bool) – True if the data comes from Caspar, false otherwise. Used to define lat/lon on rotated grid.

Returns:

The forecast dataset.

Return type:

xr.Dataset

ravenpy.extractors.routing_product module

class ravenpy.extractors.routing_product.BasinMakerExtractor(df, hru_aspect_convention='GRASS', routing_product_version='2.1')[source]

Bases: object

This is a class to encapsulate the logic of converting the Routing Product into the required data structures to generate the RVH file format.

Parameters:
  • df (GeoDataFrame) – Sub-basin information.

  • hru_aspect_convention ({"GRASS", "ArcGIS"}) – How sub-basin aspect is defined.

  • routing_product_version ({"2.1", "1.0"}) – Version of the BasinMaker data.

HRU_ASPECT_CONVENTION = 'GRASS'
MANNING_DEFAULT = 0.035
MAX_RIVER_SLOPE = 1e-05
ROUTING_PRODUCT_VERSION = '2.1'
USE_LAKE_AS_GAUGE = False
USE_LAND_AS_GAUGE = False
USE_MANNING_COEFF = False
WEIR_COEFFICIENT = 0.6
extract(hru_from_sb: bool = False) dict[source]

Extract data from the Routing Product shapefile and return dictionaries that can be parsed into Raven Commands.

Parameters:

hru_from_sb (bool) – If True, draw HRU information from subbasin information. This is likely to yield crude results.

Returns:

“sub_basins”

Sequence of dictionaries with SubBasin attributes.

”sub_basin_group”

Sequence of dictionaries with SubBasinGroup attributes.

”reservoirs”

Sequence of dictionaries with Reservoir attributes.

”channel_profile”

Sequence of dictionaries with ChannelProfile attributes.

”hrus”

Sequence of dictionaries with HRU attributes.

Return type:

dict

class ravenpy.extractors.routing_product.GridWeightExtractor(input_file_path, routing_file_path, dim_names=('lon_dim', 'lat_dim'), var_names=('longitude', 'latitude'), routing_id_field='SubId', netcdf_input_field='NetCDF_col', gauge_ids=None, sub_ids=None, area_error_threshold=0.05)[source]

Bases: object

Class to extract grid weights.

Notes

The original version of this algorithm can be found at: https://github.com/julemai/GridWeightsGenerator

AREA_ERROR_THRESHOLD = 0.05
CRS_CAEA = 3573
CRS_LLDEG = 4326
DIM_NAMES = ('lon_dim', 'lat_dim')
NETCDF_INPUT_FIELD = 'NetCDF_col'
ROUTING_ID_FIELD = 'SubId'
VAR_NAMES = ('longitude', 'latitude')
extract() dict[source]

Return dictionary to create a GridWeights command.

ravenpy.extractors.routing_product.open_shapefile(path: str | PathLike)[source]

Return GeoDataFrame from shapefile path.

ravenpy.extractors.routing_product.upstream_from_coords(lon: float, lat: float, df: DataFrame | geopandas.GeoDataFrame) DataFrame | geopandas.GeoDataFrame[source]

Return the sub-basins located upstream from outlet.

Parameters:
  • lon (float) – Longitude of outlet.

  • lat (float) – Latitude of outlet.

  • df (pandas.DataFrame or geopandas.GeoDataFrame) – Routing product.

Returns:

Sub-basins located upstream from outlet.

Return type:

pandas.DataFrame or geopandas.GeoDataFrame

ravenpy.extractors.routing_product.upstream_from_id(fid: int, df: DataFrame | geopandas.GeoDataFrame) DataFrame | geopandas.GeoDataFrame[source]

Return upstream sub-basins by evaluating the downstream networks.

Parameters:
  • fid (int) – feature ID of the downstream feature of interest.

  • df (pandas.DataFrame or geopandas.GeoDataFrame) – A GeoDataframe comprising the watershed attributes.

Returns:

Basins ids including fid and its upstream contributors.

Return type:

pandas.DataFrame or geopandas.GeoDataFrame