Select to view content in your preferred language

ArcPy Raster Function error

1758
6
12-18-2019 12:11 PM
JasonCarter1
Occasional Contributor

Hi,

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\Raster.py 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
by Anonymous User
Not applicable

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.

Thanks,

Michael

JasonCarter1
Occasional Contributor

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\Raster.py 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
0 Kudos
by Anonymous User
Not applicable

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,

Michael

JasonCarter1
Occasional Contributor

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
KenPierce
Occasional Contributor

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,
         in_true_raster_or_constant=max_chm,
         in_false_raster_or_constant=Con_img1,
         where_clause="Value > 254")

Con_Con_img11_temp.save(Con_Con_img11)

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")
try:
   targetCHMFinal_grid = mask_raster * Raster(Con_Con_img11)
except TypeError:
   print("version 2 failed")

0 Kudos
DavidPike
MVP Frequent Contributor

Use arcpy.Raster?

0 Kudos