ArcPy Raster Function error

12-18-2019 12:11 PM
New Contributor III


I'm trying to read in a raster function to read a multi-band time series raster:

filein = os.path.join(os.getcwd(),r"raster_calcs\Russian-Raster-Drought\data\baseflow_day_HadGEM2-ES_rcp85_2018-2046_drought.tif")

myRaster = arcpy.Raster(filein)

and I receive a TypeError:

---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-28-b2a611fe1e8d> in <module>      1 #create raster object from file----> 2 myRaster = arcpy.Raster(filein)C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\ in __new__(cls, in_raster, is_multidimensional)     71      72   def __new__(cls, in_raster, is_multidimensional=False):---> 73     return super().__new__(cls, in_raster, is_multidimensional)     74      75   def getVariableAttributes(self, variable_name):TypeError: expected 1 arguments, got 2

I don't see two arguments here. What am I missing? 

Tags (1)
0 Kudos
6 Replies
Esri Contributor

Hi Jason,

Looks like the error is being thrown not in your script but in the arcpy lib.

This could be due to the way in which you are calling the arcpy function.

Could you please post your entire code so that we can do some more in depth debugging?

The full error text would also help.



New Contributor III

Hi Michael,

Thanks for your help. Here is the the code and error. I just got started with the project and hit this error right away. 

import arcpy
import numpy
import os

#input raster
filein = os.path.join(os.getcwd(),r"raster_calcs\Russian-Raster-Drought\data\baseflow_day_HadGEM2-ES_rcp85_2018-2046_drought.tif")

#out raster
fileout = os.path.join(os.getcwd(),r'raster_calcs\output\output.tif')

#create raster object from file
myRaster = arcpy.Raster(filein)

TypeError Traceback (most recent call last)
<ipython-input-28-b2a611fe1e8d> in <module>
1 #create raster object from file
----> 2 myRaster = arcpy.Raster(filein)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\ in __new__(cls, in_raster, is_multidimensional)
72 def __new__(cls, in_raster, is_multidimensional=False):
---> 73 return super().__new__(cls, in_raster, is_multidimensional)
75 def getVariableAttributes(self, variable_name):

TypeError: expected 1 arguments, got 2
0 Kudos
Esri Contributor

Hi Jason,

Which IDE do you use?

PyCharm has a very nice debugging suite.

if you can put in a break at line 7 and look at what "filein" actually is, then step through the rest of the code.

At a guess i would say that the os.path.join is not combining the inputs correctly.

Try using the complete path instead of using os.path.join(os.getcwd(),....

so filein = r"C:/whereyourrastais"

It looks like the os.getcwd is causing you issues when combined with os.path.join

Hope this helps,


New Contributor III

HI Michael,

I am using Jupyter Notebook for this project.

Thanks for the suggestion. The os.path.join(os.getcwd(),... produced the correct path after I printed it. I tired using the path directly too, but received the same error. 

0 Kudos
New Contributor III

I'm having the same issue. Basically all of my Raster(some_path_to_raster) functions are returning this error "TypeError: expected 1 arguments, got 2". I've used arcpy.Exists(some_path_to_raster) to make sure the raster is their and it is. If I try my calculation without the Raster(), just use the path I get a "can't multiply by string error". I have spatial analyst checked out. This was working yesterday.

Con_Con_img11_temp = Con(in_conditional_raster=Con_img1,
         where_clause="Value > 254")

if arcpy.Exists(mask_raster):
   print("mask_raster exists")
if arcpy.Exists(Con_Con_img11):
   print("Con_Con_img11 exists")

try :
   targetCHMFinal_grid = Raster(mask_raster) * Raster(Con_Con_img11)
except TypeError:
   print("version 1 failed")
   targetCHMFinal_grid = mask_raster * Raster(Con_Con_img11)
except TypeError:
   print("version 2 failed")

0 Kudos
MVP Regular Contributor

Use arcpy.Raster?

0 Kudos