Пример #1
0
def extract_current_data_at_index(fixed_df, current_gauge_column_index):
    current_gauge_number = fixed_df.iloc[1, current_gauge_column_index]
    current_gauge_class = fixed_df.iloc[0, current_gauge_column_index]

    print('Gaguge Class: {}'.format(int(current_gauge_class)))
    print('Gauge Number: {}'.format(int(current_gauge_number)))

    if is_multiple_date_data(fixed_df):
        raw_date_column = fixed_df.iloc[:, current_gauge_column_index - 1]
    else:
        raw_date_column = fixed_df.iloc[:, 0]
    raw_flow_column = fixed_df.iloc[:, current_gauge_column_index]

    return current_gauge_class, current_gauge_number, raw_date_column, raw_flow_column
Пример #2
0
    def calculate(self):
        for root, dirs, files in os.walk(self.directory_name):
            for file in files:
                if file.endswith(self.end_with):

                    fixed_df = pd.read_csv('{}/{}'.format(
                        self.directory_name, file),
                                           sep=',',
                                           encoding='latin1',
                                           dayfirst=False,
                                           header=None,
                                           low_memory=False).dropna(axis=1,
                                                                    how='all')
                    step = is_multiple_date_data(fixed_df)

                    current_gauge_column_index = 1
                    if not self.class_number and not self.gauge_numbers:
                        while current_gauge_column_index <= (
                                len(fixed_df.iloc[1, :]) - 1):
                            self._get_result_arrays(
                                fixed_df, current_gauge_column_index)
                            current_gauge_column_index = current_gauge_column_index + step

                    elif self.gauge_numbers:
                        while current_gauge_column_index <= (
                                len(fixed_df.iloc[1, :]) - 1):
                            if int(fixed_df.iloc[1, current_gauge_column_index]
                                   ) in self.gauge_numbers:
                                self._get_result_arrays(
                                    fixed_df, current_gauge_column_index)
                            current_gauge_column_index = current_gauge_column_index + step

                    elif self.class_number:
                        while current_gauge_column_index <= (
                                len(fixed_df.iloc[1, :]) - 1):
                            if int(fixed_df.iloc[
                                    0, current_gauge_column_index]) == int(
                                        self.class_number):
                                self._get_result_arrays(
                                    fixed_df, current_gauge_column_index)
                            current_gauge_column_index = current_gauge_column_index + step
                    else:
                        print('Something went wrong!')

        self.result_to_csv()
Пример #3
0
def dim_hydrograph_plotter_layer(start_date, directory_name, end_with, class_number, gauge_numbers, plot):
    for root,dirs,files in os.walk(directory_name):
        for file in files:
            if file.endswith(end_with):
                fixed_df = pd.read_csv('{}/{}'.format(directory_name, file), sep=',', encoding='latin1', dayfirst=False, header=None).dropna(axis=1, how='all')
                step = is_multiple_date_data(fixed_df);

                current_gauge_column_index = 1

                while current_gauge_column_index <= (len(fixed_df.iloc[1,:]) - 1):
                    if gauge_numbers:
                        if int(fixed_df.iloc[1, current_gauge_column_index]) in gauge_numbers:
                            current_gauge_class, current_gauge_number, year_ranges, flow_matrix, julian_dates = convert_raw_data_to_matrix(fixed_df, current_gauge_column_index, start_date)
                            start_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['start']))
                            end_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['end']))
                            flow_matrix = flow_matrix[:,start_year_index:end_year_index]

                            _plotter(flow_matrix, julian_dates, current_gauge_number, plot, start_date)

                    elif not class_number and not gauge_numbers:
                        current_gauge_class, current_gauge_number, year_ranges, flow_matrix, julian_dates = convert_raw_data_to_matrix(fixed_df, current_gauge_column_index, start_date)
                        start_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['start']))
                        end_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['end']))
                        flow_matrix = flow_matrix[:,start_year_index:end_year_index]

                        _plotter(flow_matrix, julian_dates, current_gauge_number, plot, start_date)

                    elif int(fixed_df.iloc[0, current_gauge_column_index]) == int(class_number):
                        current_gauge_class, current_gauge_number, year_ranges, flow_matrix, julian_dates = convert_raw_data_to_matrix(fixed_df, current_gauge_column_index, start_date)
                        start_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['start']))
                        end_year_index = find_index(year_ranges, int(gauge_reference[int(current_gauge_number)]['end']))
                        flow_matrix = flow_matrix[:,start_year_index:end_year_index]

                        _plotter(flow_matrix, julian_dates, current_gauge_number, plot, start_date)

                    current_gauge_column_index = current_gauge_column_index + step
def dim_hydrograph_plotter_agg(start_date, directory_name, end_with,
                               class_number, gauge_numbers, plot):
    aggregate_matrix = np.zeros(
        (366, 7))  # change to 5 for matrix without min/max
    counter = 0
    for root, dirs, files in os.walk(directory_name):
        for file in files:
            if file.endswith(end_with):
                fixed_df = pd.read_csv('{}/{}'.format(directory_name, file),
                                       sep=',',
                                       encoding='latin1',
                                       dayfirst=False,
                                       header=None).dropna(axis=1, how='all')
                step = is_multiple_date_data(fixed_df)
                current_gauge_column_index = 1
                while current_gauge_column_index <= (len(fixed_df.iloc[1, :]) -
                                                     1):
                    if gauge_numbers:
                        if int(fixed_df.iloc[
                                1,
                                current_gauge_column_index]) in gauge_numbers:
                            current_gauge_class, current_gauge_number, year_ranges, flow_matrix, julian_dates = convert_raw_data_to_matrix(
                                fixed_df, current_gauge_column_index,
                                start_date)
                            start_year_index = find_index(
                                year_ranges,
                                int(gauge_reference[int(current_gauge_number)]
                                    ['start']))
                            end_year_index = find_index(
                                year_ranges,
                                int(gauge_reference[int(current_gauge_number)]
                                    ['end']))
                            flow_matrix = flow_matrix[:, start_year_index:
                                                      end_year_index]
                            aggregate_matrix = np.add(
                                aggregate_matrix, _getAggMatrix(flow_matrix))
                            counter = counter + 1

                    elif int(fixed_df.iloc[0,
                                           current_gauge_column_index]) == int(
                                               class_number):
                        current_gauge_class, current_gauge_number, year_ranges, flow_matrix, julian_dates = convert_raw_data_to_matrix(
                            fixed_df, current_gauge_column_index, start_date)
                        start_year_index = find_index(
                            year_ranges,
                            int(gauge_reference[int(current_gauge_number)]
                                ['start']))
                        end_year_index = find_index(
                            year_ranges,
                            int(gauge_reference[int(current_gauge_number)]
                                ['end']))
                        flow_matrix = flow_matrix[:, start_year_index:
                                                  end_year_index]
                        aggregate_matrix = np.add(aggregate_matrix,
                                                  _getAggMatrix(flow_matrix))
                        counter = counter + 1

                    current_gauge_column_index = current_gauge_column_index + step

        final_aggregate = aggregate_matrix / counter

        if class_number:
            np.savetxt(
                "post_processedFiles/Hydrographs/Class_{}_aggregate.csv".
                format(int(current_gauge_class)),
                final_aggregate,
                delimiter=",",
                fmt="%s")
        else:
            np.savetxt(
                "post_processedFiles/Hydrographs/plot_data_{}.csv".format(
                    int(current_gauge_number)),
                final_aggregate,
                delimiter=",",
                fmt="%s")
        """To output plot, uncomment line below"""
        _plotter(final_aggregate, start_date)