{
"cells": [
{
"cell_type": "markdown",
"id": "d1a669e9-8daf-4596-ab77-05bb0a732326",
"metadata": {
"editable": true,
"raw_mimetype": "",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Metadata"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "94327151-7afc-46f1-84b1-07c080d65e9f",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"import earthkit.data as ekd"
]
},
{
"cell_type": "raw",
"id": "d53140b9-a2f7-4226-a650-de61ce6762ad",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"Metadata of the various data formats are represented by :py:class:`~data.core.metadata.Metadata` objects, which are:\n",
"\n",
"- immutable\n",
"- behave like a dict\n",
"- can be updated with the *override()* method creating a new object\n",
"- derived from the abstract Metadata base class"
]
},
{
"cell_type": "markdown",
"id": "42b48cb8-7bc5-4471-83e6-a32d924ca7ff",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## RawMetadata"
]
},
{
"cell_type": "raw",
"id": "0d96ce25-7b3d-4571-b91d-d63be0f62a8a",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"The simplest metadata type is :py:class:`~data.core.metadata.RawMetadata`, which we can create in the same way as a dict:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c0b8a49f-e181-414b-870c-748efa81f711",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"from earthkit.data.core.metadata import RawMetadata\n",
"\n",
"# from dict\n",
"md = RawMetadata({\"shortName\": \"2t\", \"perturbationNumber\": 5})\n",
"\n",
"# from list of key/value pairs\n",
"md = RawMetadata([(\"shortName\", \"2t\"), (\"perturbationNumber\", 5)])\n",
"\n",
"# from keyword arguments \n",
"md = RawMetadata(shortName=\"2t\", perturbationNumber=5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "440a820a-ccb4-4346-81f5-4b9a7b2d67a1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RawMetadata({'shortName': '2t', 'perturbationNumber': 5})"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md"
]
},
{
"cell_type": "markdown",
"id": "9ddacb9a-cb10-42d2-b67e-1e392508b73b",
"metadata": {},
"source": [
"#### Value access"
]
},
{
"cell_type": "raw",
"id": "d10d7315-5eb7-4e03-8c46-e10447389d5a",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"We can get the value for a key using *[]* and :py:meth:`~data.core.metadata.RawMetadata.get` just like for a dict:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "fbc16f06-af69-4c6d-91e0-a6c6f9250d09",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2t\n",
"2t\n"
]
}
],
"source": [
"print(md[\"shortName\"])\n",
"print(md.get(\"shortName\"))"
]
},
{
"cell_type": "markdown",
"id": "485344b9-afb7-401b-abc4-81c645a687ce",
"metadata": {},
"source": [
"When a key is not available [] raises a KeyError."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "063c7576-781c-47bf-b998-7c3df2532c09",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"KeyError: 'nonExistentKey'\n"
]
}
],
"source": [
"try:\n",
" md[\"nonExistentKey\"]\n",
"except KeyError as e:\n",
" print(f\"KeyError: {e}\")"
]
},
{
"cell_type": "raw",
"id": "7d322f02-34ef-47ab-bf67-77503ebf3d5a",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
":py:meth:`~data.core.metadata.RawMetadata.get` can take a default value as a second argument. When the key is not available the default value is returned. If default is not given, it defaults to None, so that this method never raises a KeyError."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a1d2c43f-0b90-4f01-a6c8-f81f5c9d9dea",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"12\n"
]
}
],
"source": [
"print(md.get(\"nonExistentKey\"))\n",
"print(md.get(\"nonExistentKey\", 12))"
]
},
{
"cell_type": "markdown",
"id": "9aa6981a-bbb4-4988-bab8-4cacc654c32d",
"metadata": {},
"source": [
"#### Iteration"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fd9574c9-adb2-4c6d-8b10-281a403b3b42",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['shortName', 'perturbationNumber']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(md.keys())"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "45b9c42b-18d6-4b29-8f50-1e72e07f1663",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"shortName: 2t\n",
"perturbationNumber: 5\n"
]
}
],
"source": [
"for k,v in md.items():\n",
" print(f\"{k}: {v}\")"
]
},
{
"cell_type": "markdown",
"id": "c0758e40-2544-4866-b10e-d8a89838c31e",
"metadata": {},
"source": [
"#### Override"
]
},
{
"cell_type": "raw",
"id": "67ef7d14-131a-4de4-ba38-b630e9e9dd82",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"The metadata object is immutable but we can use :py:meth:`~data.core.metadata.RawMetadata.override` to create a new object with a modified content:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5cd1240f-e3e0-420a-babc-b2233c7d0c55",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"md1 = md.override({\"shortName\": \"2d\", \"step\": 6})"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e566d9ae-f491-42c9-bc82-9986e82800c1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RawMetadata({'shortName': '2d', 'perturbationNumber': 5, 'step': 6})"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md1"
]
},
{
"cell_type": "markdown",
"id": "3c6ebe6f-c598-4a6b-a755-b8fc4a9ae6a1",
"metadata": {},
"source": [
"The original metadata object did not change:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "fae4ae6c-7fe3-4d58-98f3-127262e2357e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RawMetadata({'shortName': '2t', 'perturbationNumber': 5})"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md"
]
},
{
"cell_type": "markdown",
"id": "44275c78-9a94-402f-a6a9-629f14bf325b",
"metadata": {},
"source": [
"## GribMetadata"
]
},
{
"cell_type": "markdown",
"id": "cbb338e2-e1ed-4bd3-bd36-74518ff89323",
"metadata": {},
"source": [
"For this exercise we read a GRIB file containing 4 messages:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "88c0ec56-9d8c-4b4d-b660-24b2495d13ec",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" centre | \n",
" shortName | \n",
" typeOfLevel | \n",
" level | \n",
" dataDate | \n",
" dataTime | \n",
" stepRange | \n",
" dataType | \n",
" number | \n",
" gridType | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" ecmf | \n",
" t | \n",
" isobaricInhPa | \n",
" 500 | \n",
" 20070101 | \n",
" 1200 | \n",
" 0 | \n",
" an | \n",
" 0 | \n",
" regular_ll | \n",
"
\n",
" \n",
" | 1 | \n",
" ecmf | \n",
" z | \n",
" isobaricInhPa | \n",
" 500 | \n",
" 20070101 | \n",
" 1200 | \n",
" 0 | \n",
" an | \n",
" 0 | \n",
" regular_ll | \n",
"
\n",
" \n",
" | 2 | \n",
" ecmf | \n",
" t | \n",
" isobaricInhPa | \n",
" 850 | \n",
" 20070101 | \n",
" 1200 | \n",
" 0 | \n",
" an | \n",
" 0 | \n",
" regular_ll | \n",
"
\n",
" \n",
" | 3 | \n",
" ecmf | \n",
" z | \n",
" isobaricInhPa | \n",
" 850 | \n",
" 20070101 | \n",
" 1200 | \n",
" 0 | \n",
" an | \n",
" 0 | \n",
" regular_ll | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" centre shortName typeOfLevel level dataDate dataTime stepRange \\\n",
"0 ecmf t isobaricInhPa 500 20070101 1200 0 \n",
"1 ecmf z isobaricInhPa 500 20070101 1200 0 \n",
"2 ecmf t isobaricInhPa 850 20070101 1200 0 \n",
"3 ecmf z isobaricInhPa 850 20070101 1200 0 \n",
"\n",
" dataType number gridType \n",
"0 an 0 regular_ll \n",
"1 an 0 regular_ll \n",
"2 an 0 regular_ll \n",
"3 an 0 regular_ll "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ekd.download_example_file(\"test4.grib\")\n",
"ds = ekd.from_source(\"file\", \"test4.grib\")\n",
"ds.ls()"
]
},
{
"cell_type": "raw",
"id": "9c3850ea-1ac6-4d0f-8c3d-5c1b6375208b",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"We cannot create GRIB metadata object from a dict or :py:class:`~data.core.metadata.RawMetadata`, but can get it from a GRIB field. The resulting :py:class:`~data.readers.grib.metadata.GribMetadata` instance will store a reference to the ecCodes handle of its parent field."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "d9e78ce1-a8af-4635-8fb3-8b8c3d486710",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"md = ds[0].metadata()"
]
},
{
"cell_type": "raw",
"id": "9b98cfb0-a283-4ab3-9471-d805ed01eb70",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
":py:class:`~data.readers.grib.metadata.GribMetadata` works like a dict:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "05a8b857-e3d5-40a6-8201-adafe0239c74",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t\n",
"t\n",
"None\n",
"12\n"
]
}
],
"source": [
"print(md[\"shortName\"])\n",
"print(md.get(\"shortName\"))\n",
"print(md.get(\"nonExistentKey\"))\n",
"print(md.get(\"nonExistentKey\", 12))"
]
},
{
"cell_type": "raw",
"id": "8bd7cd30-9c59-44e3-a845-a6f41dff9236",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"However, it is also aware of the :xref:`eccodes_namespace`\\s, when we use :py:meth:`~data.readers.grib.metadata.GribMetadata.as_namespace` or :py:meth:`~data.readers.grib.metadata.GribMetadata.dump`. "
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f3c0c9da-0c41-4c39-8094-b2b8a50f1680",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'typeOfLevel': 'isobaricInhPa', 'level': 500}"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md.as_namespace(\"vertical\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "6fcf977a-f1e5-44ba-8d0b-549c018b3551",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"GribFieldMetadata
\n",
"\n",
"
\n",
"\n",
"
\n",
"
\n",
"\n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| globalDomain | g |
| GRIBEditionNumber | 1 |
| eps | 0 |
| offsetSection0 | 0 |
| section0Length | 8 |
| totalLength | 130428 |
| editionNumber | 1 |
| WMO | 0 |
| productionStatusOfProcessedData | 0 |
| section1Length | 52 |
| wrongPadding | 0 |
| table2Version | 128 |
| centre | ecmf |
| centreDescription | European Centre for Medium-Range Weather Forecasts |
| generatingProcessIdentifier | 145 |
| gridDefinition | 255 |
| indicatorOfParameter | 130 |
| parameterName | Temperature |
| parameterUnits | K |
| indicatorOfTypeOfLevel | pl |
| pressureUnits | hPa |
| typeOfLevelECMF | isobaricInhPa |
| typeOfLevel | isobaricInhPa |
| level | 500 |
| yearOfCentury | 7 |
| month | 1 |
| day | 1 |
| hour | 12 |
| minute | 0 |
| second | 0 |
| unitOfTimeRange | 1 |
| P1 | 0 |
| P2 | 0 |
| timeRangeIndicator | 0 |
| numberIncludedInAverage | 0 |
| numberMissingFromAveragesOrAccumulations | 0 |
| centuryOfReferenceTimeOfData | 21 |
| subCentre | 0 |
| paramIdECMF | 130 |
| paramId | 130 |
| cfNameECMF | air_temperature |
| cfName | air_temperature |
| unitsECMF | K |
| units | K |
| nameECMF | Temperature |
| name | Temperature |
| decimalScaleFactor | 0 |
| setLocalDefinition | 0 |
| optimizeScaleFactor | 0 |
| dataDate | 20070101 |
| year | 2007 |
| dataTime | 1200 |
| julianDay | 2454102.0 |
| stepUnits | 1 |
| stepType | instant |
| stepRange | 0 |
| startStep | 0 |
| endStep | 0 |
| marsParam | 130.128 |
| validityDate | 20070101 |
| validityTime | 1200 |
| validityDateTime | 2454101.5083333333 |
| deleteLocalDefinition | 0 |
| localUsePresent | 1 |
| reservedNeedNotBePresent | [''] |
| localDefinitionNumber | 1 |
| GRIBEXSection1Problem | 0 |
| marsClass | ea |
| marsType | an |
| marsStream | oper |
| experimentVersionNumber | 0001 |
| perturbationNumber | 0 |
| numberOfForecastsInEnsemble | 0 |
| padding_local1_1 | 00 |
| grib2LocalSectionNumber | 1 |
| localExtensionPadding | |
| _x | None |
| section1Padding | |
| shortNameECMF | t |
| shortName | t |
| cfVarNameECMF | t |
| cfVarName | t |
| ifsParam | 130 |
| stepTypeForConversion | unknown |
| md5Section1 | e4c6d9f0d01b01247d9c57dad662ee30 |
| md5Product | ed3159ec68703fb0415e15e859b4eb02 |
| paramIdForConversion | 0 |
| gridDescriptionSectionPresent | 1 |
| bitmapPresent | 0 |
| angleSubdivisions | 1000 |
| section2Length | 32 |
| radius | 6367470 |
| numberOfVerticalCoordinateValues | 0 |
| neitherPresent | 255 |
| pvlLocation | 255 |
| dataRepresentationType | 0 |
| gridDefinitionDescription | Latitude/Longitude Grid |
| gridDefinitionTemplateNumber | 0 |
| Ni | 360 |
| Nj | 181 |
| latitudeOfFirstGridPoint | 90000 |
| latitudeOfFirstGridPointInDegrees | 90.0 |
| longitudeOfFirstGridPoint | 0 |
| longitudeOfFirstGridPointInDegrees | 0.0 |
| resolutionAndComponentFlags | 128 |
| ijDirectionIncrementGiven | 1 |
| earthIsOblate | 0 |
| resolutionAndComponentFlags3 | 0 |
| resolutionAndComponentFlags4 | 0 |
| uvRelativeToGrid | 0 |
| resolutionAndComponentFlags6 | 0 |
| resolutionAndComponentFlags7 | 0 |
| resolutionAndComponentFlags8 | 0 |
| latitudeOfLastGridPoint | -90000 |
| latitudeOfLastGridPointInDegrees | -90.0 |
| longitudeOfLastGridPoint | 359000 |
| longitudeOfLastGridPointInDegrees | 359.0 |
| iDirectionIncrement | 1000 |
| jDirectionIncrement | 1000 |
| isGridded | 1 |
| scanningMode | 0 |
| iScansNegatively | 0 |
| jScansPositively | 0 |
| jPointsAreConsecutive | 0 |
| alternativeRowScanning | 0 |
| iScansPositively | 1 |
| jScansNegatively | 1 |
| scanningMode4 | 0 |
| scanningMode5 | 0 |
| scanningMode6 | 0 |
| scanningMode7 | 0 |
| scanningMode8 | 0 |
| swapScanningAlternativeRows | 0 |
| jDirectionIncrementInDegrees | 1.0 |
| iDirectionIncrementInDegrees | 1.0 |
| numberOfDataPoints | 65160 |
| numberOfValues | 65160 |
| zeros | |
| PVPresent | 0 |
| padding_sec2_2 | |
| PLPresent | 0 |
| padding_sec2_1 | |
| deletePV | 1 |
| padding_sec2_3 | |
| md5Section2 | d0ccb07e4b36a8911817cc07539cf859 |
| isSpectral | 0 |
| lengthOfHeaders | 85 |
| md5Headers | b2ff552cc12a4ea08bfbd989ed20c0fb |
| missingValue | 9999 |
| tableReference | 0 |
| section4Length | 130332 |
| halfByte | 8 |
| dataFlag | 8 |
| binaryScaleFactor | -10 |
| referenceValue | 224.05772399902344 |
| referenceValueError | 1.52587890625e-05 |
| sphericalHarmonics | 0 |
| complexPacking | 0 |
| integerPointValues | 0 |
| additionalFlagPresent | 0 |
| orderOfSPD | 2 |
| boustrophedonic | 0 |
| hideThis | 0 |
| packingType | grid_simple |
| bitsPerValue | 16 |
| constantFieldHalfByte | 8 |
| bitMapIndicator | 255 |
| numberOfCodedValues | 65160 |
| packingError | 0.00049591064453125 |
| unpackedError | 1.52587890625e-05 |
| maximum | 273.33799743652344 |
| minimum | 224.05772399902344 |
| average | 252.5098487718183 |
| standardDeviation | 13.372886915179645 |
| skewness | -0.2209591997514728 |
| kurtosis | -1.2738579926507174 |
| isConstant | 0.0 |
| numberOfMissing | 0 |
| dataLength | 16290 |
| changeDecimalPrecision | 0 |
| decimalPrecision | 0 |
| bitsPerValueAndRepack | 16 |
| setPackingType | grid_simple |
| scaleValuesBy | 1.0 |
| offsetValuesBy | 0.0 |
| gridType | regular_ll |
| getNumberOfValues | 65160 |
| padding_sec4_1 | |
| md5Section4 | 73097e43c94a4e2947a55799222424c2 |
| section5Length | 4 |
| 7777 | 7777 |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| edition | 1 |
| centre | ecmf |
| typeOfLevel | isobaricInhPa |
| level | 500 |
| dataDate | 20070101 |
| stepRange | 0 |
| dataType | an |
| shortName | t |
| packingType | grid_simple |
| gridType | regular_ll |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| bitmapPresent | 0 |
| Ni | 360 |
| Nj | 181 |
| latitudeOfFirstGridPointInDegrees | 90.0 |
| longitudeOfFirstGridPointInDegrees | 0.0 |
| latitudeOfLastGridPointInDegrees | -90.0 |
| longitudeOfLastGridPointInDegrees | 359.0 |
| iScansNegatively | 0 |
| jScansPositively | 0 |
| jPointsAreConsecutive | 0 |
| jDirectionIncrementInDegrees | 1.0 |
| iDirectionIncrementInDegrees | 1.0 |
| gridType | regular_ll |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| domain | g |
| levtype | pl |
| levelist | 500 |
| date | 20070101 |
| time | 1200 |
| step | 0 |
| param | t |
| class | ea |
| type | an |
| stream | oper |
| expver | 0001 |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| centre | ecmf |
| paramId | 130 |
| units | K |
| name | Temperature |
| shortName | t |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| max | 273.33799743652344 |
| min | 224.05772399902344 |
| avg | 252.5098487718183 |
| sd | 13.372886915179645 |
| skew | -0.2209591997514728 |
| kurt | -1.2738579926507174 |
| const | 0.0 |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| dataDate | 20070101 |
| dataTime | 1200 |
| stepUnits | 1 |
| stepType | instant |
| stepRange | 0 |
| startStep | 0 |
| endStep | 0 |
| validityDate | 20070101 |
| validityTime | 1200 |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
"| typeOfLevel | isobaricInhPa |
| level | 500 |
\n",
"
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
\n",
"\n",
"
\n",
" "
],
"text/plain": [
"{'default': {'globalDomain': 'g',\n",
" 'GRIBEditionNumber': 1,\n",
" 'eps': 0,\n",
" 'offsetSection0': 0,\n",
" 'section0Length': 8,\n",
" 'totalLength': 130428,\n",
" 'editionNumber': 1,\n",
" 'WMO': 0,\n",
" 'productionStatusOfProcessedData': 0,\n",
" 'section1Length': 52,\n",
" 'wrongPadding': 0,\n",
" 'table2Version': 128,\n",
" 'centre': 'ecmf',\n",
" 'centreDescription': 'European Centre for Medium-Range Weather Forecasts',\n",
" 'generatingProcessIdentifier': 145,\n",
" 'gridDefinition': 255,\n",
" 'indicatorOfParameter': 130,\n",
" 'parameterName': 'Temperature',\n",
" 'parameterUnits': 'K',\n",
" 'indicatorOfTypeOfLevel': 'pl',\n",
" 'pressureUnits': 'hPa',\n",
" 'typeOfLevelECMF': 'isobaricInhPa',\n",
" 'typeOfLevel': 'isobaricInhPa',\n",
" 'level': 500,\n",
" 'yearOfCentury': 7,\n",
" 'month': 1,\n",
" 'day': 1,\n",
" 'hour': 12,\n",
" 'minute': 0,\n",
" 'second': 0,\n",
" 'unitOfTimeRange': 1,\n",
" 'P1': 0,\n",
" 'P2': 0,\n",
" 'timeRangeIndicator': 0,\n",
" 'numberIncludedInAverage': 0,\n",
" 'numberMissingFromAveragesOrAccumulations': 0,\n",
" 'centuryOfReferenceTimeOfData': 21,\n",
" 'subCentre': 0,\n",
" 'paramIdECMF': '130',\n",
" 'paramId': 130,\n",
" 'cfNameECMF': 'air_temperature',\n",
" 'cfName': 'air_temperature',\n",
" 'unitsECMF': 'K',\n",
" 'units': 'K',\n",
" 'nameECMF': 'Temperature',\n",
" 'name': 'Temperature',\n",
" 'decimalScaleFactor': 0,\n",
" 'setLocalDefinition': 0,\n",
" 'optimizeScaleFactor': 0,\n",
" 'dataDate': 20070101,\n",
" 'year': 2007,\n",
" 'dataTime': 1200,\n",
" 'julianDay': 2454102.0,\n",
" 'stepUnits': 1,\n",
" 'stepType': 'instant',\n",
" 'stepRange': '0',\n",
" 'startStep': 0,\n",
" 'endStep': 0,\n",
" 'marsParam': '130.128',\n",
" 'validityDate': 20070101,\n",
" 'validityTime': 1200,\n",
" 'validityDateTime': 2454101.5083333333,\n",
" 'deleteLocalDefinition': 0,\n",
" 'localUsePresent': 1,\n",
" 'reservedNeedNotBePresent': [''],\n",
" 'localDefinitionNumber': 1,\n",
" 'GRIBEXSection1Problem': 0,\n",
" 'marsClass': 'ea',\n",
" 'marsType': 'an',\n",
" 'marsStream': 'oper',\n",
" 'experimentVersionNumber': '0001',\n",
" 'perturbationNumber': 0,\n",
" 'numberOfForecastsInEnsemble': 0,\n",
" 'padding_local1_1': '00',\n",
" 'grib2LocalSectionNumber': 1,\n",
" 'localExtensionPadding': '',\n",
" '_x': None,\n",
" 'section1Padding': '',\n",
" 'shortNameECMF': 't',\n",
" 'shortName': 't',\n",
" 'cfVarNameECMF': 't',\n",
" 'cfVarName': 't',\n",
" 'ifsParam': 130,\n",
" 'stepTypeForConversion': 'unknown',\n",
" 'md5Section1': 'e4c6d9f0d01b01247d9c57dad662ee30',\n",
" 'md5Product': 'ed3159ec68703fb0415e15e859b4eb02',\n",
" 'paramIdForConversion': 0,\n",
" 'gridDescriptionSectionPresent': 1,\n",
" 'bitmapPresent': 0,\n",
" 'angleSubdivisions': 1000,\n",
" 'section2Length': 32,\n",
" 'radius': 6367470,\n",
" 'numberOfVerticalCoordinateValues': 0,\n",
" 'neitherPresent': 255,\n",
" 'pvlLocation': 255,\n",
" 'dataRepresentationType': 0,\n",
" 'gridDefinitionDescription': 'Latitude/Longitude Grid',\n",
" 'gridDefinitionTemplateNumber': 0,\n",
" 'Ni': 360,\n",
" 'Nj': 181,\n",
" 'latitudeOfFirstGridPoint': 90000,\n",
" 'latitudeOfFirstGridPointInDegrees': 90.0,\n",
" 'longitudeOfFirstGridPoint': 0,\n",
" 'longitudeOfFirstGridPointInDegrees': 0.0,\n",
" 'resolutionAndComponentFlags': 128,\n",
" 'ijDirectionIncrementGiven': 1,\n",
" 'earthIsOblate': 0,\n",
" 'resolutionAndComponentFlags3': 0,\n",
" 'resolutionAndComponentFlags4': 0,\n",
" 'uvRelativeToGrid': 0,\n",
" 'resolutionAndComponentFlags6': 0,\n",
" 'resolutionAndComponentFlags7': 0,\n",
" 'resolutionAndComponentFlags8': 0,\n",
" 'latitudeOfLastGridPoint': -90000,\n",
" 'latitudeOfLastGridPointInDegrees': -90.0,\n",
" 'longitudeOfLastGridPoint': 359000,\n",
" 'longitudeOfLastGridPointInDegrees': 359.0,\n",
" 'iDirectionIncrement': 1000,\n",
" 'jDirectionIncrement': 1000,\n",
" 'isGridded': 1,\n",
" 'scanningMode': 0,\n",
" 'iScansNegatively': 0,\n",
" 'jScansPositively': 0,\n",
" 'jPointsAreConsecutive': 0,\n",
" 'alternativeRowScanning': 0,\n",
" 'iScansPositively': 1,\n",
" 'jScansNegatively': 1,\n",
" 'scanningMode4': 0,\n",
" 'scanningMode5': 0,\n",
" 'scanningMode6': 0,\n",
" 'scanningMode7': 0,\n",
" 'scanningMode8': 0,\n",
" 'swapScanningAlternativeRows': 0,\n",
" 'jDirectionIncrementInDegrees': 1.0,\n",
" 'iDirectionIncrementInDegrees': 1.0,\n",
" 'numberOfDataPoints': 65160,\n",
" 'numberOfValues': 65160,\n",
" 'zeros': '',\n",
" 'PVPresent': 0,\n",
" 'padding_sec2_2': '',\n",
" 'PLPresent': 0,\n",
" 'padding_sec2_1': '',\n",
" 'deletePV': '1',\n",
" 'padding_sec2_3': '',\n",
" 'md5Section2': 'd0ccb07e4b36a8911817cc07539cf859',\n",
" 'isSpectral': 0,\n",
" 'lengthOfHeaders': 85,\n",
" 'md5Headers': 'b2ff552cc12a4ea08bfbd989ed20c0fb',\n",
" 'missingValue': 9999,\n",
" 'tableReference': 0,\n",
" 'section4Length': 130332,\n",
" 'halfByte': 8,\n",
" 'dataFlag': 8,\n",
" 'binaryScaleFactor': -10,\n",
" 'referenceValue': 224.05772399902344,\n",
" 'referenceValueError': 1.52587890625e-05,\n",
" 'sphericalHarmonics': 0,\n",
" 'complexPacking': 0,\n",
" 'integerPointValues': 0,\n",
" 'additionalFlagPresent': 0,\n",
" 'orderOfSPD': 2,\n",
" 'boustrophedonic': 0,\n",
" 'hideThis': 0,\n",
" 'packingType': 'grid_simple',\n",
" 'bitsPerValue': 16,\n",
" 'constantFieldHalfByte': 8,\n",
" 'bitMapIndicator': 255,\n",
" 'numberOfCodedValues': 65160,\n",
" 'packingError': 0.00049591064453125,\n",
" 'unpackedError': 1.52587890625e-05,\n",
" 'maximum': 273.33799743652344,\n",
" 'minimum': 224.05772399902344,\n",
" 'average': 252.5098487718183,\n",
" 'standardDeviation': 13.372886915179645,\n",
" 'skewness': -0.2209591997514728,\n",
" 'kurtosis': -1.2738579926507174,\n",
" 'isConstant': 0.0,\n",
" 'numberOfMissing': 0,\n",
" 'dataLength': 16290,\n",
" 'changeDecimalPrecision': 0,\n",
" 'decimalPrecision': 0,\n",
" 'bitsPerValueAndRepack': 16,\n",
" 'setPackingType': 'grid_simple',\n",
" 'scaleValuesBy': 1.0,\n",
" 'offsetValuesBy': 0.0,\n",
" 'gridType': 'regular_ll',\n",
" 'getNumberOfValues': 65160,\n",
" 'padding_sec4_1': '',\n",
" 'md5Section4': '73097e43c94a4e2947a55799222424c2',\n",
" 'section5Length': 4,\n",
" '7777': '7777'},\n",
" 'ls': {'edition': 1,\n",
" 'centre': 'ecmf',\n",
" 'typeOfLevel': 'isobaricInhPa',\n",
" 'level': 500,\n",
" 'dataDate': 20070101,\n",
" 'stepRange': '0',\n",
" 'dataType': 'an',\n",
" 'shortName': 't',\n",
" 'packingType': 'grid_simple',\n",
" 'gridType': 'regular_ll'},\n",
" 'geography': {'bitmapPresent': 0,\n",
" 'Ni': 360,\n",
" 'Nj': 181,\n",
" 'latitudeOfFirstGridPointInDegrees': 90.0,\n",
" 'longitudeOfFirstGridPointInDegrees': 0.0,\n",
" 'latitudeOfLastGridPointInDegrees': -90.0,\n",
" 'longitudeOfLastGridPointInDegrees': 359.0,\n",
" 'iScansNegatively': 0,\n",
" 'jScansPositively': 0,\n",
" 'jPointsAreConsecutive': 0,\n",
" 'jDirectionIncrementInDegrees': 1.0,\n",
" 'iDirectionIncrementInDegrees': 1.0,\n",
" 'gridType': 'regular_ll'},\n",
" 'mars': {'domain': 'g',\n",
" 'levtype': 'pl',\n",
" 'levelist': 500,\n",
" 'date': 20070101,\n",
" 'time': 1200,\n",
" 'step': 0,\n",
" 'param': 't',\n",
" 'class': 'ea',\n",
" 'type': 'an',\n",
" 'stream': 'oper',\n",
" 'expver': '0001'},\n",
" 'parameter': {'centre': 'ecmf',\n",
" 'paramId': 130,\n",
" 'units': 'K',\n",
" 'name': 'Temperature',\n",
" 'shortName': 't'},\n",
" 'statistics': {'max': 273.33799743652344,\n",
" 'min': 224.05772399902344,\n",
" 'avg': 252.5098487718183,\n",
" 'sd': 13.372886915179645,\n",
" 'skew': -0.2209591997514728,\n",
" 'kurt': -1.2738579926507174,\n",
" 'const': 0.0},\n",
" 'time': {'dataDate': 20070101,\n",
" 'dataTime': 1200,\n",
" 'stepUnits': 1,\n",
" 'stepType': 'instant',\n",
" 'stepRange': '0',\n",
" 'startStep': 0,\n",
" 'endStep': 0,\n",
" 'validityDate': 20070101,\n",
" 'validityTime': 1200},\n",
" 'vertical': {'typeOfLevel': 'isobaricInhPa', 'level': 500}}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md.dump()"
]
},
{
"cell_type": "raw",
"id": "07b127e2-3401-44a7-9e83-5feb2e116b79",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"When we call :py:meth:`~data.readers.grib.metadata.GribMetadata.override` the new ecCodes handle is cloned and updated then added to the resulting object. The original metadata will not change."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "ac4195c6-9473-4db2-8747-38ddc5205a34",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"500\n",
"850\n"
]
}
],
"source": [
"md1 = md.override(level=850)\n",
"print(md.get(\"level\"))\n",
"print(md1.get(\"level\"))"
]
},
{
"cell_type": "markdown",
"id": "b0dec726-be53-4fb0-b06d-7ca572e2655f",
"metadata": {},
"source": [
"Naturally, md1 still works when md is released:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "23d7a755-b46c-4b68-b5f1-e5c016e0f260",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"850"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"md = None\n",
"md1[\"level\"]"
]
},
{
"cell_type": "raw",
"id": "dc74c7bc-e6c7-4fad-970c-9471e03c1a39",
"metadata": {
"editable": true,
"raw_mimetype": "text/restructuredtext",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
":py:meth:`~data.readers.grib.metadata.GribMetadata.override` also works with other Metadata objects:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "3ea5c463-e17e-4cce-9bd8-a10df6b58589",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"700\n",
"pt\n"
]
}
],
"source": [
"raw_md = RawMetadata(level=700, shortName=\"pt\")\n",
"md2 = md1.override(raw_md)\n",
"print(md2.get(\"level\"))\n",
"print(md2.get(\"shortName\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6baea78-3c27-452e-81c7-262e481a5c58",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "dev_ecc",
"language": "python",
"name": "dev_ecc"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}