def fix_precip_attributes(path):
    nc_file = NetCDF(path, mode='r+')
    nc_file.history = ''
    nc_file.variables['precip'].long_name = 'Daily Precipitation Rate at surface'

    if 'Identification' in nc_file.ncattrs():
        nc_file.Identification = ''
    if 'Documentation' in nc_file.ncattrs():
        nc_file.Documentation = ''
    if 'About' in nc_file.ncattrs():
        nc_file.About = ''

    nc_file.close()
        if l_interp_daily:
            #
            #print('LOLO: current time is rt =', rt)
            for jtd in range(jr1, Nt_tot_daily - 1):
                if vtime_d[jtd] <= rt and vtime_d[jtd + 1] > rt:
                    jr1 = jtd
                    jr2 = jtd + 1
                    break
            #print('LOLO: what we found is:', vtime_d[jr1], vtime_d[jr2])
            #
            ivd = 0
            for cvar in list_var_daily_expected:
                # Linear interpolation !!!
                rslope = (xdata_d[ivd, jr2] -
                          xdata_d[ivd, jr1]) / (vtime_d[jr2] - vtime_d[jr1])
                ido_var[iv][jt, :, :] = xdata_d[
                    ivd, jr1] + rslope * (rt - vtime_d[jr1])
                if cvar in list_temp_to_degC:
                    ido_var[iv][jt, :, :] = ido_var[iv][jt, :, :] - 273.15
                iv = iv + 1
                ivd = ivd + 1

        for cvar in list_extra:
            ido_var[iv][jt, :, :] = rval_extra[iv - nbfld_tot]
            iv = iv + 1

    id_fo.About = "Input file for 'STATION_ASF' NEMO test-case, generated with 'download_prepare_ERA5_for_SASF.py' of AeroBulk (https://github.com/brodeau/aerobulk)."

    id_fi.close()
    id_fo.close()
        # Attributes
        id_tim.units = cunt_time

        #id_lat.long_name     = clnm_lat
        id_lat.units = cunt_lat
        #id_lat.standard_name = csnm_lat

        #id_lon.long_name     = clnm_lon
        id_lon.units = cunt_lon
        #id_lon.standard_name = csnm_lon

        id_tim.units = cunt_time

        id_q2.long_name = 'Surface specific humidity at 2m, built from D2M and MSL'
        id_q2.units = 'kg/kg'
        id_q2.code = '133'
        id_q2.table = '128'

        f_out.About = 'Created by L. Brodeau using MSL and D2M corresponding fields'

        # Filling variables:
        id_lat[:] = vlat[:]
        id_lon[:] = vlon[:]

    id_tim[jt] = vtime[jt]
    id_q2[jt, :, :] = xq2[:, :]

    if jt == Nt - 1: f_out.close()

print 'Bye!'
Exemple #4
0
id_lat.long_name = clnm_lat
id_lat.units = cunt_lat
id_lat.standard_name = csnm_lat

id_lon.long_name = clnm_lon
id_lon.units = cunt_lon
id_lon.standard_name = csnm_lon

id_tim.units = cunt_time

id_crl.long_name = 'Curl of vector ' + cv_Vx + ' and ' + cv_Vy
id_crl.units = CUNIT_CRL
id_crl.code = '???'
id_crl.table = '128'

f_out.About = 'Created by Barakuda using ' + cv_Vx + ' and ' + cv_Vy + '.'

# Filling variables:
id_lat[:] = vlat[:]
id_lon[:] = vlon[:]

for jt in range(Nt):

    print ' *** jt = ', jt

    xty = rmult * f_Vy_in.variables[cv_Vy][jt, :, :]
    xtx = rmult * f_Vx_in.variables[cv_Vx][jt, :, :]

    xtmp[:, :] = xtx[:, :] * xcosphi[:, :]

    xcurl[1:nj-1,1:ni-1] =   ( xty[1:nj-1,2:ni]   - xty[1:nj-1,0:ni-2] ) / dlamx2 \
        # Attributes
        id_tim.units = cunt_time
        #id_tim.calendar = ccal_time

        id_lat.units = cunt_lat
        id_lat.long_name = clnm_lat
        #id_lat.standard_name = csnm_lat

        id_lon.units = cunt_lon
        id_lon.long_name = clnm_lon
        #id_lon.standard_name = csnm_lon

        id_q2.units = 'kg/kg'
        id_q2.long_name = 'Surface specific humidity at 2m, built from ' + cv_d2 + ' and ' + cv_p0
        id_q2.code = '133'
        id_q2.table = '128'

        f_out.About = 'Created with "build_q2_from_d2_slp.py" of AeroBulk, using ' + cv_p0 + ' and ' + cv_d2 + '. [https://github.com/brodeau/aerobulk]'

        # Filling variables:
        id_lat[:] = vlat[:]
        id_lon[:] = vlon[:]

    id_tim[jt] = vtime[jt]
    id_q2[jt, :, :] = xq2[:, :]

    if jt == Nt - 1: f_out.close()

print('Bye!')
if NbDim == 3:
    id_msk = f_out.createVariable('mask',
                                  'i1', (
                                      cdim_z,
                                      cdim_y,
                                      cdim_x,
                                  ),
                                  zlib=True,
                                  complevel=8)
    id_msk[:, :, :] = mask[:, :, :]
else:
    id_msk = f_out.createVariable('mask',
                                  'i1', (
                                      cdim_y,
                                      cdim_x,
                                  ),
                                  zlib=True,
                                  complevel=8)
    id_msk[:, :] = mask[:, :]

id_msk.long_name = 'Land-Sea mask'

f_out.About = 'Land-sea mask built out of variable `' + cv_nc + '` of file `' + path.basename(
    cf_nc) + '` !'
f_out.Author = 'Generated with `' + path.basename(
    sys.argv[0]) + '` of `climporn` (https://github.com/brodeau/climporn)'

f_out.close()

print(cf_msk + ' created!!!')
Exemple #7
0
if NbDim == 3: f_out.createDimension(cdim_z, nz)

#if l_fake_coor:
#    id_lon  = f_out.createVariable('lon0','f4',(cdim_x,))
#    id_lat  = f_out.createVariable('lat0','f4',(cdim_y,))
#    id_lon[:] = vlon[:]
#    id_lat[:] = vlat[:]

if NbDim == 3:
    id_msk = f_out.createVariable('mask', 'i1', (
        cdim_z,
        cdim_y,
        cdim_x,
    ))
    id_msk[:, :, :] = mask[:, :, :]
else:
    id_msk = f_out.createVariable('mask', 'i1', (
        cdim_y,
        cdim_x,
    ))
    id_msk[:, :] = mask[:, :]

id_msk.long_name = 'Land-Sea mask'

f_out.About = 'Variable ' + cv_nc + ' converted to a mask...'
f_out.Author = 'Generated with image_to_netcdf.py of BARAKUDA (https://github.com/brodeau/barakuda)'

f_out.close()

print cf_msk + ' created!!!'
     #id_lat.long_name     = clnm_lat
     id_lat.units         = cunt_lat
     #id_lat.standard_name = csnm_lat
 
     #id_lon.long_name     = clnm_lon
     id_lon.units         = cunt_lon
     #id_lon.standard_name = csnm_lon
 
     id_tim.units         = cunt_time
 
     id_q2.long_name = 'Surface specific humidity at 2m, built from D2M and MSL'
     id_q2.units = 'kg/kg'
     id_q2.code  = '133'
     id_q2.table = '128'
 
     f_out.About = 'Created by L. Brodeau using MSL and D2M corresponding fields'
 
     # Filling variables:
     id_lat[:] = vlat[:]
     id_lon[:] = vlon[:]
     
 id_tim[jt]     = vtime[jt]
 id_q2[jt,:,:]  = xq2[:,:] 
 
 if jt == Nt-1: f_out.close()
 
 
 
 
 
 
     #id_lat.long_name     = clnm_lat
     id_lat.units         = cunt_lat
     #id_lat.standard_name = csnm_lat
 
     #id_lon.long_name     = clnm_lon
     id_lon.units         = cunt_lon
     #id_lon.standard_name = csnm_lon
 
     id_tim.units         = cunt_time
 
     #id_wm.long_name = 'Surface specific humidity at 2m, built from U10M, V10M and MSL'
     #id_wm.units = 'kg/kg'
     #id_wm.code  = '133'
     #id_wm.table = '128'
 
     f_out.About = 'Created by L. Brodeau using MSL, U10M and V10M corresponding fields'
 
     # Filling variables:
     id_lat[:] = vlat[:]
     id_lon[:] = vlon[:]
     
 id_tim[jt]     = vtime[jt]
 id_wm[jt,:,:]  = xwm[:,:]
 id_ke[jt,:,:]  = xke[:,:] 
 
 if jt == Nt-1: f_out.close()
 
 
 
 
 
        #id_lat.long_name     = clnm_lat
        id_lat.units = cunt_lat
        #id_lat.standard_name = csnm_lat

        #id_lon.long_name     = clnm_lon
        id_lon.units = cunt_lon
        #id_lon.standard_name = csnm_lon

        id_tim.units = cunt_time

        #id_wm.long_name = 'Surface specific humidity at 2m, built from U10M, V10M and MSL'
        #id_wm.units = 'kg/kg'
        #id_wm.code  = '133'
        #id_wm.table = '128'

        f_out.About = 'Created by L. Brodeau using MSL, U10M and V10M corresponding fields'

        # Filling variables:
        id_lat[:] = vlat[:]
        id_lon[:] = vlon[:]

    id_tim[jt] = vtime[jt]
    id_wm[jt, :, :] = xwm[:, :]
    id_ke[jt, :, :] = xke[:, :]

    if jt == Nt - 1: f_out.close()

print ' *** file ' + cf_wm + ' created !'

print 'Bye!'
        # Attributes
        id_tim.units = cunt_time
        id_tim.calendar = ccal_time

        id_lat.units = cunt_lat
        id_lat.long_name = clnm_lat
        #id_lat.standard_name = csnm_lat

        id_lon.units = cunt_lon
        id_lon.long_name = clnm_lon
        #id_lon.standard_name = csnm_lon

        id_out.units = cunt_in
        id_out.long_name = clnm_in
        #id_out.code  = '133'
        #id_out.table = '128'

        f_out.About = cv_in + ' masked and deflated with "mask_field_ecmwf.py" of AeroBulk. [https://github.com/brodeau/aerobulk].'

        # Filling variables:
        id_lat[:] = vlat[:]
        id_lon[:] = vlon[:]

    id_tim[jt] = vtime[jt]
    id_out[jt, :, :] = xfout[:, :]

    if jt == Nt - 1: f_out.close()

print 'Bye!'
Exemple #12
0
        f_ice.createDimension(cv_tim, None)
        # Variables
        ido_lon = f_ice.createVariable(cv_lon, 'f4', (
            'y',
            'x',
        ), zlib=True)
        ido_lat = f_ice.createVariable(cv_lat, 'f4', (
            'y',
            'x',
        ), zlib=True)
        ido_tim = f_ice.createVariable(cv_tim, 'f4', (cv_tim, ), zlib=True)
        # Attributes
        ido_tim.units = cunt_time
        ido_lat.units = cunt_lat
        ido_lon.units = cunt_lon
        f_ice.About = 'prepare_PAPA_forcing_STATION-ASF_ICE.py of AeroBulk for NEMO/STATION-ASF test-case. Gaps in time-series are filled by means of linear interpolation.'
        # Filling variables:
        ido_lat[:, :] = vlat[0]
        ido_lon[:, :] = vlon[0]
        for jt in range(Nt):
            ido_tim[jt] = vtime[jt]

    if list_real[iv] == 'atm':
        id_atm = f_forc.createVariable(list_varo[iv],
                                       'f4', (
                                           cv_tim,
                                           'y',
                                           'x',
                                       ),
                                       zlib=True)
        #, fill_value=rmiss)
        # Dimensions:
        f_out.createDimension(cv_lon, ni)
        f_out.createDimension(cv_lat, nj)
        f_out.createDimension('time', None)

        # Variables
        id_lon = f_out.createVariable(cv_lon, 'f4', (cv_lon, ), zlib=True)
        id_lat = f_out.createVariable(cv_lat, 'f4', (cv_lat, ), zlib=True)
        id_tim = f_out.createVariable('time', 'f4', ('time', ), zlib=True)

        # Attributes
        id_tim.units = cunt_time
        id_lat.units = cunt_lat
        id_lon.units = cunt_lon

        f_out.About = 'Created by L. Brodeau for AeroBulk. Gaps in time-series are filled by means of linear interpolation.'

        # Filling variables:
        id_lat[:] = vlat[:]
        id_lon[:] = vlon[:]
        for jt in range(Nt):
            id_tim[jt] = vtime[jt]

    id_out = f_out.createVariable(list_varo[iv],
                                  'f4', (
                                      'time',
                                      cv_lat,
                                      cv_lon,
                                  ),
                                  zlib=True)
    #, fill_value=rmiss)
    'lon',
))

# Attributes

id_tim.units = cunt_time
id_lev.units = cunt_lev
id_lat.long_name = clnm_lat
id_lat.units = cunt_lat
id_lon.long_name = clnm_lon
id_lon.units = cunt_lon
id_R.long_name = 'Relative Humidity'
id_R.units = '%'
id_R.code = '157'
id_R.table = '128'
f_out.About = 'Created by L. Brodeau using Q, T and pressure from pressure levels!'

# Filling variables:
id_lev[:] = vlev[:]
id_lat[:] = vlat[:]
id_lon[:] = vlon[:]

for jt in range(nt):
    id_tim[jt] = vtime[jt]
    id_R[jt, :, :, :] = xR[jt, :, :, :]

f_out.close()

print cf_R + ' is created!'

print 'build_RH_new.py: Bye!'
Exemple #15
0
            ido_var.units = id_fi.variables[cvec].units
            ido_var.long_name = id_fi.variables[cvec].long_name

        # Filling coordinates:
        ido_lon[:] = vlon[:]
        ido_lat[:] = nmp.flipud(vlat[:])

        # Filling fields
        for jt in range(Nt):

            print('   * "' + cvec + '" => jt = ', jt, '  /', Nt)
            ido_tim[jt] = vtime[jt]

            if jt == 0: Xvar = nmp.zeros((nj, ni))

            Xvar[:, :] = id_fi.variables[cvec][jt, :, :]

            Xvar[:, :] = nmp.flipud(Xvar[:, :])

            ido_var[jt, :, :] = Xvar[:, :]

            # Flux conversion ???
            if cvec in list_flx:
                idx = list_flx.index(cvec)
                ido_var[jt, :, :] = ido_var[jt, :, :] * fact_flx[idx]
                #
        id_fo.About = "Generated with 'download_prepare_ERA5.py' of AeroBulk (https://github.com/brodeau/aerobulk)."

        id_fo.close()
        id_fi.close()
Exemple #16
0
    id_blue = f_out.createVariable('blue', 'f4', (
        cdim_y,
        cdim_x,
    ))
    id_blue.long_name = 'Blue (of RGB)'

    id_red[:, :] = nmp.flipud(xpic[:, :, 0])
    id_green[:, :] = nmp.flipud(xpic[:, :, 1])
    id_blue[:, :] = nmp.flipud(xpic[:, :, 2])

else:
    #if l_nemo_like:
    #    id_bw  = f_out.createVariable('bw','i1',('t',cdim_y,cdim_x,))
    #    id_bw.long_name = 'Grey scale'
    #    #id_bw[0,:,:]   = nmp.flipud(xpic[:,:]) / idiv
    #    id_bw[0,:,:]   = 1 - (nmp.flipud(xpic[:,:]) + 1)/idiv
    #else:
    id_bw = f_out.createVariable('bw', 'i1', (
        cdim_y,
        cdim_x,
    ))
    id_bw.long_name = 'Grey scale'
    id_bw[:, :] = 1 - (nmp.flipud(xpic[:, :]) + 1) / idiv

f_out.About = 'Image ' + cf_im + ' converted to netcdf.'
f_out.Author = 'Generated with `imageBW_to_NetCDF.py` of `climporn` (https://github.com/brodeau/climporn)'

f_out.close()

print(cf_nc + ' created!!!\n')
Exemple #17
0
id_lat = f_out.createVariable('nav_lat', 'f4', (
    'y',
    'x',
))

id_lon[:, :] = nav_lon[:, :]
id_lat[:, :] = nav_lat[:, :]

jb = 0
jbt = 0
for cb in vbasins:

    if vtreat[jb]:
        #id_bas  = f_out.createVariable(crout+cb,'i1',('y','x',))
        id_bas = f_out.createVariable(crout + cb, 'f4', (
            'y',
            'x',
        ))
        id_bas.long_name = vbnames[jb] + ' ' + vocesea[jb] + ' basin'
        id_bas[:, :] = XBASINS[jbt, :, :] * mask[:, :]
        jbt = jbt + 1

    jb = jb + 1

f_out.About = 'ORCA025, masks for main ocean basins, created with orca_mesh_mask_to_bitmap.py, Gimp, and tiff_to_orca_mask.py, ' + cdate + '.'
f_out.Author = 'L. Brodeau (https://github.com/brodeau/barakuda)'

f_out.close()

print cf_bm + ' created!!!'
id_lon  = f_out.createVariable('nav_lon','f4',('y','x',))
id_lat  = f_out.createVariable('nav_lat','f4',('y','x',))

id_atl  = f_out.createVariable('tmaskatl' ,'f4',('y','x',)) ; id_atl.long_name = 'Atlantic Basin'
id_pac  = f_out.createVariable('tmaskpac' ,'f4',('y','x',)) ; id_pac.long_name = 'Pacific Basin'
id_ind  = f_out.createVariable('tmaskind' ,'f4',('y','x',)) ; id_ind.long_name = 'Indian Basin'
id_soc  = f_out.createVariable('tmasksoc' ,'f4',('y','x',)) ; id_soc.long_name = 'Southern Basin'
id_inp  = f_out.createVariable('tmaskinp' ,'f4',('y','x',)) ;  id_inp.long_name = 'Indo-Pacific Basin'


# Filling variables:
id_lat[:,:]    =   xlat[:,:]
id_lon[:,:]    =   xlon[:,:]

id_atl[:,:]  =  mask_atl[:,:]
id_pac[:,:]  =  mask_pac[:,:]
id_ind[:,:]  =  mask_ind[:,:]
id_soc[:,:]  =  mask_soc[:,:]

id_inp[:,:]  =  mask_inp[:,:]


f_out.About  = 'ORCA1 main oceanic basin land-sea mask created from '+cf_mm
f_out.Author = ' Generated with "orca025_create_basin_mask_from_meshmask.py" of BaraKuda (https://github.com/brodeau/barakuda)'

f_out.close()


print cf_out+' sucessfully created!'

        f_atm.createDimension(cv_tim, None)
        # Variables
        ida_lon = f_atm.createVariable(cv_lon, 'f4', (
            'y',
            'x',
        ), zlib=True)
        ida_lat = f_atm.createVariable(cv_lat, 'f4', (
            'y',
            'x',
        ), zlib=True)
        ida_tim = f_atm.createVariable(cv_tim, 'f4', (cv_tim, ), zlib=True)
        # Attributes
        ida_tim.units = cunt_time
        ida_lat.units = cunt_lat
        ida_lon.units = cunt_lon
        f_atm.About = 'prepare_PAPA_forcing_STATION-ASF.py of AeroBulk for NEMO/STATION-ASF test-case. Gaps in time-series are filled by means of linear interpolation.'
        # Filling variables:
        ida_lat[:, :] = vlat[0]
        ida_lon[:, :] = vlon[0]
        for jt in range(Nt):
            ida_tim[jt] = vtime[jt]

        # Creating output file for ocean:
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        f_oce = Dataset(cf_oce, 'w', format='NETCDF4')
        # Dimensions:
        f_oce.createDimension('x', ni)
        f_oce.createDimension('y', nj)
        f_oce.createDimension(cv_tim, None)
        # Variables
        ido_lon = f_oce.createVariable(cv_lon, 'f4', (