preprocessing
Contains some helper functions for Marthe model preprocessing
Functions
|
Helper function to aggregate (and transform) values that are in same model cell. |
|
Extract geology on a projected Marthe Model extension from BRGM |
|
Helper function to extract available observation points (stations) in a Marthe model extension. |
|
Helper function to extract water table/head records at a observation point (station) |
Module Contents
- preprocessing.spatial_aggregation(mm, x, y, layer, value, agg='sum', trans='none', only_active=True, base=0)
Helper function to aggregate (and transform) values that are in same model cell.
Parameters:
- mm (MartheModel)MartheModel instance.
Note: must contain spatial index.
- x, y ([float])xy points coordinates in model extension.
Note: must have the same length.
- layer (int/iterable)layer id to search of point localisation (0-based).
If layer is an integer, same layer id will be considered for all points. Note: for some values such as river pumping, layer has to be
be set to 0 (superficial aquifer).
- value ([float])related point values to aggregate.
Note: must be same length as x and y.
- agg (func/str, optional)Function or function name to perform aggregation.
Can be: ‘mean’, ‘median’, ‘sum’, ‘count’, np.sum, … Default is ‘sum’.
- trans (str/func, optional)keyword/function to use for transforming aggregated values.
- Can be:
function (np.log10, np.sqrt, …)
string function name (‘log10’, ‘sqrt’)
If ‘none’, values will not be transformed. Default if ‘none’.
- only_active (bool, optional)whatever considering active cells only.
Default is True. Note: for some values such as river pumping, only_active
has to be set to False.
- base (int, optional)output layer id n-base.
Marthe is 1-based (base=1), PyMarthe is 0-based (base=0). Default is 0.
Returns:
- res (DataFrame)aggregated and transformed values.
- Format:
node x y layer value
0 789 458963.2 698754.1 4 0.0023 1 856 458456.5 698702.8 2 0.0046 .
Examples:
x = [458963.2, .., 458456.5] y = [698754.1, .., 698702.8] layer = [4, .., 2] value = [0.0023, .., 0.0046] df = spatial_aggregation(mm, x, y, layer, value,
agg = ‘sum’, trans =’lambda x: -x’, only_active= True, base=1)
df.to_csv(‘file.txt’, header=False, index = False, sep=’ ‘)
- preprocessing.extract_model_geology(mm, shpout, epsg=2154, on_grid=False)
Extract geology on a projected Marthe Model extension from BRGM BDCharm50 data base. (only available for projected model located in France country).
- Parameters:
(MartheModel) (mm) –
(str) (shpout) –
(int (epsg) – Default is 2154 (RGF93).
optional) (whatever set geological data on grid cell.) – Default is 2154 (RGF93).
(bool (on_grid) – If False, real geological polygons on model extension will be written. If True, a spatial join operation will be performed between grid and geological data. Default is False.
optional) – If False, real geological polygons on model extension will be written. If True, a spatial join operation will be performed between grid and geological data. Default is False.
Examples
mm = MartheModel(‘mymodel.rma’) extract_model_geology(mm, ‘Lambert_3_model_geol.shp’, epsg=27572, on_grid=True)
- preprocessing.extract_Hubeau_stations(mm, epsg, only_active=True)
Helper function to extract available observation points (stations) in a Marthe model extension. Perform a requests to the French Hubeau API.
- Specific python module required:
pyproj
requests
shapely
geopandas
Inspired by Guillaume Attard https://guillaumeattard.com/exploring-hydro-geological-data-of-france-with-python/
Parameters:
- mm (MartheModel)MartheModel instance.
- Note: model must be (1) projected
located on French territory
epsg (int) : Geodetic Parameter Dataset. only_active (bool) : keep only stations located in model active domain.
Default is True.
Returns:
stations (GeoDataFrame) : available stations.
Examples:
mm = MartheModel(‘my_projected_model.rma’) stations = extract_Hubeau_stations(mm, epsg=2154)
- preprocessing.extract_Hubeau_head_records(code_bss, start_date, end_date)
Helper function to extract water table/head records at a observation point (station) referenced by it’s BSS id. Perform a requests to the French Hubeau API.
- Specific python module required:
requests
Inspired by Guillaume Attard https://guillaumeattard.com/exploring-hydro-geological-data-of-france-with-python/
Parameters:
code_bss (str) : normalized station name (ex: ‘07334X0540/F’) start_date, end_date (str) : required time window (ex: ‘2021-03-04’)
Returns:
- df (DataFrame)available data between required time window.
- Note: water table <=> ‘profondeur_nappe’
head <=> ‘niveau_nappe_eau’
Examples:
mm = MartheModel(‘my_projected_model.rma’) start_date, end_date = [str(ts.date()) for ts in mm.get_time_window()] df = extract_Hubeau_head_records(‘07334X0579/F’, ‘2003-01-01’, ‘2008-02-01’)