Polygon Example¶
In [ ]:
Copied!
import earthkit.data
request = {
"class": "od",
"stream" : "enfo",
"type" : "pf",
"date" : -1, # Note: date must be within the last two days
"time" : "1200",
"levtype" : "sfc",
"expver" : "0001",
"domain" : "g",
"param" : "167/169",
"number" : "1",
"step": "0",
"feature": {
"type": "polygon",
"shape": [[41.870881288,-8.8791360], [41.694339317422646, -8.824238614026456], [40.171924585721314, -8.902386975546364], [38.75694209400925, -9.493088042617785], [38.42424252381525, -9.171674240710018], [38.49907333213173, -8.676525850529856], [37.057269459205145, -8.971873318897366], [37.162874354643776, -7.406745406502978], [38.19776118392036, -6.931663452624974], [38.4280922170291, -7.321584397020473], [39.011852875635526, -6.9787177479519755], [39.66227871551288, -7.5393956904523804], [39.66568774825791, -7.03915852435145], [40.0019453234905, -6.883203763416162], [40.20373392742229, -7.035724907677206], [40.350463990828985, -6.8135246275213035], [41.030499770212515, -6.905947651233703], [41.593647729084154, -6.22847017956974], [41.67712153119277, -6.544984134823352], [41.949682257268876, -6.567927092516641], [41.96960294343674, -7.1747800681640115], [41.88337981339092, -7.196871678410446], [41.81334515396762,-8.156666519264604], [42.14242723772878, -8.205142297350534], [41.870881288,-8.8791360]],
},
}
ds = earthkit.data.from_source("polytope", "ecmwf-mars", request, stream=False, address='polytope.ecmwf.int')
import earthkit.data
request = {
"class": "od",
"stream" : "enfo",
"type" : "pf",
"date" : -1, # Note: date must be within the last two days
"time" : "1200",
"levtype" : "sfc",
"expver" : "0001",
"domain" : "g",
"param" : "167/169",
"number" : "1",
"step": "0",
"feature": {
"type": "polygon",
"shape": [[41.870881288,-8.8791360], [41.694339317422646, -8.824238614026456], [40.171924585721314, -8.902386975546364], [38.75694209400925, -9.493088042617785], [38.42424252381525, -9.171674240710018], [38.49907333213173, -8.676525850529856], [37.057269459205145, -8.971873318897366], [37.162874354643776, -7.406745406502978], [38.19776118392036, -6.931663452624974], [38.4280922170291, -7.321584397020473], [39.011852875635526, -6.9787177479519755], [39.66227871551288, -7.5393956904523804], [39.66568774825791, -7.03915852435145], [40.0019453234905, -6.883203763416162], [40.20373392742229, -7.035724907677206], [40.350463990828985, -6.8135246275213035], [41.030499770212515, -6.905947651233703], [41.593647729084154, -6.22847017956974], [41.67712153119277, -6.544984134823352], [41.949682257268876, -6.567927092516641], [41.96960294343674, -7.1747800681640115], [41.88337981339092, -7.196871678410446], [41.81334515396762,-8.156666519264604], [42.14242723772878, -8.205142297350534], [41.870881288,-8.8791360]],
},
}
ds = earthkit.data.from_source("polytope", "ecmwf-mars", request, stream=False, address='polytope.ecmwf.int')
Convert to xarray¶
In [9]:
Copied!
da = ds.to_xarray()
da
da = ds.to_xarray()
da
Out[9]:
<xarray.Dataset>
Dimensions: (datetimes: 1, number: 1, steps: 1, points: 1093)
Coordinates:
* datetimes (datetimes) <U20 '2024-09-17T12:00:00Z'
* number (number) int64 1
* steps (steps) int64 0
* points (points) int64 0 1 2 3 4 5 6 ... 1087 1088 1089 1090 1091 1092
x (points) float64 37.08 37.08 37.08 37.15 ... 42.0 42.0 42.0 42.07
y (points) float64 351.1 351.2 351.3 351.1 ... 351.6 351.7 351.7
z (points) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
Data variables:
2t (datetimes, number, steps, points) float64 298.7 298.0 ... 297.4
ssrd (datetimes, number, steps, points) float64 0.0 0.0 ... 0.0 0.0
Attributes:
class: od
Forecast date: 2024-09-17T12:00:00Z
domain: g
expver: 0079
levtype: sfc
number: 1
step: 0
stream: enfo
type: pf
date: 2024-09-17T12:00:00ZVisualise data¶
In [10]:
Copied!
da = ds.to_xarray()
import earthkit.plots
chart = earthkit.plots.Map(domain="Portugal")
chart.point_cloud(da['2t'], x="y", y="x")
chart.coastlines()
chart.borders()
chart.gridlines()
chart.title("{variable_name} (number={number})")
chart.legend()
chart.show()
da = ds.to_xarray()
import earthkit.plots
chart = earthkit.plots.Map(domain="Portugal")
chart.point_cloud(da['2t'], x="y", y="x")
chart.coastlines()
chart.borders()
chart.gridlines()
chart.title("{variable_name} (number={number})")
chart.legend()
chart.show()