Exemplo n.º 1
0
def test_can_initialize_frostnumber_method_from_timeseries_file():
    """ Test fn initialization from config file (time series) """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_timeseries.cfg')
    fn.initialize(cfg_file=cfg_file)
    files_to_remove.append(fn.fn_out_filename)
Exemplo n.º 2
0
def test_frostnumber_method_has_date_info():
    """ Test that fn has time values """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_scalar.cfg')
    fn.initialize(cfg_file=cfg_file)
    assert_greater_equal(fn.year, 0)
    assert_equal(fn.year, fn.start_year)
Exemplo n.º 3
0
def test_end_year_before_start_year_error():
    """ Test end_year before start_year """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
    fn.start_year = 2000
    fn.end_year = 1990
    fn.initialize_frostnumber_component()
    assert_equal(fn.start_year, fn.end_year)
Exemplo n.º 4
0
def test_frostnumber_method_updates():
    """ Test fn update() """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_timeseries.cfg')
    fn.initialize(cfg_file=cfg_file)
    fn.update()
    assert_equal(fn.year, 2001)
    assert_almost_equal(fn.air_frost_number, 0.5, places=3)
def test_frostnumber_method_updates():
    """ Test fn update() """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_timeseries.cfg')
    fn.initialize(cfg_file=cfg_file)
    fn.update()
    assert fn.year == 2001
    assert fn.air_frost_number == approx(0.5)
Exemplo n.º 6
0
def test_frostnumber_generates_output():
    """ Test fn generates output file """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_timeseries.cfg')
    fn.initialize(cfg_file=cfg_file)
    fn.update()
    fn.write_output_to_file()
    assert_true(os.path.isfile(fn.fn_out_filename))
    files_to_remove.append(fn.fn_out_filename)
Exemplo n.º 7
0
def test_frostnumber_method_calculates_exact_fn():
    """ Test fn gets calculated """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
    fn.T_air_min = [5.0]
    fn.T_air_max = [15.0]
    fn.calculate_air_frost_number()
    assert_almost_equal(fn.air_frost_number, 0.0, places=3)
    fn.T_air_min = [-25.0]
    fn.T_air_max = [-5.0]
    fn.calculate_air_frost_number()
    assert_almost_equal(fn.air_frost_number, 1.0, places=3)
def test_frostnumber_method_calculates_exact_fn():
    """ Test fn gets calculated """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
    fn.T_air_min = [5.0]
    fn.T_air_max = [15.0]
    fn.calculate_air_frost_number()
    assert fn.air_frost_number == approx(0.0)
    fn.T_air_min = [-25.0]
    fn.T_air_max = [-5.0]
    fn.calculate_air_frost_number()
    assert fn.air_frost_number == approx(1.0)
Exemplo n.º 9
0
def test_frostnumber_generates_output():
    """ Test fn generates output file """
    fn = frost_number.FrostnumberMethod()
    cfg_file = os.path.join(examples_directory,
                            'Frostnumber_example_timeseries.cfg')
    fn.initialize(cfg_file=cfg_file)
    fn.update()
    output_written = fn.write_output_to_file()
    if output_written:
        assert_true(os.path.isfile(fn.fn_out_filename))
        files_to_remove.append(fn.fn_out_filename)
    else:
        print('Unable to test output to: {}'.format(fn.fn_out_filename))
Exemplo n.º 10
0
    def initialize(self, cfg_file=None):
        """ this overwrites initialize() in PermafrostComponent """
        self._model = frost_number.FrostnumberMethod()
        # This allows testing to not use protected access to _model
        self.model = self._model

        self._model.initialize_from_config_file(cfg_file=cfg_file)
        self._model.initialize_frostnumber_component()

        # Verify that all input and output variable names are in the
        # variable name and the units map
        for varname in self._input_var_names:
            assert varname in self._var_name_map
            assert varname in self._var_units_map
        for varname in self._output_var_names:
            assert varname in self._var_name_map
            assert varname in self._var_units_map

        # Set the Frost Number grids, based on input and output variables
        # Set the names and types of the grids
        gridnumber = 0
        for varname in self._input_var_names:
            self._grids[gridnumber] = varname
            self._grid_type[gridnumber] = 'scalar'
            gridnumber += 1
        for varname in self._output_var_names:
            self._grids[gridnumber] = varname
            self._grid_type[gridnumber] = 'scalar'
            gridnumber += 1

        # Set the internal (frost number) variables that correspond
        # to the input and output variable names
        # Note: since we used Topoflow's _var_name_map for this, it is that
        self._values = {
            # These are the links to the model's variables and
            # should be consistent with _var_name_map
            'atmosphere_bottom_air__time_min_of_temperature':
            self._model.T_air_min,
            'atmosphere_bottom_air__time_max_of_temperature':
            self._model.T_air_max,
            'frostnumber__air': self._model.air_frost_number,
            'frostnumber__surface': self._model.surface_frost_number,
            'frostnumber__stefan': self._model.stefan_frost_number,
        }
Exemplo n.º 11
0
def test_frostnumber_method_calculates_fn():
    """ Test fn gets calculated """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
    assert_almost_equal(fn.air_frost_number, 0.63267, places=3)
Exemplo n.º 12
0
def test_initialize_frostnumber_method():
    """ Test fn initialization without config file """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
def test_frostnumber_method_calculates_fn():
    """ Test fn gets calculated """
    fn = frost_number.FrostnumberMethod()
    fn.initialize()
    assert fn.air_frost_number == approx(0.6326749410343562)