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

SnowEx Database Add #18

Merged
merged 27 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aad51c6
add database tutorial
micah-prime Jun 17, 2024
8baf7c5
add api examples
micah-prime Jun 17, 2024
2eee3ff
add toc entries
micah-prime Jun 17, 2024
014c08d
Add snowexsql dependency
micah-prime Jun 18, 2024
3d83eb4
clear cell outputs
micah-prime Jun 18, 2024
fe5a8cf
Fixed merge conflict with main
micahjohnson150 Jul 23, 2024
ab89920
First pass at introduction
micahjohnson150 Jul 30, 2024
dc4ccbe
Working through #2 of the db tutorial
micahjohnson150 Jul 30, 2024
0d9db15
Working on tutorial for forming queries with the API
micahjohnson150 Jul 30, 2024
d8fecab
A bit of cleanup
micahjohnson150 Aug 1, 2024
026ce30
Updated minor things, added in most of the raster example
micahjohnson150 Aug 1, 2024
6232861
removed exporting of data
micahjohnson150 Aug 11, 2024
2910f6d
Merge branch 'main' of github.com:snowex-hackweek/website-2024 into d…
micahjohnson150 Aug 11, 2024
ddb0336
Polishing up tutorial on cryo
micahjohnson150 Aug 15, 2024
ecc3d6b
migrated tutorial file name to match my current patter
micahjohnson150 Aug 15, 2024
110d86e
added more code comments a bit expanded text for non-inperson attendees
micahjohnson150 Aug 15, 2024
71ffc12
Rerun with final data upload
micahjohnson150 Aug 15, 2024
73cb951
DUN
micahjohnson150 Aug 16, 2024
db6a9d0
updating on top of main
micahjohnson150 Aug 16, 2024
72bb886
Added snowexsql 0.5.0 to environment
micahjohnson150 Aug 16, 2024
5f7cab1
fixed toc
micahjohnson150 Aug 16, 2024
1ad296a
Fixed qc issues in mine and the cond environment file
micahjohnson150 Aug 16, 2024
c9ad390
Fixed unordered headers. Removed example that errors out on purpose.
micahjohnson150 Aug 16, 2024
af498f9
Merge branch 'main' into database_initial
micahjohnson150 Aug 17, 2024
dfd7f79
Merge branch 'database_initial' of github.com:micahjohnson150/website…
micahjohnson150 Aug 17, 2024
220d6eb
Added show import
micahjohnson150 Aug 17, 2024
c9dddd5
Cleared the output from cells
micahjohnson150 Aug 17, 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
9 changes: 9 additions & 0 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ parts:
- file: tutorials/Data_access/earthdata_search.md
- file: tutorials/Data_access/earthaccess_snowex.ipynb
- file: tutorials/Data_access/earthaccess_icesat2.ipynb
- file: tutorials/snowex_database/index
title: Introduction to the SnowEx Database
sections:
- file: tutorials/snowex_database/1_getting_started_example
- file: tutorials/snowex_database/2_database_structure
- file: tutorials/snowex_database/3_forming_queries
- file: tutorials/snowex_database/4_get_spiral_example
- file: tutorials/snowex_database/5_plot_raster_example
- file: tutorials/snowex_database/6_wrap_up
- file: tutorials/swesarr/index
title: SWESARR
sections:
Expand Down
137 changes: 137 additions & 0 deletions book/tutorials/snowex_database/1_getting_started_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SnowEx Database Introduction\n",
"\n",
" \n",
"__Tutorial Author Micah'__: [Micah Sandusky](https://github.com/micah-prime)\n",
"\n",
"__Tutorial Author Micah_o__: [Micah Johnson](https://github.com/micahjohnson150)\n",
"\n",
"[SnowEx](https://snow.nasa.gov/campaigns/snowex) has introduced a unique opportunity to study SWE in a way thats unprecedented, but with more data comes new challenges. \n",

Check failure on line 14 in book/tutorials/snowex_database/1_getting_started_example.ipynb

View workflow job for this annotation

GitHub Actions / quality-control

thats ==> that's
"\n",
"![examples](./images/data_examples.png)\n",
"\n",
"\n",
"<!-- \n",
"<img src=\"https://snowexsql.readthedocs.io/en/latest/_images/gallery_overview_example_12_0.png\" alt=\"Grand Mesa Overview\" width=\"1000px\"> -->\n",
"\n",
"**The SnowEx database is a resource that shortcuts the time it takes to ask cross dataset questions**\n",
"\n",
" \n",
"- Standardizing diverse data\n",
"- Cross referencing data\n",
"- Provenance!\n",
"- Added GIS functionality\n",
"- Connect w/ ArcGIS or QGIS!\n",
"- **CITABLE** \n",
"\n",
" * [*2022- Estimating snow accumulation and ablation with L-band interferometric synthetic aperture radar (InSAR)*](https://tc.copernicus.org/articles/17/1997/2023/tc-17-1997-2023-discussion.html)\n",
" * [*2024 - Thermal infrared shadow-hiding in GOES-R ABI imagery: snow and forest temperature observations from the SnowEx 2020 Grand Mesa field campaign*](https://tc.copernicus.org/articles/18/2257/2024/)\n",
" \n",
" \n",
"\n",
"## What's in it?\n",
"\n",
"* Snow pits - Density, hardness profiles, grain types + sizes\n",
"* Manual snow depths - TONS of depths (Can you say spirals?)\n",
"* Snow Micropenetrometer (SMP) profiles - (Subsampled to every 100th)\n",
"* Snow depth + SWE rasters from ASO Inc.\n",
"* GPR\n",
"* Pit site notes\n",
"* Camera Derived snow depths\n",
"* Snow off DEM from USGS 3DEP \n",
"* And almost all the associated metadata\n",
"\n",
"## Technically, what is it?\n",
"\n",
"* PostgreSQL database\n",
"* PostGIS extension\n",
"* Supports vector and raster data\n",
"* And a host of GIS operations\n",
"* AND NOW WITH API!\n",
"\n",
"\n",
"### So whats the catch?\n",

Check failure on line 58 in book/tutorials/snowex_database/1_getting_started_example.ipynb

View workflow job for this annotation

GitHub Actions / quality-control

whats ==> what's
"New tech can create barriers...\n",
"\n",
"```{figure} ./images/pits_not_bits.jpg\n",
":scale: 20 %\n",
":alt: pits not bits\n",
"```\n",
"\n",
"### TL;DR Do less wrangling, do more crunching. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## How do I get at this magical box of data ?\n",
"* [SQL](https://www.postgresql.org/docs/13/tutorial-sql.html) \n",
"* [snowexsql](https://github.com/SnowEx/snowexsql/) <span style=\"font-size:20pt;\"> **&#8592; 😎**</span>\n",
"\n",
"\n",
"### Welcome to API Land"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from snowexsql.api import PointMeasurements\n",
"\n",
"df = PointMeasurements.from_filter(type=\"depth\", instrument='pit ruler', limit=100)\n",
"df.plot(column='value', cmap='jet', vmin=10, vmax=150)\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Old Ways / Advanced Users \n",
"Advanced queries can be made using SQL or SQAlchemy under the hood. \n",
"\n",
"See previous presentations\n",
"\n",
"Engine objects, session objects, and a crash course in ORM, oh my! \n",
"* [Hackweek 2021](https://snowex-2021.hackweek.io/tutorials/database/index.html)\n",
"* [Hackweek 2022](https://snowex-2022.hackweek.io/tutorials/database/index.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
150 changes: 150 additions & 0 deletions book/tutorials/snowex_database/2_database_structure.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8d563d3c",
"metadata": {},
"source": [
"# How is the Database Structured?\n",
"\n",
"The goal of the database is to hold as much of the SnowEx data in one place and make it easier to \n",
"do research with. With that in mind follow the steps below to see how the the data base is structured.\n"
]
},
{
"cell_type": "markdown",
"id": "a9f0a9c7",
"metadata": {},
"source": [
"## Where do datasets live (i.e. tables)?\n",
"\n",
"Data in the database lives in 1 of 4 places. \n",
"\n",
"\n",
"```{figure} ./images/structure.png\n",
":scale: 50 %\n",
":alt: Structure of the snowex db\n",
"\n",
"Layout of the database tables\n",
"\n",
"```\n",
"\n",
"The 4th table is a table detailing the site information. Lots and lots of metadata for which the API has not been written yet.\n",
"\n",
"So how does this look in python?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "979fad96",
"metadata": {},
"outputs": [],
"source": [
"from snowexsql.api import PointMeasurements, LayerMeasurements, RasterMeasurements"
]
},
{
"cell_type": "markdown",
"id": "07bf71eb",
"metadata": {},
"source": [
"## How are tables structured?\n",
"Each table consists of rows and columns. Below are the available columns!\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8fd4e693",
"metadata": {},
"outputs": [],
"source": [
"# Import the class reflecting the points table in the db\n",
"from snowexsql.api import PointMeasurements as measurements\n",
"\n",
"# Grab one measurement to see what attributes are available\n",
"df = measurements.from_filter(type=\"depth\", limit=1)\n",
"\n",
"# Print out the results nicely\n",
"print(\"These are the available columns in the table:\\n \\n* {}\\n\".format('\\n* '.join(df.columns)))"
]
},
{
"cell_type": "markdown",
"id": "ba2df485",
"metadata": {},
"source": [
"**Try this:** Using what we just did, but swap out PointMeasurements for LayerMeasurements.\n",
"\n",
"\n",
"**Question:** Did you collect any data? What is it? What table do you think it would go in?\n",
"\n",
"For more detail, checkout the readthedocs page on [database structure](https://snowexsql.readthedocs.io/en/latest/database_structure.html) to see how data gets categorized. "
]
},
{
"cell_type": "markdown",
"id": "6d106e6e",
"metadata": {},
"source": [
"## Bonus Step: Learning to help yourself\n",
"[snowexsql](https://github.com/SnowEx/snowexsql/) has a host of resources for you to help your self. First when you are looking for something be sure to check the snowexsql's docs.\n",
"There you will find notes on the database structure. datasets, and of course our new API! \n",
"\n",
"### Database Usage/Examples\n",
"* [snowexsql Code](https://github.com/SnowEx/snowexsql/) \n",
"* [snowexsql Documentation](https://snowexsql.readthedocs.io/en/latest/) \n",
"\n",
"### Database Building/Notes\n",
"* [snowex_db Code](https://github.com/SnowEx/snowex_db/) \n",
"* [snowex_db Documentation](https://snowex_db.readthedocs.io/en/latest/) "
]
},
{
"cell_type": "markdown",
"id": "fbe9ae13",
"metadata": {},
"source": [
"## Recap \n",
"You just explored the database structure and discussed how they differ.\n",
"\n",
"**You should know:**\n",
"* Which table a dataset might live in\n",
"* What columns you can work with (or how to get the available columns)\n",
"* Some resources to begin helping yourself.\n",
"\n",
"If you don't feel comfortable with these, you are probably not alone, let's discuss it!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e260d71e-c4d8-4f4f-b170-4f64f8fa56ed",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading