Skip to content
This repository was archived by the owner on Sep 21, 2025. It is now read-only.

Commit 63bde3f

Browse files
committed
solved comflict
1 parent d961b1b commit 63bde3f

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/mopper/mop_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,10 @@ def define_attrs(ctx):
11101110
ctx : click context
11111111
Includes obj dict with 'cmor' settings, exp attributes
11121112
"""
1113-
#var_log = logging.getLogger(ctx.obj['var_log'])
1114-
attrs = ctx.obj['attrs']
1113+
var_log = logging.getLogger(ctx.obj['var_log'])
1114+
attrs = ctx.obj['attrs'].copy()
11151115
notes = attrs.get('notes', '')
1116+
var_log.debug(f"in define_attrs, notes: {notes}")
11161117
# open file containing notes
11171118
fname = import_files('mopdata').joinpath('notes.yaml')
11181119
data = read_yaml(fname)['notes']
@@ -1125,7 +1126,8 @@ def define_attrs(ctx):
11251126
fval = ctx.obj[field]
11261127
for k,v in data[field].items():
11271128
if k == fval or (k[0] == '~' and k[1:] in fval):
1128-
notes += v
1129+
notes += f" {v} "
11291130
if notes != '':
1130-
attrs['notes'] = notes
1131+
attrs['notes'] = notes.strip()
1132+
var_log.debug(f"in define_attrs, attrs: {attrs}")
11311133
return attrs

tests/test_mop_utils.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import logging
2323
from pathlib import Path
2424

25-
from mopper.mop_utils import (check_timestamp, get_cmorname,)
25+
from mopper.mop_utils import (check_timestamp, get_cmorname,
26+
define_attrs)
2627

2728

2829
ctx = click.Context(click.Command('cmd'),
@@ -121,8 +122,25 @@ def test_get_cmorname(caplog):
121122
assert iname == 'longitude'
122123
assert jname == 'latitude'
123124
assert zname == 'plev3'
124-
# test generic axis alevel
125125
ctx.obj['axes'] = 'longitude latitude alevel time'
126126
with ctx:
127127
zname = get_cmorname('theta_model_level_number')
128128
assert zname == 'hybrid_height'
129+
130+
def test_define_attrs(caplog):
131+
global ctx
132+
caplog.set_level(logging.DEBUG, logger='varlog_1')
133+
ctx.obj['attrs'] = {'notes': "some existing note"}
134+
ctx.obj['variable_id'] = "ta"
135+
ctx.obj['calculation'] = "... plevinterp(var[0]) "
136+
with ctx:
137+
out = define_attrs()
138+
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"
139+
# repeating to make sure we are not using reference to ctx see issue #190
140+
with ctx:
141+
out = define_attrs()
142+
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"
143+
ctx.obj['attrs'] = {}
144+
with ctx:
145+
out = define_attrs()
146+
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 commit comments

Comments
 (0)