Beispiel #1
0
    def test_set_array(self):

        h = SeasonalHyperparameters(n_spatial_components=3,
                                    common_log_sigma=0.8,
                                    common_log_rho=1.0)
        h.set_array([88.2, 103.4, 0.2, 0.3, 0.4, 0.5])
        numpy.testing.assert_equal(h.harmonics,
                                   [88.2, 103.4, 0.2, 0.3, 0.4, 0.5])
Beispiel #2
0
    def test_harmonic_parameters(self):

        h = SeasonalHyperparameters(n_spatial_components=3,
                                    common_log_sigma=0.8,
                                    common_log_rho=1.0)
        h.set_array([88.2, 103.4, 0.2, 0.3, 0.4, 0.5])
        self.assertEqual(0.2, h.harmonic_parameters(1).log_sigma)
        self.assertEqual(103.4, h.harmonic_parameters(0).log_rho)
        self.assertEqual({
            'log_sigma': 0.4,
            'log_rho': 0.5
        },
                         h.harmonic_parameters(2).get_dictionary())
Beispiel #3
0
    def __init__(self, covariates_descriptor):
        if covariates_descriptor is not None:
            loader = LoadCovariateElement(covariates_descriptor)
            loader.check_keys()
            covariate_elements, covariate_hyperparameters = loader.load_covariates_and_hyperparameters(
            )
            print(
                'The following fields have been added as covariates of the climatology model'
            )
            print(loader.data.keys())
        else:
            covariate_elements, covariate_hyperparameters = [], []

        setup = MovingClimatologySetup()

        model_elements = CombinationElement([
            AnnualKroneckerElement(
                setup.seasonal_spline_settings.n_triangulation_divisions, setup
                .seasonal_spline_settings.alpha, setup.seasonal_spline_settings
                .starttime, setup.seasonal_spline_settings.endtime,
                setup.seasonal_spline_settings.n_nodes,
                setup.seasonal_spline_settings.overlap_factor,
                setup.seasonal_spline_settings.H,
                setup.seasonal_spline_settings.wrap_dimensions),
            #SeasonalElement(setup.seasonal_settings.n_triangulation_divisions,
            #setup.seasonal_settings.n_harmonics,
            #include_local_mean=setup.seasonal_settings.include_local_mean),
            GrandMeanElement(),
            LatitudeSplineElement(
                setup.latitude_settings.alpha,
                setup.latitude_settings.n_nodes,
                setup.latitude_settings.overlap_factor,
                setup.latitude_settings.H,
            ),
        ] + covariate_elements)

        seasonal_hyperparameters = SeasonalHyperparameters(
            setup.seasonal_settings.n_spatial_components,
            numpy.log(setup.seasonal_settings.amplitude),
            numpy.log(numpy.radians(
                setup.seasonal_settings.space_length_scale)))

        seasonal_spline_hyperparameters = SpaceTimeSPDEHyperparameters(
            numpy.log(setup.seasonal_spline_settings.amplitude),
            numpy.log(
                numpy.radians(
                    setup.seasonal_spline_settings.space_length_scale)),
            numpy.log(setup.seasonal_spline_settings.time_length_scale))

        seasonal_params = zip(
            numpy.log(setup.seasonal_settings.harmonic_amplitudes),
            numpy.log(
                numpy.radians(setup.seasonal_settings.harmonic_length_scales)))
        seasonal_hyperparameters.set_array(
            [val for pair in seasonal_params for val in pair])

        model_hyperparameters = CombinationHyperparameters([
            seasonal_spline_hyperparameters,
            #seasonal_hyperparameters,
            CovariateHyperparameters(
                numpy.log(setup.covariate_settings.grandmean_amplitude)),
            #SpaceTimeSPDEHyperparameters(numpy.log(setup.slow_settings.amplitude),
            #numpy.log(numpy.radians(setup.slow_settings.space_length_scale)),
            #numpy.log(setup.slow_settings.time_length_scale)),
            LocalHyperparameters(
                numpy.log(setup.latitude_settings.amplitude),
                numpy.log(setup.latitude_settings.length_scale))
        ] + covariate_hyperparameters)

        super(ClimatologyDefinition, self).__init__(model_elements,
                                                    model_hyperparameters)