Esempio n. 1
0
def get_cube(start_date, end_date, var_name, frequency='6hr', 
                constraints=None, verbose=True):

    """

    Get /Path/filenames for ERA-Interim files within date range

    Start and end date can be specified using a range of strings:
            e.g., '19790101', '1979-01-01', '19790101010101'

    var_name is a constraint on the cube variable name (i.e., cube.var_name)
        e.g., var_name = 'T2'

    """

    ### Iris v2.2 hangs when saving netcdf files, use NETCDF3-CLASSIC 
    ### as a workaround - SH

    level = level_from_var_name(var_name)

    if frequency == '6hr': 
        df = get_erai_6h_cat(start_date, end_date, level, verbose=verbose)
    else:
        raise ValueError('Only 6hr frequency currently supported')
    
    con = iris.Constraint(cube_func=lambda cube: cube.var_name == var_name)
    
    ### Additional constrains (level, time)
    if (constraints != None): con = con & constraints

    fnames = df['Filename'].values
    print('first & last files=', fnames[0].split('/')[-1], fnames[-1].split('/')[-1])
    with units.suppress_errors():
        cubelist = iris.load(fnames, constraints=con, 
                                callback=edit_erai_attrs)

    ### Setup new coord to add to cube (see below)
    model_coord = iris.coords.AuxCoord('ERA-Interim', long_name='Model', 
                                            units='no_unit')

    ### Fix cubes to all match a reference cube before we can merge
    ref = cubelist[0]
    for c in cubelist: 
        c.coord('latitude').points         = ref.coord('latitude').points
        c.coord('longitude').points        = ref.coord('longitude').points
        c.coord('latitude').standard_name  = ref.coord('latitude').standard_name
        c.coord('longitude').standard_name = ref.coord('longitude').standard_name
        c.add_aux_coord(model_coord)       # Add model name as a scalar coord

    iris.util.unify_time_units(cubelist)
    cube = cubelist.concatenate_cube()
    cube = iris.util.squeeze(cube)

    ### add bounds to lon/lat coordinates
    cube.coord('latitude').guess_bounds()
    cube.coord('longitude').guess_bounds()

    return cube
Esempio n. 2
0
 def test_meaningless_operation(self):
     u = Unit("volt")
     emsg = "UT_MEANINGLESS"
     with self.assertRaisesRegex(ValueError, emsg), suppress_errors():
         u.root(2)
Esempio n. 3
0
 def setUp(self):
     unit.suppress_errors()
Esempio n. 4
0
 def test_no_unit(self):
     u = Unit("no unit")
     emsg = "Failed to offset"
     with self.assertRaisesRegex(ValueError, emsg), suppress_errors():
         u.offset_by_time(unit.encode_time(1970, 1, 1, 0, 0, 0))
Esempio n. 5
0
 def test_meaningless_operation(self):
     u = Unit('volt')
     msg = 'UT_MEANINGLESS'
     with self.assertRaisesRegexp(ValueError, msg), unit.suppress_errors():
         u.root(2)
Esempio n. 6
0
 def setUp(self):
     unit.suppress_errors()
Esempio n. 7
0
 def test_no_unit(self):
     u = Unit('no unit')
     msg = 'Failed to offset'
     with self.assertRaisesRegexp(ValueError, msg), unit.suppress_errors():
         u.offset_by_time(unit.encode_time(1970, 1, 1, 0, 0, 0))
Esempio n. 8
0
 def test_meaningless_operation(self):
     u = Unit('volt')
     emsg = 'UT_MEANINGLESS'
     with six.assertRaisesRegex(self, ValueError, emsg), suppress_errors():
         u.root(2)
Esempio n. 9
0
 def test_no_unit(self):
     u = Unit('no unit')
     emsg = 'Failed to offset'
     with six.assertRaisesRegex(self, ValueError, emsg), suppress_errors():
         u.offset_by_time(unit.encode_time(1970, 1, 1, 0, 0, 0))
Esempio n. 10
0
def get_land_mask():
    with units.suppress_errors():
        cube = iris.load_cube(root+'/era-interim/erai_invariant.nc', 
                                'land_binary_mask')
    return cube
Esempio n. 11
0
 def test_meaningless_operation(self):
     u = Unit('volt')
     msg = 'UT_MEANINGLESS'
     with self.assertRaisesRegexp(ValueError, msg), unit.suppress_errors():
         u.root(2)
Esempio n. 12
0
 def test_unit_unknown(self):
     u = Unit('unknown')
     msg = 'Failed to offset'
     with self.assertRaisesRegexp(ValueError, msg), unit.suppress_errors():
         u.offset_by_time(unit.encode_time(1970, 1, 1, 0, 0, 0))