Esempio n. 1
0
 def test_get_remaining_dims_7d_anonymous(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     used_dims = (names[5], names[3], names[0])
     remaining_dims = gl.get_remaining_dims(names, used_dims)
     self.assertEqual(remaining_dims, [names[1], names[2], names[4],
                      names[6]])
Esempio n. 2
0
 def test_get_dim_names_7d(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     self.assertEqual(names, [
         "*ANONYMOUS*0", "*ANONYMOUS*1", "*ANONYMOUS*2", "*ANONYMOUS*3",
         "*ANONYMOUS*4", "*ANONYMOUS*5", "*ANONYMOUS*6"
     ])
Esempio n. 3
0
 def test_get_dim_index(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     dim = "model_level_number"
     index = gl.get_dim_index(dim, names)
     expected_index = 1
     self.assertEqual(index, expected_index)
Esempio n. 4
0
 def test_get_dim_index(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     dim = "model_level_number"
     index = gl.get_dim_index(dim, names)
     expected_index = 1
     self.assertEqual(index, expected_index)
Esempio n. 5
0
 def test_get_remaining_dims_7d_anonymous(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     used_dims = (names[5], names[3], names[0])
     remaining_dims = gl.get_remaining_dims(names, used_dims)
     self.assertEqual(remaining_dims,
                      [names[1], names[2], names[4], names[6]])
Esempio n. 6
0
 def test_get_dim_names_7d(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     self.assertEqual(names, ["*ANONYMOUS*0", "*ANONYMOUS*1",
                              "*ANONYMOUS*2", "*ANONYMOUS*3",
                              "*ANONYMOUS*4", "*ANONYMOUS*5",
                              "*ANONYMOUS*6"])
Esempio n. 7
0
 def test_get_dim_values_date_time(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "time", names)
     points = cube.coord("time").points
     coord = cube.coord("time")
     expected_values = [coord.units.num2date(point) for point in points]
     self.assertEqual(all(values), all(expected_values))
Esempio n. 8
0
 def test_get_dim_values_date_time(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "time", names)
     points = cube.coord("time").points
     coord = cube.coord("time")
     expected_values = [coord.units.num2date(point) for point in points]
     self.assertEqual(all(values), all(expected_values))
Esempio n. 9
0
def sort_axis_labels(cube, axis_labels):
    """
    Takes in the axis labels, and arranges them so that they are sorted into
    the form xlabel, ylabel.

    Args:

    * cube
        The cube to which the labels belong. (The full cube before collapsing)

    *axis_labels
        List of Strings, representing the coordinate names of the x and y axes
        of the plot.

    """
    dim_names = get_dim_names(cube)
    sorted_list = []
    for name in dim_names:
        if name in axis_labels:
            sorted_list.append(name)
    if len(sorted_list) != 2:
        sorted_list = ('', '')
    return sorted_list[1], sorted_list[0]
Esempio n. 10
0
def sort_axis_labels(cube, axis_labels):
    """
    Takes in the axis labels, and arranges them so that they are sorted into
    the form xlabel, ylabel.

    Args:

    * cube
        The cube to which the labels belong. (The full cube before collapsing)

    *axis_labels
        List of Strings, representing the coordinate names of the x and y axes
        of the plot.

    """
    dim_names = get_dim_names(cube)
    sorted_list = []
    for name in dim_names:
        if name in axis_labels:
            sorted_list.append(name)
    if len(sorted_list) != 2:
        sorted_list = ("", "")
    return sorted_list[1], sorted_list[0]
Esempio n. 11
0
    def set_dimension_combos(self):
        """
        This method is responisble for ensuring that all of the revelant
        combo boxes are filled with the correct coordinate names. It is
        called whenever the cube is changed.

        """
        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)

        self.clear_dims()

        # Cube is set and the summary is printed to the information tab.
        self.cube = self.get_current_cube()
        self.print_cube_browser.setText(str(self.cube))

        # we check to see if we need to add or remove collapsed dim slots
        old_ndim = self.ndim if self.ndim > 3 else 3
        new_ndim = self.cube.ndim if self.cube.ndim > 3 else 3

        difference = new_ndim - old_ndim

        # adds more slots until there are enough.
        if difference > 0:
            for i in xrange(difference):
                self.num_collapsed_dims += 1
                self.add_collapsed_dim(self.num_collapsed_dims)

        # removes slots until there are the correct amount.
        if difference < 0:
            for _ in xrange(abs(difference)):
                self.remove_collapsed_dim(self.num_collapsed_dims)
                self.num_collapsed_dims -= 1

        # Set some instance variables about the cube.
        self.dim_names = gl.get_dim_names(self.cube)
        self.ndim = self.cube.ndim

        # Fill the combo boxes
        self.fill_combo("select_dimension_1", self.dim_names, True)

        if self.ndim >= 2:
            self.fill_combo("select_dimension_2", self.dim_names, True)

        if self.ndim >= 3:
            self.fill_combo("select_sliced_dim", self.dim_names, True)

            # get data on the coord points, and fill the combo box.
            dim = self.select_sliced_dim.currentText()
            data = gl.get_coord_values(self.cube, dim, self.dim_names)
            self.fill_combo("select_slice_combo", data, True)
            self.set_slice_scroll()
            self.select_slice_scroll.setEnabled(True)
            self.action_next_slice.setEnabled(True)
            self.action_previous_slice.setEnabled(True)

        self.set_initial_index()
        self.set_collapsed_dims()

        # Collapsed dims refers to all dimensions above 3. these dimensions
        # are not the plotted dimensions, nor are they the dimension in which
        # slices are to be taken... They are simply collapsed as chosen by the
        # user.

        self.set_enabled()

        # These placeholder variables keep a record of the current state of
        # the selectCoordinate combo boxes.
        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        QApplication.restoreOverrideCursor()
Esempio n. 12
0
 def test_get_dim_values_4d(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "grid_latitude", names)
     expected_values = cube.coord("grid_latitude").points
     self.assertEqual(all(values), all(expected_values))
Esempio n. 13
0
 def test_get_dim_values_anonymous_dim(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "*ANONYMOUS*4", names)
     expected_values = (range(5))
     self.assertEqual(values, expected_values)
Esempio n. 14
0
 def test_get_dim_values_anonymous_dim(self):
     cube = tcl.setup_7d_anonymous_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "*ANONYMOUS*4", names)
     expected_values = (range(5))
     self.assertEqual(values, expected_values)
Esempio n. 15
0
 def test_get_dim_values_4d(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     values = gl.get_coord_values(cube, "grid_latitude", names)
     expected_values = cube.coord("grid_latitude").points
     self.assertEqual(all(values), all(expected_values))
Esempio n. 16
0
 def test_get_dim_names_1d(self):
     cube = tcl.setup_1d_cube()
     names = gl.get_dim_names(cube)
     self.assertEqual(names, ["time"])
Esempio n. 17
0
 def test_get_remaining_dims_4d(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     used_dims = (names[2], names[0], names[3])
     remaining_dims = gl.get_remaining_dims(names, used_dims)
     self.assertEqual(remaining_dims, [names[1]])
Esempio n. 18
0
    def set_dimension_combos(self):
        """
        This method is responisble for ensuring that all of the revelant
        combo boxes are filled with the correct coordinate names. It is
        called whenever the cube is changed.

        """
        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)

        self.clear_dims()

        # Cube is set and the summary is printed to the information tab.
        self.cube = self.get_current_cube()
        self.print_cube_browser.setText(str(self.cube))

        # we check to see if we need to add or remove collapsed dim slots
        old_ndim = self.ndim if self.ndim > 3 else 3
        new_ndim = self.cube.ndim if self.cube.ndim > 3 else 3

        difference = new_ndim - old_ndim

        # adds more slots until there are enough.
        if difference > 0:
            for i in xrange(difference):
                self.num_collapsed_dims += 1
                self.add_collapsed_dim(self.num_collapsed_dims)

        # removes slots until there are the correct amount.
        if difference < 0:
            for _ in xrange(abs(difference)):
                self.remove_collapsed_dim(self.num_collapsed_dims)
                self.num_collapsed_dims -= 1

        # Set some instance variables about the cube.
        self.dim_names = gl.get_dim_names(self.cube)
        self.ndim = self.cube.ndim

        # Fill the combo boxes
        self.fill_combo("select_dimension_1", self.dim_names, True)

        if self.ndim >= 2:
            self.fill_combo("select_dimension_2", self.dim_names, True)

        if self.ndim >= 3:
            self.fill_combo("select_sliced_dim", self.dim_names, True)

            # get data on the coord points, and fill the combo box.
            dim = self.select_sliced_dim.currentText()
            data = gl.get_coord_values(self.cube, dim, self.dim_names)
            self.fill_combo("select_slice_combo", data, True)
            self.set_slice_scroll()
            self.select_slice_scroll.setEnabled(True)
            self.action_next_slice.setEnabled(True)
            self.action_previous_slice.setEnabled(True)

        self.set_initial_index()
        self.set_collapsed_dims()

        # Collapsed dims refers to all dimensions above 3. these dimensions
        # are not the plotted dimensions, nor are they the dimension in which
        # slices are to be taken... They are simply collapsed as chosen by the
        # user.

        self.set_enabled()

        # These placeholder variables keep a record of the current state of
        # the selectCoordinate combo boxes.
        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        QApplication.restoreOverrideCursor()
Esempio n. 19
0
 def test_get_dim_names_1d(self):
     cube = tcl.setup_1d_cube()
     names = gl.get_dim_names(cube)
     self.assertEqual(names, ["time"])
Esempio n. 20
0
 def test_get_remaining_dims_4d(self):
     cube = tcl.setup_4d_cube()
     names = gl.get_dim_names(cube)
     used_dims = (names[2], names[0], names[3])
     remaining_dims = gl.get_remaining_dims(names, used_dims)
     self.assertEqual(remaining_dims, [names[1]])