|
49 | 49 | "outputs": [], |
50 | 50 | "source": [ |
51 | 51 | "# Imports\n", |
52 | | - "from pathlib import Path\n", |
| 52 | + "from __future__ import annotations\n", |
| 53 | + "\n", |
53 | 54 | "import datetime as dt\n", |
| 55 | + "from pathlib import Path\n", |
54 | 56 | "\n", |
55 | 57 | "import dask.dataframe as dd\n", |
56 | 58 | "import icepyx as ipx\n", |
|
60 | 62 | "import xarray as xr\n", |
61 | 63 | "\n", |
62 | 64 | "from nsidc.iceflow import (\n", |
63 | | - " make_iceflow_parquet,\n", |
64 | | - " DatasetSearchParameters,\n", |
65 | 65 | " BoundingBox,\n", |
66 | | - " find_iceflow_data,\n", |
| 66 | + " DatasetSearchParameters,\n", |
| 67 | + " IceflowDataFrame,\n", |
67 | 68 | " download_iceflow_results,\n", |
68 | | - " IceflowDataFrame\n", |
| 69 | + " find_iceflow_data,\n", |
| 70 | + " make_iceflow_parquet,\n", |
69 | 71 | ")" |
70 | 72 | ] |
71 | 73 | }, |
|
90 | 92 | "source": [ |
91 | 93 | "# Constants\n", |
92 | 94 | "\n", |
93 | | - "# All of our data will be downloaded to this location. \n", |
94 | | - "OUTPUT_DIR = Path(\"./downloaded-data/\")\n", |
| 95 | + "# All of our data will be downloaded to this location.\n", |
| 96 | + "OUTPUT_DIR = Path(\"./downloaded-data/\")\n", |
95 | 97 | "\n", |
96 | 98 | "# ICESat2 data products use ITRF2014 (e.g., see https://nsidc.org/data/atl06/versions/6):\n", |
97 | 99 | "# > WGS 84 ellipsoid, ITRF2014 reference frame\n", |
|
100 | 102 | "ICESAT2_ITRF = \"ITRF2014\"\n", |
101 | 103 | "\n", |
102 | 104 | "# This bounding box covers an area near Sermeq Kujalleq (Jakobshavn Isbrae)\n", |
103 | | - "BBOX = BoundingBox(lower_left_lon=-49.149, lower_left_lat=69.186, upper_right_lon=-48.949, upper_right_lat=69.238)\n", |
| 105 | + "BBOX = BoundingBox(\n", |
| 106 | + " lower_left_lon=-49.149,\n", |
| 107 | + " lower_left_lat=69.186,\n", |
| 108 | + " upper_right_lon=-48.949,\n", |
| 109 | + " upper_right_lat=69.238,\n", |
| 110 | + ")\n", |
104 | 111 | "\n", |
105 | 112 | "# Range of dates we want to evaluate\n", |
106 | 113 | "DATE_RANGE = (dt.date(2007, 1, 1), dt.date(2024, 10, 28))" |
|
195 | 202 | "source": [ |
196 | 203 | "iceflow_df = dd.read_parquet(parquet_path)\n", |
197 | 204 | "\n", |
198 | | - "# Ensure that our index is set as a datetime object \n", |
| 205 | + "# Ensure that our index is set as a datetime object\n", |
199 | 206 | "iceflow_df = iceflow_df.reset_index()\n", |
200 | 207 | "iceflow_df[\"utc_datetime\"] = dd.to_datetime(iceflow_df[\"utc_datetime\"])\n", |
201 | 208 | "iceflow_df = iceflow_df.set_index(\"utc_datetime\")\n", |
|
290 | 297 | " reader.vars.append(var_list=[\"h_li\", \"latitude\", \"longitude\"])\n", |
291 | 298 | " ds = reader.load()\n", |
292 | 299 | " datasets.append(ds)\n", |
293 | | - " except:\n", |
| 300 | + " except Exception:\n", |
294 | 301 | " print(f\"{file=} contains an error and will not be read\")\n", |
295 | 302 | " continue\n", |
296 | 303 | "\n", |
|
364 | 371 | "# Drop rows where lat, lon, or elev are missing.\n", |
365 | 372 | "df = df.dropna(subset=[\"latitude\", \"longitude\", \"elevation\"], how=\"any\")\n", |
366 | 373 | "df = df.set_index(\"utc_datetime\")\n", |
367 | | - "# Cast the df as an IceflowDataFrame. \n", |
368 | | - "# The `atl06_df` can now be used with e.g., `iceflow`'s ITRF conversion function \n", |
| 374 | + "# Cast the df as an IceflowDataFrame.\n", |
| 375 | + "# The `atl06_df` can now be used with e.g., `iceflow`'s ITRF conversion function\n", |
369 | 376 | "# to perform plate motion model adjustments if desired.\n", |
370 | 377 | "atl06_df = IceflowDataFrame(df)\n", |
371 | 378 | "atl06_df.head()" |
|
434 | 441 | "\n", |
435 | 442 | "iceflow_df_sampled = iceflow_df_sampled[iceflow_df_sampled.elevation > 0]\n", |
436 | 443 | "\n", |
437 | | - "iceflow_avg = iceflow_df_sampled.resample(\"W\").agg({\n", |
438 | | - " \"elevation\": \"mean\",\n", |
439 | | - " \"dataset\": lambda x: \", \".join(x.astype(\"str\").unique()), \n", |
440 | | - "})\n", |
441 | | - "iceflow_avg = iceflow_avg.replace([np.inf, -np.inf], np.nan) \n", |
| 444 | + "iceflow_avg = iceflow_df_sampled.resample(\"W\").agg(\n", |
| 445 | + " {\n", |
| 446 | + " \"elevation\": \"mean\",\n", |
| 447 | + " \"dataset\": lambda x: \", \".join(x.astype(\"str\").unique()),\n", |
| 448 | + " }\n", |
| 449 | + ")\n", |
| 450 | + "iceflow_avg = iceflow_avg.replace([np.inf, -np.inf], np.nan)\n", |
442 | 451 | "iceflow_avg = iceflow_avg.dropna(how=\"any\")\n", |
443 | 452 | "iceflow_avg = iceflow_avg.compute()\n", |
444 | 453 | "\n", |
|
479 | 488 | "for dataset, marker in iceflow_marker_map.items():\n", |
480 | 489 | " subset = iceflow_avg[iceflow_avg.dataset == dataset]\n", |
481 | 490 | " if subset.elevation.any():\n", |
482 | | - " plt.scatter(subset.index, subset.elevation, marker=marker, label=dataset, linestyle=\"\", color=\"black\")\n", |
| 491 | + " plt.scatter(\n", |
| 492 | + " subset.index,\n", |
| 493 | + " subset.elevation,\n", |
| 494 | + " marker=marker,\n", |
| 495 | + " label=dataset,\n", |
| 496 | + " linestyle=\"\",\n", |
| 497 | + " color=\"black\",\n", |
| 498 | + " )\n", |
483 | 499 | "\n", |
484 | | - "plt.scatter(atl06_avg_df.index, atl06_avg_df.elevation, color=\"black\", marker=\"*\", label=\"ATL06v6\", linestyle=\"\")\n", |
| 500 | + "plt.scatter(\n", |
| 501 | + " atl06_avg_df.index,\n", |
| 502 | + " atl06_avg_df.elevation,\n", |
| 503 | + " color=\"black\",\n", |
| 504 | + " marker=\"*\",\n", |
| 505 | + " label=\"ATL06v6\",\n", |
| 506 | + " linestyle=\"\",\n", |
| 507 | + ")\n", |
485 | 508 | "\n", |
486 | 509 | "plt.xlabel(\"Date\")\n", |
487 | 510 | "plt.ylabel(\"Elevation\")\n", |
|
0 commit comments