Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

if function within an while - python novice

$
0
0
Dear all,

I'm attempting to calculate a field value that is dependent on a number of other fields.

In the following example I'm attempting to calculate values for FIII dependent on the relative values of other F fields.

The issue I have is that there are a large number of '0' values, which in fact signify an absence - I suppose they really ought to be null, but I'm working from a shapefile and I can't nullify the values.

To try and get around this I've tried to incorporate the while function, and only perform the analysis where values are > 0.

Code:

def Reclass(FIII, FIA, FIB, FIIA, FIIB, FIVA, FIVB, FIVC):
  Depths = (FIA, FIB, FIIA, FIIB, FIVA, FIVB, FIVC)
  while (Depths > 0):
    if (FIII <= 0):
      return 0
    elif (FIII < min (FIA, FIB, FIIA, FIIB, FIVA, FIVB, FIVC)):
      return FIII
    elif (FIII > max(FIA, FIB)) and (FIII < FIIA):
      return FIII - max(FIA, FIB)
    elif (FIII > FIIA) and (max(FIA, FIB) <= 0):
      return FIII - FIIA
    elif (FIII > min(FIVA, FIVB, FIVC)):
      return (FIII - min(FIVA, FIVB, FIVC))

Is far as I can make out the while function isn't working at all - I assume I just have the syntax incorrect.

Otherwise the major issue is on lines 8 and 9, where FIIA is frequently 0, this means that the condition for the elif statement is never fulfilled, meaning that the return calculation is not performed.

Any pointers gratefully appreciated - apologies for confused thread: I've been staring at the screen all day.

Matt

Viewing all articles
Browse latest Browse all 2485

Trending Articles