Polytope
  • Home
  • Installation
  • Quick Start
  • Data Portfolio

Full Fields

  • Full Fields

Features

  • Overview
  • Time Series
  • Vertical Profile
  • Polygon
  • Bounding Box
  • Trajectory
  • Circle
  • Position

Examples

  • Examples
Polytope
  • Polygon Example

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:00Z
xarray.Dataset
    • datetimes: 1
    • number: 1
    • steps: 1
    • points: 1093
    • datetimes
      (datetimes)
      <U20
      '2024-09-17T12:00:00Z'
      array(['2024-09-17T12:00:00Z'], dtype='<U20')
    • number
      (number)
      int64
      1
      array([1])
    • steps
      (steps)
      int64
      0
      array([0])
    • points
      (points)
      int64
      0 1 2 3 4 ... 1089 1090 1091 1092
      array([   0,    1,    2, ..., 1090, 1091, 1092])
    • x
      (points)
      float64
      37.08 37.08 37.08 ... 42.0 42.07
      array([37.08260023, 37.08260023, 37.08260023, ..., 42.00351395,
             42.00351395, 42.07381272])
    • y
      (points)
      float64
      351.1 351.2 351.3 ... 351.7 351.7
      array([351.08322325, 351.20211361, 351.32100396, ..., 351.61572052,
             351.74672489, 351.73469388])
    • z
      (points)
      float64
      0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
      array([0., 0., 0., ..., 0., 0., 0.])
    • 2t
      (datetimes, number, steps, points)
      float64
      298.7 298.0 292.3 ... 296.3 297.4
      type :
      Parameter
      units :
      K
      long_name :
      2t
      array([[[[298.66398621, 297.95890808, 292.26359558, ..., 298.64445496,
                296.25968933, 297.35929871]]]])
    • ssrd
      (datetimes, number, steps, points)
      float64
      0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
      type :
      Parameter
      units :
      J m**-2
      long_name :
      ssrd
      array([[[[0., 0., 0., ..., 0., 0., 0.]]]])
    • datetimes
      PandasIndex
      PandasIndex(Index(['2024-09-17T12:00:00Z'], dtype='object', name='datetimes'))
    • number
      PandasIndex
      PandasIndex(Int64Index([1], dtype='int64', name='number'))
    • steps
      PandasIndex
      PandasIndex(Int64Index([0], dtype='int64', name='steps'))
    • points
      PandasIndex
      PandasIndex(Int64Index([   0,    1,    2,    3,    4,    5,    6,    7,    8,    9,
                  ...
                  1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092],
                 dtype='int64', name='points', length=1093))
  • 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:00Z

Visualise 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()
No description has been provided for this image

Built with MkDocs using a theme provided by Read the Docs.