def get_result_arrays(self, current_gauge): current_gauge.fall_flush_timings_durations() """Remove offset""" for percent in self.percentilles: current_gauge_fall_timing = np.nanpercentile( current_gauge.fall_timings, percent) current_gauge_fall_wet_timing = np.nanpercentile( current_gauge.fall_wet_timings, percent) current_gauge_fall_timing = remove_offset_from_julian_date( current_gauge_fall_timing, self.julian_start_date) current_gauge_fall_wet_timing = remove_offset_from_julian_date( current_gauge_fall_wet_timing, self.julian_start_date) self.fall_timings[percent].append(current_gauge_fall_timing) self.fall_magnitudes[percent].append( np.nanpercentile(current_gauge.fall_magnitudes, percent)) self.fall_wet_timings[percent].append( current_gauge_fall_wet_timing) self.fall_durations[percent].append( np.nanpercentile(current_gauge.fall_durations, percent)) """Get nonP result""" self.metrics['FAFL_Tim'][current_gauge.class_number] += list( current_gauge.fall_timings) self.metrics['FAFL_Mag'][current_gauge.class_number] += list( current_gauge.fall_magnitudes) self.metrics['FAFL_Tim_Wet'][current_gauge.class_number] += list( current_gauge.fall_wet_timings) self.metrics['FAFL_Dur'][current_gauge.class_number] += list( current_gauge.fall_durations)
def get_result_arrays(self, current_gauge): current_gauge.start_of_summer() current_gauge.spring_transition_timing_magnitude() current_gauge.spring_transition_duration() current_gauge.spring_transition_roc() """Remove offset""" for percent in self.percentilles: current_gauge_spring_timing = np.nanpercentile( current_gauge.spring_timings, percent) current_gauge_spring_timing = remove_offset_from_julian_date( current_gauge_spring_timing, self.julian_start_date) self.spring_timings[percent].append(current_gauge_spring_timing) self.spring_durations[percent].append( np.nanpercentile(current_gauge.spring_durations, percent)) self.spring_magnitudes[percent].append( np.nanpercentile(current_gauge.spring_magnitudes, percent)) self.spring_rocs[percent].append( np.nanpercentile(current_gauge.spring_rocs, percent)) """Get nonP result""" self.metrics['SP_Tim'][self.gauge_class_array[-1]] += list( current_gauge.spring_timings) self.metrics['SP_Mag'][self.gauge_class_array[-1]] += list( current_gauge.spring_magnitudes) self.metrics['SP_Dur'][self.gauge_class_array[-1]] += list( current_gauge.spring_durations) self.metrics['SP_ROC'][self.gauge_class_array[-1]] += list( current_gauge.spring_rocs)
def get_result_arrays(self, current_gauge): current_gauge.winter_highflow_annual() """Remove offset""" for percent in self.all_exceedances: for percentille in self.percentilles: current_gauge_winter_timing = np.nanpercentile( current_gauge.winter_timings[percent], percentille) current_gauge_winter_timing = remove_offset_from_julian_date( current_gauge_winter_timing, self.julian_start_date) self.timing[percent][percentille].append( current_gauge_winter_timing) self.duration[percent][percentille].append( np.nanpercentile(current_gauge.winter_durations[percent], percentille)) self.freq[percent][percentille].append( np.nanpercentile(current_gauge.winter_frequencys[percent], percentille)) self.mag[percent][percentille].append( np.nanpercentile(current_gauge.winter_magnitudes[percent], percentille)) """Get nonP result""" for percent in self.all_exceedances: self.metrics['WIN_Tim_{}'.format(percent)][ current_gauge.class_number] += list( current_gauge.winter_timings[percent]) self.metrics['WIN_Dur_{}'.format(percent)][ current_gauge.class_number] += list( current_gauge.winter_durations[percent]) self.metrics['WIN_Fre_{}'.format(percent)][ current_gauge.class_number] += list( current_gauge.winter_frequencys[percent]) self.metrics['WIN_Mag_{}'.format(percent)][ current_gauge.class_number] += list( current_gauge.winter_magnitudes[percent])
def get_result_arrays(self, current_gauge): current_gauge.winter_highflow_POR() self.gauges.append( GaugePlotter(self.gauge_class_array[-1], self.gauge_number_array[-1], current_gauge.winter_timings_POR, current_gauge.winter_durations_POR, current_gauge.winter_frequencys_POR, current_gauge.winter_magnitudes_POR, self.exceedance_percent)) for percent in self.exceedance_percent: for percentille in self.percentilles: current_gauge_winter_timing = np.nanpercentile( current_gauge.winter_timings_POR[percent], percentille) current_gauge_winter_timing = remove_offset_from_julian_date( current_gauge_winter_timing, self.julian_start_date) self.timing[percent][percentille].append( current_gauge_winter_timing) self.duration[percent][percentille].append( np.nanpercentile( current_gauge.winter_durations_POR[percent], percentille)) self.freq[percent][percentille].append( np.nanpercentile( current_gauge.winter_frequencys_POR[percent], percentille))
def get_result_arrays(self, current_gauge): current_gauge.start_of_summer() current_gauge.fall_flush_timings_durations() current_gauge.summer_baseflow_durations_magnitude() """Remove offset""" for percentile in self.percentilles: current_gauge_summer_timing = np.nanpercentile( current_gauge.summer_timings, percentile) current_gauge_summer_timing = remove_offset_from_julian_date( current_gauge_summer_timing, self.julian_start_date) self.summer_timings[percentile].append(current_gauge_summer_timing) self.summer_10_magnitudes[percentile].append( np.nanpercentile(current_gauge.summer_10_magnitudes, percentile)) self.summer_50_magnitudes[percentile].append( np.nanpercentile(current_gauge.summer_50_magnitudes, percentile)) self.summer_flush_durations[percentile].append( np.nanpercentile(current_gauge.summer_flush_durations, percentile)) self.summer_wet_durations[percentile].append( np.nanpercentile(current_gauge.summer_wet_durations, percentile)) self.summer_no_flow_counts[percentile].append( np.nanpercentile(current_gauge.summer_no_flow_counts, percentile)) """Get nonP result""" self.metrics['SU_BFL_Tim'][current_gauge.class_number] += list( current_gauge.summer_timings) self.metrics['SU_BFL_Mag_10'][current_gauge.class_number] += list( current_gauge.summer_10_magnitudes) self.metrics['SU_BFL_Mag_50'][current_gauge.class_number] += list( current_gauge.summer_50_magnitudes) self.metrics['SU_BFL_Dur_Fl'][current_gauge.class_number] += list( current_gauge.summer_flush_durations) self.metrics['SU_BFL_Dur_Wet'][current_gauge.class_number] += list( current_gauge.summer_wet_durations) self.metrics['SU_BFL_No_Flow'][current_gauge.class_number] += list( current_gauge.summer_no_flow_counts)
def create_result_csv(self): self.all_year() self.start_of_summer() self.fall_flush_timings_durations() self.summer_baseflow_durations_magnitude() self.winter_highflow_annual() self.spring_transition_timing_magnitude() self.spring_transition_duration() self.spring_transition_roc() self.fall_winter_baseflow() """Convert offset dates to non-offset dates""" spring_timings = [] summer_timings = [] fall_timings = [] fall_wet_timings = [] for index, year in enumerate(self.year_ranges): julian_start_date = datetime.strptime("{}/{}".format(self.start_date, year), "%m/%d/%Y").timetuple().tm_yday spring_timings.append(remove_offset_from_julian_date(self.spring_timings[index], julian_start_date)) summer_timings.append(remove_offset_from_julian_date(self.summer_timings[index], julian_start_date)) fall_timings.append(remove_offset_from_julian_date(self.fall_timings[index], julian_start_date)) fall_wet_timings.append(remove_offset_from_julian_date(self.fall_wet_timings[index], julian_start_date)) winter_timings = {} for percent in self.exceedance_percent: winter_timings[percent] = [] for index, year in enumerate(self.year_ranges): julian_start_date = datetime.strptime("{}/{}".format(self.start_date, year), "%m/%d/%Y").timetuple().tm_yday winter_timings[percent].append(remove_offset_from_julian_date(self.winter_timings[percent][index], julian_start_date)) low_end = general_params['annual_result_low_Percentille_filter'] high_end = general_params['annual_result_high_Percentille_filter'] """Filter data only to contain from low_end to high_end""" self.average_annual_flows = [np.nan if ele < np.nanpercentile(self.average_annual_flows, low_end) or ele > np.nanpercentile(self.average_annual_flows, high_end) else ele for index, ele in enumerate(self.average_annual_flows)] self.standard_deviations = [np.nan if ele < np.nanpercentile(self.standard_deviations, low_end) or ele > np.nanpercentile(self.standard_deviations, high_end) else ele for index, ele in enumerate(self.standard_deviations)] self.coefficient_variations = [np.nan if ele < np.nanpercentile(self.coefficient_variations, low_end) or ele > np.nanpercentile(self.coefficient_variations, high_end) else ele for index, ele in enumerate(self.coefficient_variations)] spring_timings = [np.nan if ele < np.nanpercentile(spring_timings, low_end) or ele > np.nanpercentile(spring_timings, high_end) else ele for index, ele in enumerate(spring_timings)] self.spring_magnitudes = [np.nan if ele < np.nanpercentile(self.spring_magnitudes, low_end) or ele > np.nanpercentile(self.spring_magnitudes, high_end) else ele for index, ele in enumerate(self.spring_magnitudes)] self.spring_durations = [np.nan if ele < np.nanpercentile(self.spring_durations, low_end) or ele > np.nanpercentile(self.spring_durations, high_end) else ele for index, ele in enumerate(self.spring_durations)] self.spring_rocs = [np.nan if ele < np.nanpercentile(self.spring_rocs, low_end) or ele > np.nanpercentile(self.spring_rocs, high_end) else ele for index, ele in enumerate(self.spring_rocs)] summer_timings = [np.nan if ele < np.nanpercentile(summer_timings, low_end) or ele > np.nanpercentile(summer_timings, high_end) else ele for index, ele in enumerate(summer_timings)] self.summer_10_magnitudes = [np.nan if ele < np.nanpercentile(self.summer_10_magnitudes, low_end) or ele > np.nanpercentile(self.summer_10_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_10_magnitudes)] self.summer_50_magnitudes = [np.nan if ele < np.nanpercentile(self.summer_50_magnitudes, low_end) or ele > np.nanpercentile(self.summer_50_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_50_magnitudes)] self.summer_flush_durations = [np.nan if ele < np.nanpercentile(self.summer_flush_durations, low_end) or ele > np.nanpercentile(self.summer_flush_durations, high_end) else ele for index, ele in enumerate(self.summer_flush_durations)] self.summer_wet_durations = [np.nan if ele < np.nanpercentile(self.summer_wet_durations, low_end) or ele > np.nanpercentile(self.summer_wet_durations, high_end) else ele for index, ele in enumerate(self.summer_wet_durations)] self.summer_no_flow_counts = [np.nan if ele < np.nanpercentile(self.summer_no_flow_counts, low_end) or ele > np.nanpercentile(self.summer_no_flow_counts, high_end) else ele for index, ele in enumerate(self.summer_no_flow_counts)] fall_timings = [np.nan if ele < np.nanpercentile(fall_timings, low_end) or ele > np.nanpercentile(fall_timings, high_end) else ele for index, ele in enumerate(fall_timings)] self.fall_magnitudes = [np.nan if ele < np.nanpercentile(self.fall_magnitudes, low_end) or ele > np.nanpercentile(self.fall_magnitudes, high_end) else ele for index, ele in enumerate(self.fall_magnitudes)] fall_wet_timings = [np.nan if ele < np.nanpercentile(fall_wet_timings, low_end) or ele > np.nanpercentile(fall_wet_timings, high_end) else ele for index, ele in enumerate(fall_wet_timings)] self.fall_durations = [np.nan if ele < np.nanpercentile(self.fall_durations, low_end) or ele > np.nanpercentile(self.fall_durations, high_end) else ele for index, ele in enumerate(self.fall_durations)] self.wet_baseflows = [np.nan if ele < np.nanpercentile(self.wet_baseflows, low_end) or ele > np.nanpercentile(self.wet_baseflows, high_end) else ele for index, ele in enumerate(self.wet_baseflows)] for percent in self.exceedance_percent: winter_timings[percent] = [np.nan if ele < np.nanpercentile(winter_timings[percent], low_end) or ele > np.nanpercentile(winter_timings[percent], high_end) else ele for index, ele in enumerate(winter_timings[percent])] self.winter_durations[percent] = [np.nan if ele < np.nanpercentile(self.winter_durations[percent], low_end) or ele > np.nanpercentile(self.winter_durations[percent], high_end) else ele for index, ele in enumerate(self.winter_durations[percent])] self.winter_frequencys[percent] = [np.nan if ele < np.nanpercentile(self.winter_frequencys[percent], low_end) or ele > np.nanpercentile(self.winter_frequencys[percent], high_end) else ele for index, ele in enumerate(self.winter_frequencys[percent])] self.winter_magnitudes[percent] = [np.nan if ele < np.nanpercentile(self.winter_magnitudes[percent], low_end) or ele > np.nanpercentile(self.winter_magnitudes[percent], high_end) else ele for index, ele in enumerate(self.winter_magnitudes[percent])] """result to CSV""" result_matrix = [] result_matrix.append(self.year_ranges) result_matrix.append(self.average_annual_flows) result_matrix.append(self.standard_deviations) result_matrix.append(self.coefficient_variations) result_matrix.append(spring_timings) result_matrix.append(self.spring_magnitudes) result_matrix.append(self.spring_durations) result_matrix.append(self.spring_rocs) result_matrix.append(summer_timings) result_matrix.append(self.summer_10_magnitudes) result_matrix.append(self.summer_50_magnitudes) result_matrix.append(self.summer_flush_durations) result_matrix.append(self.summer_wet_durations) result_matrix.append(self.summer_no_flow_counts) result_matrix.append(fall_timings) result_matrix.append(self.fall_magnitudes) result_matrix.append(fall_wet_timings) result_matrix.append(self.fall_durations) result_matrix.append(self.wet_baseflows) for percent in self.exceedance_percent: result_matrix.append(winter_timings[percent]) result_matrix.append(self.winter_durations[percent]) result_matrix.append(self.winter_frequencys[percent]) result_matrix.append(self.winter_magnitudes[percent]) column_header = ['Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'SU_BFL_Tim', 'SU_BFL_Mag_10', 'SU_BFL_Mag_50', 'SU_BFL_Dur_Fl', 'SU_BFL_Dur_Wet', 'SU_BFL_No_Flow', 'FAFL_Tim', 'FAFL_Mag', 'FAFL_Tim_Wet', 'FAFL_Dur', 'Wet_BFL_Mag', 'WIN_Tim_2', 'WIN_Dur_2', 'WIN_Fre_2', 'WIN_Mag_2', 'WIN_Tim_5', 'WIN_Dur_5', 'WIN_Fre_5', 'WIN_Mag_5', 'WIN_Tim_10', 'WIN_Dur_10', 'WIN_Fre_10', 'WIN_Mag_10', 'WIN_Tim_20', 'WIN_Dur_20', 'WIN_Fre_20', 'WIN_Mag_20', 'WIN_Tim_50', 'WIN_Dur_50', 'WIN_Fre_50', 'WIN_Mag_50'] # column_header = ['Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'SU_Tim', 'SU_Mag_10', 'SU_Mag_50', 'SU_Dur_Fl', 'SU_Dur_Wet', 'SU_No_Flow', 'FA_Tim', 'FA_Mag', 'FA_Tim_Wet', 'FA_Dur', 'Wet_BFL_Mag', 'Tim_2', 'Dur_2', 'Fre_2', 'Mag_2', 'Tim_5', 'Dur_5', 'Fre_5', 'Mag_5','Tim_10', 'Dur_10', 'Fre_10', 'Mag_10', 'Tim_20', 'Dur_20', 'Fre_20', 'Mag_20', 'Tim_50', 'Dur_50', 'Fre_50', 'Mag_50'] new_result_matrix = [] for index, row in enumerate(result_matrix): new_result_matrix.append(list(result_matrix[index])) if len(new_result_matrix) == len(column_header): new_result_matrix = insert_column_header(new_result_matrix, column_header) else: print('Column header does not have the same dimension as result matrix') np.savetxt("post_processedFiles/{}_annual_result_matrix.csv".format( int(self.gauge_number)), new_result_matrix, delimiter=",", fmt="%s")
def format_func(value, tick_number): julian_start_date = datetime.strptime("{}/2001".format(self.start_date), "%m/%d/%Y").timetuple().tm_yday return int(remove_offset_from_julian_date(value, julian_start_date))
def create_result_csv(self): self.all_year() self.start_of_summer() self.fall_flush_timings_durations() self.summer_baseflow_durations_magnitude() self.winter_highflow_annual() self.spring_transition_timing_magnitude() self.spring_transition_duration() self.spring_transition_roc() self.fall_winter_baseflow() """Convert offset dates to non-offset dates""" spring_timings_julian = [] summer_timings_julian = [] fall_timings_julian = [] fall_wet_timings_julian = [] for index, year in enumerate(self.year_ranges): julian_start_date = datetime.strptime( "{}/{}".format(self.start_date, year), "%m/%d/%Y").timetuple().tm_yday spring_timings_julian.append( remove_offset_from_julian_date(self.spring_timings[index], julian_start_date)) summer_timings_julian.append( remove_offset_from_julian_date(self.summer_timings[index], julian_start_date)) fall_timings_julian.append( remove_offset_from_julian_date(self.fall_timings[index], julian_start_date)) fall_wet_timings_julian.append( remove_offset_from_julian_date(self.fall_wet_timings[index], julian_start_date)) low_end = general_params['annual_result_low_Percentille_filter'] high_end = general_params['annual_result_high_Percentille_filter'] """Filter data only to contain from low_end to high_end""" self.average_annual_flows = [ np.nan if ele < np.nanpercentile(self.average_annual_flows, low_end) or ele > np.nanpercentile(self.average_annual_flows, high_end) else ele for index, ele in enumerate(self.average_annual_flows) ] self.standard_deviations = [ np.nan if ele < np.nanpercentile(self.standard_deviations, low_end) or ele > np.nanpercentile(self.standard_deviations, high_end) else ele for index, ele in enumerate(self.standard_deviations) ] self.coefficient_variations = [ np.nan if ele < np.nanpercentile(self.coefficient_variations, low_end) or ele > np.nanpercentile(self.coefficient_variations, high_end) else ele for index, ele in enumerate(self.coefficient_variations) ] spring_timings = [ np.nan if ele < np.nanpercentile(self.spring_timings, low_end) or ele > np.nanpercentile(self.spring_timings, high_end) else ele for index, ele in enumerate(self.spring_timings) ] spring_timings_julian = [ np.nan if ele < np.nanpercentile(spring_timings_julian, low_end) or ele > np.nanpercentile(spring_timings_julian, high_end) else ele for index, ele in enumerate(spring_timings_julian) ] self.spring_magnitudes = [ np.nan if ele < np.nanpercentile(self.spring_magnitudes, low_end) or ele > np.nanpercentile(self.spring_magnitudes, high_end) else ele for index, ele in enumerate(self.spring_magnitudes) ] self.spring_durations = [ np.nan if ele < np.nanpercentile(self.spring_durations, low_end) or ele > np.nanpercentile(self.spring_durations, high_end) else ele for index, ele in enumerate(self.spring_durations) ] self.spring_rocs = [ np.nan if ele < np.nanpercentile(self.spring_rocs, low_end) or ele > np.nanpercentile(self.spring_rocs, high_end) else ele for index, ele in enumerate(self.spring_rocs) ] summer_timings = [ np.nan if ele < np.nanpercentile(self.summer_timings, low_end) or ele > np.nanpercentile(self.summer_timings, high_end) else ele for index, ele in enumerate(self.summer_timings) ] summer_timings_julian = [ np.nan if ele < np.nanpercentile(summer_timings_julian, low_end) or ele > np.nanpercentile(summer_timings_julian, high_end) else ele for index, ele in enumerate(summer_timings_julian) ] self.summer_90_magnitudes = [ np.nan if ele < np.nanpercentile(self.summer_90_magnitudes, low_end) or ele > np.nanpercentile(self.summer_90_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_90_magnitudes) ] self.summer_50_magnitudes = [ np.nan if ele < np.nanpercentile(self.summer_50_magnitudes, low_end) or ele > np.nanpercentile(self.summer_50_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_50_magnitudes) ] self.summer_flush_durations = [ np.nan if ele < np.nanpercentile(self.summer_flush_durations, low_end) or ele > np.nanpercentile(self.summer_flush_durations, high_end) else ele for index, ele in enumerate(self.summer_flush_durations) ] self.summer_wet_durations = [ np.nan if ele < np.nanpercentile(self.summer_wet_durations, low_end) or ele > np.nanpercentile(self.summer_wet_durations, high_end) else ele for index, ele in enumerate(self.summer_wet_durations) ] self.summer_no_flow_counts = [ np.nan if ele < np.nanpercentile(self.summer_no_flow_counts, low_end) or ele > np.nanpercentile(self.summer_no_flow_counts, high_end) else ele for index, ele in enumerate(self.summer_no_flow_counts) ] fall_timings = [ np.nan if ele < np.nanpercentile(self.fall_timings, low_end) or ele > np.nanpercentile(self.fall_timings, high_end) else ele for index, ele in enumerate(self.fall_timings) ] fall_timings_julian = [ np.nan if ele < np.nanpercentile(fall_timings_julian, low_end) or ele > np.nanpercentile(fall_timings_julian, high_end) else ele for index, ele in enumerate(fall_timings_julian) ] self.fall_magnitudes = [ np.nan if ele < np.nanpercentile(self.fall_magnitudes, low_end) or ele > np.nanpercentile(self.fall_magnitudes, high_end) else ele for index, ele in enumerate(self.fall_magnitudes) ] fall_wet_timings = [ np.nan if ele < np.nanpercentile(self.fall_wet_timings, low_end) or ele > np.nanpercentile(self.fall_wet_timings, high_end) else ele for index, ele in enumerate(self.fall_wet_timings) ] fall_wet_timings_julian = [ np.nan if ele < np.nanpercentile(fall_wet_timings_julian, low_end) or ele > np.nanpercentile(fall_wet_timings_julian, high_end) else ele for index, ele in enumerate(fall_wet_timings_julian) ] self.fall_durations = [ np.nan if ele < np.nanpercentile(self.fall_durations, low_end) or ele > np.nanpercentile(self.fall_durations, high_end) else ele for index, ele in enumerate(self.fall_durations) ] self.wet_baseflows_10 = [ np.nan if ele < np.nanpercentile(self.wet_baseflows_10, low_end) or ele > np.nanpercentile(self.wet_baseflows_10, high_end) else ele for index, ele in enumerate(self.wet_baseflows_10) ] self.wet_baseflows_50 = [ np.nan if ele < np.nanpercentile(self.wet_baseflows_50, low_end) or ele > np.nanpercentile(self.wet_baseflows_50, high_end) else ele for index, ele in enumerate(self.wet_baseflows_50) ] self.wet_bfl_durs = [ np.nan if ele < np.nanpercentile(self.wet_bfl_durs, low_end) or ele > np.nanpercentile(self.wet_bfl_durs, high_end) else ele for index, ele in enumerate(self.wet_bfl_durs) ] all_exceedances = [2, 5, 10, 20, 50, 12, 15, 110, 120] for percent in all_exceedances: # self.winter_timings[percent] = [np.nan if ele < np.nanpercentile(self.winter_timings[percent], low_end) or ele > np.nanpercentile( # self.winter_timings[percent], high_end) else ele for index, ele in enumerate(self.winter_timings[percent])] self.winter_durations[percent] = [ np.nan if ele < np.nanpercentile(self.winter_durations[percent], low_end) or ele > np.nanpercentile(self.winter_durations[percent], high_end) else ele for index, ele in enumerate(self.winter_durations[percent]) ] self.winter_frequencys[percent] = [ np.nan if ele < np.nanpercentile( self.winter_frequencys[percent], low_end) or ele > np.nanpercentile(self.winter_frequencys[percent], high_end) else ele for index, ele in enumerate(self.winter_frequencys[percent]) ] self.winter_magnitudes[percent] = [ np.nan if ele < np.nanpercentile( self.winter_magnitudes[percent], low_end) or ele > np.nanpercentile(self.winter_magnitudes[percent], high_end) else ele for index, ele in enumerate(self.winter_magnitudes[percent]) ] """result to CSV""" result_matrix = [] self.year_ranges = [year + 1 for year in self.year_ranges] result_matrix.append(self.year_ranges) result_matrix.append(self.average_annual_flows) result_matrix.append(self.standard_deviations) result_matrix.append(self.coefficient_variations) result_matrix.append(spring_timings) # result_matrix.append(spring_timings_julian) result_matrix.append(self.spring_magnitudes) result_matrix.append(self.spring_durations) result_matrix.append(self.spring_rocs) result_matrix.append(summer_timings) # result_matrix.append(summer_timings_julian) result_matrix.append(self.summer_90_magnitudes) result_matrix.append(self.summer_50_magnitudes) # result_matrix.append(self.summer_flush_durations) result_matrix.append(self.summer_wet_durations) result_matrix.append(self.summer_no_flow_counts) result_matrix.append(fall_timings) # result_matrix.append(fall_timings_julian) result_matrix.append(self.fall_magnitudes) result_matrix.append(fall_wet_timings) # result_matrix.append(fall_wet_timings_julian) result_matrix.append(self.fall_durations) result_matrix.append(self.wet_baseflows_10) result_matrix.append(self.wet_baseflows_50) result_matrix.append(self.wet_bfl_durs) # all_exceedances = [2, 5, 10, 20, 50, 12, 15, 110, 120] # only ouput peak flows all_exceedances = [2, 5, 10, 20, 50] for percent in all_exceedances: # result_matrix.append(self.winter_timings[percent]) result_matrix.append(self.winter_durations[percent]) result_matrix.append(self.winter_frequencys[percent]) result_matrix.append(self.winter_magnitudes[percent]) column_header = [ 'Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'DS_Tim', 'DS_Mag_90', 'DS_Mag_50', 'DS_Dur_WS', 'DS_No_Flow', 'FA_Tim', 'FA_Mag', 'Wet_Tim', 'FA_Dur', 'Wet_BFL_Mag_10', 'Wet_BFL_Mag_50', 'Wet_BFL_Dur', 'Peak_Dur_2', 'Peak_Fre_2', 'Peak_2', 'Peak_Dur_5', 'Peak_Fre_5', 'Peak_5', 'Peak_Dur_10', 'Peak_Fre_10', 'Peak_10', 'Peak_Dur_20', 'Peak_Fre_20', 'Peak_20', 'Peak_Dur_50', 'Peak_Fre_50', 'Peak_50' ] # OMG not me again.... # column_header = ['Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'SU_Tim', 'SU_Mag_10', 'SU_Mag_50', 'SU_Dur_Fl', 'SU_Dur_Wet', 'SU_No_Flow', 'FA_Tim', 'FA_Mag', 'FA_Tim_Wet', 'FA_Dur', # 'Wet_BFL_Mag', 'Tim_2', 'Dur_2', 'Fre_2', 'Mag_2', 'Tim_5', 'Dur_5', 'Fre_5', 'Mag_5', 'Tim_10', 'Dur_10', 'Fre_10', 'Mag_10', 'Tim_20', 'Dur_20', 'Fre_20', 'Mag_20', 'Tim_50', 'Dur_50', 'Fre_50', 'Mag_50'] wateryear_type_matrix = create_wateryear_labels(result_matrix) np.savetxt("post_processedFiles/Wateryear_Type/{}.csv".format( int(self.gauge_number)), wateryear_type_matrix, delimiter=",", fmt="%s") new_result_matrix = [] for index, _ in enumerate(result_matrix): new_result_matrix.append(list(result_matrix[index])) if len(new_result_matrix) == len(column_header): new_result_matrix = insert_column_header(new_result_matrix, column_header) else: print( 'Column header does not have the same dimension as result matrix' ) np.savetxt( "post_processedFiles/Class-{}/{}_annual_result_matrix.csv".format( int(self.class_number), int(self.gauge_number)), new_result_matrix, delimiter=",", fmt="%s") '''File format for FFC QA data input'''
def create_result_csv(self): self.all_year() self.start_of_summer() self.fall_flush_timings_durations() self.summer_baseflow_durations_magnitude() self.winter_highflow_annual() self.spring_transition_timing_magnitude() self.spring_transition_duration() self.spring_transition_roc() self.fall_winter_baseflow() """Convert offset dates to non-offset dates""" spring_timings = [] summer_timings = [] fall_timings = [] fall_wet_timings = [] for index, year in enumerate(self.year_ranges): julian_start_date = datetime.strptime( "{}/{}".format(self.start_date, year), "%m/%d/%Y").timetuple().tm_yday spring_timings.append( remove_offset_from_julian_date(self.spring_timings[index], julian_start_date)) summer_timings.append( remove_offset_from_julian_date(self.summer_timings[index], julian_start_date)) fall_timings.append( remove_offset_from_julian_date(self.fall_timings[index], julian_start_date)) fall_wet_timings.append( remove_offset_from_julian_date(self.fall_wet_timings[index], julian_start_date)) winter_timings = {} for percent in self.exceedance_percent: winter_timings[percent] = [] for index, year in enumerate(self.year_ranges): julian_start_date = datetime.strptime( "{}/{}".format(self.start_date, year), "%m/%d/%Y").timetuple().tm_yday winter_timings[percent].append( remove_offset_from_julian_date( self.winter_timings[percent][index], julian_start_date)) low_end = general_params['annual_result_low_Percentille_filter'] high_end = general_params['annual_result_high_Percentille_filter'] #sigma = summer_params['sigma'] """Filter data only to contain from low_end to high_end""" self.average_annual_flows = [ np.nan if ele < np.nanpercentile(self.average_annual_flows, low_end) or ele > np.nanpercentile(self.average_annual_flows, high_end) else ele for index, ele in enumerate(self.average_annual_flows) ] self.standard_deviations = [ np.nan if ele < np.nanpercentile(self.standard_deviations, low_end) or ele > np.nanpercentile(self.standard_deviations, high_end) else ele for index, ele in enumerate(self.standard_deviations) ] self.coefficient_variations = [ np.nan if ele < np.nanpercentile(self.coefficient_variations, low_end) or ele > np.nanpercentile(self.coefficient_variations, high_end) else ele for index, ele in enumerate(self.coefficient_variations) ] spring_timings = [ np.nan if ele < np.nanpercentile(spring_timings, low_end) or ele > np.nanpercentile(spring_timings, high_end) else ele for index, ele in enumerate(spring_timings) ] self.spring_magnitudes = [ np.nan if ele < np.nanpercentile(self.spring_magnitudes, low_end) or ele > np.nanpercentile(self.spring_magnitudes, high_end) else ele for index, ele in enumerate(self.spring_magnitudes) ] self.spring_durations = [ np.nan if ele < np.nanpercentile(self.spring_durations, low_end) or ele > np.nanpercentile(self.spring_durations, high_end) else ele for index, ele in enumerate(self.spring_durations) ] self.spring_rocs = [ np.nan if ele < np.nanpercentile(self.spring_rocs, low_end) or ele > np.nanpercentile(self.spring_rocs, high_end) else ele for index, ele in enumerate(self.spring_rocs) ] summer_timings = [ np.nan if ele < np.nanpercentile(summer_timings, low_end) or ele > np.nanpercentile(summer_timings, high_end) else ele for index, ele in enumerate(summer_timings) ] self.summer_10_magnitudes = [ np.nan if ele < np.nanpercentile(self.summer_10_magnitudes, low_end) or ele > np.nanpercentile(self.summer_10_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_10_magnitudes) ] self.summer_50_magnitudes = [ np.nan if ele < np.nanpercentile(self.summer_50_magnitudes, low_end) or ele > np.nanpercentile(self.summer_50_magnitudes, high_end) else ele for index, ele in enumerate(self.summer_50_magnitudes) ] self.summer_flush_durations = [ np.nan if ele < np.nanpercentile(self.summer_flush_durations, low_end) or ele > np.nanpercentile(self.summer_flush_durations, high_end) else ele for index, ele in enumerate(self.summer_flush_durations) ] self.summer_wet_durations = [ np.nan if ele < np.nanpercentile(self.summer_wet_durations, low_end) or ele > np.nanpercentile(self.summer_wet_durations, high_end) else ele for index, ele in enumerate(self.summer_wet_durations) ] self.summer_no_flow_counts = [ np.nan if ele < np.nanpercentile(self.summer_no_flow_counts, low_end) or ele > np.nanpercentile(self.summer_no_flow_counts, high_end) else ele for index, ele in enumerate(self.summer_no_flow_counts) ] fall_timings = [ np.nan if ele < np.nanpercentile(fall_timings, low_end) or ele > np.nanpercentile(fall_timings, high_end) else ele for index, ele in enumerate(fall_timings) ] self.fall_magnitudes = [ np.nan if ele < np.nanpercentile(self.fall_magnitudes, low_end) or ele > np.nanpercentile(self.fall_magnitudes, high_end) else ele for index, ele in enumerate(self.fall_magnitudes) ] fall_wet_timings = [ np.nan if ele < np.nanpercentile(fall_wet_timings, low_end) or ele > np.nanpercentile(fall_wet_timings, high_end) else ele for index, ele in enumerate(fall_wet_timings) ] self.fall_durations = [ np.nan if ele < np.nanpercentile(self.fall_durations, low_end) or ele > np.nanpercentile(self.fall_durations, high_end) else ele for index, ele in enumerate(self.fall_durations) ] self.wet_baseflows = [ np.nan if ele < np.nanpercentile(self.wet_baseflows, low_end) or ele > np.nanpercentile(self.wet_baseflows, high_end) else ele for index, ele in enumerate(self.wet_baseflows) ] for percent in self.exceedance_percent: winter_timings[percent] = [ np.nan if ele < np.nanpercentile(winter_timings[percent], low_end) or ele > np.nanpercentile(winter_timings[percent], high_end) else ele for index, ele in enumerate(winter_timings[percent]) ] self.winter_durations[percent] = [ np.nan if ele < np.nanpercentile(self.winter_durations[percent], low_end) or ele > np.nanpercentile(self.winter_durations[percent], high_end) else ele for index, ele in enumerate(self.winter_durations[percent]) ] self.winter_frequencys[percent] = [ np.nan if ele < np.nanpercentile( self.winter_frequencys[percent], low_end) or ele > np.nanpercentile(self.winter_frequencys[percent], high_end) else ele for index, ele in enumerate(self.winter_frequencys[percent]) ] self.winter_magnitudes[percent] = [ np.nan if ele < np.nanpercentile( self.winter_magnitudes[percent], low_end) or ele > np.nanpercentile(self.winter_magnitudes[percent], high_end) else ele for index, ele in enumerate(self.winter_magnitudes[percent]) ] """result to CSV""" result_matrix = [] self.year_ranges = [year + 1 for year in self.year_ranges] result_matrix.append(self.year_ranges) result_matrix.append(self.average_annual_flows) result_matrix.append(self.standard_deviations) result_matrix.append(self.coefficient_variations) result_matrix.append(spring_timings) result_matrix.append(self.spring_magnitudes) result_matrix.append(self.spring_durations) result_matrix.append(self.spring_rocs) result_matrix.append(summer_timings) result_matrix.append(self.summer_10_magnitudes) result_matrix.append(self.summer_50_magnitudes) result_matrix.append(self.summer_flush_durations) result_matrix.append(self.summer_wet_durations) result_matrix.append(self.summer_no_flow_counts) result_matrix.append(fall_timings) result_matrix.append(self.fall_magnitudes) result_matrix.append(fall_wet_timings) result_matrix.append(self.fall_durations) result_matrix.append(self.wet_baseflows) for percent in self.exceedance_percent: result_matrix.append(winter_timings[percent]) result_matrix.append(self.winter_durations[percent]) result_matrix.append(self.winter_frequencys[percent]) result_matrix.append(self.winter_magnitudes[percent]) column_header = [ 'Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'DS_Tim', 'DS_Mag_10', 'DS_Mag_50', 'DS_Dur_WSI', 'DS_Dur_WS', 'DS_No_Flow', 'WSI_Tim', 'WSI_Mag', 'Wet_Tim', 'WSI_Dur', 'Wet_BFL_Mag', 'Peak_Tim_2', 'Peak_Dur_2', 'Peak_Fre_2', 'Peak_Mag_2', 'Peak_Tim_5', 'Peak_Dur_5', 'Peak_Fre_5', 'Peak_Mag_5', 'Peak_Tim_10', 'Peak_Dur_10', 'Peak_Fre_10', 'Peak_Mag_10', 'Peak_Tim_20', 'Peak_Dur_20', 'Peak_Fre_20', 'Peak_Mag_20', 'Peak_Tim_50', 'Peak_Dur_50', 'Peak_Fre_50', 'Peak_Mag_50' ] # OMG not me again.... # column_header = ['Year', 'Avg', 'Std', 'CV', 'SP_Tim', 'SP_Mag', 'SP_Dur', 'SP_ROC', 'SU_Tim', 'SU_Mag_10', 'SU_Mag_50', 'SU_Dur_Fl', 'SU_Dur_Wet', 'SU_No_Flow', 'FA_Tim', 'FA_Mag', 'FA_Tim_Wet', 'FA_Dur', # 'Wet_BFL_Mag', 'Tim_2', 'Dur_2', 'Fre_2', 'Mag_2', 'Tim_5', 'Dur_5', 'Fre_5', 'Mag_5', 'Tim_10', 'Dur_10', 'Fre_10', 'Mag_10', 'Tim_20', 'Dur_20', 'Fre_20', 'Mag_20', 'Tim_50', 'Dur_50', 'Fre_50', 'Mag_50'] wateryear_type_matrix = create_wateryear_labels(result_matrix) np.savetxt("post_processedFiles/Wateryear_Type/{}.csv".format( int(self.gauge_number)), wateryear_type_matrix, delimiter=",", fmt="%s") new_result_matrix = [] for index, _ in enumerate(result_matrix): new_result_matrix.append(list(result_matrix[index])) if len(new_result_matrix) == len(column_header): new_result_matrix = insert_column_header(new_result_matrix, column_header) else: print( 'Column header does not have the same dimension as result matrix' ) # remove 50 percentile values from final matrix. Will need to update this code if variables are added or deleted. if len(new_result_matrix) > 35: new_result_matrix = new_result_matrix[:-4] np.savetxt( "post_processedFiles/{}_sigma{}_annual_result_matrix.csv".format( int(self.gauge_number), int(sigmaa)), new_result_matrix, delimiter=",", fmt="%s") #1/29/2019 adding sigma to the name in the two lines above '''File format for FFC QA data input'''