Skip to content

Commit

Permalink
Refactored toolkit so that download is top level (#30), and adjusted …
Browse files Browse the repository at this point in the history
…runs to use the new layout
  • Loading branch information
zachsa committed Apr 25, 2023
1 parent 46f3724 commit cb91734
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 82 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/run_algoa-bay-forecast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,12 @@ jobs:
-e COPERNICUS_USERNAME=${{ env.COPERNICUS_USERNAME }} \
-e COPERNICUS_PASSWORD=${{ env.COPERNICUS_PASSWORD }} \
${{ needs.toolkit.outputs.image }}:${{ env.SHA }} \
ops \
download \
--provider gfs \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 22,31,-37,-31
download \
--provider gfs \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 22,31,-37,-31
- name: Download Mercator
uses: nick-fields/retry@master
with:
Expand All @@ -272,13 +271,12 @@ jobs:
-e COPERNICUS_USERNAME=${{ env.COPERNICUS_USERNAME }} \
-e COPERNICUS_PASSWORD=${{ env.COPERNICUS_PASSWORD }} \
${{ needs.toolkit.outputs.image }}:${{ env.SHA }} \
ops \
download \
--provider mercator \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 22,31,-37,-31
download \
--provider mercator \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 22,31,-37,-31
# CROCOTOOLS is a collection of MatLab scripts for converting environmental data (i.e. the boundary data downloaded previously)
# into NetCDF files that can be used as input to the CROCO model. https://www.croco-ocean.org/documentation/crocotools-documentation/
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/run_false-bay-forecast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,12 @@ jobs:
-e COPERNICUS_USERNAME=${{ env.COPERNICUS_USERNAME }} \
-e COPERNICUS_PASSWORD=${{ env.COPERNICUS_PASSWORD }} \
${{ needs.toolkit.outputs.image }} \
ops \
download \
--provider gfs \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 15,24.5,-37,-31
download \
--provider gfs \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 15,24.5,-37,-31
- name: Download Mercator
uses: nick-fields/retry@master
with:
Expand All @@ -248,13 +247,12 @@ jobs:
-e COPERNICUS_USERNAME=${{ env.COPERNICUS_USERNAME }} \
-e COPERNICUS_PASSWORD=${{ env.COPERNICUS_PASSWORD }} \
${{ needs.toolkit.outputs.image }} \
ops \
download \
--provider mercator \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 15,24.5,-37,-31
download \
--provider mercator \
--workdir /tmp/somisana/current/forcing-inputs \
--matlab-env /tmp/somisana/current/.env \
--download-date ${{ env.MODEL_RUN_DATE }} \
--domain 15,24.5,-37,-31
# CROCOTOOLS is a collection of MatLab scripts for converting environmental data (i.e. the boundary data downloaded previously)
# into NetCDF files that can be used as input to the CROCO model. https://www.croco-ocean.org/documentation/crocotools-documentation/
Expand Down
6 changes: 6 additions & 0 deletions .vscode/.filedump
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

begin
f = addfile("/home/zach/code/saeon/repositories/somisana/toolkit/.output/mercator_20230425.nc","r")
print(f)
end

22 changes: 10 additions & 12 deletions toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,22 @@ cd $SOMISANA_DIR

```sh
somisana \
ops \
download \
--workdir $WORKDIR/forcing-inputs \
--matlab-env $WORKDIR/.env \
--provider gfs \
--domain 22,31,-37,-31
download \
--workdir $WORKDIR/forcing-inputs \
--matlab-env $WORKDIR/.env \
--provider gfs \
--domain 22,31,-37,-31
```

**_(3) Download Mercator boundary data_**

```sh
somisana \
ops \
download \
--workdir $WORKDIR/forcing-inputs \
--matlab-env $WORKDIR/.env \
--provider mercator \
--domain 22,31,-37,-31
download \
--workdir $WORKDIR/forcing-inputs \
--matlab-env $WORKDIR/.env \
--provider mercator \
--domain 22,31,-37,-31
```

**_(4) Create forcing files_**
Expand Down
5 changes: 4 additions & 1 deletion toolkit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def main():

# (1) Build applications
app_objects = {
"ops": (getattr(getattr(define, "ops"), "build")(module_parser), apps.ops),
"download": (
getattr(getattr(define, "download"), "build")(module_parser),
apps.download,
),
"mhw": (getattr(getattr(define, "mhw"), "build")(module_parser), apps.mhw),
"lacce": (
getattr(getattr(define, "lacce"), "build")(module_parser),
Expand Down
4 changes: 2 additions & 2 deletions toolkit/cli/applications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from cli.applications import lacce, mhw, ops, kerchunk, update, pg, croco
from cli.applications import lacce, mhw, kerchunk, update, pg, croco, download

__all__ = ["lacce", "mhw", "ops", "kerchunk", "update", "pg", "croco"]
__all__ = ["lacce", "mhw", "kerchunk", "update", "pg", "croco", "download"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from datetime import datetime, timedelta
from pathlib import Path
from cli.applications.ops.download.mercator import download as mercator_download
from cli.applications.ops.download.gfs import download as gfs_download
from cli.applications.download.mercator import download as mercator_download
from cli.applications.download.gfs import download as gfs_download


def download(args):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from datetime import datetime, timedelta, time
from cli.applications.ops.download.gfs.functions import (
from cli.applications.download.gfs.functions import (
download_file,
get_latest_available_dt,
set_params,
Expand Down
3 changes: 0 additions & 3 deletions toolkit/cli/applications/ops/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions toolkit/cli/define/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from cli.define import lacce, mhw, ops, kerchunk, update, pg, croco
from cli.define import lacce, mhw, download, kerchunk, update, pg, croco

__all__ = ["lacce", "mhw", "ops", "kerchunk", "update", "pg", "croco"]
__all__ = ["lacce", "mhw", "download", "kerchunk", "update", "pg", "croco"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,40 @@


def build(module_parser):
ops = module_parser.add_parser("ops", help="CROCO Operational Models module")
ops_parser = ops.add_subparsers(
title="Operational ocean forecasting",
description="Run localised, high resolution ocean forecasts using the CROCO modelling suite",
dest="ops_command",
metavar="Available commands",
download = module_parser.add_parser(
"download", help="Download boundary conditions and forcing files"
)

# DOWNLOAD
ops_download = ops_parser.add_parser(
"download", help="Download forcing input files"
)
ops_download.add_argument(
download.add_argument(
"--workdir", default=".output", help="Directory output of forcing files"
)
ops_download.add_argument(
download.add_argument(
"--matlab-env", default=".output/.env", help="Path to MatLab configuration file"
)
ops_download.add_argument(
download.add_argument(
"--download-date", default=NOW, help="Download date (yyyymmdd)"
)
ops_download.add_argument(
download.add_argument(
"--provider",
type=str,
choices=["gfs", "mercator"],
help="Forcing data provider",
required=True,
)
ops_download.add_argument(
download.add_argument(
"--hdays",
type=int,
default=5,
help="Hindcast download days",
)
ops_download.add_argument(
download.add_argument(
"--fdays",
type=int,
default=5,
help="Forecast download days",
)
ops_download.add_argument(
download.add_argument(
"--domain",
help="Bounding box in 4326 projection (i.e. min_long,max_long,min_lat,max_lat)",
required=True,
)
return ops
return download
4 changes: 2 additions & 2 deletions toolkit/cli/parse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from cli.parse import lacce, mhw, ops, kerchunk, update, pg, croco
from cli.parse import lacce, mhw, download, kerchunk, update, pg, croco

__all__ = ["lacce", "mhw", "ops", "kerchunk", "update", "pg", "croco"]
__all__ = ["lacce", "mhw", "download", "kerchunk", "update", "pg", "croco"]
10 changes: 10 additions & 0 deletions toolkit/cli/parse/download/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def parse(cmd, args, module):
def e(*args):
print(cmd.format_help())
exit()

try:
return module.download
except Exception as e:
print(e)
return e
10 changes: 0 additions & 10 deletions toolkit/cli/parse/ops/__init__.py

This file was deleted.

0 comments on commit cb91734

Please sign in to comment.