Skip to content

Commit

Permalink
Merge pull request #52 from nsidc/measures
Browse files Browse the repository at this point in the history
Notebook to access, download and plot GeoTIFFs using MEaSUREs data sets as examples
  • Loading branch information
asteiker committed Jun 14, 2023
2 parents d4928ac + 17673f4 commit 4ccbdee
Show file tree
Hide file tree
Showing 30 changed files with 2,573 additions and 600 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- setup_remote_docker
- run:
name: Build and save Docker image
working_directory: ~/tutorials/binder
command: |
DOCKER_IMAGE=nsidc/tutorials
Expand All @@ -32,7 +33,7 @@ jobs:
docker save -o build/saved-docker-image.tar ${DOCKER_IMAGE}:${TAG}
echo "${DOCKER_IMAGE}:${TAG}" > build/docker-image-name.txt
- persist_to_workspace:
root: ~/tutorials
root: ~/tutorials/binder
paths:
- build

Expand All @@ -41,7 +42,7 @@ jobs:
steps:
- setup_remote_docker
- attach_workspace:
at: ~/tutorials
at: ~/tutorials/binder
- deploy:
name: Publish Docker image
command: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/scan_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def ensure_environment(notebook, libraries):

def scan_notebook(notebook_path):
notebook_path = notebook_path.replace(" ", "\\ ")
command = f"pipreqsnb {notebook_path} --print"
command = f"pipreqsnb {notebook_path} --print --debug"

libraries = []
libraries = set()
p = subprocess.Popen(
command,
shell=True,
Expand All @@ -42,8 +42,10 @@ def scan_notebook(notebook_path):
parsed_out = inline.decode("UTF-8").lower()
if "==" in parsed_out:
library = parsed_out.split("==")[0]
libraries.append(library)
print(libraries)
if library.lower() == "gdal":
library = "osgeo"
libraries.add(library)
print(list(libraries))

ensure_environment(notebook_path, libraries)

Expand Down
114 changes: 63 additions & 51 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,84 @@
name: Test Notebooks

on:
push:
pull_request:
paths:
- notebooks/**
- binder/**
- '.github/workflows/'
types: [opened, synchronize]

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

jobs:
posix:
name: Runtime (${{ matrix.os }}, Mambaforge)
linux:
name: Linux tests
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v3
- name: "Install Conda environment with Micromamba"
uses: mamba-org/setup-micromamba@v1
with:
cache-env: true
environment-file: binder/conda-linux-64.lock
environment-name: nsidc-tutorials

- name: "Verify micromamba"
shell: bash -l {0}
run: |
micromamba info
jupyter kernelspec list
which python
conda list | sort
- name: "Verify that libraries used in notebooks are present in the environment"
shell: bash -l {0}
run: |
find notebooks -type f -iname \*.ipynb -not -path '*\.ipynb_checkpoints/*' -not -path '*/iceflow/*' | xargs -I % python .github/workflows/scan_notebooks.py -n %
- name: "Setup Quarto"
uses: quarto-dev/quarto-actions/setup@v2
with:
# version: 1.1.251
version: 1.3.361

- name: "Execute notebooks with Quarto"
env:
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}
shell: bash -l {0}
run: |
find notebooks -type f -name "*.ipynb" -not -path '*\.ipynb_checkpoints/*' -not -path '*endered*' -not -path '*SnowEx*' | xargs -I F quarto render "F" --execute-daemon-restart
win-osx:
name: Runtime (${{ matrix.os }}, micromamba)
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "macos"]
os: ["windows", "macos"]
include:
- os: ubuntu
environment-file: binder/conda-linux-64.lock
miniforge-variant: Mambaforge
miniforge-version: latest
- os: windows
environment-file: binder/conda-win-64.lock
- os: macos
environment-file: binder/conda-osx-64.lock
miniforge-variant: Mambaforge
miniforge-version: latest
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v3
- name: "Install Conda environment with Micromamba"
uses: mamba-org/setup-micromamba@v1
with:
cache-env: true
environment-file: ${{ matrix.environment-file }}
miniforge-variant: ${{ matrix.miniforge-variant }}
miniforge-version: ${{ matrix.miniforge-version }}
use-mamba: true
environment-name: nsidc-tutorials

- name: Bash
- name: "Verify micromamba"
shell: bash -l {0}
run: |
conda info
conda list
micromamba info
jupyter kernelspec list
printenv | sort
find notebooks -type f -iname \*.ipynb -not -path '*\.ipynb_checkpoints/*' -not -path "*/iceflow/*" | xargs -I % python .github/workflows/scan_notebooks.py -n %
# windows:
# name: Runtime Windows Mambaforge
# runs-on: windows-latest
# strategy:
# fail-fast: false
# steps:
# - uses: actions/checkout@v2
# - uses: conda-incubator/setup-miniconda@v2
# with:
# environment-file: binder/conda-win-64.lock
# miniforge-variant: Mambaforge
# miniforge-version: latest
# use-mamba: true

# - name: PowerShell
# shell: powershell
# run: |
# conda info
# conda list

# - name: PowerShell Core
# shell: pwsh
# run: |
# conda info
# conda list

# - name: Cmd.exe
# shell: cmd /C CALL {0}
# run: >-
# conda info && conda list
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MANIFEST
notebook/Outputs
build
bin
dist
_build
docs/man/*.gz
Expand Down
22 changes: 0 additions & 22 deletions Dockerfile

This file was deleted.

13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/nsidc/NSIDC-Data-Tutorial/main?urlpath=lab/tree/notebooks)

[![CircleCI](https://circleci.com/gh/nsidc/NSIDC-Data-Tutorials.svg?style=svg)](https://circleci.com/gh/nsidc/NSIDC-Data-Tutorials)
[![Test Notebooks](https://github.com/nsidc/NSIDC-Data-Tutorials/actions/workflows/test.yml/badge.svg)](https://github.com/nsidc/NSIDC-Data-Tutorials/actions/workflows/test.yml)

## Summary

Expand Down Expand Up @@ -42,6 +42,17 @@ The notebooks on this project demonstrate how to search and access ITS_LIVE velo

Originally presented to the UWG (User Working Group) in May 2022, this tutorial demonstrates how to search for ICESat-2 data hosted in the Earthdata Cloud and how to directly access it from an Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instance using the `earthaccess` package.

### [MEaSUREs](./notebooks/measures)

**Download, crop, resample, and plot multiple GeoTIFFs**

This tutorial guides you through programmatically accessing and downloading GeoTIFF files from the NSIDC DAAC to your local computer. We then crop and resample one GeoTIFF based on the extent and pixel size of another GeoTIFF, then plot one on top of the other.

We will use two data sets from the NASA [MEaSUREs](https://nsidc.org/data/measures) (Making Earth System data records for Use in Research Environments) program as an example:

* [MEaSUREs Greenland Ice Mapping Project (GrIMP) Digital Elevation Model from GeoEye and WorldView Imagery, Version 2 (NSIDC-0715)](https://nsidc.org/data/nsidc-0715/versions/2)
* [MEaSUREs Greenland Ice Velocity: Selected Glacier Site Velocity Maps from InSAR, Version 4 (NSIDC-0481)](https://nsidc.org/data/nsidc-0481/versions/4)

## Usage with Binder

The Binder button above allows you to explore and run the notebook in a shared cloud computing environment without the need to install dependencies on your local machine. Note that this option will not directly download data to your computer; instead the data will be downloaded to the cloud environment.
Expand Down
6 changes: 6 additions & 0 deletions binder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM pangeo/base-image:2023.01.13


USER $NB_UID

ENTRYPOINT ["jupyter", "lab","--ip=0.0.0.0","--allow-root"]

0 comments on commit 4ccbdee

Please sign in to comment.