Пример #1
0
def cruncep_year(y):
    """Creates an ORCHIDEE forcing file for the specified year by
    copying and/or manipulating the variables found in the individual
    cruncep files."""

    o_fname = 'cruncep_halfdeg_%04d.nc' % y
    ofile = None

    #for i in [ 4 ] :
    for i in range(len(file_vars)):
        fname = 'cruncep_%s_%04d.nc' % (file_vars[i], y)
        print fname
        d = nc.Dataset(fname)

        # If first time thru loop, init the output file
        if ofile == None:
            m = d.variables['mask'][:]
            ofile, ca = t.compressedAxesFactory(o_fname, dims, c_dim, m)
            len_c_dim = len(ofile.dimensions[c_dim])

            lat = d.variables['latitude'][:]
            lon = d.variables['longitude'][:]
            nav_lat = ofile.createVariable('nav_lat', lon.dtype, ('y', 'x'))
            nav_lon = ofile.createVariable('nav_lon', lat.dtype, ('y', 'x'))

            nav_lat[:], nav_lon[:] = make_nav_latlon(lat[:], lon[:])

            tsteps = len(d.dimensions['time_counter'])
            init_time(ofile, y, tsteps)

        orig_v = d.variables[orig_varnames[i]]
        v = ofile.createVariable(orchidee_varnames[i],
                                 orig_v.dtype, ('tstep', c_dim),
                                 chunksizes=(1, len_c_dim),
                                 fill_value=1.e20)
        v.title = orig_v.title
        v.units = orig_v.units
        v.missing_value = 1.e20

        # compress the grid for each timestep...
        for j in range(tsteps):
            if file_vars[i] == "swdown":
                # fix known units issue with the shortwave radiation
                v[j, :] = ca.compress(np.squeeze(orig_v[j, :, :] / 21600.))
            else:
                v[j, :] = ca.compress(np.squeeze(orig_v[j, :, :]))

        d.close()

    partition_precip(ofile, ca, y)

    ofile.close()
Пример #2
0
def cruncep_year(y) : 
    """Creates an ORCHIDEE forcing file for the specified year by
    copying and/or manipulating the variables found in the individual
    cruncep files."""

    o_fname = 'cruncep_halfdeg_%04d.nc' % y
    ofile = None

    #for i in [ 4 ] : 
    for i in range(len(file_vars)) : 
        fname = 'cruncep_%s_%04d.nc' % (file_vars[i], y)
        print fname
        d = nc.Dataset(fname)

        # If first time thru loop, init the output file
        if ofile == None : 
            m = d.variables['mask'][:]
            ofile,ca = t.compressedAxesFactory(o_fname, dims, c_dim, m)
            len_c_dim = len(ofile.dimensions[c_dim])

            lat = d.variables['latitude'][:]
            lon = d.variables['longitude'][:]
            nav_lat = ofile.createVariable('nav_lat', lon.dtype, ('y','x'))
            nav_lon = ofile.createVariable('nav_lon', lat.dtype, ('y','x'))

            nav_lat[:], nav_lon[:] = make_nav_latlon( lat[:], lon[:] )
            
            tsteps = len(d.dimensions['time_counter'])
            init_time(ofile, y, tsteps)


        orig_v = d.variables[orig_varnames[i]]
        v = ofile.createVariable(orchidee_varnames[i], orig_v.dtype, 
                ('tstep',c_dim), chunksizes=(1,len_c_dim), fill_value=1.e20)
        v.title = orig_v.title
        v.units = orig_v.units
        v.missing_value = 1.e20
        
        # compress the grid for each timestep...
        for j in range(tsteps) : 
            if file_vars[i] == "swdown" :
                # fix known units issue with the shortwave radiation
                v[j,:] = ca.compress(np.squeeze(orig_v[j,:,:]/21600.))
            else : 
                v[j,:] = ca.compress(np.squeeze(orig_v[j,:,:]))

        d.close()

    partition_precip(ofile,ca,y)

    ofile.close()
Пример #3
0
def wfdei_year(y) : 
    
    o_fname = 'wfdei_halfdeg_%04d.nc' % y
    ofile = None

    for i in range(len(file_vars)) : 
        cum_tsteps = 0
        for i_month in range(12) :
            fname = '%s/%s_%04d%02d.nc' % (file_vars[i], file_vars[i], y, i_month+1)
            print fname
            d = nc.Dataset(fname)
            orig_v = d.variables[orig_varnames[i]]

            # If first time thru loop, init the output file
            if ofile == None : 
                m = orig_v[0,:].mask
                ofile,ca = t.compressedAxesFactory(o_fname, dims, c_dim, bmask=m)
                len_c_dim = len(ofile.dimensions[c_dim])
    
                lat = d.variables['lat'][:]
                lon = d.variables['lon'][:]
                nav_lat = ofile.createVariable('nav_lat', lon.dtype, ('y','x'))
                nav_lon = ofile.createVariable('nav_lon', lat.dtype, ('y','x'))
    
                nav_lat[:], nav_lon[:] = make_nav_latlon( lat[:], lon[:] )
                
                #tsteps = len(d.dimensions['time_counter'])
                init_time(ofile, y, 365*8)


            if i_month == 0 : 
                v = ofile.createVariable(orchidee_varnames[i], orig_v.dtype, 
                    ('tstep',c_dim), chunksizes=(1,len_c_dim), fill_value=1e20)
                v.title = orig_v.title
                v.units = orig_v.units
                v.missing_value = 1.e20
        
            # compress the grid for each timestep...
            tsteps = len(d.dimensions['tstep'])
            for j in range(tsteps) : 
                v[j+cum_tsteps,:] = ca.compress(np.squeeze(orig_v[j,:,:]))

            cum_tsteps += tsteps

            d.close()

    null_wind_component(ofile, c_dim, len_c_dim)
    ofile.close()