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

let fre cmor run process tripolar ocean data #303

Merged
merged 50 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6dce8ef
add in cmip6-cmor-tables as a submodule, remove un-maintained gitpyth…
ilaflott Dec 24, 2024
f59bd87
i guess .gitmodules isnt meant to be edited by hand!
ilaflott Dec 24, 2024
1168d5d
Revert "i guess .gitmodules isnt meant to be edited by hand!"
ilaflott Dec 24, 2024
a197538
actually add the submodule...
ilaflott Dec 24, 2024
ff8d8ce
restore deps with the exception of the pip-installed gitpython and le…
ilaflott Dec 24, 2024
32abb9b
syntax error
ilaflott Dec 24, 2024
ac61693
whitespace-cleanup some files for lint complaints, poke the test file…
ilaflott Dec 24, 2024
91a0fbc
add pyproject.toml to suppress pip warning.
ilaflott Jan 3, 2025
176ea9d
Merge branch 'main' into 298-cmor-process-ocean-tripolar-grid
ilaflott Jan 3, 2025
cec2a12
trying to get a fre make test's output out of the way, getting surpri…
ilaflott Jan 3, 2025
e5daf46
Update meta.yaml
ilaflott Jan 3, 2025
0c0b45d
Merge branch 'main' into 298-cmor-process-ocean-tripolar-grid
ilaflott Jan 6, 2025
fe0a656
remove a sys.exit or two. restore os.environ[HOME] back to what it wa…
ilaflott Jan 6, 2025
9122ef3
Merge branch '298-cmor-process-ocean-tripolar-grid' of https://github…
ilaflott Jan 6, 2025
3260539
oops
ilaflott Jan 6, 2025
50498e2
update click scaffolding to be much more lean and mean. approach cour…
ilaflott Jan 6, 2025
c92e4e8
removing now-redundant click-scaffoldding from fre app, fre check, fr…
ilaflott Jan 6, 2025
58c83c1
fix an oops, apply same approach to fre/catalog
ilaflott Jan 6, 2025
3e0096e
apply click-redundancy-removal logic to fre make
ilaflott Jan 6, 2025
19bc7a1
Revert "fix an oops, apply same approach to fre/catalog"
ilaflott Jan 6, 2025
aef76ee
remove needless shebang, put fre catalog click scaffolding back where…
ilaflott Jan 6, 2025
e03e098
fix the silly colon-oops in fre.pp again
ilaflott Jan 6, 2025
e832807
fix another syntax oops. change sys.exit to return
ilaflott Jan 6, 2025
1a01de9
more getting tests etc to clean up after themselves
ilaflott Jan 6, 2025
ada0dc7
#no more shebangs! (getit?)
ilaflott Jan 6, 2025
ab2708e
edits addressing pylint complains about no value for arguments in calls
ilaflott Jan 6, 2025
bc4a39b
further edits addressing pylint complains about no value for argument…
ilaflott Jan 6, 2025
67b67ee
notimplementederrors raised on functions not-yet-used. uncomment the …
ilaflott Jan 6, 2025
a074922
remove useless __init__ files in test directories. more pylint edits.
ilaflott Jan 6, 2025
fb62498
why last failure? unconvinced. fail again, conda_build, i dare you.
ilaflott Jan 7, 2025
21e22b4
adjust import statement in fre/cmor/tests
ilaflott Jan 7, 2025
54e02e3
carefully tidy print statements, carefully changing order of certain …
ilaflott Jan 7, 2025
d6013a6
new cmor_helpers file holds helper functions
ilaflott Jan 9, 2025
5911351
SO CLOSE
ilaflott Jan 9, 2025
dfe9ccb
pretty sure i got it!
ilaflott Jan 9, 2025
6d788b1
remove scratchwork script.
ilaflott Jan 9, 2025
8a3816e
Merge branch 'main' into 298-cmor-process-ocean-tripolar-grid
ilaflott Jan 9, 2025
baf61dc
lets just make run_test_file_cases a bunch of xfail pytests with a *p…
ilaflott Jan 13, 2025
8a71625
Merge branch 'main' into 298-cmor-process-ocean-tripolar-grid
ilaflott Jan 13, 2025
da8b4d3
ok got a format and a conditional pytest.xfail approach i am OK with.…
ilaflott Jan 13, 2025
5d7f77d
cleaner tests, all should xfail appropriately in the CI/CD
ilaflott Jan 13, 2025
1c987da
pylint things. rename cmor_lister to cmor_finder to avoid clash with …
ilaflott Jan 13, 2025
aa6c612
fix an oops in the fre cmor cli tests. tweak pytest.ini trivially
ilaflott Jan 13, 2025
fd73c43
update workflow file to upload the coverage xml for inspection. chang…
ilaflott Jan 13, 2025
c428716
why no coverage badge?? smh..
ilaflott Jan 13, 2025
dd21a0c
put coveragerc and pytest.ini back to what they were... sorry for tou…
ilaflott Jan 13, 2025
2d6730e
add */tests/__init__.py files back in... blegh
ilaflott Jan 13, 2025
be4af5c
another testing init file
ilaflott Jan 13, 2025
1923e6d
adjust pytest calls in workflows to use coverage to call pytest as mo…
ilaflott Jan 13, 2025
41a99f2
whitespace newlines and fstrings thanks pylint you great friend
ilaflott Jan 13, 2025
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
10 changes: 9 additions & 1 deletion .github/workflows/build_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ jobs:
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Add mkmf to PATH

- name: Add mkmf to GITHUB_PATH
run: |
# add mkmf to GITHUB_PATH
echo $PWD/mkmf/bin >> $GITHUB_PATH

- name: Run Conda to Build
run: |
# append the reqd channels
conda config --append channels conda-forge
conda config --append channels noaa-gfdl

# install conda-build and conda-verify
conda install conda-build conda-verify

# conda build
conda build .
29 changes: 20 additions & 9 deletions .github/workflows/create_test_conda_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
submodules: 'recursive'
- name: Create fre-cli environment
run: |
# create environment containing all dependencies
# the env cannot be explicitly activated in github CI/CD
# create env holding all deps, the env cant be explicitly activated in CI/CD
conda env create -f environment.yml --name fre-cli

# sets CONDA to wherever it may be on the image
Expand All @@ -24,36 +23,48 @@ jobs:
echo $CONDA/envs/fre-cli/bin >> $GITHUB_PATH
echo $PWD/mkmf/bin >> $GITHUB_PATH

# use *conda environment's pip* to install fre-cli
# called w/ full path to conda's python for explicitness
# called as a module (-m pip) for explicitness
# use *conda environment's pip* to install fre-cli, called w/ full path as module for explicitness
$CONDA/envs/fre-cli/bin/python -m pip install --prefix $CONDA/envs/fre-cli .

- name: Run pytest in fre-cli environment
run: |
# add spack installed binaries to front of path so that
# conda's netcdf/hdf5 installs don't break compilation tests
# add spack installed binaries to front of path so that conda's netcdf/hdf5 installs don't break compilation tests
export path_save=$PATH
export PATH="/opt/views/view/bin:$PATH"

# run pytest
pytest --junit-xml=pytest_results.xml --config-file=fre/pytest.ini --cov-config=fre/coveragerc --cov-report=xml --cov=fre fre/
coverage run -m pytest --junit-xml=pytest_results.xml --config-file=fre/pytest.ini --cov-config=fre/coveragerc --cov-report=xml --cov=fre fre/

# restore original path and install genbadge to generate coverage badge based on xml
export PATH="$path_save"

# install genbadge to make badge from coverage/test stats
pip install genbadge

# genbadge coverage
genbadge coverage -v -i coverage.xml -o docs/cov_badge.svg

# genbadge tests
genbadge tests -v -i pytest_results.xml -o docs/pytest_badge.svg

- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage.xml

- name: Run pylint in fre-cli environment
run: |
# run pylint, ignored modules avoid warnings arising from code internal to those modules
pylint --max-args 6 -ry --ignored-modules netCDF4,cmor fre/ || echo "pylint returned non-zero exit code. preventing workflow from dying with this echo."
pylint --max-line-length 120 --max-args 6 -ry --ignored-modules netCDF4,cmor fre/ || echo "pylint returned non-zero exit code. preventing workflow from dying with this echo."

- name: Install Sphinx and Build Documentation
run: |
# pip install sphinx and themes, upgrade theme
pip install sphinx renku-sphinx-theme sphinx-rtd-theme
pip install --upgrade sphinx-rtd-theme

# have sphinx build the docs
sphinx-apidoc --output-dir docs fre/ --separate
sphinx-build docs build

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "fre/gfdl_msd_schemas"]
path = fre/gfdl_msd_schemas
url = https://github.com/NOAA-GFDL/gfdl_msd_schemas
[submodule "fre/tests/test_files/cmip6-cmor-tables"]
path = fre/tests/test_files/cmip6-cmor-tables
url = https://github.com/pcmdi/cmip6-cmor-tables
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ To be developed:
- [x] **fre pp**
- [ ] **fre run**
- [ ] **fre test**
- [ ] **fre yamltools**
- [x] **fre yamltools**
7 changes: 2 additions & 5 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: fre-cli
channels:
- defaults
- conda-forge
- noaa-gfdl
dependencies:
- python
- python>=3.9.0
- pip
- click
- pyyaml
Expand All @@ -17,11 +16,9 @@ dependencies:
- conda-forge::cylc-flow>=8.2.0
- conda-forge::cylc-rose
- conda-forge::metomi-rose
- conda-forge::cmor
- conda-forge::cmor>=3.9.0
- conda-forge::cylc-uiserver
- conda-forge::pytest
- conda-forge::pytest-cov
- conda-forge::python-cdo
- conda-forge::cdo>=2.0.0
- pip:
- GitPython
10 changes: 8 additions & 2 deletions fre/analysis/freanalysis.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from analysis_scripts import available_plugins
''' fre analysis '''

# a third party package
import click

## a diff gfdl package
#from analysis_scripts import available_plugins

# this package
from .subtools import install_analysis_package, list_plugins, run_analysis, \
uninstall_analysis_package


@click.group(help=click.style(" - access fre analysis subcommands", fg=(250, 154, 90)))
def analysis_cli():
"""Entry point to fre analysis click commands."""
pass



@analysis_cli.command()
Expand Down
28 changes: 10 additions & 18 deletions fre/app/freapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
''' fre app calls '''

import time
Expand All @@ -7,7 +6,7 @@

from .mask_atmos_plevel import mask_atmos_plevel_subtool
from .generate_time_averages.generate_time_averages import generate
from .regrid_xy.regrid_xy import _regrid_xy
from .regrid_xy.regrid_xy import regrid_xy

@click.group(help=click.style(" - access fre app subcommands", fg=(250,154,90)))
def app_cli():
Expand Down Expand Up @@ -54,13 +53,11 @@ def app_cli():
help = "`defaultxyInterp` / `def_xy_interp` (env var) default lat/lon resolution " + \
"for output regridding. (change me? TODO)",
required = True)
@click.pass_context
def regrid(context,
input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp ):
# pylint: disable=unused-argument
def regrid( input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp ):
''' regrid target netcdf file '''
context.forward(_regrid_xy)
regrid_xy( input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp )

@app_cli.command()
@click.option("-i", "--infile",
Expand All @@ -74,11 +71,9 @@ def regrid(context,
@click.option("-p", "--psfile", # surface pressure... ps? TODO
help = "Input NetCDF file containing surface pressure (ps)",
required = True)
@click.pass_context
def mask_atmos_plevel(context, infile, outfile, psfile):
# pylint: disable = unused-argument
def mask_atmos_plevel(infile, outfile, psfile):
"""Mask out pressure level diagnostic output below land surface"""
context.forward(mask_atmos_plevel_subtool)
mask_atmos_plevel_subtool(infile, outfile, psfile)


@app_cli.command()
Expand Down Expand Up @@ -112,17 +107,14 @@ def mask_atmos_plevel(context, infile, outfile, psfile):
type = click.Choice(["samp","pop","samp_mean","pop_mean"]),
default = "samp",
help = "Compute standard deviations for time-averages as well")
@click.pass_context
def gen_time_averages(context, inf, outf, pkg, var, unwgt, avg_type, stddev_type):
# pylint: disable = unused-argument
def gen_time_averages(inf, outf, pkg, var, unwgt, avg_type, stddev_type):
"""
generate time averages for specified set of netCDF files.
Example: generate-time-averages.py /path/to/your/files/
"""
start_time = time.perf_counter()
context.forward(generate)
# need to change to a click.echo, not sure if echo supports f strings
print(f'Finished in total time {round(time.perf_counter() - start_time , 2)} second(s)')
generate(inf, outf, pkg, var, unwgt, avg_type, stddev_type)
click.echo(f'Finished in total time {round(time.perf_counter() - start_time , 2)} second(s)')

if __name__ == "__main__":
app_cli()
2 changes: 1 addition & 1 deletion fre/app/generate_time_averages/cdoTimeAverager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def generate_timavg(self, infile=None, outfile=None):

if self.var is not None:
print(f'WARNING: variable specification (var={self.var})' + \
f' not currently supported for cdo time averaging. ignoring!')
' not currently supported for cdo time averaging. ignoring!')

import cdo
print(f'python-cdo version is {cdo.__version__}')
Expand Down
2 changes: 1 addition & 1 deletion fre/app/generate_time_averages/frenctoolsTimeAverager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate_timavg(self, infile=None, outfile=None):

if self.var is not None:
print(f'WARNING: variable specification (var={self.var})' + \
f' not currently supported for frenctols time averaging. ignoring!')
' not currently supported for frenctols time averaging. ignoring!')

if infile is None:
print('ERROR: I need an input file, specify a value for the infile argument')
Expand Down
2 changes: 0 additions & 2 deletions fre/app/generate_time_averages/generate_time_averages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
''' tools for generating time averages from various packages '''
import click

def generate_time_average(infile=None, outfile=None,
pkg=None, var=None,
Expand Down Expand Up @@ -42,7 +41,6 @@ def generate_time_average(infile=None, outfile=None,

return exitstatus

@click.command()
def generate(inf, outf, pkg, var, unwgt, avg_type, stddev_type):
''' click entrypoint to time averaging routine '''
exitstatus=generate_time_average( inf, outf,
Expand Down
4 changes: 1 addition & 3 deletions fre/app/mask_atmos_plevel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
'''
This script contains the refineDiags that produce data at the same
frequency as the input data (no reduction) such as surface albedo,
Expand All @@ -10,9 +9,8 @@
import os
import netCDF4 as nc
import xarray as xr
import click

@click.command()

def mask_atmos_plevel_subtool(infile, outfile, psfile):
''' click entry point to fre cmor mask-atmos-plevel'''

Expand Down
12 changes: 1 addition & 11 deletions fre/app/regrid_xy/regrid_xy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#3rd party
import metomi.rose.config as rose_cfg
from netCDF4 import Dataset
import click


FREGRID_SHARED_FILES='/home/fms/shared_fregrid_remap_files'

Expand Down Expand Up @@ -465,16 +465,6 @@ def regrid_xy(input_dir = None, output_dir = None, begin = None, tmp_dir = None,
return 0


@click.command()
def _regrid_xy( input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp ):
""" click entrypoint """
click.echo(f'(_regrid_xy) locals={locals()}')
click.echo( '(_regrid_xy) click entrypoint hit- calling regrid_xy()')
return regrid_xy( input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp )


def main():
"""steering, local test/debug"""
return regrid_xy()
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions fre/app/regrid_xy/tests/test_regrid_xy.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_success_tar_grid_spec_regrid_xy(capfd):
rose_app_run_config.write( f'outputGridLat={NLAT}\n' )
rose_app_run_config.write( '\n' )
assert Path('./rose-app-run.conf').exists()

rgxy_returncode = rgxy.regrid_xy(
input_dir = WORK_YYYYMMDD_DIR,
output_dir = TEST_OUT_DIR,
Expand Down Expand Up @@ -431,7 +431,7 @@ def test_failure_wrong_datetime_regrid_xy(capfd):
rose_app_run_config.write( f'outputGridLat={NLAT}\n' )
rose_app_run_config.write( '\n' )
assert Path('./rose-app-run.conf').exists()

try:
rgxy_returncode = rgxy.regrid_xy(
input_dir = WORK_YYYYMMDD_DIR,
Expand Down
1 change: 1 addition & 0 deletions fre/catalog/frecatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'''

import click

#import catalogbuilder
from catalogbuilder.scripts import gen_intake_gfdl
from catalogbuilder.scripts import test_catalog
Expand Down
1 change: 0 additions & 1 deletion fre/catalog/tests/test_fre_catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3

def test_fre_catalog_import():
from fre import catalog
Expand Down
9 changes: 4 additions & 5 deletions fre/check/frecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@

from .frecheckexample import check_test_function

@click.group(help=click.style(" - access fre check subcommands", fg=(162,91,232)))
@click.group(help=click.style(" - access fre check subcommands (not implemented yet!)", fg=(162,91,232)))
def check_cli():
''' entry point to fre check click commands '''

@check_cli.command()
@click.option('--uppercase', '-u', is_flag=True, help = 'Print statement in uppercase.')
@click.pass_context
def function(context, uppercase):
# pylint: disable=unused-argument
def function(uppercase):
""" - Execute fre check test """
context.forward(check_test_function)
check_test_function(uppercase)
raise NotImplementedError('fre check has not been implemented yet!')

if __name__ == "__main__":
check_cli()
5 changes: 1 addition & 4 deletions fre/check/frecheckexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
NOAA | GFDL
"""

import click

@click.command()
def check_test_function(uppercase=None):
"""Execute fre list testfunction2."""
statement = "testingtestingtestingtesting"
if uppercase:
statement = statement.upper()
click.echo(statement)
print(statement)

if __name__ == '__main__':
check_test_function()
2 changes: 1 addition & 1 deletion fre/cmor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
''' for fre.cmor imports '''
from .cmor_mixer import cmor_run_subtool
from .cmor_lister import cmor_list_subtool
from .cmor_finder import cmor_find_subtool
Loading
Loading