TransWikia.com

How to set band names of multi-band GeoTIFF asset upon upload to Google Earth Engine

Geographic Information Systems Asked on July 8, 2021

I have created a multi-bands GeoTIFF using xarray in Python following this answer. When I display this raster or open it in QGIS, all the bands are named following the variable they represent:

xarray dataset showing variables used as different bands

However, when I upload the file as a Google Earth Engine raster asset, all band names are automatically renamed to b[1-9]:

Google Earth Engine asset manager

Is there a way to preserve the band names when importing a GeoTIFF? Or am I missing something in the way multi-bands GeoTIFFs are defined?

Here is the code I use. I first extract data from a NetCDF file and then write a xarray dataset:

import xarray as xr
import rioxarray as rio
import pandas as pd

#%%
rootDir = '/Users/seb/Documents/WORK/Projects/Vegetation/Fall3D/CC2011/'
dataVar = 'max'

ncfile = xr.open_dataset('{}CC2011_{}.res.nc'.format(rootDir, dataVar))

className = ['lapilli-01', 'lapilli-02', 'lapilli-03',  'coarse_ash-01',  'coarse_ash-02', 'fine_ash-01','fine_ash-02','fine_ash-03',    'fine_ash-04',    'fine_ash-05',   'aggregate-01']

data = ncfile['tephra_grn_load']
# Get last date
data = data[-1,:,:]
#Define lat/long and remove the time dimension
data = data.rio.set_spatial_dims('lon', 'lat').drop('time')
#Check for the CRS
data.rio.set_crs("epsg:4326")

# Define dataset
xr_dataset = xr.Dataset()
xr_dataset['total'] = data

for bin in range(0, len(className)):
    dataBin = ncfile['tephra_grn_load_bin']
    # Get last date
    dataBin = dataBin[-1,bin,:,:]
    #Define lat/long 
    dataBin = dataBin.rio.set_spatial_dims('lon', 'lat').drop('time').drop('tephra_bin')
    #Check for the CRS
    dataBin.rio.set_crs("epsg:4326")
    # Set name
    dataBin.name = className[bin]
    # Add to dataset
    xr_dataset[className[bin]] = dataBin

ncfile.close()

# Save
xr_dataset.rio.set_crs("epsg:4326")
xr_dataset.rio.to_raster('{}CC2011_{}_load.tif'.format(rootDir, dataVar))

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP