Skip to content

Commit

Permalink
Merge pull request #202 from zmoon/cli
Browse files Browse the repository at this point in the history
CLI: initial save/read paired dataset support for `melodies-monet run`
  • Loading branch information
zmoon authored Nov 15, 2023
2 parents 8d2c6f2 + b588ebe commit ed57dab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,33 @@ jobs:
done
cd -
- name: Prepare idealized save/read cases
shell: python
run: |
from copy import deepcopy
import yaml
with open('docs/examples/control_idealized.yaml') as f:
ctl = yaml.safe_load(f)
assert {'save', 'read'} < ctl['analysis'].keys()
ctl_save = deepcopy(ctl)
del ctl_save['analysis']['read']
with open('docs/examples/control_idealized_save.yaml', 'w') as f:
yaml.safe_dump(ctl_save, f)
ctl_read = deepcopy(ctl)
del ctl_read['analysis']['save']
with open('docs/examples/control_idealized_read.yaml', 'w') as f:
yaml.safe_dump(ctl_read, f)
- name: Check CLI works
run: |
cd docs/examples
melodies-monet --version
python -m melodies_monet --version
melodies-monet run control_idealized.yaml
melodies-monet run control_idealized_save.yaml
melodies-monet run control_idealized_read.yaml
cd -
docs:
Expand Down
9 changes: 8 additions & 1 deletion melodies_monet/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ def run(
an.open_obs()

with _timer("Pairing"):
an.pair_data()
if an.read is not None:
an.read_analysis()
else:
an.pair_data()

if an.save is not None:
with _timer("Saving paired datasets"):
an.save_analysis()

if an.control_dict.get("plots") is not None:
with _timer("Plotting and saving the figures"), _ignore_pandas_numeric_only_futurewarning():
Expand Down
4 changes: 2 additions & 2 deletions melodies_monet/util/read_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def read_analysis_ncf(filenames,xr_kws={}):
import xarray as xr

if len(filenames)==1:
print('Reading: ', filenames[0])
print('Reading:', filenames[0])
ds_out = xr.open_dataset(filenames[0],**xr_kws)

elif len(filenames)>1:
for count, file in enumerate(filenames):
print('Reading: ', file)
print('Reading:', file)

if count==0:
ds_out = xr.open_dataset(file,**xr_kws)
Expand Down

0 comments on commit ed57dab

Please sign in to comment.