diff --git a/dachar/__init__.py b/dachar/__init__.py index 67b19fea..992e45ab 100644 --- a/dachar/__init__.py +++ b/dachar/__init__.py @@ -12,9 +12,11 @@ import dachar CONFIG = get_config(dachar) -from clisops import logging +# from clisops import logging +import logging from .fixes import * from .scan import * from .utils import * -from .analyse import * \ No newline at end of file +from .analyse import * +from .decadal import generate_decadal_fix \ No newline at end of file diff --git a/generate_decadal_fix.py b/dachar/decadal.py similarity index 96% rename from generate_decadal_fix.py rename to dachar/decadal.py index dd1820f8..e53a1aef 100755 --- a/generate_decadal_fix.py +++ b/dachar/decadal.py @@ -23,6 +23,8 @@ import xarray as xr from roocs_utils.project_utils import dsid_to_datapath +ETC_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'etc')) + def arg_parse(): @@ -171,12 +173,7 @@ def get_ds_ids(fpath): return ds_ids -def main(): - args = arg_parse() - - fpath = args.fpath - ds_id = args.dsid - +def generate_decadal_fix(fpath, ds_id): data_path = dsid_to_datapath(ds_id) # put into template @@ -184,8 +181,7 @@ def main(): dt["dataset_id"] = ds_id - pathname = os.path.dirname(sys.argv[0]) - if ds_id in get_ds_ids(os.path.join(pathname, "further_info_url-dsets.txt")): + if ds_id in get_ds_ids(os.path.join(ETC_DIR, "further_info_url-dsets.txt")): global_attrs = dt["fixes"][1].get("operands").get("attrs") global_attrs.update( further_info_url="derive: daops.fix_utils.decadal_utils.fix_further_info_url" @@ -196,6 +192,14 @@ def main(): with open(fpath, "w") as fp: json.dump(dt, fp, indent=4) +def main(): + args = arg_parse() + + fpath = args.fpath + ds_id = args.dsid + + generate_decadal_fix(fpath, ds_id) + if __name__ == "__main__": main() diff --git a/further_info_url-dsets.txt b/dachar/etc/further_info_url-dsets.txt similarity index 100% rename from further_info_url-dsets.txt rename to dachar/etc/further_info_url-dsets.txt diff --git a/environment.yml b/environment.yml index 3f24a839..eb022e3b 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,6 @@ name: dachar channels: - conda-forge - - defaults dependencies: - numpy>=1.16 - xarray>=0.15 diff --git a/notebooks/.gitignore b/notebooks/.gitignore new file mode 100644 index 00000000..537b153b --- /dev/null +++ b/notebooks/.gitignore @@ -0,0 +1 @@ +fixes diff --git a/notebooks/environment.yml b/notebooks/environment.yml new file mode 100644 index 00000000..ee34c6cb --- /dev/null +++ b/notebooks/environment.yml @@ -0,0 +1,10 @@ +# conda env update -f environment.yml +name: dachar +channels: + - conda-forge +dependencies: + - pip + - ipython + - jupyterlab + - ipywidgets + - nodejs diff --git a/notebooks/publish-cmip6-decadal-fixes.ipynb b/notebooks/publish-cmip6-decadal-fixes.ipynb new file mode 100644 index 00000000..83b18d8c --- /dev/null +++ b/notebooks/publish-cmip6-decadal-fixes.ipynb @@ -0,0 +1,78 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "2b2555ab-e3f2-492a-bda3-4688fca87528", + "metadata": {}, + "source": [ + "# Publish cmip6 decadal fixes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3aea8323-442f-4025-a2c6-600708d7cb92", + "metadata": {}, + "outputs": [], + "source": [ + "import dachar\n", + "import os" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46daa659-0510-4f77-8c37-1c8e1db87120", + "metadata": {}, + "outputs": [], + "source": [ + "FIX_DIR = \"./fixes/cmip6-decadal\"\n", + "if not os.path.exists(FIX_DIR):\n", + " os.makedirs(FIX_DIR)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35bf556f-1dbf-4200-8447-23013066df49", + "metadata": {}, + "outputs": [], + "source": [ + "DRS_ID = \"CMIP6.DCPP.MOHC.HadGEM3-GC31-MM.dcppA-hindcast.s2004-r3i1p1f2.Amon.pr.gn.v20200417\"\n", + "\n", + "FIX_PATH = f\"{FIX_DIR}/{DRS_ID}.json\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbb309d0-3d51-4c56-8b0c-092338fc831f", + "metadata": {}, + "outputs": [], + "source": [ + "dachar.generate_decadal_fix(FIX_PATH, DRS_ID)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}