Public Function SuperP(t As Double, q As Range, tqs As Variant, tqn As Double, Optional qnorm As Boolean, Optional timecv As Double = 1#, Optional nqr As Long = -1, Optional qn As Double = 0#) As Variant
'
'computes the superposition function for radial-flow analysis plots. the output is on the
'time scale used for the input time, 't'. this is the key function for well-test analysis
'calculations, and has been constructed to handle badly formed data.
'
' t = time to superpose with rate-history; must be bigger than or equal to tqn.
' q = rate history; column 1 has time values at which each rate starts, column 2 is the rates
' tqs = start using rates in q from this time. blank=use first entry in q.
' tqn = time at which the analysis period starts; this is less than t and is the reference
'       time for computing delta-t = (t-tqn) in the test.
' nqr = number of rows in q to use in the summation (-1=all rows, 0=skip calcs)
' qn  = the rate for the analysis flow-period; 0 = shut-in (default).
'
'note that tqn,qn define the start-time and rate for the pressure data being analysed, and are
'set independent of q. this is done because the rate-history is normally a complete mess with
'the measurements coming from uncontrolled sources which are rarely correlated with the
'pressure data.
'
'tqs defines the start of the rate-history independent of q. this is done to allow a
'rate-history to be defined that spans a specific time range independent of what is
'actually in the rate history. this is needed when using P* for monitoring the average-pressure
'where the time range prior to the PBU should span the time-to-pseudo-steady-state, Tpss.
'
'the qnorm flag switches between a normal (delta-q)*log(delta-t) superposition function, and one that is
'normalised to the rate-change. the normalised superposition function similar to a "horner time"
'in that it is dimensionless
'
'the optional value of timecv is used to convert the rate-history time to the input 't' time.
'e.g. a factor of 24 is needed if column 1 of q contains date values and 't' is in hours.
'
'note that nqr=0 is valid input; this quickly truncates all calculations to return an error
'value and avoids scanning through the full number of rows of 'q'.
'
Dim sup As Double
Dim tcv As Double
Dim dq As Double
Dim qi As Double
Dim qlast As Double
Dim tlast As Double
Dim dt As Double
Dim ti As Double
Dim tq0 As Double
Dim i As Long
Dim nq As Long
Dim initt As Boolean
Dim qh As Variant

'SuperP = -q.Cells(1, 2) * Log(t - tqn)
'Exit Function

SuperP = CVErr(xlErrNA)
tcv = timecv
If (timecv <= 0) Then tcv = 1#

nq = q.Rows.Count
If (nq <= 0) Then Exit Function
If (t < tqn) Then Exit Function
If ((nqr >= 0) And (nqr < nq)) Then nq = nqr
'
'reference the rate-history as a variant; much more efficient
'
qh = q.Cells

initt = True
tq0 = 0
sup = 0
qlast = 0
dq = 0
dt = 0
'
'the superposition summation loop is a bit messy because it has to initialise and skip
'bad value on the fly. track each valid point in tlast,qlast and don't start the sum
'until the rate-history entry passes tq0. each earlier entry just sets and resets the
'first term in the sum.
'
For i = 1 To nq
    If (IsSIValue(qh(i, 1), True) And IsSIValue(qh(i, 2), False)) Then
        ti = tcv * qh(i, 1)
        qi = qh(i, 2)

        If (initt) Then
            If (ti >= tqn) Then
                Exit Function
            ElseIf (IsSIValue(tqs, True)) Then
                tq0 = CDbl(tqs)
                If ((tq0 < ti) Or (tq0 >= tqn)) Then tq0 = ti
            Else
                tq0 = ti
            End If
            tlast = ti
            initt = False
        End If
        
        If (ti < tlast) Then
            'skip values not in time increasing order...
        ElseIf (ti <= tq0) Then
            dt = t - tq0
            dq = qi
            sup = dq * Log(dt)
            qlast = qi
            tlast = ti
        ElseIf (ti >= tqn) Then
            Exit For
        ElseIf (qi <> qlast) Then
            dt = t - ti
            If (dt <= 0) Then Exit For
            dq = qi - qlast
            sup = sup + dq * Log(dt)
            qlast = qi
            tlast = ti
        End If
    End If
Next i
'
'if delta-t was never set to a positive value, then there is nothing to superpose. this is
'an error; the user needs to define at least one rate prior to the pressure data they
'are going to analyse. exit the function with the error value...
'
If (dt <= 0) Then Exit Function
    
If (qlast = qn) Then
    sup = sup + dq * Log((t - tqn) / dt)
ElseIf (t > tqn) Then
    dt = t - tqn
    dq = qn - qlast
    sup = sup + dq * Log(dt)
End If
    
If (qnorm = True) Then
    If (dq = 0) Then
        SuperP = CVErr(xlErrDiv0)
    Else
        SuperP = sup / dq
    End If
Else
    SuperP = sup
End If

End Function


chang this code to python