Skip to content

Commit af63f17

Browse files
clean up imports in example docs
1 parent 9193ffe commit af63f17

File tree

7 files changed

+95
-86
lines changed

7 files changed

+95
-86
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ uv.lock
99
# build files
1010
**/*.egg-info
1111
**/__pycache__
12-
**/build
12+
**/build
13+
**/.ipynb_checkpoints/

cdippy/nchashes.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33

44

55
class NcHashes:
6-
"""
7-
A class that checks for changes to datasets since by reading the online list of historic netCDF file hashes.
8-
"""
6+
"""Methods for working with the online list of historic nc file hashes."""
97

108
hashes_url = "http://cdip.ucsd.edu/data_access/metadata/wavecdf_by_datemod.txt"
119
new_hashes = {}
1210

13-
def __init__(self):
14-
"""
15-
Args:
16-
hash_file_location (str, optional): A path to the location to store the local copy of HASH.pkl. Defaults to the current directory.
17-
"""
18-
self.load_hash_table()
11+
def __init__(self, hash_file_location=""):
12+
self.hash_pkl = hash_file_location + "/HASH.pkl"
1913

2014
def load_hash_table(self):
2115
lines = url_utils.read_url(self.hashes_url).strip().split("\n")
@@ -27,14 +21,17 @@ def load_hash_table(self):
2721
continue
2822
self.new_hashes[fields[0]] = fields[6]
2923

30-
def compare_hash_tables(self) -> list:
31-
"""
32-
Compare the current in-memory list of files, loaded by `load_hash_table` to the list saved in HASH.pkl and return a list of stations that are new or have changed.
24+
def get_last_deployment(self, stn: str) -> str:
25+
"""Returns the last deployment string, e.g. 'd03'."""
26+
last_deployment = "d00"
27+
for name in self.new_hashes:
28+
if name[0:5] == stn and name[5:7] == "_d" and last_deployment < name[6:9]:
29+
last_deployment = name[6:9]
30+
return last_deployment
3331

34-
Returns:
35-
changed ([str]): A list of nc files that have changed or are since HASH.pkl was last saved.
36-
"""
37-
old_hashes = self._get_old_hashes()
32+
def compare_hash_tables(self) -> list:
33+
"""Return a list of nc files that have changed or are new."""
34+
old_hashes = self.get_old_hashes()
3835
changed = []
3936
if old_hashes:
4037
if len(self.new_hashes) == 0:

cdippy/ndbc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ def get_wmo_id(
4545
ids = cdip_utils.pkl_load(pkl_fl)
4646
if stn in ids:
4747
return ids[stn]
48-
return None
48+
else:
49+
return None

cdippy/stndata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def get_series(
269269
self.force_64bands = force_64bands
270270

271271
self.set_request_info(start, end, vrs, pub_set, apply_mask)
272+
print(self.deploy_num)
272273

273274
if prefix == "xyz" and self.deploy_num is None:
274275
return self.__merge_xyz_request()

docs/examples/cdippy-boxplot.ipynb

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

docs/examples/cdippy-compendium.ipynb

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

docs/examples/cdippy-quality-control.ipynb

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,23 @@
2828
"cell_type": "code",
2929
"execution_count": 1,
3030
"metadata": {},
31-
"outputs": [],
31+
"outputs": [
32+
{
33+
"ename": "FileNotFoundError",
34+
"evalue": "[Errno 2] No such file or directory: 'pyproject.toml'",
35+
"output_type": "error",
36+
"traceback": [
37+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
38+
"\u001b[31mFileNotFoundError\u001b[39m Traceback (most recent call last)",
39+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 10\u001b[39m\n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcalendar\u001b[39;00m\n\u001b[32m 9\u001b[39m \u001b[38;5;66;03m# CDIP imports\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m10\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\n\u001b[32m 11\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mstndata\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m StnData\n",
40+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniconda/base/envs/cdippy/lib/python3.13/site-packages/cdippy/__init__.py:2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# import public top-level modules\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m cdipnc, nchashes, ncstats, ndbc, plotting, spectra, stndata\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# import plots library for backward compatibility\u001b[39;00m\n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m plots \u001b[38;5;28;01mas\u001b[39;00m plots \u001b[38;5;66;03m# noqa: F401\u001b[39;00m\n",
41+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniconda/base/envs/cdippy/lib/python3.13/site-packages/cdippy/cdipnc.py:11\u001b[39m\n\u001b[32m 8\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumbers\u001b[39;00m\n\u001b[32m 9\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mbisect\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m bisect_left, bisect_right\n\u001b[32m---> \u001b[39m\u001b[32m11\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mndbc\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mndbc\u001b[39;00m\n\u001b[32m 12\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcu\u001b[39;00m\n\u001b[32m 13\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01murls\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01muu\u001b[39;00m\n",
42+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniconda/base/envs/cdippy/lib/python3.13/site-packages/cdippy/ndbc.py:6\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mos\u001b[39;00m\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mdatetime\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m datetime, timezone\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01murls\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01muu\u001b[39;00m\n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcdippy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutils\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcu\u001b[39;00m\n\u001b[32m 9\u001b[39m sos_base = \u001b[33m\"\u001b[39m\u001b[33mhttps://sdf.ndbc.noaa.gov/sos/server.php\u001b[39m\u001b[33m\"\u001b[39m\n",
43+
"\u001b[36mFile \u001b[39m\u001b[32m/opt/homebrew/Caskroom/miniconda/base/envs/cdippy/lib/python3.13/site-packages/cdippy/utils/urls.py:8\u001b[39m\n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01murllib\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m request, error\n\u001b[32m 6\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mxml\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01metree\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mElementTree\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mET\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m8\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpyproject.toml\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mrb\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[32m 9\u001b[39m pyproject = tomllib.load(f)\n\u001b[32m 11\u001b[39m version = pyproject[\u001b[33m\"\u001b[39m\u001b[33mproject\u001b[39m\u001b[33m\"\u001b[39m][\u001b[33m\"\u001b[39m\u001b[33mversion\u001b[39m\u001b[33m\"\u001b[39m]\n",
44+
"\u001b[31mFileNotFoundError\u001b[39m: [Errno 2] No such file or directory: 'pyproject.toml'"
45+
]
46+
}
47+
],
3248
"source": [
3349
"import netCDF4\n",
3450
"import numpy as np\n",
@@ -87,16 +103,20 @@
87103
"metadata": {},
88104
"outputs": [
89105
{
90-
"name": "stdout",
91-
"output_type": "stream",
92-
"text": [
93-
"ASTORIA CANYON, OR BUOY - 179p1\n"
106+
"ename": "NameError",
107+
"evalue": "name 'StnData' is not defined",
108+
"output_type": "error",
109+
"traceback": [
110+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
111+
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
112+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m##- Get Station Dataset object\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m stn_data = \u001b[43mStnData\u001b[49m(stn)\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m##- Get metadata (i.e. information about individual deployments)\u001b[39;00m\n\u001b[32m 5\u001b[39m meta = stn_data.get_stn_meta()\n",
113+
"\u001b[31mNameError\u001b[39m: name 'StnData' is not defined"
94114
]
95115
}
96116
],
97117
"source": [
98118
"##- Get Station Dataset object\n",
99-
"stn_data = cdippy.stndata.StnData(stn)\n",
119+
"stn_data = StnData(stn)\n",
100120
"\n",
101121
"##- Get metadata (i.e. information about individual deployments)\n",
102122
"meta = stn_data.get_stn_meta()\n",
@@ -129,24 +149,13 @@
129149
},
130150
{
131151
"cell_type": "code",
132-
"execution_count": 9,
152+
"execution_count": null,
133153
"metadata": {},
134-
"outputs": [
135-
{
136-
"data": {
137-
"text/plain": [
138-
"dict_keys(['waveTime', 'waveDp', 'waveHs', 'waveTp'])"
139-
]
140-
},
141-
"execution_count": 9,
142-
"metadata": {},
143-
"output_type": "execute_result"
144-
}
145-
],
154+
"outputs": [],
146155
"source": [
147156
"##- Use CDIPPY to convert input start/end date strings to datetime objects\n",
148-
"start = cdippy.utils.cdip_datetime(sdate)\n",
149-
"end = cdippy.utils.cdip_datetime(edate)\n",
157+
"start = cdippy.utils.utils.cdip_datetime(sdate)\n",
158+
"end = cdippy.utils.utils.cdip_datetime(edate)\n",
150159
"\n",
151160
"##- Grab default data using 'get_series' function, will mask out all non-public data\n",
152161
"data = stn_data.get_series(start, end, params)\n",
@@ -365,7 +374,7 @@
365374
"name": "python",
366375
"nbconvert_exporter": "python",
367376
"pygments_lexer": "ipython3",
368-
"version": "3.13.2"
377+
"version": "3.13.5"
369378
}
370379
},
371380
"nbformat": 4,

0 commit comments

Comments
 (0)