Skip to content

Commit

Permalink
Merge pull request #166 from nsidc/nrt-improvement-for-ops
Browse files Browse the repository at this point in the history
Nrt improvement for ops
  • Loading branch information
trey-stafford authored Sep 27, 2024
2 parents 3c6aa6e + c4b341b commit cbc46d4
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions seaice_ecdr/cli/nrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import copy
import datetime as dt
from pathlib import Path
from typing import get_args
from typing import Literal, get_args

import click
from loguru import logger
from pm_tb_data._types import Hemisphere

from seaice_ecdr.cli.util import CLI_EXE_PATH, datetime_to_date, run_cmd
from seaice_ecdr.cli.util import CLI_EXE_PATH, run_cmd
from seaice_ecdr.constants import DEFAULT_BASE_NRT_OUTPUT_DIR
from seaice_ecdr.platforms.config import NRT_PLATFORM_START_DATES_CONFIG_FILEPATH

Expand All @@ -21,9 +22,11 @@
@click.option(
"-d",
"--date",
required=True,
"--start-date",
required=False,
default=None,
type=click.DateTime(formats=("%Y-%m-%d", "%Y%m%d", "%Y.%m.%d")),
callback=datetime_to_date,
callback=lambda _ctx, _param, value: value if value is None else value.date(),
)
@click.option(
"--end-date",
Expand All @@ -40,11 +43,18 @@
default=None,
help="If given, run temporal composite for `--date` through this end date.",
)
@click.option(
"--last-n-days",
required=False,
type=click.INT,
default=None,
help="If given, run temporal composite for the last n dates.",
)
@click.option(
"-h",
"--hemisphere",
required=True,
type=click.Choice(get_args(Hemisphere)),
type=click.Choice([*get_args(Hemisphere), "both"]),
)
@click.option(
"--base-output-dir",
Expand Down Expand Up @@ -72,22 +82,43 @@
)
def cli(
*,
date: dt.date,
date: dt.date | None,
end_date: dt.date | None,
hemisphere: Hemisphere,
last_n_days: int | None,
hemisphere: Hemisphere | Literal["both"],
base_output_dir: Path,
overwrite: bool,
):

if last_n_days and (date or end_date):
raise RuntimeError(
"`--last-n-days` is incompatible with `--date` and `--end-date`"
)

if last_n_days:
date = dt.date.today() - dt.timedelta(days=last_n_days)
# The end date should be the day before today. We only expect today's
# data to be available on the following day.
end_date = dt.date.today() - dt.timedelta(days=1)

if end_date is None:
end_date = copy.copy(date)

logger.info(f"Creating NRT data for {date} through {end_date}")

overwrite_str = " --overwrite" if overwrite else ""

run_cmd(
f"export PLATFORM_START_DATES_CONFIG_FILEPATH={NRT_PLATFORM_START_DATES_CONFIG_FILEPATH} &&"
f"{CLI_EXE_PATH} nrt"
f" --hemisphere {hemisphere}"
f" --base-output-dir {base_output_dir}"
f" --date {date:%Y-%m-%d}"
f" --end-date {end_date:%Y-%m-%d}" + overwrite_str
)
if hemisphere == "both":
hemispheres = ["north", "south"]
else:
hemispheres = [hemisphere]

for hemi in hemispheres:
run_cmd(
f"export PLATFORM_START_DATES_CONFIG_FILEPATH={NRT_PLATFORM_START_DATES_CONFIG_FILEPATH} &&"
f"{CLI_EXE_PATH} nrt"
f" --hemisphere {hemi}"
f" --base-output-dir {base_output_dir}"
f" --date {date:%Y-%m-%d}"
f" --end-date {end_date:%Y-%m-%d}" + overwrite_str
)

0 comments on commit cbc46d4

Please sign in to comment.