Using GeoTIFF data

This example uses a small GeoTIFF file containing 3 bands. With from_source() we read this data into a fieldlist with one field per band.

[1]:
import earthkit.data as ekd

ds_in = ekd.from_source("sample", "multi_band.tif")

Xarray

[2]:
ds = ds_in.to_xarray()
[3]:
ds
[3]:
<xarray.Dataset> Size: 1MB
Dimensions:      (x: 315, y: 294)
Coordinates:
  * x            (x) float64 3kB 3.68e+05 3.681e+05 ... 3.839e+05 3.84e+05
  * y            (y) float64 2kB 5.632e+06 5.632e+06 ... 5.616e+06 5.616e+06
    spatial_ref  int64 8B 0
Data variables:
    band_1       (y, x) float32 370kB ...
    band_2       (y, x) float32 370kB ...
    band_3       (y, x) float32 370kB ...
Attributes:
    TIFFTAG_XRESOLUTION:     96
    TIFFTAG_YRESOLUTION:     96
    TIFFTAG_RESOLUTIONUNIT:  2 (pixels/inch)
    AREA_OR_POINT:           Area

Each band is loaded into its own variable and masking and scaling is applied by default. Values from the bands are therefore returned as floats.

[4]:
ds.dtypes
[4]:
Frozen({'band_1': dtype('float32'), 'band_2': dtype('float32'), 'band_3': dtype('float32')})

To obtain a dataset without this type conversion applied, specify mask_and_scale=False explicitly.

[5]:
ds_in.to_xarray(mask_and_scale=False).dtypes
[5]:
Frozen({'band_1': dtype('uint8'), 'band_2': dtype('uint8'), 'band_3': dtype('uint8')})

Fieldlist

[6]:
ds = ds_in.to_fieldlist()
[7]:
ds.ls()
[7]:
parameter.variable time.valid_datetime time.base_datetime time.step vertical.level vertical.level_type ensemble.member geography.grid_type
0 band_1 None None None None unknown None None
1 band_2 None None None None unknown None None
2 band_3 None None None None unknown None None
[8]:
ds[0].shape
[8]:
(294, 315)
[9]:
ds[0].values[:5]
[9]:
array([217., 217., 217., 217., 217.], dtype=float32)
[10]:
ds[0].geography.latlons()
[10]:
(array([[7.12620136, 7.12692213, 7.12764289, ..., 7.35110235, 7.35182325,
         7.35254416],
        [7.12622095, 7.12694171, 7.12766246, ..., 7.35111959, 7.35184048,
         7.35256138],
        [7.12624053, 7.12696128, 7.12768203, ..., 7.35113682, 7.35185771,
         7.3525786 ],
        ...,
        [7.13187772, 7.13259631, 7.13331489, ..., 7.35609821, 7.35681693,
         7.35753565],
        [7.13189715, 7.13261573, 7.1333343 , ..., 7.35611531, 7.35683402,
         7.35755274],
        [7.13191657, 7.13263514, 7.13335372, ..., 7.3561324 , 7.35685111,
         7.35756982]], shape=(294, 315)),
 array([[50.82441594, 50.82442752, 50.82443909, ..., 50.82781176,
         50.82782195, 50.82783213],
        [50.8239268 , 50.82393838, 50.82394995, ..., 50.82732256,
         50.82733275, 50.82734293],
        [50.82343766, 50.82344924, 50.82346081, ..., 50.82683336,
         50.82684355, 50.82685373],
        ...,
        [50.68207406, 50.68208557, 50.68209709, ..., 50.68545281,
         50.68546294, 50.68547308],
        [50.6815849 , 50.68159642, 50.68160793, ..., 50.6849636 ,
         50.68497373, 50.68498386],
        [50.68109575, 50.68110726, 50.68111878, ..., 50.68447438,
         50.68448452, 50.68449465]], shape=(294, 315)))
[11]:
ds.geography.projection()
[11]:
<Projected CRS: +proj=tmerc +ellps=WGS84 +a=6378137.0 +b=6356752.3 ...>
Name: unknown
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- undefined
Coordinate Operation:
- name: unknown
- method: Transverse Mercator
Datum: Unknown based on GRS 1980 ellipsoid
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich