Raster object loses methods after calculations

223
1
03-28-2023 10:38 AM
DavidAnderson_1701
Occasional Contributor

I am doing some work with multidimensional rasters in a Python notebook.  I've run into some problems with this workflow.

The current one is that methods appear to not be maintained through raster calculator calcuations.

Example code with error

temp_max_file = r"c:\GridMetData_2020\tmmx_2020.nc"
temp_min_file = r"C:\GridMetData_2020\tmmn_2020.nc"
max_temp_rast = arcpy.Raster(temp_max_file,True)
min_temp_rast = arcpy.Raster(temp_min_file,True)
DD5_conus = ((max_temp_rast - min_temp_rast)/2)-5
DD5_gt0_conus = arcpy.sa.Con(DD5_conus > 0.0, DD5_conus, 0.0)
DD5_gt5c_conus = arcpy.sa.Con(DD5_conus > 5.0, DD5_gt0_conus, 0.0)
DD5_gt5c_conus.mean()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
In  [25]:
Line 1:     DD5_gt5c_conus.mean()

RuntimeError: Unspecified error 
---------------------------------------------------------------------------

 

Some of the same functionality is available with the aggregateMultidimensionalRaster too,

This is however a unpythonic solution and add another level of commplextiyh to the cocde.

Any ideas on how to keep the object methods as the object groes through calculations?

1 Reply
ShaunWalbridge
Esri Regular Contributor

Can you check back on what type(obj) shows for your earlier calls? My guess is one of those did not get dynamically cast to a Raster object and assumed a scalar operation. If you explicitly cast, it should work, e.g. in your last step request a new DD5_gt5c_conus_rast = arcpy.Raster(DD5_gt5c_conus).

Cheers, Shaun

0 Kudos