Skip to content

Commit

Permalink
ioc: Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pmav99 committed Jun 23, 2022
1 parent 97510f1 commit 29938c0
Show file tree
Hide file tree
Showing 10 changed files with 26,351 additions and 11 deletions.
233 changes: 233 additions & 0 deletions examples/IOC_data.ipynb
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
}
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ geopandas = "^0.10"
typepigeon = "^1"
xarray = "^2022.3"
Shapely = "^1.8"
limits = "^2.6"
tqdm = "^4.64"
html5lib = "^1.1"
lxml = "^4.9"
more-itertools = "^8.0"

[tool.poetry.dev-dependencies]
ipykernel = "*"
Expand All @@ -56,6 +61,7 @@ pytest-recording = "^0.12.0"
types-requests = "^2.26"
sphinx = '*'
sphinx-rtd-theme = '*'
importlib-metadata = "^4.11.4"

[tool.poetry.extras]
linting = ["mypy", "prospector"]
Expand All @@ -70,6 +76,11 @@ target-version = ['py39']
minversion = "7.0"
addopts = "-ra --verbose --showlocals --tb=short --cov=searvey --cov-report term-missing"
testpaths = ["tests"]
log_cli = true
filterwarnings = [
'ignore:distutils Version classes are deprecated. Use packaging.version instead:DeprecationWarning',
]


[tool.mypy]
python_version = "3.9"
Expand Down
Loading

0 comments on commit 29938c0

Please sign in to comment.