Example #1
0
    def arrange_coords_1(self):
        """
        The arrange Methods are present to prevent any one coordinate
        being used more than once in the selectDimension1,
        selectDimension2 and selectSlicedDim combo boxes.

        When a coordinate is selected in any one of the combo boxes,
        it checks the other 2 for matches and if matches are found
        then it will put the old value for the selected combo box into
        the combo box with the match.

        """
        dim_1_name = self.select_dimension_1.currentText()
        dim_2_name = self.select_dimension_2.currentText()
        sliced_dim_name = self.select_sliced_dim.currentText()

        if dim_1_name == dim_2_name:
            self.select_dimension_2.setCurrentIndex(self.dim_1)
        elif dim_1_name == sliced_dim_name:
            self.select_sliced_dim.setCurrentIndex(self.dim_1)
        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        if self.ndim > 2:
            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.set_collapsed_dims()
Example #2
0
    def arrange_coords_2(self):
        """
        Same as arrange coords 1 except that this is for when select
        dimension 2 is changed.

        """
        dim_1_name = self.select_dimension_1.currentText()
        dim_2_name = self.select_dimension_2.currentText()
        sliced_dim_name = self.select_sliced_dim.currentText()

        if dim_2_name == dim_1_name:
            self.select_dimension_1.setCurrentIndex(self.dim_2)
        elif dim_2_name == sliced_dim_name:
            self.select_sliced_dim.setCurrentIndex(self.dim_2)

        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        if self.ndim > 2:
            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.set_collapsed_dims()
Example #3
0
    def arrange_coords_2(self):
        """
        Same as arrange coords 1 except that this is for when select
        dimension 2 is changed.

        """
        dim_1_name = self.select_dimension_1.currentText()
        dim_2_name = self.select_dimension_2.currentText()
        sliced_dim_name = self.select_sliced_dim.currentText()

        if dim_2_name == dim_1_name:
            self.select_dimension_1.setCurrentIndex(self.dim_2)
        elif dim_2_name == sliced_dim_name:
            self.select_sliced_dim.setCurrentIndex(self.dim_2)

        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        if self.ndim > 2:
            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.set_collapsed_dims()
Example #4
0
    def arrange_coords_1(self):
        """
        The arrange Methods are present to prevent any one coordinate
        being used more than once in the selectDimension1,
        selectDimension2 and selectSlicedDim combo boxes.

        When a coordinate is selected in any one of the combo boxes,
        it checks the other 2 for matches and if matches are found
        then it will put the old value for the selected combo box into
        the combo box with the match.

        """
        dim_1_name = self.select_dimension_1.currentText()
        dim_2_name = self.select_dimension_2.currentText()
        sliced_dim_name = self.select_sliced_dim.currentText()

        if dim_1_name == dim_2_name:
            self.select_dimension_2.setCurrentIndex(self.dim_1)
        elif dim_1_name == sliced_dim_name:
            self.select_sliced_dim.setCurrentIndex(self.dim_1)
        self.dim_1 = self.select_dimension_1.currentIndex()
        self.dim_2 = self.select_dimension_2.currentIndex()
        self.dim_3 = self.select_sliced_dim.currentIndex()

        if self.ndim > 2:
            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.set_collapsed_dims()
Example #5
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))
Example #6
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))
Example #7
0
    def set_slice_scroll(self):
        """
        Sets the correct number of steps there are in the scrollbar of the
        current coordinate

        """
        sliced_coord = self.select_sliced_dim.currentText()
        data = gl.get_coord_values(self.cube, sliced_coord, self.dim_names)
        max_slice = len(data)
        self.select_slice_scroll.setMaximum(max_slice - 1)
Example #8
0
    def set_slice_scroll(self):
        """
        Sets the correct number of steps there are in the scrollbar of the
        current coordinate

        """
        sliced_coord = self.select_sliced_dim.currentText()
        data = gl.get_coord_values(self.cube, sliced_coord, self.dim_names)
        max_slice = len(data)
        self.select_slice_scroll.setMaximum(max_slice - 1)
Example #9
0
    def set_collapsed_dims(self):
        """
        Beyond 3 dimensions, the program allows you to pick a single value
        to collapse the cube around. This method fills and enables the
        relevant labels and combo boxes to allow this.

        """
        if self.ndim > 3:
            used_dims = []
            used_dims.append(self.select_dimension_1.currentText())
            used_dims.append(self.select_dimension_2.currentText())
            used_dims.append(self.select_sliced_dim.currentText())
            unused_dims = gl.get_remaining_dims(self.dim_names, used_dims)

            for i in xrange(len(unused_dims)):
                label_name = "collapsed_dim_" + str(i+1)
                box_name = "select_slice_index_" + str(i+1)

                label = self.findChild(QtGui.QLabel, label_name)
                label.setText(unused_dims[i])

                data = gl.get_coord_values(self.cube, unused_dims[i],
                                           self.dim_names)
                self.fill_combo(box_name, data, True)
Example #10
0
    def set_collapsed_dims(self):
        """
        Beyond 3 dimensions, the program allows you to pick a single value
        to collapse the cube around. This method fills and enables the
        relevant labels and combo boxes to allow this.

        """
        if self.ndim > 3:
            used_dims = []
            used_dims.append(self.select_dimension_1.currentText())
            used_dims.append(self.select_dimension_2.currentText())
            used_dims.append(self.select_sliced_dim.currentText())
            unused_dims = gl.get_remaining_dims(self.dim_names, used_dims)

            for i in xrange(len(unused_dims)):
                label_name = "collapsed_dim_" + str(i+1)
                box_name = "select_slice_index_" + str(i+1)

                label = self.findChild(QtGui.QLabel, label_name)
                label.setText(unused_dims[i])

                data = gl.get_coord_values(self.cube, unused_dims[i],
                                           self.dim_names)
                self.fill_combo(box_name, data, True)
Example #11
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)
Example #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))
Example #13
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()
Example #14
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()
Example #15
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)
Example #16
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))