forked from oceanmodeling/searvey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes oceanmodeling#5 Fixes oceanmodeling#24
- Loading branch information
Showing
10 changed files
with
26,351 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "65e90d8f-6d7d-4fd2-b700-2ab7854ceb55", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import logging\n", | ||
"\n", | ||
"import shapely\n", | ||
"import geopandas as gpd\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import pandas as pd\n", | ||
"import xarray as xr\n", | ||
"\n", | ||
"from searvey import ioc\n", | ||
"\n", | ||
"logging.basicConfig(\n", | ||
" level=20,\n", | ||
" style=\"{\",\n", | ||
" format=\"{asctime:s}; {levelname:8s}; {threadName:23s}; {name:<25s} {lineno:5d}; {message:s}\",\n", | ||
")\n", | ||
"\n", | ||
"logging.getLogger(\"urllib3\").setLevel(30)\n", | ||
"logging.getLogger(\"parso\").setLevel(30)\n", | ||
"\n", | ||
"logger = logging.getLogger(__name__)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3d77b75b-17db-45e7-933d-ea7f79351f28", | ||
"metadata": { | ||
"execution": { | ||
"iopub.execute_input": "2022-06-08T12:43:45.973799Z", | ||
"iopub.status.busy": "2022-06-08T12:43:45.973432Z", | ||
"iopub.status.idle": "2022-06-08T12:43:51.596147Z", | ||
"shell.execute_reply": "2022-06-08T12:43:51.595523Z", | ||
"shell.execute_reply.started": "2022-06-08T12:43:45.973779Z" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Retrieve Station Metadata" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f0cb443c-b8a9-4abc-9bb1-e0c6e262e48b", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"ioc_stations = ioc.get_ioc_stations()\n", | ||
"ioc_stations" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1fabbee2-b165-46a6-b69f-c3bb93972e80", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"figure, axis = plt.subplots(1, 1)\n", | ||
"figure.set_size_inches(12, 12 / 1.61803398875)\n", | ||
"\n", | ||
"countries = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n", | ||
"_ = countries.plot(color='lightgrey', ax=axis, zorder=-1)\n", | ||
"_ = ioc_stations.plot(ax=axis)\n", | ||
"_ = axis.set_title(f'all IOC stations')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "10cf3a7b-8b1b-4b4d-a77e-c3d4f21e743e", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"ioc_stations.columns" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d34d10c6-8354-451d-8580-169e2cc001cf", | ||
"metadata": { | ||
"execution": { | ||
"iopub.execute_input": "2022-06-08T12:50:03.778509Z", | ||
"iopub.status.busy": "2022-06-08T12:50:03.778244Z", | ||
"iopub.status.idle": "2022-06-08T12:50:03.811163Z", | ||
"shell.execute_reply": "2022-06-08T12:50:03.810727Z", | ||
"shell.execute_reply.started": "2022-06-08T12:50:03.778483Z" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Retrieve station metadata from arbitrary polygon" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "85bb38cc-652b-4d7e-9d1a-8fb8edaecc9c", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"east_coast = shapely.geometry.box(-85, 25, -65, 45)\n", | ||
"east_coast\n", | ||
"\n", | ||
"east_stations = ioc.get_ioc_stations(region=east_coast)\n", | ||
"east_stations" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3e19b4f0-665a-40d7-b070-91be9b359229", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"east_stations[~east_stations.contacts.str.contains(\"NOAA\")]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "28065b99-94cd-4182-ba27-95d6cd61b4a3", | ||
"metadata": {}, | ||
"source": [ | ||
"## Retrieve IOC station data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f2499f27-a993-4906-83d5-43374a92bb58", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"east_data = ioc.get_ioc_data(\n", | ||
" ioc_metadata=east_stations,\n", | ||
" endtime=\"2020-05-30\",\n", | ||
" period=3,\n", | ||
")\n", | ||
"east_data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "5cf3a9bb-af44-4935-9c0d-0abc51dffed3", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def drop_all_nan_vars(ds: xr.Dataset) -> xr.Dataset:\n", | ||
" for var in ds.data_vars:\n", | ||
" if ds[var].notnull().sum() == 0:\n", | ||
" ds = ds.drop_vars(var)\n", | ||
" return ds\n", | ||
"\n", | ||
"ds = drop_all_nan_vars(east_data.sel(ioc_code=\"setp1\"))\n", | ||
"ds" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bcf72745-a293-4850-9a79-0191569bd556", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"fix, axes = plt.subplots(1, 1)\n", | ||
"\n", | ||
"_ = ds.prs.plot(ax=axes)\n", | ||
"_ = ds.rad.plot(ax=axes)\n", | ||
"_ = ds.ra2.plot(ax=axes)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "acaf9a46-e5bf-4b52-a73f-05566219bed1", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"ds.where(ds.country == \"Bahamas\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "searvey", | ||
"language": "python", | ||
"name": "searvey" | ||
}, | ||
"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.9.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.