Skip to content

Commit

Permalink
minor adjustment to docs, conf files and code after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paolap committed Aug 22, 2024
1 parent 3cef828 commit a376cc2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ACDD_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ attrs:
parent: !!bool false
# CMOR will add a tracking_id if you want to define a prefix add here
tracking_id_prefix:
comment: "post-processed using ACCESS-MOPPeR v0.6.0 https://doi.org/10.5281/zenodo.10346216"
comment: "post-processed using ACCESS-MOPPeR v1.0.0 https://doi.org/10.5281/zenodo.10346216"
4 changes: 3 additions & 1 deletion CMIP6_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ cmor:
# walltime in "hh:mm:ss"
walltime: '8:00:00'
mode: cmip6
# conda_env: <custom-env-path>/bin/activate
conda_env: default

# Global attributes: these will be added to each files comment unwanted ones
# the labels CMIP6/ACDD indicates which ones are necessary to comply with respective standards
Expand Down Expand Up @@ -161,4 +163,4 @@ attrs:
#CMOR will add a tracking_id if you want to define a prefix add here
tracking_id_prefix:
Conventions: "CF-1.7 CMIP-6.2"
comment: "post-processed using ACCESS-MOPPeR v0.6.0 https://doi.org/10.5281/zenodo.10346216"
comment: "post-processed using ACCESS-MOPPeR v1.0.0 https://doi.org/10.5281/zenodo.10346216"
12 changes: 10 additions & 2 deletions docs/mopdb_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ A user that wants to create a mapping table for another AUS2200 simulation can u

Create a mapping file
---------------------
.. code-block::

This can be done by providing the model output path and a pattern to match or directly a varlist file

From output path:

.. code-block::
mopdb template -f <output-path> -m <string-to-match> -v <access-version>
From varlist file:

.. code-block::
mopdb template -f <varlist-out> -v <access-version>
This will create a map_<exp>.csv file using, if available, information from the mapping table.
Expand Down Expand Up @@ -110,20 +113,25 @@ The other groups of records require checking, as either the version or the frequ

Create an intake catalogue
--------------------------
.. code-block::

This represents an extra step on top of the mapping, so it can be start directly from an existing mapping or from scratch by providing the model ouptut path and a match.

From output path:

.. code-block::
mopdb intake -f <output-path> -m <string-to-match> -v <access-version> { -a <alias> }
From varlist file:

.. code-block::
mopdb intake -f <output-path> -fl <varlist-out> -v <access-version> { -a <alias> }
From mapping file:

.. code-block::
mopdb intake -f <output-path> -fl <mapping-out> -v <access-version> { -a <alias> }
NB the model output path is still needed even when passing an existing mapping or variable list.
Expand Down
9 changes: 8 additions & 1 deletion src/mopdata/update_db.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def update_map(conn, varid, ctable):
"""Read mappings for variable from map file and
update them in filelist
"""
keys = ['frequency','realm','timeshot','calculation', 'positive', 'resample']
keys = ['frequency','realm','timeshot','calculation',
'positive', 'resample']
keys2 = {'vin': 'input_vars', 'in_units': 'units'}
fname = f"maps/{ctable}.json"
with open(fname, 'r') as f:
Expand All @@ -48,6 +49,12 @@ def update_map(conn, varid, ctable):
args = {k: row[k] for k in keys}
for k,v in keys2.items():
args[k] = row[v]
if 'datadir' in row.keys():
paths = row['file_structure'].split()
infile = ''
for x in paths:
infile += f"{row['datadir']}/{x} "
args['infile'] = infile
cur = conn.cursor()
sql = f"UPDATE filelist SET"
for k,v in args.items():
Expand Down
11 changes: 8 additions & 3 deletions src/mopper/mop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,13 @@ def get_coords(ctx, ovar, coords):
var_log = logging.getLogger(ctx.obj['var_log'])
# open ancil grid file to read vertices
#PP be careful this is currently hardcoded which is not ok!
ancil_file = ctx.obj[f"grid_{ctx.obj['realm']}"]
ancil_dir = ctx.obj.get('ancils_path', '')
ancil_file = ancil_dir + "/" + ctx.obj.get(f"grid_{ctx.obj['realm']}", '')
if ancil_file == '' or not Path(ancil_file).exists():
var_log.error(f"Ancil file {ancil_file} not set or inexistent")
sys.exit()
var_log.debug(f"getting lat/lon and bnds from ancil file: {ancil_file}")
ds = xr.open_dataset(f"{ctx.obj['ancils_path']}/{ancil_file}")
ds = xr.open_dataset(ancil_file)
var_log.debug(f"ancil ds: {ds}")
# read lat/lon and vertices mapping
cfile = import_files('mopdata').joinpath('latlon_vertices.yaml')
Expand Down Expand Up @@ -793,8 +797,9 @@ def get_bounds_values(ctx, ds, bname):
calc = False
var_log = logging.getLogger(ctx.obj['var_log'])
var_log.debug(f"Getting bounds values for {bname}")
ancil_file = ctx.obj[f"grid_{ctx.obj['realm']}"]
ancil_file = ctx.obj.get(f"grid_{ctx.obj['realm']}", '')
if bname in ds.variables:
var_log.debug(f"Bounds for {bname} in file")
bnds_val = ds[bname].values
elif ancil_file != "":
fname = f"{ctx.obj['ancils_path']}/{ancil_file}"
Expand Down

0 comments on commit a376cc2

Please sign in to comment.