Skip to content

Commit

Permalink
Merge pull request #192 from ACCESS-Community-Hub/issue190
Browse files Browse the repository at this point in the history
Issue190
  • Loading branch information
paolap authored Oct 30, 2024
2 parents 6873c75 + aa470e8 commit b70c614
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mopper-conda-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
conda_deployment_with_new_tag:
name: Test conda deployment of package with Python ${{ matrix.python-version }}
name: Deploy conda package with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
9 changes: 6 additions & 3 deletions ACDD_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ cmor:
# use this to indicate the path used for new or modified tables
# these will be used in preference to the package tables
tables_path: ""
# ancillary files path
# when running model with payu ancil files are copied to work/<realm>/INPUT
# you can leave these empty if processing only atmos
# Ancil files are needed only for specific variables when
# grid information is not fully available from output
# you can usually leave these empty if processing only atmos
# ancillary files relative path to <appdir> or fullpath
ancils_path: "localdata/ancils"
grid_ocean: ""
grid_ice: ""
mask_ocean: ""
# to supply land area fraction if not available in output
land_frac: ""
# to supply tile area fraction if not available in output
tile_frac: ""
# defines Controlled Vocabularies and required attributes
# leave ACDD to follow NCI publishing requirements
Expand Down
15 changes: 10 additions & 5 deletions CMIP6_conf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
################################################################
# USER OPTIONS
# Settings to manage cmorisation and set tables/variables to process
# This config file is to produce files to submit to CMIP6 project
# It's more restrictive than ACDD_conf.yaml
cmor:
# If test true it will just run the setup but not launch the job automatically
test: false
Expand Down Expand Up @@ -62,14 +64,17 @@ cmor:
# as you should use official CMOR cmip6 tables for CMIP6 mode
# use this only if current package version is obsolete
tables_path: ""
# ancillary files path
# when running model with payu ancil files are copied to work/<realm>/INPUT
# you can leave these empty if processing only atmos
ancils_path: "data/ancils"
# Ancil files are needed only for specific variables when
# grid information is not fully available from output
# you can usually leave these empty if processing only atmos
# ancillary files relative path to <appdir> or fullpath
ancils_path: "localdata/ancils"
grid_ocean: ""
mask_ocean: ""
grid_ice: ""
mask_ocean: ""
# to supply land area fraction if not available in output
land_frac: ""
# to supply tile area fraction if not available in output
tile_frac: ""
history_data: ''
# DO NOT REMOVE OR ALTER this if you don't know what you're doing :-)
Expand Down
9 changes: 4 additions & 5 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package:
name: mopper
#version: "{{ environ.get('GIT_DESCRIBE_TAG', '1.0') }}"
#version: "{{ environ.get('GIT_DESCRIBE_TAG', '1.1.0') }}"
version: '1.1.0'
#source:
# path: ./
# path: ../.

source:
#url: https://github.com/ACCESS-Hive/ACCESS-MOPPeR/archive/refs/tags/{{version}}.tar.gz
#url: https://github.com/ACCESS-Hive/ACCESS-MOPPeR/archive/refs/tags/{{ environ.get('RELEASE_VERSION') }}.tar.gz
git_url: https://github.com/ACCESS-Hive/ACCESS-MOPPeR.git
git_tag: prerelease
git_tag: "1.1.0"
#git_rev: "1.1.0"
#git_depth: 1 # (Defaults to -1/not shallow)
#path: ../.

build:
number: 1
Expand Down
10 changes: 6 additions & 4 deletions src/mopper/mop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,10 @@ def define_attrs(ctx):
ctx : click context
Includes obj dict with 'cmor' settings, exp attributes
"""
#var_log = logging.getLogger(ctx.obj['var_log'])
attrs = ctx.obj['attrs']
var_log = logging.getLogger(ctx.obj['var_log'])
attrs = ctx.obj['attrs'].copy()
notes = attrs.get('notes', '')
var_log.debug(f"in define_attrs, notes: {notes}")
# open file containing notes
fname = import_files('mopdata').joinpath('notes.yaml')
data = read_yaml(fname)['notes']
Expand All @@ -1125,7 +1126,8 @@ def define_attrs(ctx):
fval = ctx.obj[field]
for k,v in data[field].items():
if k == fval or (k[0] == '~' and k[1:] in fval):
notes += v
notes += f" {v} "
if notes != '':
attrs['notes'] = notes
attrs['notes'] = notes.strip()
var_log.debug(f"in define_attrs, attrs: {attrs}")
return attrs
22 changes: 20 additions & 2 deletions tests/test_mop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import logging
from pathlib import Path

from mopper.mop_utils import (check_timestamp, get_cmorname,)
from mopper.mop_utils import (check_timestamp, get_cmorname,
define_attrs)


ctx = click.Context(click.Command('cmd'),
Expand Down Expand Up @@ -121,8 +122,25 @@ def test_get_cmorname(caplog):
assert iname == 'longitude'
assert jname == 'latitude'
assert zname == 'plev3'
# test generic axis alevel
ctx.obj['axes'] = 'longitude latitude alevel time'
with ctx:
zname = get_cmorname('theta_model_level_number')
assert zname == 'hybrid_height'

def test_define_attrs(caplog):
global ctx
caplog.set_level(logging.DEBUG, logger='varlog_1')
ctx.obj['attrs'] = {'notes': "some existing note"}
ctx.obj['variable_id'] = "ta"
ctx.obj['calculation'] = "... plevinterp(var[0]) "
with ctx:
out = define_attrs()
assert out['notes'] == "some existing note Linearly interpolated from model levels using numpy.interp() function. NaNs are assigned to pressure levels falling out of the height range covered by the model"
# repeating to make sure we are not using reference to ctx see issue #190
with ctx:
out = define_attrs()
assert out['notes'] == "some existing note Linearly interpolated from model levels using numpy.interp() function. NaNs are assigned to pressure levels falling out of the height range covered by the model"
ctx.obj['attrs'] = {}
with ctx:
out = define_attrs()
assert out['notes'] == "Linearly interpolated from model levels using numpy.interp() function. NaNs are assigned to pressure levels falling out of the height range covered by the model"

0 comments on commit b70c614

Please sign in to comment.