Skip to content

Commit

Permalink
Extract command line interface to top package level
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Jul 22, 2024
1 parent df96b6c commit cee58e6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
35 changes: 34 additions & 1 deletion antarctica_today/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import click

from antarctica_today.generate_daily_melt_file import generate_new_daily_melt_files
from antarctica_today.generate_gap_filled_melt_picklefile import (
save_gap_filled_picklefile,
)
from antarctica_today.main import (
generate_all_plots_and_maps_main,
preprocessing_main,
)
from antarctica_today.melt_array_picklefile import save_model_array_picklefile
from antarctica_today.nsidc_download_Tb_data import download_new_files


Expand All @@ -20,14 +25,42 @@ def cli():
)
@cli.command()
def download_tb(start_date: str):
"""Download NSIDC-0080 granules.
"""Download NSIDC-0080 brightness temperature granules.
The default start date is the day after the end of the .bin data available in
`/data/daily_melt_bin_files/` directory in this repo.
"""
download_new_files(time_start=start_date)


@click.option(
"--start-date",
# TODO: Is this default right? The actual function we're calling has a default of
# 2021-10-01. Why?
default="2022-01-10",
help="TODO",
)
@cli.command()
def generate_daily_melt(start_date: str):
"""Generate daily melt file from brightness temperature granules."""
generate_new_daily_melt_files(
start_date=start_date,
overwrite=False,
)


@cli.command
def melt_array_picklefile():
"""Is this needed operationally?"""
save_model_array_picklefile()


@cli.command
def gap_filled_melt_picklefile():
"""Is this needed operationally?"""
save_gap_filled_picklefile()


@cli.command()
def preprocess():
"""Perform pre-processing steps for Antarctica Today data.
Expand Down
3 changes: 0 additions & 3 deletions antarctica_today/generate_daily_melt_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,3 @@ def create_daily_melt_array(
# output_gtif_filename=gtif_name,
# verbose=args.verbose,
# )

if __name__ == "__main__":
generate_new_daily_melt_files(overwrite=False)
4 changes: 0 additions & 4 deletions antarctica_today/generate_gap_filled_melt_picklefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,3 @@ def fill_melt_array_with_interpolations(array=None, datetimes_dict=None, verbose
# print("\t", "Day missing, fill with mean. Average:", numpy.sum(day_slice[day_slice!=-1]))

return gap_filled_array, gap_filled_dt_dict


if __name__ == "__main__":
save_gap_filled_picklefile()
5 changes: 0 additions & 5 deletions antarctica_today/melt_array_picklefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,3 @@ def read_gap_filled_melt_picklefile(
f.close()

return array, dt_dict


if __name__ == "__main__":
# Let's save the v2.5 data from Tom's stuff.
array, dt_dict = save_model_array_picklefile()
30 changes: 25 additions & 5 deletions doc/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ python antarctica_today download-tb

```bash
PYTHONPATH=.
python antarctica_today/generate_daily_melt_file.py
python antarctica_today generate-daily-melt
```

> [!WARNING]
> I receive a large number of warnings like:
>
> ```
> UserWarning: Warning: At least one NSIDC Tb file on date '20230909' is missing. Skipping
> that date.
> ```
>
> Why?
> [!NOTE]
> Binaries provided in `data/daily_melt_bin_files` are already calibrated by Tom Mote
> for pre-2016 dates. This generates new daily melt files from the NSIDC-0080 data
Expand All @@ -67,21 +77,31 @@ python antarctica_today/generate_daily_melt_file.py

## 3. Generate the database

This software manages a database covering the full climatology in the form of a pickle file.
This software manages a database covering the full climatology in the form of a pickle
file.

> [!NOTE]
> This command may take up to tens of minutes.
>
> 🛠️ _TODO_
>
> - [ ] What does this command do? Create the pickle?
> - [ ] Why is the next section called "Initializing"? Are there multiple pickle files?
> Does each command initialize one? Can we combine them all into one command?
```bash
PYTHONPATH=.
python antarctica_today preprocess
```


### Initializing
### Database initialization (?)

Create the melt array picklefile, a file containing a 2d grid for each day:

```bash
PYTHONPATH=.
python antarctica_today/melt_array_picklefile.py
python antarctica_today melt-array-picklefile
```

Create a gap-filled melt picklefile, This "fills the gaps" of missing data or missing
Expand All @@ -92,7 +112,7 @@ melt ever reaches South Pole.)

```bash
PYTHONPATH=.
python antarctica_today/generate_gap_filled_melt_picklefile.py
python antarctica_today gap-filled-melt-picklefile
```


Expand Down

0 comments on commit cee58e6

Please sign in to comment.