def read_canal_data(self): #------------------------------------------------------------------- # Note: Q_canals is same at upstream and downstream ends, but the # downstream end lags the upstream end by the travel time # from in_ID to out_ID. As a result, the duration and Q # vector for the downstream end are computed from those of # the upstream end, and the travel time, td, as: # Q_out = [0, Q_in] # dur_out = [td, dur_in] # dur_sum_out = [0, dur_sum_in] + td # Rather than create the dur_sum_canals_out and # Q_canals_out vectors, can construct them in Update_Canals. #------------------------------------------------------------------- if (self.comp_status == 'Disabled'): return if not (self.use_canals): return #--------------------------- # Can canal_file be found ? #--------------------------- f = glob.glob(self.canal_file) c = len(f) if (c == 0): msg = array(['ERROR: canal file not found. ', ' ', \ 'The file: ', ' ' + self.canal_file, \ 'was not found in the working directory. ', \ ' ']) result = GUI_Message(msg, INFO=True) self.use_canals = False return #----------------------------- # Count lines in source_file #----------------------------- #Count_Lines, n_lines, canal_file, /SILENT #n_IDs = (n_lines / 6L) #------------------------------------ # Read the lines with the nd values # and find the max, called nd_max #------------------------------------ nd = np.int32(0) nd_max = np.int32(0) n_IDs = np.int32(0) #****** line1 = '' line2 = '' line3 = '' line5 = '' line6 = '' file_unit = open(self.canal_file, 'r') while not (idl_func.eof(file_unit)): line1 = idl_func.readf(file_unit, line1) line2 = idl_func.readf(file_unit, line2) line3 = idl_func.readf(file_unit, line3) nd = idl_func.readf(file_unit, nd) line5 = idl_func.readf(file_unit, line5) line6 = idl_func.readf(file_unit, line6) #----------------------------------------- nd_max = np.maximum(nd_max, nd) n_IDs = (n_IDs + np.int32(1)) #*** file_unit.close() #-------------------- # Initialize arrays #-------------------- self.canal_in_IDs = np.zeros([n_IDs], dtype='Int32') self.canal_out_IDs = np.zeros([n_IDs], dtype='Int32') self.canal_t_vals = np.zeros([n_IDs], dtype='Int32') self.nd_vals = np.zeros([n_IDs], dtype='Int32') #***** self.dur_canals = np.zeros([nd_max, n_IDs], dtype='Float32') self.Q_canals_in = np.zeros([nd_max, n_IDs], dtype='Float32') #-------------------- # Open file to read #-------------------- file_unit = open(self.canal_file, 'r') #---------------------- # Read data from file #---------------------- ID = np.int32(0) nd = np.int32(0) k = np.int32(0) tval = np.float32(0.0) while not (idl_func.eof(file_unit)): ID = idl_func.readf(file_unit, ID) self.canal_in_IDs[k] = ID #----------------------------------- ID = idl_func.readf(file_unit, ID) self.canal_out_IDs[k] = ID #-------------------------------------- tval = idl_func.readf(file_unit, tval) self.canal_t_vals[k] = tval #----------------------------------- nd = idl_func.readf(file_unit, nd) self.nd_vals[k] = nd #----------------------------------- durs = np.zeros([nd], dtype='Float32') durs = idl_func.readf(file_unit, durs) self.dur_canals[np.int32(0):((nd - np.int32(1))) + 1, k] = durs #----------------------------------- Q = np.zeros([nd], dtype='Float32') Q = idl_func.readf(file_unit, Q) self.Q_canals_in[np.int32(0):((nd - np.int32(1))) + 1, k] = Q #----------------------------------- k = (k + np.int32(1)) #----------------------- # Close the input file #----------------------- file_unit.close() #------------------------------------ # Compute partial sums of durations #------------------------------------ dur_sum_canals_in = np.zeros([nd_max + np.int32(1), n_IDs], dtype='Float32') for k in xrange(n_IDs): for i in xrange(nd_max): dur_sum_canals_in[i + 1, k] = dur_sum_canals_in[i, k] + dur_canals[i, k] dur_sum_canals_in = dur_sum_canals_in[1:(nd_max) + 1, :] #(remove leading 0) self.dur_sum_canals_in = dur_sum_canals_in
def read_canal_data(self): # ------------------------------------------------------------------- # Note: Q_canals is same at upstream and downstream ends, but the # downstream end lags the upstream end by the travel time # from in_ID to out_ID. As a result, the duration and Q # vector for the downstream end are computed from those of # the upstream end, and the travel time, td, as: # Q_out = [0, Q_in] # dur_out = [td, dur_in] # dur_sum_out = [0, dur_sum_in] + td # Rather than create the dur_sum_canals_out and # Q_canals_out vectors, can construct them in Update_Canals. # ------------------------------------------------------------------- if self.comp_status == "Disabled": return if not (self.use_canals): return # --------------------------- # Can canal_file be found ? # --------------------------- f = glob.glob(self.canal_file) c = len(f) if c == 0: msg = array( [ "ERROR: canal file not found. ", " ", "The file: ", " " + self.canal_file, "was not found in the working directory. ", " ", ] ) result = GUI_Message(msg, INFO=True) self.use_canals = False return # ----------------------------- # Count lines in source_file # ----------------------------- # Count_Lines, n_lines, canal_file, /SILENT # n_IDs = (n_lines / 6L) # ------------------------------------ # Read the lines with the nd values # and find the max, called nd_max # ------------------------------------ nd = np.int32(0) nd_max = np.int32(0) n_IDs = np.int32(0) # ****** line1 = "" line2 = "" line3 = "" line5 = "" line6 = "" file_unit = open(self.canal_file, "r") while not (idl_func.eof(file_unit)): line1 = idl_func.readf(file_unit, line1) line2 = idl_func.readf(file_unit, line2) line3 = idl_func.readf(file_unit, line3) nd = idl_func.readf(file_unit, nd) line5 = idl_func.readf(file_unit, line5) line6 = idl_func.readf(file_unit, line6) # ----------------------------------------- nd_max = np.maximum(nd_max, nd) n_IDs = n_IDs + np.int32(1) # *** file_unit.close() # -------------------- # Initialize arrays # -------------------- self.canal_in_IDs = np.zeros([n_IDs], dtype="Int32") self.canal_out_IDs = np.zeros([n_IDs], dtype="Int32") self.canal_t_vals = np.zeros([n_IDs], dtype="Int32") self.nd_vals = np.zeros([n_IDs], dtype="Int32") # ***** self.dur_canals = np.zeros([nd_max, n_IDs], dtype="Float32") self.Q_canals_in = np.zeros([nd_max, n_IDs], dtype="Float32") # -------------------- # Open file to read # -------------------- file_unit = open(self.canal_file, "r") # ---------------------- # Read data from file # ---------------------- ID = np.int32(0) nd = np.int32(0) k = np.int32(0) tval = np.float32(0.0) while not (idl_func.eof(file_unit)): ID = idl_func.readf(file_unit, ID) self.canal_in_IDs[k] = ID # ----------------------------------- ID = idl_func.readf(file_unit, ID) self.canal_out_IDs[k] = ID # -------------------------------------- tval = idl_func.readf(file_unit, tval) self.canal_t_vals[k] = tval # ----------------------------------- nd = idl_func.readf(file_unit, nd) self.nd_vals[k] = nd # ----------------------------------- durs = np.zeros([nd], dtype="Float32") durs = idl_func.readf(file_unit, durs) self.dur_canals[np.int32(0) : ((nd - np.int32(1))) + 1, k] = durs # ----------------------------------- Q = np.zeros([nd], dtype="Float32") Q = idl_func.readf(file_unit, Q) self.Q_canals_in[np.int32(0) : ((nd - np.int32(1))) + 1, k] = Q # ----------------------------------- k = k + np.int32(1) # ----------------------- # Close the input file # ----------------------- file_unit.close() # ------------------------------------ # Compute partial sums of durations # ------------------------------------ dur_sum_canals_in = np.zeros([nd_max + np.int32(1), n_IDs], dtype="Float32") for k in xrange(n_IDs): for i in xrange(nd_max): dur_sum_canals_in[i + 1, k] = dur_sum_canals_in[i, k] + dur_canals[i, k] dur_sum_canals_in = dur_sum_canals_in[1 : (nd_max) + 1, :] # (remove leading 0) self.dur_sum_canals_in = dur_sum_canals_in
def read_sink_data(self): #---------------------------------------------------------------- # Notes: This assumes that sink_file is organized as follows: # ID (sink pixel ID as long integer) # nd (number of durations and Q values) # durations (vector of durations in minutes) # Q_sinks (vector of discharges in m^3/sec) #---------------------------------------------------------------- if (self.comp_status == 'Disabled'): return if not (self.use_sinks): return #--------------------------- # Can sink_file be found ? #--------------------------- f = glob.glob(self.sink_file) c = len(f) if (c == 0): msg = array(['ERROR: sink file not found. ', ' ', \ 'The file: ', ' ' + self.sink_file, \ 'was not found in the working directory. ', \ ' ']) result = GUI_Message(msg, INFO=True) self.use_sinks = False return #----------------------------- # Count lines in source_file #----------------------------- #Count_Lines, n_lines, self.sink_file, /SILENT #n_IDs = (n_lines / 4L) #------------------------------------ # Read the lines with the nd values # and find the max, called nd_max #------------------------------------ nd = np.int32(0) nd_max = np.int32(0) n_IDs = np.int32(0) #****** line1 = '' line3 = '' line4 = '' #--------------------------- file_unit = open(self.sink_file, 'r') while not (idl_func.eof(file_unit)): line1 = idl_func.readf(file_unit, line1) nd = idl_func.readf(file_unit, nd) line3 = idl_func.readf(file_unit, line3) line4 = idl_func.readf(file_unit, line4) #----------------------------------------- nd_max = (np.maximum(nd_max, nd)) n_IDs = (n_IDs + np.int32(1)) #*** file_unit.close() #-------------------- # Initialize arrays #-------------------- self.sink_IDs = np.zeros([n_IDs], dtype='Int32') self.nd_vals = np.zeros([n_IDs], dtype='Int32') #***** self.dur_sinks = np.zeros([nd_max, n_IDs], dtype='Float32') self.Q_sinks = np.zeros([nd_max, n_IDs], dtype='Float32') #-------------------- # Open file to read #-------------------- file_unit = open(self.sink_file, 'r') #---------------------- # Read data from file #---------------------- ID = np.int32(0) nd = np.int32(0) k = np.int32(0) while not (idl_func.eof(file_unit)): ID = idl_func.readf(file_unit, ID) self.sink_IDs[k] = ID #---------------------------------- nd = idl_func.readf(file_unit, nd) self.nd_vals[k] = nd #---------------------------------- durs = np.zeros([nd], dtype='Float32') durs = idl_func.readf(file_unit, durs) self.dur_sinks[np.int32(0):((nd - np.int32(1))) + 1, k] = durs #---------------------------------- Q = zeros([nd], dtype='Float32') Q = idl_func.readf(file_unit, Q) self.Q_sinks[np.int32(0):((nd - np.int32(1))) + 1, k] = Q #---------------------------------- k = (k + np.int32(1)) #----------------------- # Close the input file #----------------------- file_unit.close() #------------------------------------ # Compute partial sums of durations #------------------------------------ dur_sum_sinks = zeros([nd_max + np.int32(1), n_IDs], dtype='Float32') for k in xrange(n_IDs): for i in xrange(nd_max): dur_sum_sinks[i + 1, k] = dur_sum_sinks[i, k] + dur_sinks[i, k] dur_sum_sinks = dur_sum_sinks[1:(nd_max) + 1, :] #(remove leading zero) self.dur_sum_sinks = dur_sum_sinks
def read_sink_data(self): # ---------------------------------------------------------------- # Notes: This assumes that sink_file is organized as follows: # ID (sink pixel ID as long integer) # nd (number of durations and Q values) # durations (vector of durations in minutes) # Q_sinks (vector of discharges in m^3/sec) # ---------------------------------------------------------------- if self.comp_status == "Disabled": return if not (self.use_sinks): return # --------------------------- # Can sink_file be found ? # --------------------------- f = glob.glob(self.sink_file) c = len(f) if c == 0: msg = array( [ "ERROR: sink file not found. ", " ", "The file: ", " " + self.sink_file, "was not found in the working directory. ", " ", ] ) result = GUI_Message(msg, INFO=True) self.use_sinks = False return # ----------------------------- # Count lines in source_file # ----------------------------- # Count_Lines, n_lines, self.sink_file, /SILENT # n_IDs = (n_lines / 4L) # ------------------------------------ # Read the lines with the nd values # and find the max, called nd_max # ------------------------------------ nd = np.int32(0) nd_max = np.int32(0) n_IDs = np.int32(0) # ****** line1 = "" line3 = "" line4 = "" # --------------------------- file_unit = open(self.sink_file, "r") while not (idl_func.eof(file_unit)): line1 = idl_func.readf(file_unit, line1) nd = idl_func.readf(file_unit, nd) line3 = idl_func.readf(file_unit, line3) line4 = idl_func.readf(file_unit, line4) # ----------------------------------------- nd_max = np.maximum(nd_max, nd) n_IDs = n_IDs + np.int32(1) # *** file_unit.close() # -------------------- # Initialize arrays # -------------------- self.sink_IDs = np.zeros([n_IDs], dtype="Int32") self.nd_vals = np.zeros([n_IDs], dtype="Int32") # ***** self.dur_sinks = np.zeros([nd_max, n_IDs], dtype="Float32") self.Q_sinks = np.zeros([nd_max, n_IDs], dtype="Float32") # -------------------- # Open file to read # -------------------- file_unit = open(self.sink_file, "r") # ---------------------- # Read data from file # ---------------------- ID = np.int32(0) nd = np.int32(0) k = np.int32(0) while not (idl_func.eof(file_unit)): ID = idl_func.readf(file_unit, ID) self.sink_IDs[k] = ID # ---------------------------------- nd = idl_func.readf(file_unit, nd) self.nd_vals[k] = nd # ---------------------------------- durs = np.zeros([nd], dtype="Float32") durs = idl_func.readf(file_unit, durs) self.dur_sinks[np.int32(0) : ((nd - np.int32(1))) + 1, k] = durs # ---------------------------------- Q = zeros([nd], dtype="Float32") Q = idl_func.readf(file_unit, Q) self.Q_sinks[np.int32(0) : ((nd - np.int32(1))) + 1, k] = Q # ---------------------------------- k = k + np.int32(1) # ----------------------- # Close the input file # ----------------------- file_unit.close() # ------------------------------------ # Compute partial sums of durations # ------------------------------------ dur_sum_sinks = zeros([nd_max + np.int32(1), n_IDs], dtype="Float32") for k in xrange(n_IDs): for i in xrange(nd_max): dur_sum_sinks[i + 1, k] = dur_sum_sinks[i, k] + dur_sinks[i, k] dur_sum_sinks = dur_sum_sinks[1 : (nd_max) + 1, :] # (remove leading zero) self.dur_sum_sinks = dur_sum_sinks