From cee58e654c72badd8a62f97488211bc28fd38524 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Mon, 22 Jul 2024 12:47:48 -0600 Subject: [PATCH] Extract command line interface to top package level --- antarctica_today/__main__.py | 35 ++++++++++++++++++- antarctica_today/generate_daily_melt_file.py | 3 -- .../generate_gap_filled_melt_picklefile.py | 4 --- antarctica_today/melt_array_picklefile.py | 5 --- doc/operation.md | 30 +++++++++++++--- 5 files changed, 59 insertions(+), 18 deletions(-) diff --git a/antarctica_today/__main__.py b/antarctica_today/__main__.py index 0c29ec5..eaee86b 100644 --- a/antarctica_today/__main__.py +++ b/antarctica_today/__main__.py @@ -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 @@ -20,7 +25,7 @@ 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. @@ -28,6 +33,34 @@ def download_tb(start_date: str): 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. diff --git a/antarctica_today/generate_daily_melt_file.py b/antarctica_today/generate_daily_melt_file.py index 4c23bf8..51d82fd 100644 --- a/antarctica_today/generate_daily_melt_file.py +++ b/antarctica_today/generate_daily_melt_file.py @@ -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) diff --git a/antarctica_today/generate_gap_filled_melt_picklefile.py b/antarctica_today/generate_gap_filled_melt_picklefile.py index bbdeec4..673fca0 100644 --- a/antarctica_today/generate_gap_filled_melt_picklefile.py +++ b/antarctica_today/generate_gap_filled_melt_picklefile.py @@ -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() diff --git a/antarctica_today/melt_array_picklefile.py b/antarctica_today/melt_array_picklefile.py index b21595d..ba0a05e 100755 --- a/antarctica_today/melt_array_picklefile.py +++ b/antarctica_today/melt_array_picklefile.py @@ -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() diff --git a/doc/operation.md b/doc/operation.md index 273b14e..018cc2c 100644 --- a/doc/operation.md +++ b/doc/operation.md @@ -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 @@ -67,7 +77,17 @@ 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=. @@ -75,13 +95,13 @@ 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 @@ -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 ```