ucd-cws/calvin

Debug flow finder

msdogan opened this issue · 2 comments

@jdherman, @whiteellie I am trying to write a code that imports output flows (flow.csv), and goes through each column (flow time-series), and stores time-series if there is a debug flow (if flow > 0). There are two debug flows: DBUGSRC and DBUGSINK. DBUGSRC is on the left hand side of link name (if splitted with '-') and DBUGSNK is on the right hand side. The code attached finds debug links (if a link name includes DBUGSRC or DBUGSNK), however I can't iterate through columns to see if flow is > 0. Any help would be greatly appreciated. The code (debug_flow_finder.py) and flow (flow.csv) files are zipped.

debug.zip

This should work --

import csv

# load link flows
with open('flow.csv', 'rU') as f:
  reader = csv.reader(f)
  flows = list(reader)

nrows = len(flows[0])
ncols = len(flows)

# loop over columns (links)...
for j in range(1,nrows):
  l1,l2 = flows[0][j].split('-')

  # if this is a debug link ...
  if l1 == 'DBUGSRC' or l2 == 'DBUGSNK':
    ID = l1+'-'+l2

    # loop over the time series of flow values
    for i in range(1,ncols):

      # if any are nonzero, print them
      if float(flows[i][j]) > 0:
        print('Link: ' + ID + ', Time: ' + flows[i][0] + ', Flow: ' + flows[i][j])

Right now for this example it prints:

Link: DBUGSRC-SR_CR1, Time: 2003-09-30, Flow: 0.01
Link: DBUGSRC-SR_CR2, Time: 2003-09-30, Flow: 0.01
Link: HSD203-DBUGSNK, Time: 2002-11-30, Flow: 0.00335999995
Link: HSD203-DBUGSNK, Time: 2003-03-31, Flow: 0.0403199994

Great! Thanks @jdherman I will try this tomorrow. For this code to run, I made a small change in postprocessor.py Previously, we were combining two links with underscore (' _ '). However, we use (' _ ') in link names, as well. So, split function in in this debug flow finder didn't work. I updated that in postprocessor.py but I haven't pushed changes yet. Just to let you know.