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

Change API for PCRGlobWB model class #85

Merged
merged 26 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0cf2e38
Add PCRGlobWBParameterSet
Peter9192 May 17, 2021
e72b44d
Change constructor and setup methods
Peter9192 May 17, 2021
f29353a
Select container based on version argument
Peter9192 May 17, 2021
b9a329b
Update notebook and make it work
Peter9192 May 17, 2021
b013766
Fix absolute paths for additional input data
Peter9192 May 17, 2021
8fb414a
update notebook text cells
Peter9192 May 17, 2021
cbdb7c5
Remove container locations from config
Peter9192 May 17, 2021
6aeb2f6
Formatting etc.
Peter9192 May 17, 2021
5fb0053
Add (optional) forcing class to constructor
Peter9192 May 19, 2021
a9cc9d3
Add warnings to conda env
Peter9192 May 19, 2021
9b5082e
Revert "Add warnings to conda env"
Peter9192 May 20, 2021
2e68eaa
Merge remote-tracking branch 'origin/master' into pcrg-new-constructor
Peter9192 Jun 9, 2021
bff06a9
Switch to using new forcing module
Peter9192 Jun 9, 2021
614f4d0
Docstring for forcing
Peter9192 Jun 9, 2021
a18d604
Make versions a tuple
Peter9192 Jun 9, 2021
01cdfa5
Use docker:// for singularity image path
Peter9192 Jun 9, 2021
8024125
Merge remote-tracking branch 'origin/master' into pcrg-new-constructor
Peter9192 Jun 10, 2021
7f5fc18
Forcing files relative to forcing dir
Peter9192 Jun 10, 2021
fd99905
Update forcing paths in setup of default config and document
Peter9192 Jun 10, 2021
87f978d
Reduce number of configurable parameters
Peter9192 Jun 10, 2021
4db744e
Add __str__ methods on the forcing and parametersets
Peter9192 Jun 10, 2021
95a6a87
Catch timeout on singularity spawner
Peter9192 Jun 10, 2021
b5333a3
Merge remote-tracking branch 'origin/master' into pcrg-new-constructor
Peter9192 Jun 14, 2021
80f4a29
Remove additional_input_dirs option (and add black formattting)
Peter9192 Jun 18, 2021
93cafbf
Catch all futuretimeouts for starting containers
Peter9192 Jun 18, 2021
1dc36c4
Merge remote-tracking branch 'origin/master' into pcrg-new-constructor
Peter9192 Jun 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ewatercycle/config/ewatercycle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ grdc_location: null
container_engine: null
singularity_dir: null
output_dir: null
pcrglobwb.singularity_image: null
pcrglobwb.docker_image: null
92 changes: 59 additions & 33 deletions ewatercycle/forcing/_pcrglobwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@

class PCRGlobWBForcing(DefaultForcing):
"""Container for pcrglobwb forcing data."""

def __init__(
self,
start_time: str,
end_time: str,
directory: str,
shape: Optional[str] = None,
precipitationNC: Optional[str] = 'precipitation.nc',
temperatureNC: Optional[str] = 'temperature.nc',
precipitationNC: Optional[str] = "precipitation.nc",
temperatureNC: Optional[str] = "temperature.nc",
):
"""
precipitationNC (str): Input file for precipitation data.
temperatureNC (str): Input file for temperature data.
precipitationNC (str): Input file for precipitation data.
temperatureNC (str): Input file for temperature data.
"""
super().__init__(start_time, end_time, directory, shape)
self.precipitationNC = precipitationNC
Expand All @@ -37,71 +38,96 @@ def generate( # type: ignore
end_time: str,
shape: str,
start_time_climatology: str, # TODO make optional, default to start_time
end_time_climatology:
str, # TODO make optional, defaults to start_time + 1 year
end_time_climatology: str, # TODO make optional, defaults to start_time + 1 year
extract_region: dict = None,
) -> 'PCRGlobWBForcing':
) -> "PCRGlobWBForcing":
"""
start_time_climatology (str): Start time for the climatology data
end_time_climatology (str): End time for the climatology data
extract_region (dict): Region specification, dictionary must
contain `start_longitude`, `end_longitude`, `start_latitude`,
`end_latitude`
start_time_climatology (str): Start time for the climatology data
end_time_climatology (str): End time for the climatology data
extract_region (dict): Region specification, dictionary must
contain `start_longitude`, `end_longitude`, `start_latitude`,
`end_latitude`
"""
# load the ESMValTool recipe
recipe_name = "hydrology/recipe_pcrglobwb.yml"
recipe = get_recipe(recipe_name)

# model-specific updates to the recipe
preproc_names = ('crop_basin', 'preproc_pr', 'preproc_tas',
'preproc_pr_clim', 'preproc_tas_clim')
preproc_names = (
"crop_basin",
"preproc_pr",
"preproc_tas",
"preproc_pr_clim",
"preproc_tas_clim",
)

if dataset is not None:
recipe.data['diagnostics']['diagnostic_daily'][
'additional_datasets'] = [DATASETS[dataset]]
recipe.data["diagnostics"]["diagnostic_daily"][
"additional_datasets"
] = [DATASETS[dataset]]

basin = Path(shape).stem
recipe.data['diagnostics']['diagnostic_daily']['scripts']['script'][
'basin'] = basin
recipe.data["diagnostics"]["diagnostic_daily"]["scripts"]["script"][
"basin"
] = basin

if extract_region is None:
extract_region = get_extents(shape)
for preproc_name in preproc_names:
recipe.data['preprocessors'][preproc_name][
'extract_region'] = extract_region
recipe.data["preprocessors"][preproc_name][
"extract_region"
] = extract_region

variables = recipe.data['diagnostics']['diagnostic_daily']['variables']
var_names = 'tas', 'pr'
variables = recipe.data["diagnostics"]["diagnostic_daily"]["variables"]
var_names = "tas", "pr"

startyear = get_time(start_time).year
for var_name in var_names:
variables[var_name]['start_year'] = startyear
variables[var_name]["start_year"] = startyear

endyear = get_time(end_time).year
for var_name in var_names:
variables[var_name]['end_year'] = endyear
variables[var_name]["end_year"] = endyear

var_names_climatology = 'pr_climatology', 'tas_climatology'
var_names_climatology = "pr_climatology", "tas_climatology"

startyear_climatology = get_time(start_time_climatology)
for var_name in var_names_climatology:
variables[var_name]['start_year'] = startyear_climatology
variables[var_name]["start_year"] = startyear_climatology

endyear_climatology = get_time(end_time_climatology)
for var_name in var_names_climatology:
variables[var_name]['end_year'] = endyear_climatology
variables[var_name]["end_year"] = endyear_climatology

# generate forcing data and retrieve useful information
recipe_output = recipe.run()
# TODO dont open recipe output files, but use standard name from ESMValTool diagnostic
directory, forcing_files = data_files_from_recipe_output(recipe_output)

# instantiate forcing object based on generated data
return PCRGlobWBForcing(directory=directory,
start_time=start_time,
end_time=end_time,
precipitationNC=forcing_files['pr'],
temperatureNC=forcing_files['tas'])
return PCRGlobWBForcing(
directory=directory,
start_time=start_time,
end_time=end_time,
precipitationNC=forcing_files["pr"],
temperatureNC=forcing_files["tas"],
)

def plot(self):
raise NotImplementedError('Dont know how to plot')
raise NotImplementedError("Dont know how to plot")

def __str__(self):
"""Nice formatting of the forcing data object."""
return "\n".join(
[
"Forcing data for PCRGlobWB",
"--------------------------",
f"Directory: {self.directory}",
f"Start time: {self.start_time}",
f"End time: {self.end_time}",
f"Shapefile: {self.shape}",
f"Additional information for model config:",
f" - temperatureNC: {self.temperatureNC}",
f" - precipitationNC: {self.precipitationNC}",
]
)
Loading