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
  • Country Cutout Open Data Example

Country Cutout Open Data Example¶

This example shows the users how to use earthkit-geo (https://earthkit-geo.readthedocs.io) to retrieve a country cutout using Polytope.

In [ ]:
Copied!
import earthkit
import earthkit.plots
import earthkit.geo.cartography

countries = ["France", "Italy", "Spain"] # List of countries

shapes = earthkit.geo.cartography.country_polygons(countries, resolution=50e6)

request = {     
    "class": "ai",
    "stream" : "oper",
    "type" : "fc",
    "date" : -1,
    "time" : "0000",
    "levtype" : "sfc",
    "expver" : "0001", 
    "model": "aifs-single",
    "domain" : "g",
    "param" : "166/167/169",
    "step" : "0",
    "feature": {
        "type": "polygon",
        "shape": shapes,
    },
}

ds = earthkit.data.from_source("polytope", "ecmwf-mars", request, stream=False, address='polytope.ecmwf.int')
import earthkit import earthkit.plots import earthkit.geo.cartography countries = ["France", "Italy", "Spain"] # List of countries shapes = earthkit.geo.cartography.country_polygons(countries, resolution=50e6) request = { "class": "ai", "stream" : "oper", "type" : "fc", "date" : -1, "time" : "0000", "levtype" : "sfc", "expver" : "0001", "model": "aifs-single", "domain" : "g", "param" : "166/167/169", "step" : "0", "feature": { "type": "polygon", "shape": shapes, }, } ds = earthkit.data.from_source("polytope", "ecmwf-mars", request, stream=False, address='polytope.ecmwf.int')

The collection being accessed is ecmwf-mars. The endpoint being accessed is polytope.ecmwf.int. Earthkit-geo is used to return the shape of the requested countries.

A user can also convert the data to xarray in the following way:

In [2]:
Copied!
xa = ds.to_xarray()
xa
xa = ds.to_xarray() xa
Out[2]:
<xarray.Dataset> Size: 81kB
Dimensions:    (datetimes: 1, number: 1, steps: 1, points: 1444)
Coordinates:
  * datetimes  (datetimes) <U20 80B '2025-02-24T00:00:00Z'
  * number     (number) int64 8B 0
  * steps      (steps) int64 8B 0
  * points     (points) int64 12kB 0 1 2 3 4 5 ... 1438 1439 1440 1441 1442 1443
    x          (points) float64 12kB 27.68 27.96 28.24 ... 50.73 51.01 51.01
    y          (points) float64 12kB 342.0 344.4 343.4 345.9 ... 2.917 2.083 2.5
    z          (points) float64 12kB 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
Data variables:
    10v        (datetimes, number, steps, points) float64 12kB -3.243 ... 7.162
    2t         (datetimes, number, steps, points) float64 12kB 289.4 ... 284.5
    ssrd       (datetimes, number, steps, points) float64 12kB 0.0 0.0 ... 0.0
Attributes:
    class:          ai
    Forecast date:  2025-02-24T00:00:00Z
    domain:         g
    expver:         0102
    levtype:        sfc
    model:          aifs-single
    step:           0
    stream:         oper
    type:           fc
    number:         0
    date:           2025-02-24T00:00:00Z
xarray.Dataset
    • datetimes: 1
    • number: 1
    • steps: 1
    • points: 1444
    • datetimes
      (datetimes)
      <U20
      '2025-02-24T00:00:00Z'
      array(['2025-02-24T00:00:00Z'], dtype='<U20')
    • number
      (number)
      int64
      0
      array([0])
    • steps
      (steps)
      int64
      0
      array([0])
    • points
      (points)
      int64
      0 1 2 3 4 ... 1440 1441 1442 1443
      array([   0,    1,    2, ..., 1441, 1442, 1443])
    • x
      (points)
      float64
      27.68 27.96 28.24 ... 51.01 51.01
      array([27.68148967, 27.96252001, 28.24355034, ..., 50.72597397,
             51.0070042 , 51.0070042 ])
    • y
      (points)
      float64
      342.0 344.4 343.4 ... 2.083 2.5
      array([342.        , 344.375     , 343.4375    , ...,   2.91666667,
               2.08333333,   2.5       ])
    • 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.])
    • 10v
      (datetimes, number, steps, points)
      float64
      -3.243 -2.159 ... 7.671 7.162
      type :
      Parameter
      units :
      m s**-1
      long_name :
      10v
      array([[[[-3.24325562, -2.15927124, -1.68661499, ...,  6.59854126,
                 7.67080688,  7.16201782]]]])
    • 2t
      (datetimes, number, steps, points)
      float64
      289.4 283.7 281.9 ... 284.5 284.5
      type :
      Parameter
      units :
      K
      long_name :
      2t
      array([[[[289.37683105, 283.7322998 , 281.92370605, ..., 284.18347168,
                284.52722168, 284.4744873 ]]]])
    • 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(['2025-02-24T00:00:00Z'], dtype='object', name='datetimes'))
    • number
      PandasIndex
      PandasIndex(Index([0], dtype='int64', name='number'))
    • steps
      PandasIndex
      PandasIndex(Index([0], dtype='int64', name='steps'))
    • points
      PandasIndex
      PandasIndex(Index([   0,    1,    2,    3,    4,    5,    6,    7,    8,    9,
             ...
             1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442, 1443],
            dtype='int64', name='points', length=1444))
  • class :
    ai
    Forecast date :
    2025-02-24T00:00:00Z
    domain :
    g
    expver :
    0102
    levtype :
    sfc
    model :
    aifs-single
    step :
    0
    stream :
    oper
    type :
    fc
    number :
    0
    date :
    2025-02-24T00:00:00Z

Visualise¶

In [3]:
Copied!
chart = earthkit.plots.Map(domain=countries)
chart.point_cloud(xa['2t'], x="y", y="x")
chart.coastlines()
chart.borders()
chart.gridlines()
chart.legend()
chart.show()
chart = earthkit.plots.Map(domain=countries) chart.point_cloud(xa['2t'], x="y", y="x") chart.coastlines() chart.borders() chart.gridlines() chart.legend() chart.show()
No description has been provided for this image
In [ ]:
Copied!


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