Skip to content

Commit 2d6f3a8

Browse files
Add support to load global forcing data (#63)
* Upload of current exploratory files * Now all variables are downloaded * Added reading functions for global datasets * Add functions to select data from global datasets * Update download and parsing exploratory scripts * Add global data loading function to forcing * Reorder co2 molar fraction equation * Correct co2_conv calculation * Corrected co2 calculations * Add rioxarray as an optional dependency * Apply black formatting, isort * Update current state of downloading global data * Update broken test, docstring. * Add soil_init support to global STEMMUS * Support global input dir, forcing. Bugfixes. * Add latlon support to save.py * Add test data, test data script * Add explanation docstring to generate_... file * Remove unused deaccumulate function * Fix bug in save.py for global case * Add test data for soil inti, era5-land. * Fix bugs, tests. * Prospector ignore data_download_scripts * isort * Add dask to dependencies * Add scipy to dependencies * Correct link in readme * Update paths, timestep. * Apply Sarah's downloading...md document suggestions Co-authored-by: SarahAlidoost <55081872+SarahAlidoost@users.noreply.github.com> * Fix bug in sorting canopy height dims * Fix tests, update download scripts * Fix markdown link check * Fix linter issue * Update snellius shell script * Fix bug with path in save.py * Speed up era5 data loading * Bugfix in global data selection * Fix bug in config_io input dir name creation * Remove unused TIMESTEP constant * Correct mistake in test --------- Co-authored-by: SarahAlidoost <55081872+SarahAlidoost@users.noreply.github.com>
1 parent 5336241 commit 2d6f3a8

60 files changed

Lines changed: 34585 additions & 139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.prospector.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ member-warnings: false
1111

1212
ignore-paths:
1313
- docs
14+
- global_data
1415

1516
pyroma:
1617
run: true

PyStemmusScope/config_io.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,37 @@ def create_io_dir(config):
6161

6262
loc, fmt = utils.check_location_fmt(config["Location"])
6363
if fmt == "site":
64-
station_name = loc
64+
site_name = loc
65+
input_dir_name = f"{loc}_{timestamp}"
66+
elif fmt == "latlon":
67+
site_name = "global"
68+
latstr = f"{loc[0]:.3f}".replace(".", "-")
69+
lonstr = f"{loc[1]:.3f}".replace(".", "-")
70+
latstr = f"N{latstr}" if loc[0] >= 0 else f"S{latstr[1:]}"
71+
lonstr = f"E{lonstr}" if loc[1] >= 0 else f"W{lonstr[1:]}"
72+
input_dir_name = f"global_{latstr}_{lonstr}_{timestamp}"
6573
else:
6674
raise NotImplementedError()
6775

6876
# create input directory
6977
work_dir = utils.to_absolute_path(config['WorkDir'])
70-
input_dir = work_dir / "input" / f"{station_name}_{timestamp}"
78+
input_dir = work_dir / "input" / input_dir_name
7179
input_dir.mkdir(parents=True, exist_ok=True)
72-
message = f"Prepare work directory {input_dir} for the station: {station_name}"
80+
message = f"Prepare work directory {input_dir} for the location: {loc}"
7381
logger.info("%s", message)
7482

7583
# copy model parameters to work directory
7684
_copy_data(input_dir, config)
7785

7886
# create output directory
79-
output_dir = work_dir / "output" / f"{station_name}_{timestamp}"
87+
output_dir = work_dir / "output" / input_dir_name
8088
output_dir.mkdir(parents=True, exist_ok=True)
81-
message = f"Prepare work directory {output_dir} for the station: {station_name}"
89+
message = f"Prepare work directory {output_dir} for the location: {loc}"
8290
logger.info("%s", message)
8391

8492
# update config file for ForcingFileName and InputPath
8593
config_file_path = _update_config_file(input_dir, output_dir,
86-
config, station_name, timestamp)
94+
config, site_name, timestamp)
8795

8896
return str(input_dir), str(output_dir), config_file_path
8997

@@ -107,7 +115,7 @@ def _copy_data(input_dir, config):
107115
shutil.copy(str(config["input_data"]), str(input_dir))
108116

109117

110-
def _update_config_file(input_dir, output_dir, config, station_name, timestamp):
118+
def _update_config_file(input_dir, output_dir, config, site_name, timestamp):
111119
"""Update config file for each station.
112120
113121
Create config file for each forcing/station under the work directory.
@@ -117,13 +125,13 @@ def _update_config_file(input_dir, output_dir, config, station_name, timestamp):
117125
input_dir: Path to the input directory.
118126
output_dir: Path to the output directory.
119127
config: Dictionary containing all the paths.
120-
station_name: Station name inferred from forcing file.
128+
site_name: Either inferred from forcing file, or 'latlon' for global data.
121129
timestamp: Timestamp when creating the config file.
122130
123131
Returns:
124132
Path to updated config file.
125133
"""
126-
config_file_path = input_dir / f"{station_name}_{timestamp}_config.txt"
134+
config_file_path = input_dir / f"{site_name}_{timestamp}_config.txt"
127135
with open(config_file_path, 'w', encoding="utf8") as f:
128136
for key, value in config.items():
129137
if key == "InputPath":

0 commit comments

Comments
 (0)