Skip to content

Improve recharge flexibility#517

Merged
rubencalje merged 6 commits intodevfrom
improve_recharge_flexibility
Nov 19, 2025
Merged

Improve recharge flexibility#517
rubencalje merged 6 commits intodevfrom
improve_recharge_flexibility

Conversation

@rubencalje
Copy link
Collaborator

@rubencalje rubencalje commented Oct 28, 2025

This PR makes the addition of recharge to a model dataset and generating rch- and evt-packages more flexible.

The following improvements have been added:

Current implementation

When running the code:

ds = nlmod.get_ds([100000, 110000, 420000, 430000])
time = pd.date_range("2024", "2025")
ds = nlmod.time.set_ds_time(ds, start="2023", time=time)
knmi_ds = nlmod.read.knmi.get_recharge(ds)

produces for knmi_ds:

<xarray.Dataset> Size: 29MB
Dimensions:      (x: 100, y: 100, time: 367)
Coordinates:
  * x            (x) float64 800B 1e+05 1.002e+05 ... 1.098e+05 1.1e+05
  * y            (y) float64 800B 4.3e+05 4.298e+05 ... 4.202e+05 4.2e+05
  * time         (time) datetime64[ns] 3kB 2024-01-01 2024-01-02 ... 2025-01-01
    spatial_ref  int64 8B 0
Data variables:
    recharge     (time, y, x) float64 29MB 0.001472 0.001472 ... -0.0001 -0.0001
Attributes:
    gridtype:  structured

add_stn_dimensions=True

You can now add add_stn_dimensions=True to the last line (nlmod.read.knmi.get_recharge(ds, add_stn_dimensions=True)), which results in:

<xarray.Dataset> Size: 185kB
Dimensions:          (x: 100, y: 100, time: 367, stn_RD: 5, stn_EV24: 2)
Coordinates:
  * x                (x) float64 800B 1e+05 1.002e+05 ... 1.098e+05 1.1e+05
  * y                (y) float64 800B 4.3e+05 4.298e+05 ... 4.202e+05 4.2e+05
  * time             (time) datetime64[ns] 3kB 2024-01-01 ... 2025-01-01
  * stn_RD           (stn_RD) int64 40B 482 465 431 459 455
  * stn_EV24         (stn_EV24) int64 16B 344 348
    spatial_ref      int64 8B 0
Data variables:
    recharge_stn     (y, x) int64 80kB 482 482 482 482 482 ... 459 459 459 459
    recharge         (time, stn_RD) float64 15kB 0.0075 0.0102 ... 0.0 0.0
    evaporation_stn  (y, x) int64 80kB 344 344 344 344 344 ... 348 348 348 348
    evaporation      (time, stn_EV24) float64 6kB 0.0002 0.0002 ... 0.0001
Attributes:
    gridtype:  structured

So the recharge is not copied for every gridcell anymore, but is specified per rainfall- and evaporation-station (see dimensions stn_RD and stn_EV24). New variables recharge_stn and evaporation_stn are returned, that determine for which cells each station is used. This change is also supported in the generation of the rch-, evt- and uzf-packages.

to_model_time=False

We can also add to_model_time=False to this line (nlmod.read.knmi.get_recharge(ds, add_stn_dimensions=True, to_model_time=False)), which results in:

<xarray.Dataset> Size: 214kB
Dimensions:          (x: 100, y: 100, time_RD: 732, stn_RD: 5, time_EV24: 732,
                      stn_EV24: 2)
Coordinates:
  * x                (x) float64 800B 1e+05 1.002e+05 ... 1.098e+05 1.1e+05
  * y                (y) float64 800B 4.3e+05 4.298e+05 ... 4.202e+05 4.2e+05
  * time_RD          (time_RD) datetime64[ns] 6kB 2023-01-01T09:00:00 ... 202...
  * stn_RD           (stn_RD) int64 40B 482 465 431 459 455
  * time_EV24        (time_EV24) datetime64[ns] 6kB 2023-01-01T01:00:00 ... 2...
  * stn_EV24         (stn_EV24) int64 16B 344 348
    spatial_ref      int64 8B 0
Data variables:
    recharge_stn     (y, x) int64 80kB 482 482 482 482 482 ... 459 459 459 459
    recharge         (time_RD, stn_RD) float64 29kB 0.0049 0.0033 ... 0.0 0.0
    evaporation_stn  (y, x) int64 80kB 344 344 344 344 344 ... 348 348 348 348
    evaporation      (time_EV24, stn_EV24) float64 12kB 0.0001 0.0001 ... 0.0001
Attributes:
    gridtype:  structured

This does not resample the time to the model-time, and adds the dimensions time_RD and time_EV24. This may be useful for when you want to preprocess the data to the model time differently than we do now in nlmod.

More flexibility in adding meteorlogical data to rch, evt and uzf

More flexibility is added in supplying meteorological data to the rch- evt and uzf packages. recharge in rch, rate in evt and finf/pet in uzf can now be supplied as a float (see issue #505), a DataArray with only time-dimension, a DataArray with only spatial dimensions, a DataArray with both time and spatial dimensions, and by supplying data only for stations (see add_stn_dimensions=True above). This DataArray can also still be referenced by the name of the variable in ds. All changes should be backwards compatible.

@martinvonk
Copy link
Collaborator

I can't reproduce FAILED tests/test_018_knmi_data_platform.py::test_read_zip_file - RuntimeError: Unspecified error in H5DSget_num_scales (return value <0) locally on ubuntu..

@rubencalje
Copy link
Collaborator Author

I can't reproduce FAILED tests/test_018_knmi_data_platform.py::test_read_zip_file - RuntimeError: Unspecified error in H5DSget_num_scales (return value <0) locally on ubuntu..

Ok, thanks for checking. Lets hope this error will go away again by itself in the future. So this last error is not related to this PR, and I think we can merge it.

@github-project-automation github-project-automation bot moved this from Todo to In Progress in NHFLO Nov 19, 2025
@rubencalje rubencalje merged commit a8e5fe9 into dev Nov 19, 2025
1 of 3 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in NHFLO Nov 19, 2025
@rubencalje rubencalje deleted the improve_recharge_flexibility branch December 17, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants