0

I'm tryin to bilerp a cell into one value using python for a NetCDF data set. I'm new to python and I can't understand what I'm doing wrong here. I have a 2d array and I give the four points by iterating through the dataset dataArr. I use Lerp method for the calculation. Somehow when I pass the 3 values it seems to consider it as more than 3. What am I doing wrong here? Thanks in adv.

This is the error I get>> self.Lerp((dataArr[i][j]),(dataArr[i+1][j]),fraction) takes exactly 3 arguments (4 given)

def compute(self,varval):      
        vars=self.data.variables
        for var in vars:
            if var==varval:
                ntimes, ny, nx=vars[var].shape #inherit the method above.
        print(ntimes, ny, nx)
        #create the old computational grid.
        computational_grid=np.zeros((ny,nx),dtype=int) 
        fraction=.5 
        newnx,newny =(nx*fraction,ny*fraction)
        new_computational_grid=np.zeros((newny,newnx),dtype=int)
        phy_value_arr=self.get_data(varval)
        t=10 #send this t value with coords
        dataArr=self.data.variables['tos'][t]     
        for i in range(0,(ny-1),1):
            for j in range(0,(nx-1),1):
               a=self.Lerp((dataArr[i][j]),(dataArr[i+1][j]),fraction)
               b=self.Lerp((dataArr[i][j]),(dataArr[i+1][j]),fraction)
               self.tempY.append(self.Lerp(a,b,fraction))
       tempY.reshape(newnx,newny)
       pcolormesh(self.tempY)
       colorbar()

def Lerp( _a, _b, _t) :
      return _a+(_b-_a)*_t

1 Answer 1

1

You call Lerp like tihs:

self.Lerp(a,b,fraction)

By definition it will put self as the first argument. Thus you will have four in total. However, you define Lerp as

def Lerp( _a, _b, _t) : #<- this takes only three arguments

I think it should be:

def Lerp(self, _a, _b, _t) : #<- this takes four, and self is first one
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for stating the obvious! You saved lot of my time. I assume that how I access the array is fine..
I haven't been looking at array definition or access, so dont know. The Lerp definition was sticking out as incorrect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.