Skip to content

Commit

Permalink
Add PACE workshop notebook (#135)
Browse files Browse the repository at this point in the history
* Add PACE workshop notebook

* Update PACE notebooks

* Add hypoxia notebook

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add openpyxl

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add fiona and geopandas

* Update PACE notebook

* Update EARTHDATA secrets

* Update NASA EARTHDATA API Key

* Check file path

* Add earthaccess login test

* Use earthaccess.login

* Fix os import error

* Add earthaccess notebook

* Add env variables

* Update env variable

* Update notebook

* Update PACE notebook

* Update PACE notebook

* Deprecate Python 3.8

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
giswqs and pre-commit-ci[bot] authored Sep 2, 2024
1 parent 1ce1f0d commit a2cd637
Show file tree
Hide file tree
Showing 17 changed files with 1,519 additions and 49 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.11"
env:
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}

- name: Install GDAL
run: |
python -m pip install --upgrade pip
Expand All @@ -38,6 +34,9 @@ jobs:
- name: Build docs
run: |
mkdocs build
env:
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}
- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -24,4 +23,8 @@ jobs:
- name: PKG-TEST
run: |
python -m unittest discover tests/
- run: mkdocs gh-deploy --force
- name: Build docs
run: mkdocs gh-deploy --force
env:
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}
1 change: 0 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, py: "3.8" }
- { os: ubuntu-latest, py: "3.9" }
- { os: ubuntu-latest, py: "3.10" }
- { os: ubuntu-latest, py: "3.11" }
Expand Down
120 changes: 120 additions & 0 deletions docs/examples/_earthaccess.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/HyperCoast/blob/main/docs/examples/_earthaccess.ipynb)\n",
"\n",
"# Testing earthaccess login"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install \"hypercoast[extra]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import earthaccess\n",
"import hypercoast"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"EARTHDATA_USERNAME\"] = \"your_username\"\n",
"# os.environ[\"EARTHDATA_PASSWORD\"] = \"your_password\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if os.environ.get(\"EARTHDATA_USERNAME\") is None:\n",
" raise ValueError(\"Please set the EARTHDATA_USERNAME environment variable\")\n",
"if os.environ.get(\"EARTHDATA_PASSWORD\") is None:\n",
" raise ValueError(\"Please set the EARTHDATA_PASSWORD environment variable\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"earthaccess.login(persist=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results, gdf = hypercoast.search_pace(\n",
" bounding_box=(-83, 25, -81, 28),\n",
" temporal=(\"2024-07-30\", \"2024-08-15\"),\n",
" short_name=\"PACE_OCI_L2_AOP_NRT\",\n",
" count=10,\n",
" return_gdf=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hypercoast.download_pace(results[:1], out_dir=\"data\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filepath = \"data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc\"\n",
"if not os.path.exists(filepath):\n",
" raise FileNotFoundError(filepath)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "hyper",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion docs/examples/field_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Download a sample filed dataset."
"Download a sample dataset."
]
},
{
Expand Down
151 changes: 151 additions & 0 deletions docs/examples/hypoxia.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/HyperCoast/blob/main/docs/examples/hypoxia.ipynb)\n",
"\n",
"# Visualizing Hypoxia Cruise Sampling Locations in the Gulf of Mexico"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U openpyxl hypercoast"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import hypercoast"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://github.com/opengeos/datasets/releases/download/hypercoast/Hypoxia_Data_Sheet.xlsx\"\n",
"xls_path = \"data/Hypoxia_Data_Sheet.xlsx\"\n",
"hypercoast.download_file(url, xls_path, overwrite=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_excel(xls_path)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_filtered = df.dropna(subset=[\"Lon\", \"Lat\"]).reset_index(drop=True)\n",
"df_filtered.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = (\n",
" \"https://github.com/opengeos/datasets/releases/download/hypercoast/Hypoxia_Path.kml\"\n",
")\n",
"kml_path = \"data/Hypoxia_Path.kml\"\n",
"hypercoast.download_file(url, kml_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://github.com/opengeos/datasets/releases/download/hypercoast/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc\"\n",
"filepath = \"data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc\"\n",
"hypercoast.download_file(url, filepath)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataset = hypercoast.read_pace(filepath)\n",
"# dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = hypercoast.Map()\n",
"m.add_basemap(\"Hybrid\")\n",
"wavelengths = [450, 550, 650]\n",
"m.add_pace(\n",
" dataset, wavelengths, indexes=[3, 2, 1], vmin=0, vmax=0.02, layer_name=\"PACE\"\n",
")\n",
"m.add(\"spectral\")\n",
"style = {\"weight\": 2, \"color\": \"red\"}\n",
"m.add_kml(kml_path, style=style, layer_name=\"Hypoxia Path\", info_mode=None)\n",
"m.add_points_from_xy(\n",
" df_filtered,\n",
" x=\"Lon\",\n",
" y=\"Lat\",\n",
" max_cluster_radius=50,\n",
" layer_name=\"Hypoxia Data Points\",\n",
")\n",
"m.set_center(-91.46118, 28.89758, zoom=8)\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![image](https://github.com/user-attachments/assets/9a4bc3b7-2a69-4a94-a4f8-297103cb80d3)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "hyper",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
9 changes: 9 additions & 0 deletions docs/examples/jupytext.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Install jupytext using: conda install jupytext -c conda-forge
# Always pair ipynb notebooks to md files.
# formats = "ipynb,md"
formats = "ipynb,myst"

# jupytext --to ipynb *.md # convert all .md files to notebooks with no outputs
# jupytext --to ipynb --execute *.md # convert all .md files to notebooks and execute them
# jupytext --set-formats ipynb,md --execute *.md # convert all .md files to paired notebooks and execute them
# jupytext --to md *.ipynb # convert all .ipynb files to .md files
17 changes: 8 additions & 9 deletions docs/examples/pace.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"metadata": {},
"outputs": [],
"source": [
"url = \"https://github.com/opengeos/datasets/releases/download/netcdf/PACE_OCI.20240423T184658.L2.OC_AOP.V1_0_0.NRT.nc\""
"url = \"https://github.com/opengeos/datasets/releases/download/hypercoast/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc\""
]
},
{
Expand All @@ -51,8 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
"# filepath = \"data/PACE_OCI.20240423T184658.L2.OC_AOP.V1_0_0.NRT.nc\"\n",
"filepath = \"data/PACE_OCI.20240423T184658.L2.OC_AOP.V1_0_0.NRT.nc\"\n",
"filepath = \"data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc\"\n",
"hypercoast.download_file(url, filepath)"
]
},
Expand Down Expand Up @@ -133,9 +132,9 @@
"metadata": {},
"outputs": [],
"source": [
"latitude = 25.493961\n",
"longitude = -91.25617\n",
"hypercoast.filter_pace(dataset, latitude, longitude, return_plot=True)"
"latitude = 29.9307\n",
"longitude = -87.9106\n",
"hypercoast.extract_pace(dataset, latitude, longitude, return_plot=True)"
]
},
{
Expand All @@ -151,8 +150,8 @@
"metadata": {},
"outputs": [],
"source": [
"latitude = (25.49, 25.50)\n",
"longitude = (-92, -91.055)\n",
"latitude = (29.49, 29.50)\n",
"longitude = (-88.10, -88.00)\n",
"hypercoast.filter_pace(dataset, latitude, longitude, return_plot=True)"
]
},
Expand Down Expand Up @@ -232,7 +231,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit a2cd637

Please sign in to comment.