Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2 #40

Draft
wants to merge 81 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7210ee8
Add first pass at an environment specification
mfisher87 Sep 28, 2023
d6425a6
Remove DATA_VERSION conditionals
mfisher87 Sep 28, 2023
997b547
Add gdal and geopandas to env
mfisher87 Sep 28, 2023
27200b6
Replace relative paths with absolute paths
mfisher87 Sep 29, 2023
62a68ba
Add dateutil, pillow deps
mfisher87 Sep 29, 2023
c169cc9
Document running update_data.py
mfisher87 Sep 29, 2023
7fa1dac
Stub out mypy config
mfisher87 Sep 29, 2023
0c65836
Add warning about memory footprint to docs
mfisher87 Sep 29, 2023
db8a21e
Narrow scope of some imports
mfisher87 Sep 29, 2023
163d5c7
Replace all relative paths ("../") with absolute paths
mfisher87 Sep 29, 2023
706a78f
Write database to optional external location
mfisher87 Sep 29, 2023
fcda0ad
Create parent directory of melt picklefile if it doesn't exist
mfisher87 Sep 29, 2023
51fa2be
Lock environment
mfisher87 Sep 29, 2023
647ff44
Create parent dir for gap-filled pickle
mfisher87 Sep 29, 2023
65b773f
WIP operations doc
mfisher87 Sep 29, 2023
baee844
WIP documentation enhancements
mfisher87 Sep 30, 2023
014d9f7
Ensure `gdal.Open` receives strings for filepaths
mfisher87 Oct 2, 2023
037b5f3
Document Tb directory won't contain `.bin` files anymore
mfisher87 Oct 2, 2023
64c573b
Download NSIDC-0080 v2 with `earthaccess`
mfisher87 Oct 2, 2023
bb7af78
Read from NSIDC-0080v2 NetCDF files
mfisher87 Oct 3, 2023
3051567
Fixed nan assertion failures
encassano Nov 8, 2023
3d79679
Fixed nan assertion failures
encassano Nov 9, 2023
3fb8a38
Added verbiage in operation.md to address non-bash users`
encassano Nov 9, 2023
4744eaf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
50f9fb9
Fixing deprecated usages of old numpy dtypes.
mmacferrin Dec 12, 2023
40bb97d
Fix linter complaints
mfisher87 Dec 12, 2023
ea0d2ac
Minor bug fixes and improved comments.
mmacferrin Dec 13, 2023
2076a10
Updated "update_data.py" to use work with nsidc-0080 v2 data (from v1…
mmacferrin Dec 14, 2023
fb65820
Expand the documentation of processing steps in the operation.md manual.
mmacferrin Dec 14, 2023
2fe965d
Added an optional parameter to limit & filter the download of Tb brig…
mmacferrin Dec 14, 2023
c79cf46
Ignore .nc and .bin files in the Tb/nsidc-0080 folder. These are to b…
mmacferrin Dec 14, 2023
1f9c68c
Fixed a typo in Region 7 name ("Amundsen Bellinghausen" --> "Amundsen…
mmacferrin Dec 15, 2023
7a39152
Removed deprecated "numpy.product" call, replaced with call to "numpy…
mmacferrin Dec 15, 2023
659587f
Fixed runtime bug in previous update to "update_data.py" that was cau…
mmacferrin Dec 15, 2023
6b911ed
Uncommenting the code that downloaded the latest files from NSDIC in …
mmacferrin Dec 17, 2023
aa3edaa
Quick bug fix (mis-named variable).
mmacferrin Dec 17, 2023
13a7ed8
Flipped a parameter to *not* make it use symlinks when copying everyt…
mmacferrin Dec 18, 2023
2040671
Merge pull request #16 from nsidc/operationalize-db-generation
mfisher87 Jul 19, 2024
a9384b0
Update antarctica_today/generate_daily_melt_file.py
mfisher87 Jul 19, 2024
687b25c
Remove unnecessary comment
mfisher87 Jul 19, 2024
165ee6c
Merge pull request #28 from nsidc/fix_0080-netcdf_nans
mfisher87 Jul 19, 2024
6c11da0
Merge pull request #24 from nsidc/0080-netcdf
mfisher87 Jul 19, 2024
5d9d1c7
Merge pull request #29 from nsidc/fix_numpy_dtype_deprecation_errors
mfisher87 Jul 19, 2024
3213788
Merge pull request #31 from nsidc/improve_data_updates_and_plot_gener…
mfisher87 Jul 19, 2024
55eef90
Merge branch 'main' into v2
mfisher87 Jul 19, 2024
98206bf
Add continuous integration workflow
mfisher87 Jul 19, 2024
5db2179
Merge pull request #38 from nsidc/ci-workflow
mfisher87 Jul 19, 2024
606ee5e
Fix lint errors
mfisher87 Jul 19, 2024
72d5fa9
Add mypy to env
mfisher87 Jul 19, 2024
b30f1f5
Fix type checking errors
mfisher87 Jul 19, 2024
9b6fada
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 19, 2024
4c4eb58
Merge pull request #39 from nsidc/lint
mfisher87 Jul 19, 2024
5a66795
Add type annotations to an unannotated module
mfisher87 Jul 22, 2024
18d651a
Upgrade earthaccess to a version with py.typed marker
mfisher87 Jul 22, 2024
fcfad5d
Restore prior function interface
mfisher87 Jul 22, 2024
6ce8068
Help the typechecker some more
mfisher87 Jul 22, 2024
0c6f7e3
Merge pull request #44 from nsidc/typing-enhancements
mfisher87 Jul 22, 2024
c5bea4a
Re-organize operations doc
mfisher87 Jul 19, 2024
35539fb
Enable gdal to use "deprecated" projections we want to use
mfisher87 Jul 19, 2024
e79eec8
Extract CLI to top-level __main__.py
mfisher87 Jul 19, 2024
84e33dc
Correct wrong date in operations note
mfisher87 Jul 19, 2024
1972323
Extract command line interface to top package level
mfisher87 Jul 22, 2024
e4cb83e
Ensure picklefile parent dir exists before opening
mfisher87 Jul 22, 2024
beec098
Add specificity to operation doc
mfisher87 Jul 22, 2024
f48122b
Forbid print statements
mfisher87 Jul 19, 2024
5e52b30
WIP Add logging
mfisher87 Jul 23, 2024
32264c7
Replace print calls with logging
mfisher87 Jul 23, 2024
47d87ca
Merge pull request #46 from nsidc/operations
mfisher87 Jul 23, 2024
4df6c02
Merge pull request #47 from nsidc/no-print
mfisher87 Jul 23, 2024
eea3a51
Add Docker build config and continuous delivery
mfisher87 Jul 24, 2024
2784faf
Re-organize ops doc notes for consistency
mfisher87 Jul 24, 2024
7e549c0
Remove PyPI build GHActions jobs
mfisher87 Jul 24, 2024
579e3c0
Merge pull request #49 from nsidc/docker
mfisher87 Jul 24, 2024
b120fe2
Use context managers to open files
mfisher87 Jul 24, 2024
bf75dc2
Merge pull request #50 from nsidc/open-with-context-manager
mfisher87 Jul 24, 2024
ebd04e5
Extract dev compose file
mfisher87 Jul 24, 2024
bc8492c
Merge pull request #51 from nsidc/dev-compose
mfisher87 Jul 24, 2024
088ec25
Simplify CLI and add quickstart ops doc
mfisher87 Jul 24, 2024
e872a4a
Override default docker image
mfisher87 Jul 24, 2024
22a1fa1
Merge pull request #52 from nsidc/simplify-cli-and-ops-instructions
mfisher87 Jul 24, 2024
a90253f
Move all-plots into subcommand of init
mfisher87 Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Build & publish artifacts"

on:
push:
branches:
- "main"
- "v2" # TODO: Remove before merge!
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

env:
# Many color libraries just need this to be set to any value, but at least
# one distinguishes color depth, where "3" -> "256-bit color".
FORCE_COLOR: 3

jobs:
build-and-publish-docker-image:
name: "Build and publish Docker image"
uses: "nsidc/.github/.github/workflows/build-and-publish-container-image.yml@main"
with:
docker-image-name: "nsidc/antarctica_today"
secrets: "inherit"
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Continuous Integration

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# Many color libraries just need this to be set to any value, but at least
# one distinguishes color depth, where "3" -> "256-bit color".
FORCE_COLOR: 3

defaults:
run:
# Enables steps to see the micromamba environment:
shell: bash -leo pipefail {0}


jobs:
checks:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8"]
runs-on:
- ubuntu-latest
- macos-latest
# - windows-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.6-0' # any version from https://github.com/mamba-org/micromamba-releases
environment-file: environment.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

- name: Type-check package
run: mypy

# - name: Test package
# run: >-
# python -m pytest -ra --cov --cov-report=xml --cov-report=term
# --durations=20

# - name: Upload coverage report
# uses: codecov/[email protected]
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Compose
compose.override.yml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM mambaorg/micromamba:1.5.8-alpine3.20

WORKDIR /app

# Activate the conda environment during build process
ARG MAMBA_DOCKERFILE_ACTIVATE=1

COPY ./conda-lock.yml .

# NOTE: `-p` is important to install to the "base" env
RUN micromamba install -y \
-p /opt/conda \
-f conda-lock.yml \
&& micromamba clean --all --yes


# Install source
COPY ./pyproject.toml .
COPY ./antarctica_today ./antarctica_today
COPY ./qgis ./qgis

# TODO: `pip install --editable .`
ENV PYTHONPATH=.

# Extend the default micromamba entrypoint to use our CLI
ENTRYPOINT ["/usr/local/bin/_entrypoint.sh", "python", "antarctica_today"]
2 changes: 2 additions & 0 deletions Tb/nsidc-0080/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*
# Except this file
!.gitignore
*.nc
*.bin
21 changes: 21 additions & 0 deletions antarctica_today/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import sys

# IMPORTANT: If we don't specify this setting, then the projection we want to use will
# be replaced with another (and this warning will be printed)!
#
# Warning 1: CRS EPSG:3411 is deprecated. Its non-deprecated replacement EPSG:3413 will be
# used instead. To use the original CRS, set the OSR_USE_NON_DEPRECATED configuration
# option to NO.
# Warning 1: CRS EPSG:3412 is deprecated. Its non-deprecated replacement EPSG:3976 will be
# used instead. To use the original CRS, set the OSR_USE_NON_DEPRECATED configuration
# option to NO.
os.environ["OSR_USE_NON_DEPRECATED"] = "NO"


# Ignore warnings by default, while still allowing users to change the behavior, e.g. by
# upgrading them to exceptions.
if not sys.warnoptions:
import warnings

warnings.simplefilter("ignore")
100 changes: 100 additions & 0 deletions antarctica_today/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import click
from loguru import logger

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
from antarctica_today.update_data import update_everything_to_latest_date


@click.group()
def cli():
"""Antarctica Today."""
pass


@cli.group()
def init():
"""Initialize the Antarctica Today database and generate all plots."""
pass


@init.command("01-download-tb")
def download_tb():
"""Download NSIDC-0080 brightness temperature granules.

By default, data is downloaded starting on 2022-01-10, as data before then is
committed to this repository. This pre-generated data was generated from NSIDC-0001
and NSIDC-0007 datasets.
"""
download_new_files()
logger.success("Download of NSIDC-0080 granules complete.")


@init.command("02-generate-daily-melt")
def generate_daily_melt():
"""Generate daily melt files from brightness temperature granules.

These files are written as binary files with ".bin" extension in the
`/data/daily_melt_bin_files/` directory in this repository.
"""
generate_new_daily_melt_files(overwrite=False)
logger.success("Generation of daily melt files complete.")


@init.command("03-preprocess")
def preprocess():
"""Perform pre-processing steps for Antarctica Today data.

This includes CSV, TIF, and pickled numpy arrays with ".pickle" extension.
"""
preprocessing_main()
logger.success("Preprocess complete.")


@init.command("04-all-plots")
def all_plots():
"""Generate all Antarctica Today plot images from the database."""
generate_all_plots_and_maps_main()
logger.success("All plots generated.")


@init.command("all")
def init_all():
"""Initialize the Antarctica Today database and generate all plots."""
download_new_files()
generate_new_daily_melt_files(overwrite=False)
preprocessing_main()
generate_all_plots_and_maps_main()
logger.success("Antarctica Today database initialized.")


@cli.command()
def daily_update_and_plots():
"""Perform a daily update of the Antarctica Today database and produce plots.

This includes:

* A "daily melt" map of the most recent day's melt extent
* A "sum" map of the current season's total melt days
* An "anomaly" map of that season's total melt days in comparison to baseline
average values to-that-day-of-year
* A line plot of melt extent up do that date, compared to historical baseline
averages

It will copy these plots into a sub-directory `/plots/daily_plots_gathered/[date]/`
for easy collection.
"""
update_everything_to_latest_date(copy_to_gathered_dir=True)
logger.success("Database updated to the current date. New plots produced.")


if __name__ == "__main__":
cli()
Loading
Loading