Skip to content

Commit e82e2ac

Browse files
authored
Merge pull request #33 from u3ks/main
tccas update
2 parents 926c917 + 3b2ec9d commit e82e2ac

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

PRR/TCCAS_v2.ipynb

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"from datetime import datetime\n",
3838
"from shapely.geometry import box, mapping\n",
3939
"from xstac import xarray_to_stac\n",
40+
"from xstac._xstac import build_horizontal_dimension\n",
4041
"import glob\n",
4142
"import json\n",
4243
"import shapely\n",
@@ -153,8 +154,8 @@
153154
" datetime=start_time,\n",
154155
" bbox=bbox,\n",
155156
" 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",
158159
" }\n",
159160
" )\n",
160161
"\n",
@@ -192,7 +193,7 @@
192193
},
193194
{
194195
"cell_type": "code",
195-
"execution_count": null,
196+
"execution_count": 6,
196197
"id": "5bedc1dd",
197198
"metadata": {
198199
"scrolled": true
@@ -263,23 +264,39 @@
263264
"\n",
264265
" if 'lon' in ds.coords:\n",
265266
" x_dim, y_dim = 'lon', 'lat'\n",
266-
" if 'longitude' in ds.coords:\n",
267+
" elif 'longitude' in ds.coords:\n",
267268
" x_dim, y_dim ='longitude', 'latitude'\n",
268269
" elif 'x' in ds.coords:\n",
269270
" x_dim, y_dim = 'x', 'y'\n",
270271
" else:\n",
271272
" 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",
272278
" \n",
273279
" # 3. Generate the STAC Item\n",
274280
" item = xarray_to_stac(\n",
275281
" ds,\n",
276282
" template,\n",
277-
" temporal_dimension=\"time\" if 'time' in ds.variables else False,\n",
283+
" temporal_dimension=time_dim,\n",
278284
" x_dimension=x_dim,\n",
279285
" y_dimension=y_dim, \n",
280286
" reference_system=False\n",
281287
" )\n",
282288
"\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",
283300
" # validate and add the STAC Item to the collection\n",
284301
" item.validate()\n",
285302
"\n",
@@ -646,15 +663,17 @@
646663
"name": "stderr",
647664
"output_type": "stream",
648665
"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",
650667
" 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",
652669
" 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",
654673
" 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",
656675
" 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",
658677
" ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n"
659678
]
660679
}
@@ -1951,11 +1970,13 @@
19511970
"name": "stderr",
19521971
"output_type": "stream",
19531972
"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",
19551976
" 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",
19571978
" 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",
19591980
" ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n"
19601981
]
19611982
}
@@ -3205,15 +3226,17 @@
32053226
"name": "stderr",
32063227
"output_type": "stream",
32073228
"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",
32093230
" 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",
32113232
" 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",
32133236
" 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",
32153238
" 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",
32173240
" ts = (end_time - np.datetime64('1970-01-01T00:00:00Z')) / np.timedelta64(1, 's')\n"
32183241
]
32193242
}
@@ -4214,9 +4237,9 @@
42144237
],
42154238
"metadata": {
42164239
"kernelspec": {
4217-
"display_name": "pangeo",
4240+
"display_name": "Python [conda env:micromamba-pangeo] *",
42184241
"language": "python",
4219-
"name": "python3"
4242+
"name": "conda-env-micromamba-pangeo-py"
42204243
},
42214244
"language_info": {
42224245
"codemirror_mode": {

0 commit comments

Comments
 (0)