예제 #1
0
    def _clean_loaded_data(self):
        

        for i in range(len(self.data)):
            self.data[i].metadata.attributes.clear()
            self.data[i].coord("latitude").points=\
                self.data[i].coord("latitude").points.astype(np.float32)
            self.data[i].coord("longitude").points=\
                self.data[i].coord("longitude").points.astype(np.float32)
            
        self.data=self.data.concatenate_cube()
        try:
            self.data.coord(self.T).convert_units(self.U)
        except:
            print(f"Warning: could not convert {self.T} to {self.U}, simply renaming calendar.")
            new_T=cf_units.Unit(self.data.coord(self.T).units.origin,self.U.calendar)
            self.data.coord(self.T).units=new_T
            try:
                self.data.coord(self.T).convert_units(self.U)
            except:
                raise(ValueError("Unsuccesful attempt to change time units."))
        
        iccat.add_hour(self.data,self.T)
        self.data=self.data.extract(self.constraints["hour"])

        iccat.add_day_of_year(self.data,self.T)
        self.data=self.data.extract(self.constraints["calendar"])
        self.data=iris.cube.CubeList([self.data])
예제 #2
0
    def _clean_loaded_data(self):
        
        CL=iris.cube.CubeList()
        for i,cube in enumerate(self.data):
            for entry in cube.slices_over(self.T):
                
                entry.coord(self.T).convert_units(self.U)
                entry.coord(self.S).convert_units(cf_units.Unit("Days"))

                T_ref=entry.coord(self.T)
                S=entry.coord(self.S).points
                t_coord=iris.coords.AuxCoord(S+T_ref.points[0],standard_name="time")
                t_coord.units=T_ref.units
                entry.add_aux_coord(t_coord,data_dims=1)
                
                iccat.add_hour(entry,"time")
                iccat.add_day_of_year(entry,"time")

                CL.append(entry)
        CL.sort(key=lambda cube:cube.coord(self.T).points[0])            
        self.data=CL
        
        self.data=self.data.extract(self.constraints["calendar"])
        self.data=self.data.extract(self.constraints["lead"])
        self.data=self.data.extract(self.constraints["hour"])
        self.data=self.data.extract(self.constraints["ens"])
예제 #3
0
    def test_explicit_result_name_specify_coord_by_name(self):
        coord_name = 'my_hour'
        msg = 'Missing/incorrectly named result for add_hour'

        # Specify source coordinate by name
        cube = self.cube
        ccat.add_hour(cube, 'time', name=coord_name)
        result_coords = cube.coords(coord_name)
        self.assertEqual(len(result_coords), 1, msg)
예제 #4
0
    def test_explicit_result_name_specify_coord_by_name(self):
        coord_name = "my_hour"
        msg = "Missing/incorrectly named result for add_hour"

        # Specify source coordinate by name
        cube = self.cube
        ccat.add_hour(cube, "time", name=coord_name)
        result_coords = cube.coords(coord_name)
        self.assertEqual(len(result_coords), 1, msg)
예제 #5
0
    def test_basic(self):
        coord_name = 'my_hour'
        cube = self.cube
        time_coord = self.time_coord
        expected_coord = iris.coords.AuxCoord(
            self.hour_numbers % 24, long_name=coord_name)

        ccat.add_hour(cube, time_coord, coord_name)

        self.assertEqual(cube.coord(coord_name), expected_coord)
예제 #6
0
    def test_explicit_result_name_specify_coord_by_reference(self):
        coord_name = 'my_hour'
        msg = 'Missing/incorrectly named result for add_hour'

        # Specify source coordinate by coordinate reference
        cube = self.cube
        time = cube.coord('time')
        ccat.add_hour(cube, time, name=coord_name)
        result_coords = cube.coords(coord_name)
        self.assertEqual(len(result_coords), 1, msg)
예제 #7
0
    def test_basic(self):
        coord_name = 'my_hour'
        cube = self.cube
        time_coord = self.time_coord
        expected_coord = iris.coords.AuxCoord(
            self.hour_numbers % 24, long_name=coord_name)

        ccat.add_hour(cube, time_coord, coord_name)

        self.assertEqual(cube.coord(coord_name), expected_coord)
예제 #8
0
def add_extra_time_coords(cube):
    """
    Adds new coordinate for indexing a given simulation based on model and
    ensemble and adds additional time coordinates for unit manipulation
    """
    if not cube.coords('year'):
        icc.add_year(cube, 'time')
    if not cube.coords('month'):
        icc.add_month(cube, 'time')
    if not cube.coords('month_number'):
        icc.add_month_number(cube, 'time')
    if not cube.coords('day_of_month'):
        icc.add_day_of_month(cube, 'time')
    if not cube.coords('hour'):
        icc.add_hour(cube, 'time')
    return cube
예제 #9
0
 def test_bad_coord(self):
     with self.assertRaises(iris.exceptions.CoordinateNotFoundError):
         ccat.add_hour(self.cube, "DOES NOT EXIST", name="my_hour")
예제 #10
0
 def test_bad_coord(self):
     with self.assertRaises(iris.exceptions.CoordinateNotFoundError):
         ccat.add_hour(self.cube, 'DOES NOT EXIST', name='my_hour')