From 10b7cf24d4d43751db04d9c128092612eae34278 Mon Sep 17 00:00:00 2001
From: amsnyder <asnyder@usgs.gov>
Date: Wed, 17 Jan 2024 12:57:12 -0600
Subject: [PATCH] add code to pull out temporal extent from
 cftime._cftime.DatetimeNoLeap

---
 .../create_collection_from_zarr_conus404-daily.ipynb         | 5 +++++
 .../examples/create_item_from_zarr_conus404-daily.ipynb      | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb b/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb
index 0649a030..e92b5090 100644
--- a/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb
+++ b/workflows/examples/create_collection_from_zarr_conus404-daily.ipynb
@@ -317,6 +317,11 @@
     "# pull out first and last timestamps\n",
     "temporal_extent_lower = pd.Timestamp(ds[dim_names_dict['T']].data.min())\n",
     "temporal_extent_upper = pd.Timestamp(ds[dim_names_dict['T']].data.max())\n",
+    "# if you get an error:\n",
+    "# Cannot convert input [] of type <class 'cftime._cftime.DatetimeNoLeap'> to Timestamp\n",
+    "# use the following instead:\n",
+    "# temporal_extent_lower = pd.Timestamp(ds.indexes[dim_names_dict['T']].to_datetimeindex().min())\n",
+    "# temporal_extent_upper = pd.Timestamp(ds.indexes[dim_names_dict['T']].to_datetimeindex().max())\n",
     "print(f'min: {temporal_extent_lower} \\nmax: {temporal_extent_upper}')\n",
     "# create a temporal extent object\n",
     "temporal_extent = pystac.TemporalExtent(intervals=[[temporal_extent_lower, temporal_extent_upper]])"
diff --git a/workflows/examples/create_item_from_zarr_conus404-daily.ipynb b/workflows/examples/create_item_from_zarr_conus404-daily.ipynb
index 722e28c1..c18ea703 100644
--- a/workflows/examples/create_item_from_zarr_conus404-daily.ipynb
+++ b/workflows/examples/create_item_from_zarr_conus404-daily.ipynb
@@ -339,6 +339,11 @@
     "# pull out first and last timestamps\n",
     "temporal_extent_lower = pd.Timestamp(ds[dim_names_dict['T']].data.min())\n",
     "temporal_extent_upper = pd.Timestamp(ds[dim_names_dict['T']].data.max())\n",
+    "# if you get an error:\n",
+    "# Cannot convert input [] of type <class 'cftime._cftime.DatetimeNoLeap'> to Timestamp\n",
+    "# use the following instead:\n",
+    "# temporal_extent_lower = pd.Timestamp(ds.indexes[dim_names_dict['T']].to_datetimeindex().min())\n",
+    "# temporal_extent_upper = pd.Timestamp(ds.indexes[dim_names_dict['T']].to_datetimeindex().max())\n",
     "print(f'min: {temporal_extent_lower} \\nmax: {temporal_extent_upper}')"
    ]
   },
-- 
GitLab