Skip to content

Commit 6e160e5

Browse files
Merge pull request #573 from ecmwf/develop
Release 0.12.0
2 parents 38941f3 + cac4dee commit 6e160e5

39 files changed

+1622
-187
lines changed

docs/examples/grib_metadata_object.ipynb

+86-23
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"tags": []
2727
},
2828
"source": [
29-
"We will work with a GRIB file containing 6 messages. First we ensure the example file is available, then read the file with :ref:`from_source() <data-sources-file>`."
29+
"In this notebook we will work with a GRIB file containing 6 messages. First we ensure the example file is available, then read the file with :ref:`from_source() <data-sources-file>`."
3030
]
3131
},
3232
{
@@ -137,7 +137,7 @@
137137
{
138138
"data": {
139139
"text/plain": [
140-
"<earthkit.data.readers.grib.metadata.GribFieldMetadata at 0x294e37ee0>"
140+
"<earthkit.data.readers.grib.metadata.GribFieldMetadata at 0x2aba44130>"
141141
]
142142
},
143143
"execution_count": 3,
@@ -246,21 +246,84 @@
246246
},
247247
"tags": []
248248
},
249+
"outputs": [],
250+
"source": [
251+
"md_copy = md.override()"
252+
]
253+
},
254+
{
255+
"cell_type": "raw",
256+
"id": "1c511db3-f841-4936-a7cb-25dd3e3a1010",
257+
"metadata": {
258+
"editable": true,
259+
"raw_mimetype": "text/restructuredtext",
260+
"slideshow": {
261+
"slide_type": ""
262+
},
263+
"tags": []
264+
},
265+
"source": [
266+
"By default :py:meth:`~data.readers.grib.metadata.GribMetadata.override` is called with the ``headers_only_clone=True`` option to clone a new GRIB handle with all the data values (and some related information) removed. With this the resulting object can be significantly smaller, especially if the data section is large. The downside is that now the value related keys either cannot be accessed or give back wrong values. E.g when using the \"average\" key we get:"
267+
]
268+
},
269+
{
270+
"cell_type": "code",
271+
"execution_count": 6,
272+
"id": "c9ab97f0-40b7-403e-b7c9-6ce16c894d7d",
273+
"metadata": {},
249274
"outputs": [
250275
{
251276
"data": {
252277
"text/plain": [
253-
"<earthkit.data.readers.grib.metadata.StandAloneGribMetadata at 0x294e7cee0>"
278+
"(279.70703560965404, 47485.4296875)"
254279
]
255280
},
256-
"execution_count": 5,
281+
"execution_count": 6,
257282
"metadata": {},
258283
"output_type": "execute_result"
259284
}
260285
],
261286
"source": [
262-
"md_copy = md.override()\n",
263-
"md_copy"
287+
"md[\"average\"], md_copy[\"average\"]"
288+
]
289+
},
290+
{
291+
"cell_type": "markdown",
292+
"id": "fe340c05-ac04-4f7d-8c43-3ed1f415a979",
293+
"metadata": {},
294+
"source": [
295+
"To get a copy without shrinking the GRIB handle use ``headers_only_clone=False``."
296+
]
297+
},
298+
{
299+
"cell_type": "code",
300+
"execution_count": 7,
301+
"id": "a789bb5e-b493-45cd-b7ce-e5cb8b34e125",
302+
"metadata": {},
303+
"outputs": [],
304+
"source": [
305+
"md_copy_full = md.override(headers_only_clone=False)"
306+
]
307+
},
308+
{
309+
"cell_type": "code",
310+
"execution_count": 8,
311+
"id": "3b030549-2a7e-494e-bd46-0a4cd19a09ad",
312+
"metadata": {},
313+
"outputs": [
314+
{
315+
"data": {
316+
"text/plain": [
317+
"279.70703560965404"
318+
]
319+
},
320+
"execution_count": 8,
321+
"metadata": {},
322+
"output_type": "execute_result"
323+
}
324+
],
325+
"source": [
326+
"md_copy_full[\"average\"]"
264327
]
265328
},
266329
{
@@ -294,7 +357,7 @@
294357
},
295358
{
296359
"cell_type": "code",
297-
"execution_count": 6,
360+
"execution_count": 9,
298361
"id": "40c6d232-03de-402b-82bf-8647e8a7bece",
299362
"metadata": {
300363
"editable": true,
@@ -310,7 +373,7 @@
310373
"('z', 850)"
311374
]
312375
},
313-
"execution_count": 6,
376+
"execution_count": 9,
314377
"metadata": {},
315378
"output_type": "execute_result"
316379
}
@@ -336,7 +399,7 @@
336399
},
337400
{
338401
"cell_type": "code",
339-
"execution_count": 7,
402+
"execution_count": 10,
340403
"id": "ef78a3ec-4ea2-4ff5-8c90-e60b5e07e77f",
341404
"metadata": {
342405
"editable": true,
@@ -352,7 +415,7 @@
352415
"('t', 1000)"
353416
]
354417
},
355-
"execution_count": 7,
418+
"execution_count": 10,
356419
"metadata": {},
357420
"output_type": "execute_result"
358421
}
@@ -386,7 +449,7 @@
386449
"tags": []
387450
},
388451
"source": [
389-
"GRIB metadata objects play a part in building new fieldlist from (altered) values and metadata."
452+
"GRIB metadata objects play a part in building new fieldlists from (altered) values and metadata."
390453
]
391454
},
392455
{
@@ -405,7 +468,7 @@
405468
},
406469
{
407470
"cell_type": "code",
408-
"execution_count": 8,
471+
"execution_count": 11,
409472
"id": "cb59ad5f-c48b-4943-984d-3abdf48fda8d",
410473
"metadata": {
411474
"editable": true,
@@ -427,7 +490,7 @@
427490
},
428491
{
429492
"cell_type": "code",
430-
"execution_count": 9,
493+
"execution_count": 12,
431494
"id": "85c32bfb-c929-404f-add9-9adae40418d2",
432495
"metadata": {
433496
"editable": true,
@@ -496,7 +559,7 @@
496559
"0 an 0 regular_ll "
497560
]
498561
},
499-
"execution_count": 9,
562+
"execution_count": 12,
500563
"metadata": {},
501564
"output_type": "execute_result"
502565
}
@@ -520,12 +583,12 @@
520583
}
521584
},
522585
"source": [
523-
"Please note that the resulting :py:class:`~data.sources.array_list.ArrayFieldList` always contains a :py:class:`~data.readers.grib.metadata.RestrictedGribMetadata` object for each field. These objects possess their own GRIB handles, which is ensured by creating a copy with ``override()`` when needed. On top of that metadata access is limited to keys not related to data values. Getting metadata on any other keys will throw an exception. "
586+
"The resulting fieldlist contains an :py:class:`~data.sources.array_list.ArrayField`, which is composed of a numpy array storing the values and a metadata object owning its own GRIB handle with a trimmed down data section. Since the values array is decoupled from the GRIB handle stored in the metadata object, accessing metadata keys related to the data values is forbidden. Getting metadata on these keys will throw an exception. "
524587
]
525588
},
526589
{
527590
"cell_type": "code",
528-
"execution_count": 10,
591+
"execution_count": 13,
529592
"id": "c6fe87ed-ee88-4f4d-a2b6-9401b364e2df",
530593
"metadata": {
531594
"editable": true,
@@ -538,10 +601,10 @@
538601
{
539602
"data": {
540603
"text/plain": [
541-
"<earthkit.data.readers.grib.metadata.RestrictedGribMetadata at 0x294e7dc60>"
604+
"<earthkit.data.readers.grib.metadata.RestrictedGribMetadata at 0x2aba46ec0>"
542605
]
543606
},
544-
"execution_count": 10,
607+
"execution_count": 13,
545608
"metadata": {},
546609
"output_type": "execute_result"
547610
}
@@ -552,7 +615,7 @@
552615
},
553616
{
554617
"cell_type": "code",
555-
"execution_count": 11,
618+
"execution_count": 14,
556619
"id": "27686ac4-9382-4916-ad0e-be96a649d034",
557620
"metadata": {
558621
"editable": true,
@@ -568,7 +631,7 @@
568631
"'Wind speed'"
569632
]
570633
},
571-
"execution_count": 11,
634+
"execution_count": 14,
572635
"metadata": {},
573636
"output_type": "execute_result"
574637
}
@@ -579,7 +642,7 @@
579642
},
580643
{
581644
"cell_type": "code",
582-
"execution_count": 12,
645+
"execution_count": 15,
583646
"id": "dc28fa77-4020-431f-ad37-e480a69f9d7f",
584647
"metadata": {
585648
"editable": true,
@@ -620,7 +683,7 @@
620683
},
621684
{
622685
"cell_type": "code",
623-
"execution_count": 13,
686+
"execution_count": 16,
624687
"id": "8eab3462-3661-4fc1-9d23-8be05dc99cd8",
625688
"metadata": {
626689
"editable": true,
@@ -636,7 +699,7 @@
636699
"7.450183054360252"
637700
]
638701
},
639-
"execution_count": 13,
702+
"execution_count": 16,
640703
"metadata": {},
641704
"output_type": "execute_result"
642705
}

docs/examples/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Miscellaneous
172172
:glob:
173173

174174
settings.ipynb
175+
settings_env_vars.ipynb
175176
cache.ipynb
176177
projection.ipynb
177178
metadata.ipynb

docs/examples/settings.ipynb

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@
7272
"cell_type": "code",
7373
"execution_count": 2,
7474
"id": "c5d47016-6f5b-4cbc-ac15-1d231546ac10",
75-
"metadata": {},
75+
"metadata": {
76+
"editable": true,
77+
"slideshow": {
78+
"slide_type": ""
79+
},
80+
"tags": []
81+
},
7682
"outputs": [],
7783
"source": [
7884
"settings.auto_save_settings = False"

0 commit comments

Comments
 (0)