diff --git a/PRR/TCCAS_v2.ipynb b/PRR/TCCAS_v2.ipynb index 8422f4e..1536759 100644 --- a/PRR/TCCAS_v2.ipynb +++ b/PRR/TCCAS_v2.ipynb @@ -37,6 +37,7 @@ "from datetime import datetime\n", "from shapely.geometry import box, mapping\n", "from xstac import xarray_to_stac\n", + "from xstac._xstac import build_horizontal_dimension\n", "import glob\n", "import json\n", "import shapely\n", @@ -153,8 +154,8 @@ " datetime=start_time,\n", " bbox=bbox,\n", " properties= {\n", - " \"license\": \"CC-BY-4.0\",\n", - " \"description\": ' Regional and Site-level model forcing Data Sets for Sodankylä and Lapland region, part of the TCCAS project.',\n", + " \"license\": \"AGPL-3.0\",\n", + " \"description\": ' Regional and Site-level model forcing Data Sets, part of the TCCAS project.',\n", " }\n", " )\n", "\n", @@ -192,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "5bedc1dd", "metadata": { "scrolled": true @@ -263,23 +264,39 @@ "\n", " if 'lon' in ds.coords:\n", " x_dim, y_dim = 'lon', 'lat'\n", - " if 'longitude' in ds.coords:\n", + " elif 'longitude' in ds.coords:\n", " x_dim, y_dim ='longitude', 'latitude'\n", " elif 'x' in ds.coords:\n", " x_dim, y_dim = 'x', 'y'\n", " else:\n", " x_dim, y_dim = False, False\n", + "\n", + " if 'time' in ds.coords:\n", + " time_dim = \"time\"\n", + " else:\n", + " time_dim = False\n", " \n", " # 3. Generate the STAC Item\n", " item = xarray_to_stac(\n", " ds,\n", " template,\n", - " temporal_dimension=\"time\" if 'time' in ds.variables else False,\n", + " temporal_dimension=time_dim,\n", " x_dimension=x_dim,\n", " y_dimension=y_dim, \n", " reference_system=False\n", " )\n", "\n", + " if x_dim is False:\n", + " # add the multiple dimensions\n", + " dims = item.properties['cube:dimensions']\n", + " for d in list(ds.coords):\n", + " r = build_horizontal_dimension(ds, d, None, None, None, None, False).to_dict()\n", + " r['type'] = \"auxiliary\"\n", + " for k, v in r.copy().items():\n", + " if v is None:\n", + " del r[k]\n", + " dims[d] = r\n", + "\n", " # validate and add the STAC Item to the collection\n", " item.validate()\n", "\n", @@ -646,15 +663,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:8: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.\n", + "/tmp/ipykernel_25579/4202889447.py:6: FutureWarning: In a future version, xarray will not decode the variable 'SCANTIME' into a timedelta64 dtype based on the presence of a timedelta-like 'units' attribute by default. Instead it will rely on the presence of a timedelta64 'dtype' attribute, which is now xarray's default way of encoding timedelta64 values.\n", + "To continue decoding into a timedelta64 dtype, either set `decode_timedelta=True` when opening this dataset, or add the attribute `dtype='timedelta64[ns]'` to this variable on disk.\n", + "To opt-in to future behavior, set `decode_timedelta=False`.\n", " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" ] } @@ -1951,11 +1970,13 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_119170/4235652563.py:8: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.\n", + "/tmp/ipykernel_25579/4202889447.py:6: FutureWarning: In a future version, xarray will not decode the variable 'SCANTIME' into a timedelta64 dtype based on the presence of a timedelta-like 'units' attribute by default. Instead it will rely on the presence of a timedelta64 'dtype' attribute, which is now xarray's default way of encoding timedelta64 values.\n", + "To continue decoding into a timedelta64 dtype, either set `decode_timedelta=True` when opening this dataset, or add the attribute `dtype='timedelta64[ns]'` to this variable on disk.\n", + "To opt-in to future behavior, set `decode_timedelta=False`.\n", " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" ] } @@ -3205,15 +3226,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:8: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.\n", + "/tmp/ipykernel_25579/4202889447.py:6: FutureWarning: In a future version, xarray will not decode the variable 'SCANTIME' into a timedelta64 dtype based on the presence of a timedelta-like 'units' attribute by default. Instead it will rely on the presence of a timedelta64 'dtype' attribute, which is now xarray's default way of encoding timedelta64 values.\n", + "To continue decoding into a timedelta64 dtype, either set `decode_timedelta=True` when opening this dataset, or add the attribute `dtype='timedelta64[ns]'` to this variable on disk.\n", + "To opt-in to future behavior, set `decode_timedelta=False`.\n", " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" ] } @@ -4214,9 +4237,9 @@ ], "metadata": { "kernelspec": { - "display_name": "pangeo", + "display_name": "Python [conda env:micromamba-pangeo] *", "language": "python", - "name": "python3" + "name": "conda-env-micromamba-pangeo-py" }, "language_info": { "codemirror_mode": {