|
37 | 37 | "from datetime import datetime\n", |
38 | 38 | "from shapely.geometry import box, mapping\n", |
39 | 39 | "from xstac import xarray_to_stac\n", |
| 40 | + "from xstac._xstac import build_horizontal_dimension\n", |
40 | 41 | "import glob\n", |
41 | 42 | "import json\n", |
42 | 43 | "import shapely\n", |
|
153 | 154 | " datetime=start_time,\n", |
154 | 155 | " bbox=bbox,\n", |
155 | 156 | " properties= {\n", |
156 | | - " \"license\": \"CC-BY-4.0\",\n", |
157 | | - " \"description\": ' Regional and Site-level model forcing Data Sets for Sodankylä and Lapland region, part of the TCCAS project.',\n", |
| 157 | + " \"license\": \"AGPL-3.0\",\n", |
| 158 | + " \"description\": ' Regional and Site-level model forcing Data Sets, part of the TCCAS project.',\n", |
158 | 159 | " }\n", |
159 | 160 | " )\n", |
160 | 161 | "\n", |
|
192 | 193 | }, |
193 | 194 | { |
194 | 195 | "cell_type": "code", |
195 | | - "execution_count": null, |
| 196 | + "execution_count": 6, |
196 | 197 | "id": "5bedc1dd", |
197 | 198 | "metadata": { |
198 | 199 | "scrolled": true |
|
263 | 264 | "\n", |
264 | 265 | " if 'lon' in ds.coords:\n", |
265 | 266 | " x_dim, y_dim = 'lon', 'lat'\n", |
266 | | - " if 'longitude' in ds.coords:\n", |
| 267 | + " elif 'longitude' in ds.coords:\n", |
267 | 268 | " x_dim, y_dim ='longitude', 'latitude'\n", |
268 | 269 | " elif 'x' in ds.coords:\n", |
269 | 270 | " x_dim, y_dim = 'x', 'y'\n", |
270 | 271 | " else:\n", |
271 | 272 | " x_dim, y_dim = False, False\n", |
| 273 | + "\n", |
| 274 | + " if 'time' in ds.coords:\n", |
| 275 | + " time_dim = \"time\"\n", |
| 276 | + " else:\n", |
| 277 | + " time_dim = False\n", |
272 | 278 | " \n", |
273 | 279 | " # 3. Generate the STAC Item\n", |
274 | 280 | " item = xarray_to_stac(\n", |
275 | 281 | " ds,\n", |
276 | 282 | " template,\n", |
277 | | - " temporal_dimension=\"time\" if 'time' in ds.variables else False,\n", |
| 283 | + " temporal_dimension=time_dim,\n", |
278 | 284 | " x_dimension=x_dim,\n", |
279 | 285 | " y_dimension=y_dim, \n", |
280 | 286 | " reference_system=False\n", |
281 | 287 | " )\n", |
282 | 288 | "\n", |
| 289 | + " if x_dim is False:\n", |
| 290 | + " # add the multiple dimensions\n", |
| 291 | + " dims = item.properties['cube:dimensions']\n", |
| 292 | + " for d in list(ds.coords):\n", |
| 293 | + " r = build_horizontal_dimension(ds, d, None, None, None, None, False).to_dict()\n", |
| 294 | + " r['type'] = \"auxiliary\"\n", |
| 295 | + " for k, v in r.copy().items():\n", |
| 296 | + " if v is None:\n", |
| 297 | + " del r[k]\n", |
| 298 | + " dims[d] = r\n", |
| 299 | + "\n", |
283 | 300 | " # validate and add the STAC Item to the collection\n", |
284 | 301 | " item.validate()\n", |
285 | 302 | "\n", |
|
646 | 663 | "name": "stderr", |
647 | 664 | "output_type": "stream", |
648 | 665 | "text": [ |
649 | | - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 666 | + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
650 | 667 | " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
651 | | - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 668 | + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
652 | 669 | " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
653 | | - "/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", |
| 670 | + "/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", |
| 671 | + "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", |
| 672 | + "To opt-in to future behavior, set `decode_timedelta=False`.\n", |
654 | 673 | " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", |
655 | | - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 674 | + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
656 | 675 | " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
657 | | - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 676 | + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
658 | 677 | " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" |
659 | 678 | ] |
660 | 679 | } |
|
1951 | 1970 | "name": "stderr", |
1952 | 1971 | "output_type": "stream", |
1953 | 1972 | "text": [ |
1954 | | - "/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", |
| 1973 | + "/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", |
| 1974 | + "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", |
| 1975 | + "To opt-in to future behavior, set `decode_timedelta=False`.\n", |
1955 | 1976 | " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", |
1956 | | - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 1977 | + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
1957 | 1978 | " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
1958 | | - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 1979 | + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
1959 | 1980 | " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" |
1960 | 1981 | ] |
1961 | 1982 | } |
|
3205 | 3226 | "name": "stderr", |
3206 | 3227 | "output_type": "stream", |
3207 | 3228 | "text": [ |
3208 | | - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 3229 | + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
3209 | 3230 | " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
3210 | | - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 3231 | + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
3211 | 3232 | " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
3212 | | - "/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", |
| 3233 | + "/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", |
| 3234 | + "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", |
| 3235 | + "To opt-in to future behavior, set `decode_timedelta=False`.\n", |
3213 | 3236 | " ds = xr.open_dataset(root_url + dataset_filepath + '#mode=bytes')\n", |
3214 | | - "/tmp/ipykernel_119170/4235652563.py:12: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 3237 | + "/tmp/ipykernel_25579/4202889447.py:10: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
3215 | 3238 | " ts = (start_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n", |
3216 | | - "/tmp/ipykernel_119170/4235652563.py:16: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
| 3239 | + "/tmp/ipykernel_25579/4202889447.py:14: UserWarning: no explicit representation of timezones available for np.datetime64\n", |
3217 | 3240 | " ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n" |
3218 | 3241 | ] |
3219 | 3242 | } |
|
4214 | 4237 | ], |
4215 | 4238 | "metadata": { |
4216 | 4239 | "kernelspec": { |
4217 | | - "display_name": "pangeo", |
| 4240 | + "display_name": "Python [conda env:micromamba-pangeo] *", |
4218 | 4241 | "language": "python", |
4219 | | - "name": "python3" |
| 4242 | + "name": "conda-env-micromamba-pangeo-py" |
4220 | 4243 | }, |
4221 | 4244 | "language_info": { |
4222 | 4245 | "codemirror_mode": { |
|
0 commit comments