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

on-the-fly cmoriser for ACCESS native data #2430

Merged
merged 130 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
b774a36
branch for access live cmoriser
Mar 28, 2024
5acf65c
update simple version for live cmoriser
May 14, 2024
e7277a0
fix issue with multi-model-statistics
May 15, 2024
a0a05bc
comments added, ready for pull request
May 21, 2024
a32a48f
add packages in environment.yml
May 21, 2024
efcea11
change file name
May 21, 2024
9c0c9b8
reformat
May 22, 2024
f98406d
change class name to CapWords convention
May 22, 2024
2b5f8d5
Update environment.yml
rhaegar325 May 22, 2024
8043643
Update access_esm.py
rhaegar325 May 22, 2024
a86e1d9
reformat
May 22, 2024
c8bc262
reformat
May 22, 2024
f389559
summary line and description
May 22, 2024
7815a07
reformat
May 22, 2024
6db0088
reformat
May 22, 2024
4018368
reformat
May 22, 2024
0e864b6
reformat
May 22, 2024
200e2d6
update documentation
May 24, 2024
803c544
update documentation
May 24, 2024
fbfefdc
update documentation
May 24, 2024
88047fc
update documentation
May 24, 2024
0cd3498
Update find_data.rst
rbeucher May 24, 2024
7cd6cf8
update config-developer.yml
May 24, 2024
7c91b6c
restore some changes
May 24, 2024
b446f6f
add test for cmoriser
May 31, 2024
9a0104f
reformat test_access_esm.py
May 31, 2024
64054ba
reformat test_access_esm.py
May 31, 2024
b8c6057
reformat test_access_esm.py
May 31, 2024
869c481
reformat esmvalcore/_task.py
May 31, 2024
6885d9a
add access test data
May 31, 2024
8cc0f3b
change datapath
May 31, 2024
c803837
fix _fix
May 31, 2024
d2d1da3
test for access cmoriser
Jun 3, 2024
013d5f0
test for access cmoriser
Jun 3, 2024
b116bfc
test for access cmoriser
Jun 3, 2024
c371ba0
test for access cmoriser
Jun 4, 2024
84fe2ed
Merge branch 'main' into access-live-cmoriser
rbeucher Jun 4, 2024
6d80f5f
test for access cmoriser
Jun 4, 2024
a566cfd
test for access cmoriser
Jun 4, 2024
b666121
test for access cmoriser
Jun 4, 2024
f7fb9d7
test for access cmoriser
Jun 4, 2024
97acf57
add author name
Jun 4, 2024
645a203
Merge branch 'main' into access-live-cmoriser
rhaegar325 Jun 4, 2024
5f587df
clean code
Jun 6, 2024
f10b23c
Merge branch 'main' into access-live-cmoriser
rhaegar325 Jun 7, 2024
fb3ef3f
slitely change the import line
Jun 7, 2024
fdaf89d
use extra_facets
Jun 13, 2024
857b9d1
follow chnage request
Jun 13, 2024
1753b8d
follow chnage request
Jun 13, 2024
b0e1400
follow chnage request
Jun 13, 2024
7a06b34
follow chnage request
Jun 13, 2024
7f2ffeb
follow chnage request
Jun 13, 2024
24ef703
follow chnage request
Jun 13, 2024
c5c7393
change test file
Jun 13, 2024
4569cf5
fix height value
Jun 13, 2024
cadd99e
change docs
Jun 13, 2024
42ec653
change docs
Jun 13, 2024
7422346
add modeling_realm to extra_facet
Jun 14, 2024
41c6530
add modeling_realm to extra_facet
Jun 14, 2024
c92373d
add modeling_realm to extra_facet
Jun 14, 2024
fe5e4d6
fix output_file
Jun 19, 2024
fecb98b
fix output_file
Jun 19, 2024
8f744ff
add more variables to live-cmoriser
Jun 18, 2024
1456249
add more variables to live-cmoriser
Jun 18, 2024
bd3769e
add more available variables for cmoriser
rhaegar325 Jun 20, 2024
e160394
add more available variables for cmoriser
rhaegar325 Jun 20, 2024
573b4f1
add test
rhaegar325 Jun 20, 2024
f7081ba
add test
rhaegar325 Jun 20, 2024
b5143bd
Update doc/quickstart/find_data.rst
rhaegar325 Jul 3, 2024
08722f0
fix test
rhaegar325 Jul 3, 2024
8e89122
fix test
rhaegar325 Jul 3, 2024
2b93eb3
fix test
rhaegar325 Jul 3, 2024
8743481
fix test
rhaegar325 Jul 3, 2024
e909bf4
fix test
rhaegar325 Jul 3, 2024
21481a3
fix test
rhaegar325 Jul 3, 2024
17789cb
fix test
rhaegar325 Jul 3, 2024
2ee9aa0
fix test
rhaegar325 Jul 3, 2024
320ec83
fix test
rhaegar325 Jul 3, 2024
8ab57f7
fix test
rhaegar325 Jul 3, 2024
66b7d7e
fix test
rhaegar325 Jul 3, 2024
f29e18d
fix test
rhaegar325 Jul 3, 2024
442b2db
fix test
rhaegar325 Jul 3, 2024
7022df1
fix test
rhaegar325 Jul 4, 2024
151642e
remove eval()
rhaegar325 Jul 4, 2024
2f500ea
remove eval()
rhaegar325 Jul 4, 2024
5d6d519
remove eval()
rhaegar325 Jul 4, 2024
4f26996
Update esmvalcore/cmor/_fixes/access/access_esm.py
rhaegar325 Jul 4, 2024
814ece5
Update doc/quickstart/find_data.rst
rhaegar325 Jul 4, 2024
d08ae67
Update doc/quickstart/find_data.rst
rhaegar325 Jul 4, 2024
0451b7d
Update esmvalcore/cmor/_fixes/access/access_esm.py
rhaegar325 Jul 4, 2024
18ceca5
Update esmvalcore/cmor/_fixes/access/access_esm.py
rhaegar325 Jul 4, 2024
e15236e
fix format
rhaegar325 Jul 4, 2024
dcb13a7
change extra_facets
rhaegar325 Jul 4, 2024
1d3a0cf
change institude to dataset
rhaegar325 Jul 4, 2024
bac5051
change institude to dataset
rhaegar325 Jul 4, 2024
44af431
fix filename
rhaegar325 Jul 4, 2024
1106514
fix filename
rhaegar325 Jul 4, 2024
5a837e5
fix filename
rhaegar325 Jul 4, 2024
04921ea
fix filename
rhaegar325 Jul 4, 2024
9105512
add condition before fix_height_value
rhaegar325 Jul 4, 2024
ce60ea0
fix test
rhaegar325 Jul 4, 2024
41aeee0
fix test
rhaegar325 Jul 4, 2024
ef3e7de
Update doc/quickstart/find_data.rst
rhaegar325 Jul 4, 2024
b36738d
Update doc/quickstart/find_data.rst
rhaegar325 Jul 4, 2024
07519cb
fix test
rhaegar325 Jul 4, 2024
475f4b8
fix test
rhaegar325 Jul 4, 2024
5fd5b64
fix doc
rhaegar325 Jul 4, 2024
862d318
fix doc and test
rhaegar325 Jul 4, 2024
70d4258
fix test
rhaegar325 Jul 4, 2024
cb87ce6
fix test
rhaegar325 Jul 4, 2024
155c7cc
fix test
rhaegar325 Jul 4, 2024
71252bd
fix test
rhaegar325 Jul 4, 2024
f429566
fix test
rhaegar325 Jul 4, 2024
d48dac9
change class structure of cmoriser
rhaegar325 Jul 5, 2024
043b229
change class structure of cmoriser
rhaegar325 Jul 5, 2024
ab151ab
change class structure of cmoriser
rhaegar325 Jul 5, 2024
78e9a68
change class structure of cmoriser
rhaegar325 Jul 5, 2024
0e97c34
change class structure of cmoriser
rhaegar325 Jul 5, 2024
f033eea
change class structure of cmoriser
rhaegar325 Jul 5, 2024
0f2ff15
change class structure of cmoriser
rhaegar325 Jul 5, 2024
43279b0
change class structure of cmoriser
rhaegar325 Jul 5, 2024
bc69800
fix test
rhaegar325 Jul 5, 2024
f750d5a
fix test
rhaegar325 Jul 5, 2024
81be7d3
fix test
rhaegar325 Jul 5, 2024
fdf9f56
fix test
rhaegar325 Jul 5, 2024
18d31cc
fix class structure
rhaegar325 Jul 6, 2024
7370733
Move fix_height method to Tas class
rbeucher Jul 8, 2024
c5acc53
Fix blank spaces
rbeucher Jul 8, 2024
54caba7
rename to fix_data
rhaegar325 Jul 8, 2024
987bdd9
fix function name
rhaegar325 Jul 9, 2024
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: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- cartopy
- cf-units
- cftime
- csv
rbeucher marked this conversation as resolved.
Show resolved Hide resolved
- compilers
- dask
- dask-jobqueue
Expand All @@ -29,6 +30,7 @@ dependencies:
- nested-lookup
- netcdf4
- numpy !=1.24.3
- os
rbeucher marked this conversation as resolved.
Show resolved Hide resolved
- packaging
- pandas !=2.2.0,!=2.2.1 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349
- pillow
Expand Down
Empty file.
216 changes: 216 additions & 0 deletions esmvalcore/cmor/_fixes/access/access_esm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
'''On-the-fly CMORizer for ACCESS-ESM.

Check notice on line 1 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L1

Use """triple double quotes""" (found '''-quotes) (D300)

Note
----
This is the first version of ACCESS-ESM CMORizer in for ESMValCore
Currently, only two variables (`tas`,`pr`) is fully supported.


'''
import logging

import csv

from iris.cube import CubeList

from ..native_datasets import NativeDatasetFix

from esmvalcore.cmor.check import cmor_check

import os

Check notice on line 20 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L20

standard import "import os" should be placed before "from iris.cube import CubeList" (wrong-import-order)

logger = logging.getLogger(__name__)

class tas(NativeDatasetFix):

Check notice on line 24 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L24

expected 2 blank lines, found 1 (E302)
'''
Fix variable(tas) only
'''

def __init__(self, vardef, extra_facets, session, frequency):
'''
Initialise some class variable
Heritage from native_dataset
'''

super().__init__(vardef,extra_facets,session,frequency)

self.cube=None

Check notice on line 37 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L37

missing whitespace around operator (E225)

self.current_dir=os.path.dirname(__file__)

Check notice on line 39 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L39

missing whitespace around operator (E225)

Check notice on line 40 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L40

blank line contains whitespace (W293)
def _fix_height_name(self):
'''
Fix variable name of coordinate 'height'

Check notice on line 43 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L43

trailing whitespace (W291)
'''
if self.cube.coord('height').var_name!='height':

Check notice on line 45 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L45

missing whitespace around operator (E225)
self.cube.coord('height').var_name='height'

Check notice on line 46 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L46

missing whitespace around operator (E225)

def _fix_long_name(self):
'''
Fix variable long_name
'''
self.cube.long_name ='Near-Surface Air Temperature'

Check notice on line 52 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L52

missing whitespace around operator (E225)

def _fix_var_name(self):
'''
Fix variable long_name
'''
self.cube.var_name='tas'

def fix_coord_system(self):
'''
delete coord_system to make it cna be merged with other cmip dataset by iris.CubeList.merge_dube

Check notice on line 62 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L62

line too long (104 > 79 characters) (E501)
'''
for dim in self.cube.dim_coords:
if dim.coord_system!=None:
self.cube.coord(dim.standard_name).coord_system=None

Check notice on line 66 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L66

missing whitespace around operator (E225)

def _load_master_map(self,short_name):
'''
Master map is a supplimentary file for how to convert access variable to cmip data

Parameters
----------
short_name : str
short name of variable.

Returns
-------
list which contain supplimentary imformation of the variable

'''
master_map_path=f'{self.current_dir}/master_map.csv'
with open (master_map_path,'r') as map:
reader=csv.reader(map, delimiter=',')

Check notice on line 84 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L84

missing whitespace around operator (E225)
for raw in reader:
if raw[0]==short_name:

Check notice on line 86 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L86

missing whitespace around operator (E225)
return raw

def fix_metadata(self, cubes):
"""

Check notice on line 90 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L90

No blank lines allowed after function docstring (found 1) (D202)
Fix name of coordinate(height), long name and variable name of variable(tas).

Check notice on line 91 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L91

line too long (85 > 79 characters) (E501)

Parameters
----------
cubes : iris.cube.CubeList
Input cubes.

Returns
-------
iris.cube.CubeList

"""

row=self._load_master_map(self.vardef.short_name)

Check notice on line 104 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L104

missing whitespace around operator (E225)

original_short_name=row[0]

self.cube= self.get_cube(cubes, var_name=original_short_name)

Check notice on line 108 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L108

missing whitespace around operator (E225)

self.fix_height_name()

self.fix_long_name()

self.fix_var_name()

self.fix_coord_system()

cube_checked= cmor_check(cube=self.cube,cmor_table='CMIP6',mip='Amon',short_name='tas',check_level=1)

Check notice on line 118 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L118

line too long (109 > 79 characters) (E501)

return CubeList([cube_checked])


class pr(NativeDatasetFix):

Check notice on line 123 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L123

class name 'pr' should use CapWords convention (N801)
'''
Fix variable(pr) only
'''

def __init__(self,vardef,
extra_facets,
session,
frequency):

Check notice on line 131 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L131

continuation line under-indented for visual indent (E128)
'''
Initialise some class variable
Heritage from native_dataset
'''

super().__init__(vardef,extra_facets,session,frequency)

self.cube=None

self.current_dir=os.path.dirname(__file__)


def fix_var_name(self):

Check notice on line 144 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L144

too many blank lines (2) (E303)
'''
Fix variable long_name
'''
self.cube.var_name='pr'

Check notice on line 148 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L148

missing whitespace around operator (E225)

def fix_long_name(self):
'''
Fix variable long_name
'''
self.cube.long_name ='Precipitation'

Check notice on line 154 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L154

missing whitespace around operator (E225)


def fix_coord_system(self):
'''
delete coord_system to make it cna be merged with other cmip dataset by iris.CubeList.merge_dube
'''
for dim in self.cube.dim_coords:
if dim.coord_system!=None:
self.cube.coord(dim.standard_name).coord_system=None

def _load_master_map(self,short_name):
'''
Master map is a supplimentary file for how to convert access variable to cmip data

Parameters
----------
short_name : str
short name of variable.

Returns
-------
list which contain supplimentary imformation of the variable

'''
master_map_path=f'{self.current_dir}/master_map.csv'
with open (master_map_path,'r') as map:
reader=csv.reader(map, delimiter=',')
for raw in reader:
if raw[0]==short_name:
return raw

def fix_metadata(self, cubes):
"""
Fix name of coordinate(height), long name and variable name of variable(tas).

Parameters
----------
cubes : iris.cube.CubeList
Input cubes.

Returns
-------
iris.cube.CubeList

"""

row=self._load_master_map(self.vardef.short_name)

original_short_name=row[1]

cube= self.get_cube(cubes, var_name=original_short_name)

self.fix_var_name()

self.fix_long_name()

self.fix_coord_system()

cube_checked= cmor_check(cube=cube,cmor_table='CMIP6',mip='Amon',short_name='pr',check_level=1)

Check notice on line 213 in esmvalcore/cmor/_fixes/access/access_esm.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

esmvalcore/cmor/_fixes/access/access_esm.py#L213

line too long (103 > 79 characters) (E501)

return CubeList([cube_checked])

Loading