Skip to content

Commit

Permalink
Merge branch 'main' into measures
Browse files Browse the repository at this point in the history
  • Loading branch information
asteiker committed May 2, 2023
2 parents 592c748 + 140a8ec commit 4f9255f
Show file tree
Hide file tree
Showing 67 changed files with 9,521 additions and 2,145 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/binder-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: AddBinderBadge
on:
pull_request_target:

jobs:
badge:
runs-on: ubuntu-latest
steps:
- uses: manics/action-binderbadge@main
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
55 changes: 55 additions & 0 deletions .github/workflows/scan_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python

import argparse
import importlib
import subprocess
import sys


def ensure_environment(notebook, libraries):
for lib_name in libraries:
try:
importlib.import_module(lib_name)

except Exception:
try:

importlib.import_module(lib_name, f".{lib_name}")
except ModuleNotFoundError or ImportError as ee:

print(
f"{notebook} uses a library that is not present in the current environment: {ee.msg}",
file=sys.stderr,
)
exit(1)


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

libraries = []
p = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
)

while True:
inline = p.stdout.readline()
if not inline:
break
parsed_out = inline.decode("UTF-8").lower()
if "==" in parsed_out:
library = parsed_out.split("==")[0]
libraries.append(library)
print(libraries)

ensure_environment(notebook_path, libraries)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--notebook", help="<Required> Set flag", required=True)
args = parser.parse_args()
scan_notebook(args.notebook)
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Test Notebooks

on:
push:
pull_request:
types: [opened, synchronize]

jobs:
posix:
name: Runtime (${{ matrix.os }}, Mambaforge)
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "macos"]
include:
- os: ubuntu
environment-file: binder/conda-linux-64.lock
miniforge-variant: Mambaforge
miniforge-version: latest
- 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
with:
environment-file: ${{ matrix.environment-file }}
miniforge-variant: ${{ matrix.miniforge-variant }}
miniforge-version: ${{ matrix.miniforge-version }}
use-mamba: true

- name: Bash
shell: bash -l {0}
run: |
conda info
conda 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
Expand Up @@ -18,6 +18,7 @@ notebook/static/*/js/main.min.js*
notebook/static/lab/*bundle.js
notebooks/itslive/data/*.nc
notebooks/iceflow/data
notebooks/*/Outputs
.python-version
node_modules
*.py[co]
Expand Down
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
FROM jupyter/base-notebook:latest
FROM jupyter/base-notebook:2022-02-17

USER root

# Install all OS dependencies for notebook server that starts but lacks all
# features (e.g., download as all possible file formats)
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -yq --no-install-recommends git \
&& apt-get install -yq --no-install-recommends git jq \
&& apt-get clean && apt autoremove && rm -rf /var/lib/apt

USER $NB_UID

ADD binder/environment.yml $HOME
ADD binder/postBuild $HOME
RUN conda env update -f environment.yml -n base && conda clean --force --yes --all && rm $HOME/environment.yml && \
RUN mamba env update -f environment.yml -n base && conda clean --force --yes --all && rm $HOME/environment.yml && \
npm cache clean --force && \
rm -rf /opt/conda/lib/python3.7/site-packages/awscli/examples \
rm -rf /opt/conda/lib/python3.9/site-packages/awscli/examples \
&& find /opt/conda/ -follow -type f -name '*.a' -delete \
&& find /opt/conda/ -follow -type f -name '*.pyc' -delete \
&& fix-permissions /home/$NB_USER && fix-permissions $HOME \
&& ./postBuild
&& fix-permissions /home/$NB_USER && fix-permissions

ENTRYPOINT ["jupyter", "lab","--ip=0.0.0.0","--allow-root"]
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Summary

This combined repository includes tutorials and code resources provided by the NASA National Snow and Ice Data Center Distributed Active Archive Center (NSIDC DAAC). These tutorials are provided as Python-based Jupyter notebooks that provide guidance on working with various data products, including how to access, subset, transform, and visualize data. Each tutorial can be accessed by navigating to the /notebooks folder of this repository. Please see the README files associated with each individual tutorial folder for more information on each tutorial and their learning objectives.
This combined repository includes tutorials and code resources provided by the NASA National Snow and Ice Data Center Distributed Active Archive Center (NSIDC DAAC). These tutorials are provided as Python-based Jupyter notebooks that provide guidance on working with various data products, including how to access, subset, transform, and visualize data. Each tutorial can be accessed by navigating to the /notebooks folder of this repository. Please see the README files associated with each individual tutorial folder for more information on each tutorial and their learning objectives. Please note that all branches outside of `Main` should be considered in development and are not supported.

## Tutorials

Expand Down Expand Up @@ -36,6 +36,12 @@ The Inter-mission Time Series of Land Ice Velocity and Elevation (ITS_LIVE) proj

The notebooks on this project demonstrate how to search and access ITS_LIVE velocity pairs and provide a simple example on how to build a data cube.

### [ICESat-2_Cloud_Access](./notebooks/ICESat-2_Cloud_Access)

**Accessing and working with ICESat-2 Data in the Cloud**

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.

## 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 Expand Up @@ -143,33 +149,39 @@ If you started your container with the `-d`/`--detach` option, check `docker log

8. You can now interact with the notebooks to explore and access data.

## Usage with Conda
## Usage with Mamba/Conda

Install miniconda3 (Python 3.7) for your platform from [https://docs.conda.io/en/latest/miniconda.html](https://docs.conda.io/en/latest/miniconda.html)
> Note: If we already have conda or mamba installed we can skip the first step.
Download the [NSIDC-Data-Tutorials](https://github.com/nsidc/NSIDC-Data-Tutorials) repository from Github by clicking the green 'Code' button located at the top right of the repository page and clicking 'Download Zip'.
1. Install mambaforge (Python 3.9+) for your platform from [mamba documentation](https://mamba.readthedocs.io/en/latest/installation.html)

Unzip the file, and open a command line or terminal window in the NSIDC-Data-Tutorials folder's location.

From a command line or terminal window, install the required environment with the following commands:
2. Download the [NSIDC-Data-Tutorials](https://github.com/nsidc/NSIDC-Data-Tutorials) repository from Github by clicking the green 'Code' button located at the top right of the repository page and clicking 'Download Zip'. Unzip the file, and open a command line or terminal window in the NSIDC-Data-Tutorials folder's location.

3. From a command line or terminal window, install the required environment with the following commands:

Linux
```bash
conda env create -f binder/environment.yml && conda activate tutorials
./binder/postBuild
mamba create -n nsidc-tutorials --file binder/conda-linux-64.lock
```

You should now see that the dependencies were installed and our environment is ready to be used.

If you are a returning user, please make sure your repository is up to date and run the following to update your environment:

OSX
```bash
mamba create -n nsidc-tutorials --file binder/conda-osx-64.lock
```
conda env update -f binder/environment.yml

Windows
```bash
mamba create -n nsidc-tutorials --file binder/conda-win-64.lock
```

You should now see that the dependencies were installed and our environment is ready to be used.


Activate the environment with

```
conda activate tutorials
conda activate nsidc-tutorials
```

Launch the notebook locally with the following command:
Expand All @@ -180,6 +192,20 @@ jupyter lab

This should open a browser window with the JupyterLab IDE, showing your current working directory on the left-hand navigation. Navigate to the tutorial folder of choice and click on their associated *.ipynb files to get started.


### Tutorial Environments

Although the nsidc-tutorial environment should run all the notebooks in this repository, we also include tutorial-specific environments that will only contain the dependencies for them. If we don't want to "pollute" our conda environments and we are only going to work with one of the tutorials we recommend to use them instead of the `nsidc-tutorial` environment. The steps to install them are exactly the same but the environment files are inside the environment folders in each of the tutorials. e.g. for ITS_LIVE

```bash
cd notebooks/itslive
mamba create -n nsidc-itslive --file environment/conda-linux-64.lock
conda activate nsidc-itslive
jupyter lab
```

This should create a pinned environment that should be fully reproducible across platforms.

> **NOTE:** Sometimes Conda environments change (break) even with pinned down dependencies. If you run into an issue with dependencies for the tutorials please open an issue and we'll try to fix it as soon as possible.

Expand Down
10 changes: 10 additions & 0 deletions binder/apt.txt
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
curl
git
jq
htop
tmux
tree
vim
neovim
net-tools
iproute2
ffmpeg
Loading

0 comments on commit 4f9255f

Please sign in to comment.