ArcPy NumPyArrayToRaster not working properly (Python)

1377
5
08-01-2019 12:23 PM
LubomirFranko
New Contributor

Hello, I am trying to convert my NumPy array of shape (360,700,450) to multidimensional raster file. My goal is to export raster data to point feature layer.

What I'm trying to do is timeseries of average temperature for certain points. I have my temperature data stored in NetCDF file, which I am trying to convert to raster, so I can use ExtractMultiValuesToPoints method. 

Firstly I made a cycle, which converted n-th dimension of .nc file to 2D array, then converted to raster using NumPyArrayToRaster, then extracted data to points and removed raster. The cycle repeated this for all days of timeseries. This worked fine but whole process took a long long time. 

What I wanted to do is firstly make 3D array, with first dimension value of "day". I created array succesfuly but using NumPyArrayToRaster I am unable to create multidimensional raster. Process works just fine, I get "succesful" message after finishing NumPyArrayToRaster . However, I am unable to generate something else than singleband raster. 

So again, the problem is: NumPyArrayToRaster always returns singleband raster, no matter how many dimensions does the array have. 

ArcGIS Pro 2.4

0 Kudos
5 Replies
KoryKramer
Esri Community Moderator

Looks like there is a bug logged for this: https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDExNDExNw==

That link lists a workaround of compositing the single band output back into a multi-band raster.

LubomirFranko
New Contributor

Feels little bit strange that bug is reported for ArcGIS Desktop only and also that it's already been a year since the bug was reported for the first time.

Thank you for your answer tho. I had a look at alternate solutions but as I mentioned above, I want to extract data from multidimensional raster, because it is way faster than generating 5 000 singleband rasters, merging them together, nd extracting multidimensional data to points afterwards (this would take like 6 hours of processing time on pretty good setup (tested)).

0 Kudos
DanPatterson_Retired
MVP Emeritus

If your data are already in array format, why don't you use numpy (or alternatives).

I usually have the reverse problem going from rasters to arrays to do things like cell statistics on raster composites.

For example

/blogs/dan_patterson/2018/02/06/cell-statistics-made-easy-raster-data-over-time 

If you can't do what you want with netcdf files, getting them into numpy array format might be quicker than dealing with esri rasters or tif files and trying to stack those.

0 Kudos
LubomirFranko
New Contributor
Well, as I mentioned in first post, I already have my data in NumPy Array format. To perform point timeseries, I need to extract values at point locations. Thats why I need raster with multiple layers.
Next thing I’ve been thinking of is to get point values from exact pixels in array. There might be a problem with interpolation however. If the point is located at the edge of a “array pixel”, the value which I want is not the value of a pixel but interpolated value of 2 neigbouring pixels. NumPyArrayToRaster provides the interpolation I need. 
As I said, I am able to perform timeseries by extraction data to points from temporary singleband raster in while loop. However, extracting data to points from raster one by one takes a lot of tim 
0 Kudos
KevinSampson
New Contributor

I recently ran into this bug when trying to export a multi-dimensional array (from netCDF) to raster using NumpyArrayToRaster in ArcGIS Desktop 10.8. It is a bit disappointing that the bug was reported in 10.6 and has not been resolved more than 2 years later.

I also tried using this tool in ArcGIS Pro 2.5.0 and found mixed results. When saving to a GeoTiff, the result was a multi-band raster. When saving to GRID format, the tool builds BOTH a multi-band raster AND multiple 1-band rasters.

0 Kudos