-
Notifications
You must be signed in to change notification settings - Fork 3
Write files in etc directories as python files
#539
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
Closed
Naomi Parsons (NParsonsMO)
wants to merge
13
commits into
main
from
538-write-files-in-etc-directories-as-python-files
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b89d990
configure_standardise YAMLs
NParsonsMO efa7ee9
configure_for YAML
NParsonsMO 74056b9
configure_for importlib
NParsonsMO 0e33c7c
configure_standardise importlib
NParsonsMO dc9cc3f
docstring parameters
NParsonsMO 4c875c2
actual info as default rather than file
NParsonsMO 13ce3bb
configure_for tests
NParsonsMO 9329e92
changing unit tests
NParsonsMO d8bccd3
Changing names for importing
NParsonsMO 24f81f1
Docstring correction
NParsonsMO 330ddcf
comment correction
NParsonsMO 39bdb52
Correct docstring
NParsonsMO af81757
Docstring
NParsonsMO 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env python | ||
| # (C) Crown Copyright 2026, Met Office. | ||
| # The LICENSE.md file contains full licensing details. | ||
|
|
||
| # Information about the locations of specific ESMValTool recipes. | ||
| recipes_dict = { | ||
| "correlation": { | ||
| "recipe_name": "recipe_correlation.yml", | ||
| "recipe_fp": "examples/recipe_correlation.yml", | ||
| "empty_additional_datasets": True, | ||
| }, | ||
| "python": { | ||
| "recipe_name": "recipe_python.yml", | ||
| "recipe_fp": "examples/recipe_python.yml", | ||
| }, | ||
| "ref_cre": { | ||
| "recipe_name": "recipe_ref_cre.yml", | ||
| "recipe_fp": "ref/recipe_ref_cre.yml", | ||
| }, | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
CMEW/app/configure_standardise/bin/config_configure_standardise.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env python | ||
| # (C) Crown Copyright 2026, Met Office. | ||
| # The LICENSE.md file contains full licensing details. | ||
|
|
||
| # Information on which streams contain variables from different MIP tables. | ||
| streams_dict = { | ||
| "apm": [ | ||
| "Amon/hfls", | ||
| "Amon/hfss", | ||
| "Amon/rlds", | ||
| "Amon/rlut", | ||
| "Amon/rlutcs", | ||
| "Amon/rsds", | ||
| "Amon/rsdt", | ||
| "Amon/rsut", | ||
| "Amon/rsutcs", | ||
| "Amon/tas", | ||
| "Emon/rls", | ||
| "Emon/rss", | ||
| ], | ||
| "inm": [ | ||
| "SImon/siconc", | ||
| ], | ||
| "onm/grid-T": [ | ||
| "Omon/tos", | ||
| ], | ||
| } | ||
|
|
||
| # Default information to write into the CDDS request file. | ||
| requests_defaults = { | ||
| "metadata": { | ||
| "base_date": "1850-01-01T00:00:00", | ||
| "branch_method": "no parent", | ||
| "license": ( | ||
| "GCModelDev model data is licensed under the " | ||
| "Open Government License v3 " | ||
| "(https://www.nationalarchives.gov.uk/" | ||
| "doc/open-government-licence/version/3/)" | ||
| ), | ||
| "mip": "ESMVal", | ||
| "mip_era": "GCModelDev", | ||
| "model_type": "AGCM AER", | ||
| }, | ||
| "common": { | ||
| "mode": "relaxed", | ||
| "package": "round-1", | ||
| }, | ||
| "data": { | ||
| "mass_data_class": "crum", | ||
| "model_workflow_branch": "trunk", | ||
| "model_workflow_revision": "not used except with data request", | ||
| }, | ||
| "misc": { | ||
| "atmos_timestep": 1200, | ||
| }, | ||
| "conversion": { | ||
| "mip_convert_plugin": "HadGEM3", | ||
| "skip_archive": True, | ||
| "cylc_args": "--no-detach -v", | ||
| }, | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,58 +10,35 @@ | |
| from pathlib import Path | ||
| import yaml | ||
| import logging | ||
| from config_configure_standardise import requests_defaults, streams_dict | ||
|
|
||
| logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
| filename = os.path.basename(__file__) | ||
| logger = logging.getLogger(filename) | ||
|
|
||
|
|
||
| def load_request_defaults(): | ||
| def list_streams(stream_dict=streams_dict): | ||
| """ | ||
| Load default values for request file. | ||
| Lists only the streams in the stream_dict. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| CDDS request configuration default settings. | ||
| """ | ||
| # Get path to default settings | ||
| defaults = os.environ["REQUEST_DEFAULTS_PATH"] | ||
|
|
||
| # Read the defaults | ||
| with open(defaults, "r") as f: | ||
| config = yaml.safe_load(f) | ||
|
|
||
| logger.debug( | ||
| "Default config:\n%s", | ||
| config, | ||
| ) | ||
| return config | ||
|
|
||
|
|
||
| def list_streams(): | ||
| """ | ||
| Lists all streams in the ../etc/streams.yml file. | ||
| Parameters | ||
| ---------- | ||
| stream_dict : dict | ||
| A dictionary containing information about data streams. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| Space separated list of all streams. | ||
| """ | ||
| # Get path to stream mappings | ||
| streams_config = os.environ["STREAM_CONFIG_PATH"] | ||
|
|
||
| # Read the stream mappings | ||
| with open(streams_config, "r") as f: | ||
| config = yaml.safe_load(f) | ||
| logger.debug( | ||
| "Stream config:\n%s", | ||
| config, | ||
| ) | ||
| # Load the stream information dictionary | ||
| logger.debug("Stream information:\n%s", stream_dict) | ||
|
|
||
| # List all streams (keys) | ||
| all_streams = [] | ||
| for stream in config: | ||
| for stream in stream_dict: | ||
| # For substreams we only want the first part | ||
| stream = stream.split("/")[0] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new but needed for variables that Hannah was wanting to retrieve (those with substreams). There's a new unit test. Otherwise trying to make this change separately around these other changes seemed tricky to time. |
||
| all_streams.append(stream) | ||
|
|
||
| # Return as a space separated list | ||
|
|
@@ -74,18 +51,25 @@ def list_streams(): | |
| return stream_str | ||
|
|
||
|
|
||
| def create_request(model_run): | ||
| def create_request(model_run, request_defaults=requests_defaults): | ||
| """ | ||
| Build a CDDS request configuration for a run identified by a suite_id. | ||
|
|
||
| Uses information from the model_runs.yml file. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| model_run : str | ||
| The suite ID as a model run identifier. | ||
| request_defaults : dict | ||
| A dictionary containing the CDDS request default values. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| CDDS request configuration. | ||
| """ | ||
| defaults = load_request_defaults() | ||
| defaults = request_defaults | ||
|
|
||
| mip_table_dir = os.environ["MIP_TABLE_DIR"] | ||
|
|
||
|
|
@@ -103,8 +87,7 @@ def create_request(model_run): | |
| request = {} | ||
| request["metadata"] = { | ||
| **defaults["metadata"], | ||
| # The internal dictionary replaces the T with a space | ||
| "base_date": defaults["metadata"]["base_date"].isoformat(), | ||
| "base_date": defaults["metadata"]["base_date"], | ||
| "calendar": dataset_dict["calendar"], | ||
| "experiment_id": dataset_dict["experiment_id"], | ||
| "institution_id": dataset_dict["institute"], | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
This is the new variable that has a substream (see comment on other file).