{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
centreshortNametypeOfLevelleveldataDatedataTimestepRangedataTypenumbergridType
0ecmftisobaricInhPa5002007010112000an0regular_ll
1ecmfzisobaricInhPa5002007010112000an0regular_ll
2ecmftisobaricInhPa8502007010112000an0regular_ll
3ecmfzisobaricInhPa8502007010112000an0regular_ll
\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", "\n", "
globalDomaing
GRIBEditionNumber1
eps0
offsetSection00
section0Length8
totalLength130428
editionNumber1
WMO0
productionStatusOfProcessedData0
section1Length52
wrongPadding0
table2Version128
centreecmf
centreDescriptionEuropean Centre for Medium-Range Weather Forecasts
generatingProcessIdentifier145
gridDefinition255
indicatorOfParameter130
parameterNameTemperature
parameterUnitsK
indicatorOfTypeOfLevelpl
pressureUnitshPa
typeOfLevelECMFisobaricInhPa
typeOfLevelisobaricInhPa
level500
yearOfCentury7
month1
day1
hour12
minute0
second0
unitOfTimeRange1
P10
P20
timeRangeIndicator0
numberIncludedInAverage0
numberMissingFromAveragesOrAccumulations0
centuryOfReferenceTimeOfData21
subCentre0
paramIdECMF130
paramId130
cfNameECMFair_temperature
cfNameair_temperature
unitsECMFK
unitsK
nameECMFTemperature
nameTemperature
decimalScaleFactor0
setLocalDefinition0
optimizeScaleFactor0
dataDate20070101
year2007
dataTime1200
julianDay2454102.0
stepUnits1
stepTypeinstant
stepRange0
startStep0
endStep0
marsParam130.128
validityDate20070101
validityTime1200
validityDateTime2454101.5083333333
deleteLocalDefinition0
localUsePresent1
reservedNeedNotBePresent['']
localDefinitionNumber1
GRIBEXSection1Problem0
marsClassea
marsTypean
marsStreamoper
experimentVersionNumber0001
perturbationNumber0
numberOfForecastsInEnsemble0
padding_local1_100
grib2LocalSectionNumber1
localExtensionPadding
_xNone
section1Padding
shortNameECMFt
shortNamet
cfVarNameECMFt
cfVarNamet
ifsParam130
stepTypeForConversionunknown
md5Section1e4c6d9f0d01b01247d9c57dad662ee30
md5Producted3159ec68703fb0415e15e859b4eb02
paramIdForConversion0
gridDescriptionSectionPresent1
bitmapPresent0
angleSubdivisions1000
section2Length32
radius6367470
numberOfVerticalCoordinateValues0
neitherPresent255
pvlLocation255
dataRepresentationType0
gridDefinitionDescriptionLatitude/Longitude Grid
gridDefinitionTemplateNumber0
Ni360
Nj181
latitudeOfFirstGridPoint90000
latitudeOfFirstGridPointInDegrees90.0
longitudeOfFirstGridPoint0
longitudeOfFirstGridPointInDegrees0.0
resolutionAndComponentFlags128
ijDirectionIncrementGiven1
earthIsOblate0
resolutionAndComponentFlags30
resolutionAndComponentFlags40
uvRelativeToGrid0
resolutionAndComponentFlags60
resolutionAndComponentFlags70
resolutionAndComponentFlags80
latitudeOfLastGridPoint-90000
latitudeOfLastGridPointInDegrees-90.0
longitudeOfLastGridPoint359000
longitudeOfLastGridPointInDegrees359.0
iDirectionIncrement1000
jDirectionIncrement1000
isGridded1
scanningMode0
iScansNegatively0
jScansPositively0
jPointsAreConsecutive0
alternativeRowScanning0
iScansPositively1
jScansNegatively1
scanningMode40
scanningMode50
scanningMode60
scanningMode70
scanningMode80
swapScanningAlternativeRows0
jDirectionIncrementInDegrees1.0
iDirectionIncrementInDegrees1.0
numberOfDataPoints65160
numberOfValues65160
zeros
PVPresent0
padding_sec2_2
PLPresent0
padding_sec2_1
deletePV1
padding_sec2_3
md5Section2d0ccb07e4b36a8911817cc07539cf859
isSpectral0
lengthOfHeaders85
md5Headersb2ff552cc12a4ea08bfbd989ed20c0fb
missingValue9999
tableReference0
section4Length130332
halfByte8
dataFlag8
binaryScaleFactor-10
referenceValue224.05772399902344
referenceValueError1.52587890625e-05
sphericalHarmonics0
complexPacking0
integerPointValues0
additionalFlagPresent0
orderOfSPD2
boustrophedonic0
hideThis0
packingTypegrid_simple
bitsPerValue16
constantFieldHalfByte8
bitMapIndicator255
numberOfCodedValues65160
packingError0.00049591064453125
unpackedError1.52587890625e-05
maximum273.33799743652344
minimum224.05772399902344
average252.5098487718183
standardDeviation13.372886915179645
skewness-0.2209591997514728
kurtosis-1.2738579926507174
isConstant0.0
numberOfMissing0
dataLength16290
changeDecimalPrecision0
decimalPrecision0
bitsPerValueAndRepack16
setPackingTypegrid_simple
scaleValuesBy1.0
offsetValuesBy0.0
gridTyperegular_ll
getNumberOfValues65160
padding_sec4_1
md5Section473097e43c94a4e2947a55799222424c2
section5Length4
77777777
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
edition1
centreecmf
typeOfLevelisobaricInhPa
level500
dataDate20070101
stepRange0
dataTypean
shortNamet
packingTypegrid_simple
gridTyperegular_ll
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
bitmapPresent0
Ni360
Nj181
latitudeOfFirstGridPointInDegrees90.0
longitudeOfFirstGridPointInDegrees0.0
latitudeOfLastGridPointInDegrees-90.0
longitudeOfLastGridPointInDegrees359.0
iScansNegatively0
jScansPositively0
jPointsAreConsecutive0
jDirectionIncrementInDegrees1.0
iDirectionIncrementInDegrees1.0
gridTyperegular_ll
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
domaing
levtypepl
levelist500
date20070101
time1200
step0
paramt
classea
typean
streamoper
expver0001
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
centreecmf
paramId130
unitsK
nameTemperature
shortNamet
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
max273.33799743652344
min224.05772399902344
avg252.5098487718183
sd13.372886915179645
skew-0.2209591997514728
kurt-1.2738579926507174
const0.0
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
dataDate20070101
dataTime1200
stepUnits1
stepTypeinstant
stepRange0
startStep0
endStep0
validityDate20070101
validityTime1200
\n", "
\n", " \n", "\n", "\n", "
\n", "\n", "\n", "\n", "
typeOfLevelisobaricInhPa
level500
\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 }