Ejemplo n.º 1
0
    def test_invalid_temperature_change(self):
        """
        Test that an error is raised when a grid cell's temperature is changed
        to an invalid value after the cell is instantiated. Also ensures that
        the grid cell's temperature is unchanged after the attempt.
        """
        cell = GridCell(273.15, 65, 0.6)
        cell.set_temperature(274.15)

        with self.assertRaises(ValueError):
            cell.set_temperature(-1)

        self.assertEqual(cell.get_temperature(), 274.15)
        self.assertEqual(cell.get_temperature_change(), 1)
Ejemplo n.º 2
0
    def test_temperature_change_tracks(self):
        """
        Test that changes to a grid cell's temperature are reflected properly
        in both its temperature value and temperature change value.
        """
        temp = 298
        r_hum = 37.25
        albedo = 0.5

        cell = GridCell(temp, r_hum, albedo)
        self.assertEqual(cell.get_temperature_change(), 0)

        cell.set_temperature(temp + 1)
        self.assertEqual(cell.get_temperature(), temp + 1)
        self.assertEqual(cell.get_temperature_change(), 1)

        cell.set_temperature(temp - 1)
        self.assertEqual(cell.get_temperature(), temp - 1)
        self.assertEqual(cell.get_temperature_change(), -1)
Ejemplo n.º 3
0
    def test_extract_temperature_change(self):
        """
        Test that extracting temperature change data from a grid returns an
        array structure of the right dimensions, containing the right delta
        temperature data in the right order.
        """
        cell_00 = GridCell(1, 2, 0.1)
        cell_01 = GridCell(2, 4, 0.2)
        cell_10 = GridCell(3, 6, 0.3)
        cell_11 = GridCell(4, 8, 0.4)

        cell_01.set_temperature(2.5)
        cell_10.set_temperature(4)
        cell_11.set_temperature(5.5)

        cells = [[cell_00, cell_01], [cell_10, cell_11]]

        grid = LatLongGrid(cells)
        delta_temp_data = grid.extract_datapoint("delta_t")
        expected_delta_temp_data = [[0, 0.5], [1, 1.5]]

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

        # Loop for comparison, because extract_datapoint may return its data
        # in a non-list format such as an array.
        for i in range(len(cells)):
            for j in range(len(cells[0])):
                self.assertEqual(delta_temp_data[i][j],
                                 expected_delta_temp_data[i][j])