Xarray: Saving UKCP18 NetCDF4 file with 2D lat/lon coordinates as TIFF

208 Views Asked by At

I'm working with UKCP18 climate data (2.2km), which uses an unfamiliar georeferencing (see link https://www.metoffice.gov.uk/pub/data/weather/uk/ukcp18/science-reports/UKCP-Convection-permitting-model-projections-report.pdf at Section 2.3 for desc.), and am trying to convert the file into a TIFF to use, but with traditional lat, lon (aka, EPSG:4326).

It uses two spatial dimensions "grid_latitude" and "grid_longitude" (in this unfamiliar georeferenced grid) and I'm looking to convert the file into the non-dimensional coordinates "latitude" and "longitude" present within the file, both of which are functions of (grid_latitude, grid_longitude). I'm new to working with files of this type, but want to avoid unnecessary reprojections later in gdalwarp if the file itself actually contains lat, lon info like this one already does; as 2D coordinates.

How do I find a way to set the spatial dimensions as latitude and longitude when converting to a raster? It seems lots of people online have had this issue, but I have not seen a successful fix to the issue.

Here is the current state of the xr.DataArray after working on the file:

<xarray.DataArray 'tasmin' (grid_latitude: 606, grid_longitude: 484)>
dask.array<mean_agg-aggregate, shape=(606, 484), dtype=float32, chunksize=(606, 484), chunktype=numpy.ndarray>
Coordinates:
  * grid_latitude   (grid_latitude) float64 -4.683 -4.647 -4.611 ... 8.027 8.063
  * grid_longitude  (grid_longitude) float64 353.9 354.0 354.0 ... 364.3 364.3
    latitude        (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>
    longitude       (grid_latitude, grid_longitude) float64 dask.array<chunksize=(606, 484), meta=np.ndarray>

If I can get the file in the format:

<xarray.DataArray 'tasmin' (latitude: 606, longitude: 484)>

... that would be perfect.

The file itself recognises how this would be georeferenced with lat, lon as I can plot it with:

da.plot(x='longitude', y='latitude')

which gives: image of gridded minimum temperatures over the United Kingdom on an irregular mesh

Thanks in advance!

0

There are 0 best solutions below