Skip to content

Instantly share code, notes, and snippets.

@Peter9192
Last active April 7, 2023 07:45
Show Gist options
  • Save Peter9192/8a09dfc3ab55d22298c195e0f4d2075d to your computer and use it in GitHub Desktop.
Save Peter9192/8a09dfc3ab55d22298c195e0f4d2075d to your computer and use it in GitHub Desktop.
Wishful_api_ewatercycle
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Current API (pcrglobwb)\n",
"import ewatercycle.forcing\n",
"import ewatercycle.models\n",
"import ewatercycle.parameter_sets\n",
"\n",
"ewatercycle.parameter_sets.available_parameter_sets()\n",
"parameter_set = ewatercycle.parameter_sets.get_parameter_set(\"wflow_rhinemeuse_30min\")\n",
"custom_parameter_set = ewatercycle.parameter_sets.ParameterSet(name=\"custom_parameter_set\", target_model=\"wflow\", common_args, model_specific_args)\n",
"\n",
"forcing = ewatercycle.forcing.load(\"sample_dir\")\n",
"forcing = ewatercycle.forcing.generate(model=wflow, common_args, model_specific_args)\n",
"forcing = ewatercycle.forcing.load_foreign(model=\"wflow\", common_args, model_specific_args)\n",
"\n",
"ewatercycle.models.Wflow.available_versions\n",
"\n",
"wflow = ewatercycle.models.Wflow(version=\"setters\", parameter_set=parameter_set, forcing=forcing)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# New API option (each model own public API)\n",
"from ewatercycle_wflow import Wflow, WflowForcing, parameter_sets\n",
"\n",
"parameters = WflowParameterSet.load()\n",
"parameters = WflowParameterSet.list()\n",
"parameter_sets.list()\n",
"parameter_sets.load()\n",
"\n",
"forcing = WflowForcing.load(...) # inherited from ewatercycle.defaults.Forcing\n",
"forcing = WflowForcing.load_foreign(...) # overwritten\n",
"forcing = WflowForcing.generate(...) # overwritten\n",
"\n",
"Wflow.available_versions\n",
"wflow = Wflow(parameter_set=parameter_set, forcing: WflowForcing = forcing, docker_image='wflow:latest') # specifies docker/apptainer image(s?)\n",
"wflow = Wflow(parameter_set=parameter_set, forcing: WflowForcing = forcing, bmi=WflowBmi) # specifies docker/apptainer image(s?)\n",
"\n",
"# eWaterCycle API\n",
"from ewatercycle.defaults import Model, Forcing, ParameterSet\n",
"\n",
"parameter_set = ParameterSet(directory=..., config=...)\n",
"parameter_set = ParameterSet.load(name) # requires config with catalog\n",
"parameter_set = ParameterSet.generate_lumped(catchment)\n",
"\n",
"forcing = Forcing.load(directory)\n",
"forcing = Forcing.generate(...)\n",
"\n",
"# model = ExampleModel(version=..., forcing=forcing, parameter_set=parameter_set)\n",
"\n",
"model = _BaseModel(bmi: BmiPromise = ..., forcing=forcing, parameter_set=parameter_set) # bmi can be either Bmi class or Grpc4Bmi instance\n",
"model = ContainerizedModel(bmi: Bmi = BlaBmi, forcing=forcing, parameter_set=parameter_set) # infers\n",
"model = ContainerizedModel(image = \"bla:2020.1\", forcing=forcing, parameter_set=parameter_set) # infers\n",
"model = ContainerizedModel(image = \"docker://bla:2020.1\", forcing=forcing, parameter_set=parameter_set) # container_engine = Apptainer\n",
"model = ContainerizedModel(image = \"bla.sif\", forcing=forcing, parameter_set=parameter_set) # automatically sets container engine to apptainer?\n",
"\n",
"\n",
"Model.__init__(bmi=None, image=None):\n",
" if bmi is not None:\n",
" self._bmi = bmi\n",
" ... setup attaches self._bmi()\n",
" elif image is not None:\n",
" \n",
" else: \n",
" raise ValueError(specify bmi or image)\n",
"\n",
"ContainerizedModel.__init__(bmi=None, image)\n",
" if bmi is None\n",
" super(bmi)\n",
" else:\n",
" super()\n",
" \n",
" setup():\n",
" if self.bmi is None\n",
" self.bmi = start(self.image)\n",
"\n",
"\n",
"AbstractModel(...)\n",
"LocalModel(AbstractModel)\n",
"ContainerizedModel(AbstractModel)\n",
"DockerModel(ContainerizedModel)\n",
"ApptainerModel(ContainerizedModel)\n",
"\n",
"\n",
"class NotImplementedBmi():\n",
" ...\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment