Exemplo n.º 1
0
def print_solo_statistics(data: GriddedData) -> None:
    """
    Display a series of tables and statistics based on model run results.
    Which outputs are displayed is determined by the current output
    controller, and its settings under the SpecialReportDatatype and
    ReportDatatype categories.
    """
    output_center = out_cnf.global_output_center()

    # Prepare data tables.
    temp_name = out_cnf.ReportDatatype.REPORT_TEMP.value
    delta_t_name = out_cnf.ReportDatatype.REPORT_TEMP_CHANGE.value

    temp_data = \
        extract_multidimensional_grid_variable(data, temp_name)
    temp_table = convert_grid_data_to_table(temp_data)

    output_center.submit_output(out_cnf.ReportDatatype.REPORT_TEMP,
                                temp_table)

    delta_temp_data = \
        extract_multidimensional_grid_variable(data, delta_t_name)
    delta_temp_table = convert_grid_data_to_table(delta_temp_data)

    # Print tables of data.
    output_center.submit_output(
        out_cnf.ReportDatatype.REPORT_TEMP_CHANGE,
        delta_temp_table
    )
Exemplo n.º 2
0
    def write_images(self: 'ModelOutput',
                     data: List['LatLongGrid'],
                     output_path: str,
                     run_id: str = "") -> None:
        """
        Produce a series of maps displaying some of the results of an
        Arrhenius model run according to what variable the output controller
        allows. Images are stored in a directory given by output_path.

        One image will be produced per time segment per variable for which
        output is allowed by the output controller, based on which
        ReportDatatype output types are enabled. The optional argument
        img_base_name specifies a prefix that will be added to each of the
        image files to identify which model run they belong to.

        :param data:
            The output from an Arrhenius model run
        :param output_path:
            The directory where image files will be stored
        :param run_id:
            A prefix that will start off the names of all the image files
        """
        output_controller = global_output_center()

        # Attempt to output images for each variable output type.
        for output_type in ReportDatatype:
            variable_name = output_type.value
            variable = extract_multidimensional_grid_variable(
                data, variable_name)
            img_type_path = path.join(output_path, variable_name)

            output_controller.submit_output(output_type, variable,
                                            img_type_path, variable_name,
                                            run_id)
Exemplo n.º 3
0
    def write_images(self: 'ModelOutput',
                     data: List['LatLongGrid'],
                     output_path: str,
                     config: 'ArrheniusConfig') -> None:
        """
        Produce a series of maps displaying some of the results of an
        Arrhenius model run according to what variable the output controller
        allows. Images are stored in a directory given by output_path.

        One image will be produced per time segment per variable for which
        output is allowed by the output controller, based on which
        ReportDatatype output types are enabled. Names of these image files
        are based on variable and time unit, as well as config.

        :param data:
            The output from an Arrhenius model run
        :param output_path:
            The directory where image files will be stored
        :param config:
            Configuration options for the model run
        """
        output_controller = global_output_center()

        # Attempt to output images for each variable output type.
        for output_type in ReportDatatype:
            var_name = output_type.value
            variable = extract_multidimensional_grid_variable(data, var_name)

            output_controller.submit_output(output_type, variable,
                                            output_path,
                                            var_name,
                                            config)
Exemplo n.º 4
0
def print_relation_statistics(data: GriddedData, expected: np.ndarray) -> None:
    """
    Print a series of tables and statistics based on the relation between
    model run results, given by data, and an array of expected results for
    temperature change, given by the parameter expected.

    The expected results must have dimensions appropriate to the model data
    in table format. Table format reduces the number of dimensions of the data
    by one, by aggregating latitude bands. Otherwise, the dimensions of the
    data remain in the same order (time, level, longitude).

    :param data:
        A nested list of model run results
    :param expected:
        An array of expected temperature change values for the model run
    """
    delta_t_name = out_cnf.ReportDatatype.REPORT_TEMP_CHANGE.value
    delta_temp_data = \
        extract_multidimensional_grid_variable(data, delta_t_name)
    delta_temp_table = convert_grid_data_to_table(delta_temp_data)

    output_center = out_cnf.global_output_center()
    diff = expected - delta_temp_table

    output_center.submit_output(
        out_cnf.SpecialReportData.REPORT_DELTA_TEMP_DEVIATIONS, diff)

    output_center.submit_output(
        out_cnf.AccuracyMetrics.TEMP_DELTA_AVG_DEVIATION, mean(diff))

    output_center.submit_output(
        out_cnf.AccuracyMetrics.TEMP_DELTA_STD_DEVIATION, std_dev(diff))

    output_center.submit_output(out_cnf.AccuracyMetrics.TEMP_DELTA_VARIANCE,
                                variance(diff))
Exemplo n.º 5
0
    def print_statistic_tables(self: 'ModelRun') -> None:
        """
        Display a series of tables and statistics based on model run results.
        Which outputs are displayed is determined by the current output
        controller, and its settings under the SpecialReportDatatype and
        ReportDatatype categories.
        """
        output_center = out_cnf.global_output_center()

        # Prepare data tables.
        temp_name = out_cnf.ReportDatatype.REPORT_TEMP.value
        delta_t_name = out_cnf.ReportDatatype.REPORT_TEMP_CHANGE.value

        temp_data = \
            extract_multidimensional_grid_variable(self.grids, temp_name)
        temp_table = convert_grid_data_to_table(temp_data)

        output_center.submit_output(out_cnf.ReportDatatype.REPORT_TEMP,
                                    temp_table)

        delta_temp_data = \
            extract_multidimensional_grid_variable(self.grids, delta_t_name)
        delta_temp_table = convert_grid_data_to_table(delta_temp_data)

        # Print tables of data.
        output_center.submit_output(out_cnf.ReportDatatype.REPORT_TEMP_CHANGE,
                                    delta_temp_table)

        expected = X2_EXPECTED
        diff = expected - delta_temp_table

        output_center.submit_output(
            out_cnf.SpecialReportData.REPORT_DELTA_TEMP_DEVIATIONS, diff)

        output_center.submit_output(
            out_cnf.AccuracyMetrics.TEMP_DELTA_AVG_DEVIATION, mean(diff))

        output_center.submit_output(
            out_cnf.AccuracyMetrics.TEMP_DELTA_STD_DEVIATION, std_dev(diff))
Exemplo n.º 6
0
    def write_dataset(self: 'ModelOutput',
                      data: List['LatLongGrid'],
                      dir_path: str,
                      dataset_name: str) -> None:
        """
        Produce a NetCDF dataset, with the name given by dataset_name.nc,
        containing the variables in the data parameter that the output
        controller allows. The dataset will be written to the specified
        path in the file system.

        The dataset contains all the dimensions that are used in the data
        (e.g. time, latitude, longitude) as well as variables including
        final temperature, temperature change, humidity, etc. according
        to which of the ReportDatatype output types are enabled in the
        current output controller.

        :param data:
            Output from an Arrhenius model run
        :param dir_path:
            The directory where the dataset will be written
        :param dataset_name:
            The name of the dataset
        """
        # Write the data out to a NetCDF file in the output directory.
        grid_by_count = self._grid.dims_by_count()
        output_path = path.join(dir_path, dataset_name)

        global_output_center().submit_output(Debug.PRINT_NOTICES,
                                             "Writing NetCDF dataset...")
        self._dataset.global_attribute("description", "Output for an"
                                                      "Arrhenius model run.")\
            .dimension('time', np.int32, len(data), (0, len(data)))\
            .dimension('latitude', np.int32, grid_by_count[0], (-90, 90)) \
            .dimension('longitude', np.int32, grid_by_count[1], (-180, 180)) \

        for output_type in ReportDatatype:
            variable_data =\
                extract_multidimensional_grid_variable(data,
                                                       output_type.value)
            global_output_center().submit_output(output_type, variable_data,
                                                 output_type.value)

        self._dataset.write(output_path)
Exemplo n.º 7
0
    def test_extract_three_dimensional_datapoint(self):
        """
        Test conversion of a one-level of grids into a three-dimensional
        structure of temperature data extracted from the grid. Checks
        correct ordering of data in the output.
        """
        cell_000 = GridCell(1, 2, 0.1)
        cell_001 = GridCell(2, 4, 0.2)
        cell_010 = GridCell(3, 6, 0.3)
        cell_011 = GridCell(4, 8, 0.4)

        cell_100 = GridCell(5, 10, 0.5)
        cell_101 = GridCell(6, 12, 0.6)
        cell_110 = GridCell(7, 14, 0.7)
        cell_111 = GridCell(8, 16, 0.8)

        cells0 = [[cell_000, cell_001], [cell_010, cell_011]]
        cells1 = [[cell_100, cell_101], [cell_110, cell_111]]

        grid0 = LatLongGrid(cells0)
        grid1 = LatLongGrid(cells1)

        grid0_temp_expected = [[1, 2], [3, 4]]
        grid1_temp_expected = [[5, 6], [7, 8]]

        temp_data = extract_multidimensional_grid_variable([grid0, grid1],
                                                           "temperature")

        self.assertEqual(len(temp_data), 2)
        self.assertEqual(len(temp_data[0]), 2)
        self.assertEqual(len(temp_data[0][0]), 2)

        for i in range(len(temp_data)):
            for j in range(len(temp_data[0])):
                self.assertEqual(temp_data[0][i][j], grid0_temp_expected[i][j])
                self.assertEqual(temp_data[1][i][j], grid1_temp_expected[i][j])