Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ravenpy models #128

Merged
merged 20 commits into from
May 17, 2024
Merged

Ravenpy models #128

merged 20 commits into from
May 17, 2024

Conversation

richardarsenault
Copy link
Contributor

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • (If applicable) Documentation has been added / updated (for bug fixes / features).
  • (If applicable) Tests have been added.
  • CHANGES.rst has been updated (with summary of main changes).
    • Link to issue (:issue:number) and pull request (:pull:number) has been added.

What kind of change does this PR introduce?

This PR implements classes for ravenpy modelling and model calibration, instead of dictionary and function-based modelling.

Does this PR introduce a breaking change?

No, but one test for hydrotel fails that is unrelated (I think).

Other information:

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added notebooks Run tests against notebooks CI labels Mar 30, 2024
@richardarsenault richardarsenault changed the base branch from main to hydrotel April 3, 2024 17:56
@RondeauG RondeauG mentioned this pull request Apr 12, 2024
5 tasks
Base automatically changed from hydrotel to main April 16, 2024 15:23
xhydro/modelling/_ravenpy_models.py Outdated Show resolved Hide resolved
Comment on lines 85 to 94
# Create HRU object for ravenpy based on catchment properties
self.model_simulations = None
self.qsim = None
hru = dict(
area=drainage_area,
elevation=elevation,
latitude=latitude,
longitude=longitude,
hru_type="land",
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On va probablement aussi vouloir qu'un utilisateur puisse pointer vers un fichier de HRU déjà construit? Je pense ici au travail pour l'Atlas, par exemple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm c'est un bon point. En fait, ce qu'on voudrait, c'est qu'un usager puisse prendre ses fichiers .rvX au complet et rouler dans xhydro comme n'importe quel modèle. On a des outils pour ça aussi. Laisse-moi voir ce que je peux faire.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bon, à bien y penser, je ne suis pas certain que ça soit idéal d'avoir les modèles custom dans xhydro (du moins pour Ravenpy). Ravenpy a déjà un mécanisme permettant de "loader" un modèle à partir de sa configuration déjà construite et de le faire tourner. Le code pour le faire est très simple:

from ravenpy import OutputReader
from ravenpy.ravenpy import run

# Get the .rvX files paths
config = [
    get_file(f"raven-gr4j-cemaneige/raven-gr4j-salmon.{ext}")
    for ext in ["rvt", "rvc", "rvi", "rvh", "rvp"]
]

configdir = config[0].parent

outputs_path = run(modelname="raven-gr4j-salmon", configdir=configdir, overwrite=True)
outputs = OutputReader(run_name=None, path=outputs_path)

Cependant, on ne peut pas calibrer ces modèles car ils peuvent avoir toutes sortes de paramètres custom. Si on fait un modèle spécifique pour le projet (ex. ravenpy HBVEC distribué) alors je crois que c'est mieux d'avoir une fonction spécifique pour celui-là.

Le HRU tel qu'il est indiqué ici est la manière de faire pour les modèles qu'on a "en stock" dans ravenpy actuellement alors je ne le changerais pas.

Qu'en penses-tu?

Copy link
Contributor

@lou-a lou-a Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que l'idée serait que l'utilisateur puisse faire tourner le modèle 1) à partir de ses fichiers .rvx ou 2) d'une shapefile des HRUs avec un NetCDF des inputs météo ? Dans le cas 1) on n'aurait même pas besoin de créer la configuration de l'émulateur ("# Create the emulator configuration") si je ne me trompe pas ? Si on préfère aller vers l'option 2), je suggérerais d'aller vers quelque chose d'un peu plus flexible pour créer le .rvh de HRUs et de remplacer cette partie du code (lignes 95-101) avec :

HRUs_gdf = gpd.read_file(hru_file.shp)
rvh_config = BasinMakerExtractor(HRUs_gdf).extract()

Puis ensuite lorsque l'on crée l'émulateur (ligne 104) on peut fournir au dictionnaire :

sub_basins=rvh_config['sub_basins'],
sub_basin_group=rvh_config['sub_basin_group'], # optionnel ?
reservoirs=rvh_config['reservoirs'], # optionnel
channel_profile=rvh_config['channel_profile'],
hrus=rvh_config['hrus'],

Qu'en pensez vous ?

xhydro/modelling/_ravenpy_models.py Outdated Show resolved Hide resolved
xhydro/modelling/_ravenpy_models.py Outdated Show resolved Hide resolved
@@ -22,6 +22,7 @@ dependencies:
- spotpy
- stackstac
- statsmodels
- ravenpy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour ce fichier (et les autres associés), tu pourrais quand même mettre une version minimal si tu penses que c'est nécessaire pour ce que tu as fait.

@github-actions github-actions bot added the approved Approved for additional tests label May 9, 2024
@richardarsenault
Copy link
Contributor Author

@Zeitsperre Hi! I see there are dependencies failing and some tests that are not related to this PR that are also failing. Any idea what these are / how to fix (especially the dependencies, which I suspect are playing a role in the failing unit tests?)

@Zeitsperre
Copy link
Collaborator

Zeitsperre commented May 13, 2024

@richardarsenault

We made some breaking changes to a few statistical functions in xclim v0.49.0. I can add a pin here on that version, but I'm curious as to what @RondeauG has to say. Should we open a PR to update some tests?

Edit: The changes don't appear to be coming from xclim, xscen, or scipy. Any idea where these different test results might be coming from?

@RondeauG
Copy link
Collaborator

RondeauG commented May 13, 2024

Just to not block this PR, we could temporarily add a pin to both xclim (<0.49.0) and xscen (<0.9.0), then create an Issue and look it up elsewhere.

@RondeauG RondeauG merged commit e06c3b4 into main May 17, 2024
24 checks passed
@RondeauG RondeauG deleted the ravenpy_models branch May 17, 2024 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests CI notebooks Run tests against notebooks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants