RasterToXarray

Zusammenfassung

Converts a multidimensional raster to an xarray.Dataset containing labeled arrays (data array objects) with aligned dimensions.

Diskussion

xarray is a Python module that supports multidimensional arrays with labels of dimensions, coordinates, and attributes. It builds on and integrates NumPy and pandas, and deals with multidimensional data in the Python SciPy ecosystem for numerical computing. For more information, refer to the xarray documentation.

You may want to convert an ArcGIS multidimensional raster to an xarray dataset to perform the following kinds of operations:

  • Implement one of the many functions in the xarray module, for example, run multidimensional interpolation, resampling, and grouped operations on an xarray.DataArray object.
  • Take advantage of other Python modules that directly work with xarray.DataArray objects in various domains including geosciences, machine learning, and more. For example, the import EOF (Empirical Orthogonal Functions) Python package and perform EOF analysis on data in xarray.DataArray.
  • Convert a multidimensional raster to xarray.DataArray and then to another Python data type or formats, for example, to pandas DataFrame objects, or to netCDF.

Syntax

RasterToXarray (in_raster)
ParameterErläuterungDatentyp
in_raster

The input multidimensional raster to convert to an xarray. It can be a Raster object, a file path to a multidimensional raster dataset, or a netCDF file.

Raster
Rückgabewert
DatentypErläuterung
xarray.Dataset

The output xarray.Dataset object.

Codebeispiel

RasterToXarray example

Python window sample for the RasterToXarray function.

import arcpy
import xarray

# Get input Raster multidimensional information
inRas = arcpy.Raster('C:/data/temperature_3hour.crf', True)
inRas.mdinfo

# Convert Raster to Xarray Dataset
xrr = arcpy.ia.RasterToXarray(inRas)

# Upsample the data from originally 3 hour to hourly time interval
newXrr = xrr.resample(StdTime='1H').nearest(tolerance="1H")

#Convert Xarray dataset back to raster 
newRaster = arcpy.ia.XarrayToRaster(newXrr)
newRaster.save("C:/output/temperature_hourly.crf")