Пример #1
0
    def write_landfrac(self, convert_to_um=False):
        """
        Write out the land fraction.  
        """

        assert(self.landfrac is not None)

        f = nc.Dataset(self.lfrac_filename_nc, 'w', format='NETCDF3_CLASSIC')
        
        # Put in basic header elements lat, lon, time etc. 
        self.put_basic_header(f)
        f.createDimension('ht', 1)

        ht = f.createVariable('ht', 'f8', dimensions=('ht'))
        ht.long_name = 'Height'
        ht.units = 'm'
        ht.positive = 'up'
        lsm = f.createVariable('lsm', 'f8',
                               dimensions=('t', 'ht', 'latitude', 'longitude'))
        lsm.name = 'lsm'
        lsm.title = 'Stash code = 505'
        lsm.title = 'Land fraction in grid box'
        lsm.valid_min = 0.0
        lsm.valid_max = 1.0

        lsm[0, 0, :, :] = self.landfrac[:]
        f.close()

        # Convert to UM format.
        if convert_to_um:
            mkancil = Mkancil()
            ret = mkancil.convert_lfrac()
            assert(ret == 0)
            assert(os.path.exists(self.lfrac_filename_um))
Пример #2
0
    def write_mask(self, convert_to_um=False):
        """
        Write out mask used by the UM.
        
        This mask is used to differentiate between points that have some land
        fraction and those which have none at all.
        """
        assert(self.landfrac is not None)

        f = nc.Dataset(self.mask_filename_nc, 'w', format='NETCDF3_CLASSIC')
        # Put in basic header elements lat, lon, time etc. 
        self.put_basic_header(f)

        f.createDimension('surface', 1)

        surface = f.createVariable('surface', 'f8', dimensions=('surface'))
        surface.long_name = 'Surface'
        surface.units = 'level'
        surface.positive = 'up'

        lsm = f.createVariable('lsm', 'f8',
                               dimensions=('t', 'surface', 'latitude', 'longitude'))
        lsm.name = 'lsm'
        lsm.title = 'LAND MASK (No halo) (LAND=TRUE)'
        lsm.valid_min = 0.0
        lsm.valid_max = 1.0

        # Make the mask using the land fraction.
        mask = np.copy(self.landfrac)
        mask[np.where(self.landfrac[:] != 0)] = 1
        lsm[0, 0, :, :] = mask[:]
        f.close()            

        # Convert to UM format.
        if convert_to_um:
            mkancil = Mkancil()
            ret = mkancil.convert_mask()
            assert(ret == 0)
            assert(os.path.exists(self.mask_filename_um))