1

I'm writing some code that consists of a general superclass and more specific subclasses that will have slightly varying properties. I've set up one of the subclasses and defined a function within it, but when i call the function (as in, subclass.function(args)) i get an error saying that i'm including the wrong number of arguments:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-45d26bca20e5> in <module>()
     80 
     81 example = CR0098('test',10,10)
---> 82 example.Curve(34)

TypeError: Curve() takes exactly 1 argument (2 given)

I can't seem to resolve this. The code is shown below:

import math
class Spectra(object):
    def __init__(self, name, PGA=0.3, Damping=5):
        self.name = name
        self.PGA = PGA
        self.Damping = Damping

class CR0098(Spectra):
   def __init__(self, name, vaRatio, ADV, PGA=0.3, Damping=5):
        Spectra.__init__(self,name,PGA,Damping)
        self.vaRatio = vaRatio
        self.ADV = ADV


   def Curve(freq):
    if self.Damping == 0.5: #Factors from NUREG 98 Table 3 based on damping percentage
        AperAprime = 5.1
        VperVprime = 3.84
        DperDprime = 3.04
    elif self.Damping == 1:
        AperAprime = 4.38
        VperVprime = 3.38
        DperDprime = 2.73
    elif self.Damping == 2:
        AperAprime = 3.66
        VperVprime = 2.92
        DperDprime = 2.42
    elif self.Damping == 3:
        AperAprime = 3.24
        VperVprime = 2.64
        DperDprime = 2.24
    elif self.Damping == 5:
        AperAprime = 2.71
        VperVprime = 2.3
        DperDprime = 2.01
    elif self.Damping == 7:
        AperAprime = 2.36
        VperVprime = 2.08
        DperDprime = 1.85
    elif self.Damping == 10:
        AperAprime = 1.99
        VperVprime = 1.84
        DperDprime = 1.69
    else:
        pass
    factor = 386.4 #Factor converts g's to in per sec^2
    vPrime = self.vaRatio * self.PGA #V' calculation
    dPrime = self.ADV *(vPrime**2)/(self.PGA*factor)
    A = self.PGA*AperAprime*factor #Peak Spectral Acceleration
    V = vPrime * VperVprime #Peak Spectral Velocity
    D = dPrime * DperDprime #Peak spectral displacement

    #Control Points
    sF1 = 0.1 #Freqency for control point 1
    sA1 = D/((2*math.pi*(0.1))**2) #Point 1 with freqency of 0.1 hz
    sF2 = (V/D)/(2*math.pi) #Frequency for point 2 in hz
    sA2 = D/((2*math.pi*(sF2))**2) #Acceleration for Point 2
    sF3 = (A/V)/(2*math.pi) #frequency for point 3 in hz
    sA3 = V/(2*math.pi*sF3) # Acceleration for point 3 
    sF4 = 8 #Frequency for control point 4
    sA4 = sA3 #Acceleration for control point 4, same as point 3
    sF5 = 33 #Frequency for control point 5, rigid
    sA5 = self.PGA #Acceleration for control point 5

    aSlope = math.log10(sA5/sA4)/math.log10(sF5/sF4) #Acceleration slope factor

    dispA = D * ((2*math.pi * freq)**2)/factor #Spectral Acceleration based on spectral displacement
    velA =  V * (2*math.pi * freq)/factor #Spectral Acceleration based on spectral velocity
    AFactor = math.log10(sA4)+math.log10(freq/sF4)*aSlope #Special acceleration factor

    if freq < sF4: #calculates the acceleration based on which frequency range
        accelA1 = A/factor
    else:
        accelA1 = 10**AFactor
    accelA = max(accelA1, sA5) #verifies that the acceleration is above the rigid acceleration

    SpectralAcceleration = min(dispA,velA,accelA)
    return SpectralAcceleration

example = CR0098('test',10,10)
example.Curve(34)
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
Tsnorthern
  • 27
  • 5

3 Answers3

2

You forgot the self argument in the method definition.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

You forgot the self argument in the Curve definition:

def Curve(self, freq):

The first implicit argument is always the reference on the current instance. See What is the purpose of self? for more explanations on this very common subject.

Community
  • 1
  • 1
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
2

You need to define the method with self as the first argument:

def Curve(self, freq):

This argument is passed implicitly every time you call an instance method, in front of the other arguments. As written, self is being passed to the freq argument, with nothing left to accept your actual freq argument.


From documentation on self:

There are no shorthands for referencing the object’s members from its methods: the method function is declared with an explicit first argument representing the object, which is provided implicitly by the call.

mhlester
  • 22,781
  • 10
  • 52
  • 75