Пример #1
0
    def _add_data(self, cdf_data, pdf_data, key_list):
        """
        Slice the cube over 'percentile' and update data_dict

        """
        for i, cdf_d in enumerate(cdf_data):
            pdf_point = value_to_string(pdf_data[i])
            cdf_point = value_to_string(cdf_d)
            try:
                self.data_dict[cdf_point].append(pdf_point)
            except KeyError:
                key_list.append(cdf_point)
                self.data_dict[cdf_point] = [pdf_point]
Пример #2
0
    def _write_sample(self, cube, i, key_list):
        # add the variable label to the header
        self.header.append(self.input_data.get_value_label(InputType.VARIABLE)[i])

        for sample_slice in cube.slices_over("sample"):
            sample_id = int(sample_slice.coord("sample").points[0])
            value = value_to_string(sample_slice.data)

            try:
                self.data_dict[sample_id].append(value)
            except KeyError:
                key_list.append(sample_id)
                self.data_dict[sample_id] = [value]
    def _read_percentile_cube(self, cube, key_list):
        """
        Slice the cube over 'percentile' and update data_dict

        """
        for _slice in cube.slices_over("percentile"):
            value = value_to_string(_slice.data)
            # ensure the percentile is reported as no more the 2 dp
            percentile = str(round(_slice.coord("percentile").points[0], 2))
            try:
                self.data_dict[percentile].append(value)
            except KeyError:
                key_list.append(percentile)
                self.data_dict[percentile] = [value]
Пример #4
0
    def _write_time_cube(self, cube, key_list):
        """
        Slice the cube over 'time' and update data_dict

        """
        data = cube.data[:]
        coords = cube.coord("time")[:]
        for time_ in range(0, data.shape[0]):
            value = value_to_string(data[time_])
            time_str = coords[time_].cell(0).point.strftime("%Y-%m-%d")
            try:
                self.data_dict[time_str].append(value)
            except KeyError:
                key_list.append(time_str)
                self.data_dict[time_str] = [value]
Пример #5
0
    def _read_returnlevel_cube(self, cube, key_list):
        """
        Slice the cube over 'return_period' and update data_dict

        """
        data = cube.data[:]
        coords = cube.coord("return_period")[:]
        for period in range(0, data.shape[0]):
            value = value_to_string(data[period])
            time_str = int(round(coords[period].cell(0).point))
            try:
                self.data_dict[time_str].append(value)
            except KeyError:
                key_list.append(time_str)
                self.data_dict[time_str] = [value]
Пример #6
0
    def _write_region_csv(self):
        """
        Write out region data to a file.

        The data can have multiple regions and percentiles. N.B. only the 10th, 50th
        and 90th percentiles are output, there may be additional percentiles in the
        cube.

        """
        LOG.debug("_write_region_csv")

        # There should only be one cube so we only make reference to self.cube_list[0]
        cube = self.cube_list[0]

        # update the header
        self.header.append(str(cube.coords(var_name="geo_region")[0].long_name))

        var = self.input_data.get_value_label(InputType.VARIABLE)[0]

        # extract 10th, 50th and 90th percentiles
        percentiles = [10, 50, 90]
        key_list = []
        for percentile in percentiles:
            # update the header
            self.header.append(f"{var}({percentile}th Percentile)")

        output_data_file_path = self._get_full_file_name()
        self._write_headers(output_data_file_path)

        for percentile in percentiles:

            percentile_cube = cube.extract(iris.Constraint(percentile=percentile))

            # rows of data
            for region_slice in percentile_cube.slices_over("region"):
                region = str(region_slice.coords(var_name="geo_region")[0].points[0])

                value = value_to_string(region_slice.data)
                try:
                    self.data_dict[region].append(value)
                except KeyError:
                    key_list = [region] + key_list
                    self.data_dict[region] = [value]

        output_data_file_path = self._get_full_file_name()
        self._write_data_dict(output_data_file_path, key_list)

        return [output_data_file_path]