Inspecting the Vegetation Biomass layer in QGreenland

This is a short example solution to the Data inspection with Jupyterlab exercise.

👐 Open the dataset with xarray

from pathlib import Path
import xarray as xra

datafile_path = Path('/home/jovyan/shared/QGreenland/QGreenland_v2.0.0/Biology/Vegetation/Vegetation biomass 2010 (12.4km)/vegetation_biomass_2010.tif')
ds = xra.open_dataset(datafile_path)
ds
<xarray.Dataset>
Dimensions:      (band: 1, x: 180, y: 265)
Coordinates:
  * band         (band) int64 1
  * x            (x) float64 -9.918e+05 -9.794e+05 ... 1.215e+06 1.228e+06
  * y            (y) float64 -3.358e+05 -3.482e+05 ... -3.597e+06 -3.609e+06
    spatial_ref  int64 ...
Data variables:
    band_data    (band, y, x) float32 ...

We can see so far that this dataset has a grid of 180 columns (x) and 265 rows (y). The data will be taller than it is wide. The data is of type float32 (see the data variable called band_data)

🔎 Learn more with xarray and rioxarray

rioxarray, if installed, provides convenience methods and attributes on any xarray dataset. Simply access dataset.rio to use those features.

# Show the available "public" methods and attributes provided by `rioxarray`:
print([i for i in dir(ds.rio) if not i.startswith('_')])
['bounds', 'clip', 'clip_box', 'count', 'crs', 'estimate_utm_crs', 'get_gcps', 'grid_mapping', 'height', 'interpolate_na', 'isel_window', 'pad_box', 'reproject', 'reproject_match', 'resolution', 'set_attrs', 'set_crs', 'set_encoding', 'set_spatial_dims', 'shape', 'slice_xy', 'to_raster', 'transform', 'transform_bounds', 'update_attrs', 'update_encoding', 'vars', 'width', 'write_coordinate_system', 'write_crs', 'write_gcps', 'write_grid_mapping', 'write_transform', 'x_dim', 'y_dim']
# Show the available "public" units on `rioxarray`'s `crs` interface
print([i for i in dir(ds.rio.crs) if not i.startswith('_')])
['data', 'from_authority', 'from_dict', 'from_epsg', 'from_proj4', 'from_string', 'from_user_input', 'from_wkt', 'get', 'is_epsg_code', 'is_geographic', 'is_projected', 'is_valid', 'items', 'linear_units', 'linear_units_factor', 'to_authority', 'to_dict', 'to_epsg', 'to_proj4', 'to_string', 'to_wkt', 'units_factor', 'wkt']
print(f'CRS: {ds.rio.crs}')
print(f'Units: {ds.rio.crs.linear_units}')
print(f'Bounds: {ds.rio.bounds()}')
print(f'Height: {ds.rio.height}')
print(f'Width: {ds.rio.width}')
print(f'Grid pixel resolution: {ds.rio.resolution()}')
CRS: EPSG:3413
Units: metre
Bounds: (-998012.0000002026, -3615624.0, 1233987.9999997974, -329624.00000000006)
Height: 265
Width: 180
Grid pixel resolution: (12400.0, -12400.0)

📝 Summary

We used xarray & rioxarray to open and inspect the dataset and we found that its metadata was populated with the expected geospatial information. Thanks to this, we are able to open this dataset with QGIS and view its data plotted correctly alongside other QGreenland layers.