-
Notifications
You must be signed in to change notification settings - Fork 145
EN4 cmorizer #4193
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
Open
hanellis
wants to merge
19
commits into
ESMValGroup:main
Choose a base branch
from
hanellis:cmorize_en4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EN4 cmorizer #4193
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4c0739c
Initial files to cmorise EN4 data
hanellis 80734fb
Tested scripts. Added doc and citation details.
hanellis ebde5fb
fixed formatting
hanellis cea576e
Merge branch 'main' of https://github.com/ESMValGroup/ESMValTool intoβ¦
hanellis 850b339
extra tests/formatting
hanellis 194a642
Merge branch 'main' into cmorize_en4
hanellis 36034d2
fixed indents for zenodo and yml file
hanellis 5283551
Update .zenodo.json
hanellis 91e7d17
Merge branch 'cmorize_en4' of github.com:hanellis/ESMValTool into cmoβ¦
hanellis 1ec95c5
Merge branch 'main' into cmorize_en4
valeriupredoi 4c2d379
removed tos/sos from input table
hanellis d535c97
Merge branch 'cmorize_en4' of github.com:hanellis/ESMValTool into cmoβ¦
hanellis 8c5c085
Merge branch 'main' into cmorize_en4
hanellis 0eebbfa
Update esmvaltool/cmorizers/data/formatters/datasets/en4.py
hanellis daee30e
Update esmvaltool/cmorizers/data/formatters/datasets/en4.py
hanellis 298b1bc
Requested changes following sci review
hanellis ae3f0e8
Spacing change
hanellis 451c96e
Merge branch 'main' into cmorize_en4
hanellis 5941d89
Merge branch 'main' into cmorize_en4
jlenh 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
|
|
||
| # Filename | ||
| filename: 'EN.4.2.2.f.analysis.g10.*.nc' | ||
|
|
||
| # Common global attributes for Cmorizer output | ||
| attributes: | ||
| dataset_id: EN4 | ||
| version: '4.2.2' | ||
| tier: 2 | ||
| modeling_realm: reanaly | ||
| project_id: OBS6 | ||
| source: 'https://www.metoffice.gov.uk/hadobs/en4/download-en4-2-2.html' | ||
| reference: 'good2013jgr' | ||
| comment: 'Uses analyses with Gouretski and Reseghetti (2010) XBT corrections and Gouretski and Cheng (2020) MBT corrections applied.' | ||
|
|
||
| # Variables to cmorize | ||
| variables: | ||
| thetao: | ||
| mip: Omon | ||
| raw_var: sea_water_potential_temperature | ||
| srf_var: tos | ||
| so: | ||
| mip: Omon | ||
| raw_var: sea_water_salinity | ||
| srf_var: sos | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """ | ||
| CMORizer for EN4 dataset. | ||
|
|
||
| This script processes EN4 ocean temperature and salinity data to CMOR-compliant format for use in ESMValTool. | ||
|
|
||
| Tier | ||
| Tier 2: other freely-available dataset. | ||
|
|
||
| Source | ||
| https://www.metoffice.gov.uk/hadobs/en4/download-en4-2-2.html | ||
|
|
||
| Last access | ||
| 2025-06-13 | ||
|
|
||
| Info | ||
| EN4: quality controlled subsurface ocean temperature and salinity objective analyses. | ||
| Script tested using analyses with Gouretski and Reseghetti (2010) XBT corrections | ||
| and Gouretski and Cheng (2020) MBT corrections applied. | ||
|
|
||
| Download instructions | ||
| - Edit the text file for your chosen years, https://www.metoffice.gov.uk/hadobs/en4/EN.4.2.2.analyses.g10.download-list.txt | ||
| - Save .txt file in directory for data to be downloaded to. | ||
| - Run 'wget -i EN.4.2.2.profiles.g10.download-list.txt' in same directory. | ||
| - Unzip files prior to running the cmorizer script. | ||
|
|
||
| """ | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| import iris | ||
|
|
||
| from esmvaltool.cmorizers.data import utilities as utils | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def load_and_prepare_cube(fullpath, var, var_info, glob_attrs, cmor_table): | ||
| """ | ||
| Load and prepare a data cube for CMORization. Fix attributes, coordinates, and units. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| fullpath : str | ||
| Path to the input file. | ||
| var : str | ||
| Name of the variable to save in output cube. | ||
| var_info : dict | ||
| Variable information dictionary. | ||
| glob_attrs : dict | ||
| Global attributes to set on the cube. | ||
| cmor_table : object | ||
| CMOR table. | ||
|
|
||
| Returns | ||
| ------- | ||
| iris.cube.Cube | ||
| The prepared data cube. | ||
| """ | ||
| glob_attrs["mip"] = var_info["mip"] | ||
| raw_var = var_info["raw_var"] | ||
| cmor_info = cmor_table.get_variable(var_info["mip"], var) | ||
|
|
||
| cubes = iris.load(fullpath, raw_var) | ||
| iris.util.equalise_attributes(cubes) | ||
| cube = cubes.concatenate_cube() | ||
|
|
||
| if cube.units == "K": | ||
| cube.convert_units("degC") | ||
|
|
||
| cube.coord("depth").units = "m" | ||
| cube = utils.fix_coords(cube) | ||
| utils.fix_var_metadata(cube, cmor_info) | ||
| utils.set_global_atts(cube, glob_attrs) | ||
|
|
||
| return cube | ||
|
|
||
|
|
||
| def extract_surface_var(cube, cmor_info): | ||
| """ | ||
| Extract the surface level variable from a data cube. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| cube : iris.cube.Cube | ||
| Input data cube. | ||
| cmor_info : object | ||
| CMOR table object for the surface variable. | ||
|
|
||
| Returns | ||
| ------- | ||
| iris.cube.Cube | ||
| The extracted surface level cube. | ||
| """ | ||
| logger.info("Extracting surface level") | ||
|
|
||
| depth0 = iris.Constraint(depth=cube.coord("depth").points[0]) | ||
| surface_cube = cube.extract(depth0) | ||
|
|
||
| utils.fix_var_metadata(surface_cube, cmor_info) | ||
|
|
||
| return surface_cube | ||
|
|
||
|
|
||
| def cmorization(in_dir, out_dir, cfg, cfg_user, start_date, end_date): | ||
| """Cmorization main function call.""" | ||
| cmor_table = cfg["cmor_table"] | ||
| glob_attrs = cfg["attributes"] | ||
| fullpath = str(Path(in_dir) / cfg["filename"]) | ||
|
|
||
| for var, var_info in cfg["variables"].items(): | ||
| logger.info("Loading %s", fullpath) | ||
|
|
||
| srf_var = var_info["srf_var"] | ||
| cmor_info_srf = cmor_table.get_variable(var_info["mip"], srf_var) | ||
|
|
||
| cube = load_and_prepare_cube( | ||
| fullpath, var, var_info, glob_attrs, cmor_table | ||
| ) | ||
| surface_cube = extract_surface_var(cube, cmor_info_srf) | ||
| logger.info("Saving for %s", var) | ||
| utils.save_variable(cube, var, out_dir, glob_attrs) | ||
|
|
||
| logger.info("Saving for %s", srf_var) | ||
| utils.save_variable(surface_cube, srf_var, out_dir, glob_attrs) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @article{Good2013EN4:Estimates, | ||
| title = {{EN4: Quality controlled ocean temperature and salinity profiles and monthly objective analyses with uncertainty estimates}}, | ||
| year = {2013}, | ||
| journal = {Journal of Geophysical Research: Oceans}, | ||
| author = {Good, Simon A. and Martin, Matthew J. and Rayner, Nick A.}, | ||
| number = {12}, | ||
| pages = {6704--6716}, | ||
| volume = {118}, | ||
| publisher = {Blackwell Publishing Ltd}, | ||
| doi = {10.1002/2013JC009067}, | ||
| issn = {21699291}, | ||
| keywords = {objective analysis, ocean observations, quality control, uncertainty estimation} |
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.
Uh oh!
There was an error while loading. Please reload this page.