-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add india ECMWF Job #17
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,69 @@ | ||
import nwp_consumer.cmd.main as consumer | ||
import contextlib | ||
import os | ||
from dagster import Config, OpExecutionContext, op | ||
from dagster_docker import execute_docker_container | ||
|
||
@contextlib.contextmanager | ||
def modify_env(vars: dict[str, str]): | ||
"""Temporarily modify the environment.""" | ||
for var in vars: | ||
oldval = os.environ.get(var) | ||
newval = vars[var] | ||
os.environ[var] = newval | ||
vars[var] = oldval | ||
try: | ||
yield | ||
finally: | ||
for var in vars: | ||
os.environ[var] = oldval | ||
|
||
class NWPConsumerConfig(Config): | ||
"""Configuration for the NWP consumer.""" | ||
|
||
date_from: str | ||
date_to: str | ||
source: str | ||
docker_volumes: list[str] | ||
raw_dir: str | ||
zarr_dir: str | ||
env_vars: list[str] | ||
|
||
@op | ||
def nwp_consumer_docker_op(context: OpExecutionContext, config: NWPConsumerConfig): | ||
execute_docker_container( | ||
context=context, | ||
image="ghcr.io/openclimatefix/nwp-consumer:latest", | ||
command=[ | ||
"consume", f'--source={config.source}', | ||
f'--from={config.date_from}', | ||
f'--to={config.date_to}' | ||
], | ||
env_vars=config.env_vars, | ||
container_kwargs={ | ||
"volumes": config.docker_volumes | ||
} | ||
) | ||
env_overrides: dict[str, str] | ||
|
||
pass | ||
|
||
@op | ||
def nwp_consumer_download_op(context: OpExecutionContext, config: NWPConsumerConfig): | ||
def nwp_consumer_download_op(context: OpExecutionContext, config: NWPConsumerConfig) \ | ||
-> NWPConsumerConfig: | ||
"""Download the data from the source.""" | ||
consumer.run({ | ||
"download": True, | ||
"convert": False, | ||
"consume": False, | ||
"check": False, | ||
"--source": config.source, | ||
"--sink": "local", | ||
"--from": config.date_from, | ||
"--to": config.date_to, | ||
"--rdir": config.raw_dir, | ||
"--zdir": config.zarr_dir, | ||
"--create-latest": False, | ||
}) | ||
with modify_env(config.env_overrides): | ||
consumer.run({ | ||
"download": True, | ||
"convert": False, | ||
"consume": False, | ||
"check": False, | ||
"--source": config.source, | ||
"--sink": "local", | ||
"--from": config.date_from, | ||
"--to": config.date_to, | ||
"--rdir": config.raw_dir, | ||
"--zdir": config.zarr_dir, | ||
"--create-latest": False, | ||
}) | ||
|
||
return config | ||
|
||
@op | ||
def nwp_consumer_convert_op(context: OpExecutionContext, downloadedConfig: NWPConsumerConfig): | ||
"""Convert the downloaded data to zarr format.""" | ||
consumer.run({ | ||
"download": False, | ||
"convert": True, | ||
"consume": False, | ||
"check": False, | ||
"--source": downloadedConfig.source, | ||
"--sink": "local", | ||
"--from": downloadedConfig.date_from, | ||
"--to": downloadedConfig.date_to, | ||
"--rdir": downloadedConfig.raw_dir, | ||
"--zdir": downloadedConfig.zarr_dir, | ||
"--create-latest": False, | ||
}) | ||
with modify_env(downloadedConfig.env_overrides): | ||
consumer.run({ | ||
"download": False, | ||
"convert": True, | ||
"consume": False, | ||
"check": False, | ||
"--source": downloadedConfig.source, | ||
"--sink": "local", | ||
"--from": downloadedConfig.date_from, | ||
"--to": downloadedConfig.date_to, | ||
"--rdir": downloadedConfig.raw_dir, | ||
"--zdir": downloadedConfig.zarr_dir, | ||
"--create-latest": False, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a directory called "UK" (in caps) here where it seems you are looking to save. Not sure how that affects what you're doing but I can move over what i have done merging the ECMWF into there.