Debian Codegraph @

docs/source/tutorial.rst

raw ◀ ▶
1 Debian patch touch this file
1 Tutorial
2 ========
3
4 This run-through tutorial is intended to display a variety of methods for combining datasets using the ``kerchunk.combine.MultiZarrtoZarr`` API.
5
6 You can find additional tutorial materials at the `project pythia kerchunk cookbook <https://github.com/ProjectPythia/kerchunk-cookbook>`_.
7
8 Initially we create a pair of single file jsons for two ERA5 variables using ``Kerchunk.hdf.SingleHdf5ToZarr``. This ERA5 dataset is free to access and so it is possible to replicate this workflow on a local machine without credentials.
9
10 Single file JSONs
11 -----------------
12
13 The ``Kerchunk.hdf.SingleHdf5ToZarr`` method is used to create a single ``.json`` reference file for each file url passed to it. Here we use it to create a number of reference files for the ERA5 public dataset on `AWS <https://registry.opendata.aws/ecmwf-era5/>`__. We will compute a number of different times and variables to demonstrate different methods of combining them.
14
15 The Kerchunk package is still in a development phase and so changes frequently. Installing directly from the source code is recommended.
16
17 .. code::
18
19 !pip install git+https://github.com/fsspec/kerchunk
20
21 Here we are considering Netcdf4 files and so use the kerchunk ``hdf`` module. Support for ``fits``, ``grib2``, ``tiff``, ``netCDF3`` and ``zarr`` are available in other kerchunk modules. Alternatively it is also possible to manually create reference jsons for more specific cases. The Earth Big Data `example <https://github.com/fsspec/kerchunk/blob/main/examples/earthbigdata.ipynb>`__ provides a demonstration of this.
22
23 .. code::
24
25 from kerchunk.hdf import SingleHdf5ToZarr
26 import fsspec
27
28 Using fsspec to create a pythonic filesystem, provides a convenient way to manage file urls.
29
30 The ``SingleHdf5ToZarr`` method takes both an ``h5f`` file and a ``url`` as input. The ``h5f`` file can either be a binary Python file-like object or a url, in which case it will be opened using ``fsspec`` and ``storage_options``. The ``url`` input is not used to open the file and is intended to allow the user to compute the reference files on data before it is uploaded to its final storage location. Thus the ``url`` input should be the url of the final file destination and not the current location.
31
32 .. code::
33
34 fs = fsspec.filesystem('s3', anon=True) #S3 file system to manage ERA5 files
35 flist = (fs.glob('s3://era5-pds/2020/*/data/air_pressure_at_mean_sea_level.nc')[:2]
36 + fs.glob('s3://era5-pds/2020/*/data/*sea_surface_temperature.nc')[:2])
37
38 fs2 = fsspec.filesystem('') #local file system to save final jsons to
39
40 from pathlib import Path
41 import os
42 import ujson
43
44 so = dict(mode='rb', anon=True, default_fill_cache=False, default_cache_type='first') # args to fs.open()
45 # default_fill_cache=False avoids caching data in between file chunks to lowers memory usage.
46
47 def gen_json(file_url):
48 with fs.open(file_url, **so) as infile:
49 h5chunks = SingleHdf5ToZarr(infile, file_url, inline_threshold=300)
50 # inline threshold adjusts the Size below which binary blocks are included directly in the output
51 # a higher inline threshold can result in a larger json file but faster loading time
52 variable = file_url.split('/')[-1].split('.')[0]
53 month = file_url.split('/')[2]
54 outf = f'{month}_{variable}.json' #file name to save json to
55 with fs2.open(outf, 'wb') as f:
56 f.write(ujson.dumps(h5chunks.translate()).encode());
57
58 ERA5-pds is located in us-west-2 and so depending on where this computation is taking place the time taken can vary dramatically.
59
60 .. code::
61
62 %%time
63 for file in flist:
64 gen_json(file)
65
66
67 .. parsed-literal::
68
69 CPU times: user 30.4 s, sys: 4.74 s, total: 35.1 s
70 Wall time: 14min 44s
71
72
73 The ``.json`` reference files we have generated can now be used to open virtual datasets through xarray or zarr. It is necessary to specify location of the reference ``json`` files, using the ``target_options`` argument, and the source data using the ``remote_options`` and ``remote_protocol`` arguments. Here specifying that the source data is stored on ``AWS S3`` and can be accessed anonymously.
74
75
76 .. code::
77
78 import xarray as xr
79
80 %%time
81 ds = xr.open_dataset("reference://", engine="zarr", backend_kwargs={
82 "consolidated": False,
83 "storage_options": {"fo": '01_air_pressure_at_mean_sea_level.json', "remote_protocol": "s3","remote_options": {"anon": True}}
84 })
85 print(ds)
86
87
88 .. parsed-literal::
89
90 <xarray.Dataset>
91 Dimensions: (time0: 744, lat: 721, lon: 1440)
92 Coordinates:
93 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
94 * lon (lon) float32 nan 0.25 0.5 ... 359.5 359.8
95 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
96 Data variables:
97 air_pressure_at_mean_sea_level (time0, lat, lon) float32 dask.array<chunksize=(24, 100, 100), meta=np.ndarray>
98 Attributes:
99 institution: ECMWF
100 source: Reanalysis
101 title: ERA5 forecasts
102 CPU times: user 162 ms, sys: 17.4 ms, total: 180 ms
103 Wall time: 235 ms
104
105
106 Combine multiple kerchunked datasets into a single logical aggregate dataset
107 ----------------------------------------------------------------------------
108
109 The ``Kerchunk.combine.MultiZarrtoZarr`` method combines the ``.json`` reference files generated above to create a single virtual dataset, such that one reference file maps to all of the chunks in the individual files.
110
111 .. code::
112
113 from kerchunk.combine import MultiZarrToZarr
114
115 MultiZarrtoZarr provides a number of convenience methods to combine reference files. The simplest is to concatenate along a specified dimension using the ``concat_dims`` argument, ``"Time0"`` in this instance. Variables that should not be concatenated (because they are not a function of the concat coordinates) should be listed in the ``identical_dims`` argument.
116
117 .. code::
118
119 json_list = fs2.glob("*_air_pressure_at_mean_sea_level.json")
120
121 mzz = MultiZarrToZarr(json_list,
122 remote_protocol='s3',
123 remote_options={'anon':True},
124 concat_dims=['time0'],
125 identical_dims = ['lat', 'lon'])
126
127 d = mzz.translate()
128
129 with fs2.open('air_pressure_at_mean_sea_level_combined.json', 'wb') as f:
130 f.write(ujson.dumps(d).encode())
131
132 The reference json we have just generated can now be opened to reveal a single virtual dataset spanning both the input files, with little to no latency.
133
134 .. code::
135
136 %%time
137 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
138 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
139
140
141 .. parsed-literal::
142
143 <xarray.Dataset>
144 Dimensions: (time0: 1440, lat: 721, lon: 1440)
145 Coordinates:
146 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
147 * lon (lon) float32 nan 0.25 0.5 ... 359.5 359.8
148 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
149 Data variables:
150 air_pressure_at_mean_sea_level (time0, lat, lon) float32 ...
151 Attributes:
152 institution: ECMWF
153 source: Reanalysis
154 title: ERA5 forecasts
155 CPU times: user 42.3 ms, sys: 128 µs, total: 42.5 ms
156 Wall time: 40.9 ms
157
158
159 Using coo_map
160 ~~~~~~~~~~~~~
161
162 When the dimension along which we would like to concatenate is not already in the dataset, or when considering datasets from across an ensemble we can use the ``coo_map`` argument to create a new dimension.
163
164 .. code::
165
166 new_dims = ['a' , 'b']
167
168 mzz = MultiZarrToZarr(json_list,
169 remote_protocol='s3',
170 remote_options={'anon':True},
171 coo_map = {'new_dimension':new_dims},
172 concat_dims=['new_dimension'],
173 identical_dims = ['lat', 'lon']
174 )
175
176 d = mzz.translate()
177
178 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
179 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
180
181
182 .. parsed-literal::
183
184 <xarray.Dataset>
185 Dimensions: (new_dimension: 2, time0: 744, lat: 721,
186 lon: 1440)
187 Coordinates:
188 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
189 * lon (lon) float32 nan 0.25 0.5 ... 359.5 359.8
190 * new_dimension (new_dimension) object 'a' 'b'
191 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
192 Data variables:
193 air_pressure_at_mean_sea_level (new_dimension, time0, lat, lon) float32 ...
194 Attributes:
195 institution: ECMWF
196 source: Reanalysis
197 title: ERA5 forecasts
198
199
200 Here by providing a list of literal values to ``coo_map`` we created ``new_dimension``.
201
202 For more complex uses it is also possible to pass in a compiled ``regex`` function which operates on the input file urls to generate a unique variable for each file.
203
204 .. code::
205
206 import re
207 ex = re.compile(r'.*(\d+)_air')
208 print(ex.match(json_list[0]).groups()[0])
209
210 .. parsed-literal::
211
212 '1'
213
214 .. code::
215
216 mzz = MultiZarrToZarr(json_list,
217 remote_protocol='s3',
218 remote_options={'anon':True},
219 coo_map = {'new_dimension':ex},
220 concat_dims=['new_dimension'],
221 identical_dims = ['lat', 'lon']
222 )
223
224 d = mzz.translate()
225
226 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
227 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
228
229
230 .. parsed-literal::
231
232 <xarray.Dataset>
233 Dimensions: (new_dimension: 2, time0: 744, lat: 721,
234 lon: 1440)
235 Coordinates:
236 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
237 * lon (lon) float32 nan 0.25 0.5 ... 359.5 359.8
238 * new_dimension (new_dimension) object '1' '2'
239 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
240 Data variables:
241 air_pressure_at_mean_sea_level (new_dimension, time0, lat, lon) float32 ...
242 Attributes:
243 institution: ECMWF
244 source: Reanalysis
245 title: ERA5 forecasts
246
247 Here the ``new_dimension`` values have been populated by the compiled ``regex`` function ``ex`` which takes the file urls as input.
248
249 To extract time information from file names, a custom function can be defined of the form ``(index, fs, var, fn) -> value`` to generate a valid ``datetime.datetime`` data type, typically using regular expressions. These datetime objects are then used to generate time coordinates through the ``coo_dtypes`` argument in the ``MultiZarrToZarr`` function.
250
251 Here's an example for file names following the pattern ``cgl_TOC_YYYYmmddHHMM_X21Y05_S3A_v1.1.0.json``:
252
253 .. code::
254
255 def fn_to_time(index, fs, var, fn):
256 import re
257 import datetime
258 subst = re.search(r"\d{12}", fn)[0]
259 return datetime.datetime.strptime(subst, '%Y%m%d%H%M')
260
261 mzz = MultiZarrToZarr(sorted(glob.iglob(r'*.json')),
262 remote_protocol='file',
263 coo_map={'time': fn_to_time},
264 coo_dtypes={'time': np.dtype('M8[s]')},
265 concat_dims=['time'],
266 identical_dims=['lat', 'lon'],
267 )
268
269 .. parsed-literal::
270
271 <xarray.Dataset>
272 Dimensions: (time: 4, lat: 3360, lon: 3360)
273 Coordinates:
274 * lat (lat) float64 35.0 35.0 34.99 ... 25.01 25.01 25.0
275 * lon (lon) float64 30.0 30.0 30.01 ... 39.99 39.99 40.0
276 * time (time) datetime64[s] 2022-10-11T07:01:00 ... 2022-10...
277 Data variables: (12/53)
278 AC_process_flag (time, lat, lon) float32 dask.array<chunksize=(1, 168, 168), meta=np.ndarray>
279 Oa02_toc (time, lat, lon) float32 dask.array<chunksize=(1, 168, 168), meta=np.ndarray>
280 ... ...
281 VZA_olci (time, lat, lon) float32 dask.array<chunksize=(1, 168, 168), meta=np.ndarray>
282 Attributes: (12/17)
283 Conventions: CF-1.6
284 archive_facility: vito
285 copyright: Copernicus Service information 2022
286
287 Similarly we can map each file to a new variable using the special ``var`` key in coo_map. Here we use the same ``regex`` function but instead map these as new variables.
288
289 .. code::
290
291 mzz = MultiZarrToZarr(json_list,
292 remote_protocol='s3',
293 remote_options={'anon':True},
294 coo_map = {"var":ex},
295 concat_dims=['time0'],
296 identical_dims = ['lat', 'lon']
297 )
298
299 d = mzz.translate()
300
301 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
302 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
303
304
305 .. parsed-literal::
306
307 <xarray.Dataset>
308 Dimensions: (time0: 1440, lat: 721, lon: 1440)
309 Coordinates:
310 * lat (lat) float32 90.0 89.75 89.5 89.25 ... -89.25 -89.5 -89.75 -90.0
311 * lon (lon) float32 nan 0.25 0.5 0.75 1.0 ... 359.0 359.2 359.5 359.8
312 * time0 (time0) datetime64[ns] 2020-01-01 ... 2020-02-29T23:00:00
313 Data variables:
314 1 (time0, lat, lon) float32 ...
315 2 (time0, lat, lon) float32 ...
316 Attributes:
317 institution: ECMWF
318 source: Reanalysis
319 title: ERA5 forecasts
320
321
322 Another special key in ``coo_map`` is ``attr:``. This allows the user to access values from each dataset's global attributes.
323
324 .. code::
325
326 mzz = MultiZarrToZarr(json_list,
327 remote_protocol='s3',
328 remote_options={'anon':True},
329 coo_map = {"var":"attr:institution"},
330 concat_dims=['time0'],
331 identical_dims = ['lat', 'lon']
332 )
333
334 d = mzz.translate()
335
336 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
337 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
338
339
340 .. parsed-literal::
341
342 <xarray.Dataset>
343 Dimensions: (time0: 1440, lat: 721, lon: 1440)
344 Coordinates:
345 * lat (lat) float32 90.0 89.75 89.5 89.25 ... -89.25 -89.5 -89.75 -90.0
346 * lon (lon) float32 nan 0.25 0.5 0.75 1.0 ... 359.0 359.2 359.5 359.8
347 * time0 (time0) datetime64[ns] 2020-01-01 ... 2020-02-29T23:00:00
348 Data variables:
349 ECMWF (time0, lat, lon) float32 ...
350 Attributes:
351 institution: ECMWF
352 source: Reanalysis
353 title: ERA5 forecasts
354
355
356 The special value ``vattr:{var}:{attr}`` allows access to variable attributes. Here renaming the variable to instead use its short name.
357
358 .. code::
359
360 mzz = MultiZarrToZarr(json_list,
361 remote_protocol='s3',
362 remote_options={'anon':True},
363 coo_map = {"var":"vattr:air_pressure_at_mean_sea_level:shortNameECMWF"},
364 concat_dims=['time0'],
365 identical_dims = ['lat', 'lon']
366 )
367
368 d = mzz.translate()
369
370 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
371 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
372
373
374 .. parsed-literal::
375
376 <xarray.Dataset>
377 Dimensions: (lat: 721, lon: 1440, time0: 1440)
378 Coordinates:
379 * lat (lat) float32 90.0 89.75 89.5 89.25 ... -89.25 -89.5 -89.75 -90.0
380 * lon (lon) float32 nan 0.25 0.5 0.75 1.0 ... 359.0 359.2 359.5 359.8
381 * time0 (time0) datetime64[ns] 2020-01-01 ... 2020-02-29T23:00:00
382 Data variables:
383 msl (time0, lat, lon) float32 ...
384 Attributes:
385 institution: ECMWF
386 source: Reanalysis
387 title: ERA5 forecasts
388
389 There are a number of other special characters for ``coo_map`` documented in the `API reference <https://fsspec.github.io/kerchunk/reference.html#kerchunk.combine.MultiZarrToZarr>`__
390
391
392 Merging variables across jsons
393 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394
395 The ``Kerchunk.combine.merge_vars`` convenience function can be used to merge variables across datasets if we know the coordinates and global file attributes are identical.
396
397 .. code::
398
399 from kerchunk.combine import merge_vars
400
401 json_list = fs2.glob("01_sea_surface_temperature.json") + fs2.glob("01_air_pressure_at_mean_sea_level.json")
402
403 d = merge_vars(json_list)
404
405 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
406 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
407
408
409 .. parsed-literal::
410
411 <xarray.Dataset>
412 Dimensions: (time0: 744, lat: 721, lon: 1440)
413 Coordinates:
414 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
415 * lon (lon) float32 nan 0.25 0.5 ... 359.5 359.8
416 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
417 Data variables:
418 air_pressure_at_mean_sea_level (time0, lat, lon) float32 ...
419 sea_surface_temperature (time0, lat, lon) float32 ...
420 Attributes:
421 institution: ECMWF
422 source: Reanalysis
423 title: ERA5 forecasts
424
425
426 Preprocessing
427 ~~~~~~~~~~~~~
428
429 Pre-process can be used to apply arbitrary functions to the refs item in the input jsons before combining. In this case we use preprocessing to drop the ``air_pressure_at_mean_sea_level`` variable before combining ``sea_surface_temperature`` with a json containing data for the following month.
430
431 .. code::
432
433 def pre_process(refs):
434 for k in list(refs):
435 if k.startswith('air_pressure_at_mean_sea_level'):
436 refs.pop(k)
437 return refs
438
439 json_list = fs2.glob("vars_combined.json") + fs2.glob("02_sea_surface_temperature.json")
440
441 mzz = MultiZarrToZarr(json_list,
442 remote_protocol='s3',
443 remote_options={'anon':True},
444 concat_dims=['time0'],
445 identical_dims = ['lat', 'lon'],
446 preprocess = pre_process)
447
448 d = mzz.translate()
449
450 with fs2.open('sea_surface_temperature_combined.json', 'wb') as f:
451 f.write(ujson.dumps(d).encode())
452
453 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
454 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
455
456
457 .. parsed-literal::
458
459 <xarray.Dataset>
460 Dimensions: (lat: 721, lon: 1440, time0: 696)
461 Coordinates:
462 * lat (lat) float32 90.0 89.75 89.5 ... -89.75 -90.0
463 * lon (lon) float32 nan 0.25 0.5 ... 359.2 359.5 359.8
464 * time0 (time0) datetime64[ns] 2020-02-01 ... 2020-02-29...
465 Data variables:
466 sea_surface_temperature (time0, lat, lon) float32 ...
467 Attributes:
468 institution: ECMWF
469 source: Reanalysis
470 title: ERA5 forecasts
471
472
473 Postprocessing
474 ~~~~~~~~~~~~~~
475
476 Similarly post-process can be used to apply an arbitrary function to the final dictionary before returning. A known issue with this particular dataset is that no fill value has been assigned to the lat and lon coordinates and thus default to 0, here we use post process to change the zarr fill_value attribute by opening the final json as a zarr store.
477
478 Changing the fill_values could also be achieved by editing the final json through string manipulations or even a simple find and replace through an IDE.
479
480 .. code::
481
482 import zarr
483 def modify_fill_value(out):
484 out_ = zarr.open(out)
485 out_.lon.fill_value = -999
486 out_.lat.fill_value = -999
487 return out
488
489 def postprocess(out):
490 out = modify_fill_value(out)
491 return out
492
493 json_list = fs2.glob("air_pressure_at_mean_sea_level_combined.json") + fs2.glob("sea_surface_temperature_combined.json")
494
495 mzz = MultiZarrToZarr(json_list,
496 remote_protocol='s3',
497 remote_options={'anon':True},
498 concat_dims=['time0'],
499 identical_dims = ['lat', 'lon'],
500 postprocess = postprocess)
501
502 d = mzz.translate()
503
504 with fs2.open('combined.json', 'wb') as f:
505 f.write(ujson.dumps(d).encode())
506
507
508 backend_args = {"consolidated": False, "storage_options": {"fo": d, "remote_protocol": "s3","remote_options": {"anon": True}}}
509 print(xr.open_dataset("reference://", engine="zarr", backend_kwargs=backend_args))
510
511
512 .. parsed-literal::
513
514 <xarray.Dataset>
515 Dimensions: (time0: 1440, lat: 721, lon: 1440)
516 Coordinates:
517 * lat (lat) float32 90.0 89.75 ... -89.75 -90.0
518 * lon (lon) float32 0.0 0.25 0.5 ... 359.5 359.8
519 * time0 (time0) datetime64[ns] 2020-01-01 ... 202...
520 Data variables:
521 air_pressure_at_mean_sea_level (time0, lat, lon) float32 ...
522 sea_surface_temperature (time0, lat, lon) float32 ...
523 Attributes:
524 institution: ECMWF
525 source: Reanalysis
526 title: ERA5 forecasts
527
528
529 Using the output
530 ----------------
531
532 To open a previously computed referenced dataset it is not necessary to have kerchunk installed. Only ``fsspec`` to generate the file mapping.
533
534 Here we open a remotely stored reference file that maps to 10 ERA5 variables across a 43 year time span.
535
536 The sidecar file has been compressed using zstd, from the original 1.8GB to 194MB. Opening this virtual dataset requires 7GB of free system memory.
537
538 A smaller file containing only 2 years of data is available at:
539 s3://esip-qhub-public/ecmwf/ERA5_2020_2022_multivar.json.zst
540
541 .. code::
542
543 %%time
544 fs = fsspec.filesystem('reference', fo='s3://esip-qhub-public/ecmwf/ERA5_1979_2022_multivar.json.zst',
545 target_options={'compression': 'zstd', 'anon':True},
546 remote_protocol='s3', remote_options={'anon':True})
547 m = fs.get_mapper('')
548 ds = xr.open_dataset(m, engine='zarr', backend_kwargs={'consolidated':False})
549 print(ds)
550
551
552 .. parsed-literal::
553
554 <xarray.Dataset>
555 Dimensions: (time0: 380568, lat: 721, lon: 1440)
556 Coordinates:
557 * lat (lat) float32 90.0 89.75 ... -90.0
558 * lon (lon) float32 0.0 0.25 ... 359.5 359.8
559 * time0 (time0) datetime64[ns] 1979-01-01 ....
560 Data variables:
561 air_pressure_at_mean_sea_level (time0, lat, lon) float32 ...
562 air_temperature_at_2_metres (time0, lat, lon) float32 ...
563 dew_point_temperature_at_2_metres (time0, lat, lon) float32 ...
564 eastward_wind_at_100_metres (time0, lat, lon) float32 ...
565 eastward_wind_at_10_metres (time0, lat, lon) float32 ...
566 lwe_thickness_of_surface_snow_amount (time0, lat, lon) float32 ...
567 northward_wind_at_100_metres (time0, lat, lon) float32 ...
568 sea_surface_temperature (time0, lat, lon) float32 ...
569 Attributes:
570 institution: ECMWF
571 source: Reanalysis
572 title: ERA5 forecasts
573 CPU times: user 48.8 s, sys: 5.61 s, total: 54.4 s
574 Wall time: 1min 8s
575
576 The above script required to open reference is rather complex. For this reason it is suggested to instead hide the script in an `intake <https://intake.readthedocs.io/en/latest/index.html>`__ catalog such that all that is required to open the dataset is the following:
577
578 .. code::
579
580 import intake
581 catalog = intake.open_catalog('s3://esip-qhub-public/ecmwf/intake_catalog.yml')
582 list(catalog)
583
584
585 .. parsed-literal::
586
587 ['ERA5-Kerchunk-1979-2022', 'ERA5-Kerchunk-2020-2022']
588
589 .. code::
590
591 ds = catalog['ERA5-Kerchunk-1979-2022'].to_dask()
592
593 Multiple different different datasets can be managed in a single intake catalog and so can be used to create a one stop shop containing all datasets available to a group of users.
594
595 Once the referenced dataset is loaded it can be operated on just like any other lazy `xarray <https://docs.xarray.dev/en/stable/>`__ dataset.
596
597 .. code::
598
599 %%time
600 da = ds.sel(time0 = '2021-01-01T00:00:00')
601 da['air_pressure_at_mean_sea_level'].plot()
602
603 .. image:: output_62_2.png
604
605 .. parsed-literal::
606
607 CPU times: user 3.79 s, sys: 382 ms, total: 4.18 s
608 Wall time: 6.22 s
609
610 .. code::
611
612 %%time
613 da = ds.sel(lat = -34).sel(lon = 198)
614 da.air_temperature_at_2_metres.sel(time0 = slice('2000-01-01','2000-12-31')).plot()
615
616 .. image:: output_63_2.png
617
618 .. parsed-literal::
619
620 CPU times: user 9.92 s, sys: 663 ms, total: 10.6 s
621 Wall time: 16.5 s