Example #1
0
def applymask(arg):
  # load data
  data_in = Dataset(arg.file_in)
  data_out = Dataset(arg.file_out, 'r+')

  # dimensions and time series
  data_out.variables['x'][:] = data_in.variables['x'][160:400]
  data_out.variables['y'][:] = data_in.variables['y'][:]
  data_out.variables['z'][:] = data_in.variables['z'][:]
  data_out.variables['time'][:] = data_in.variables['time'][:]
  #data_out.variables['time'][1:] = data_in.variables['time'][1::] - data_in.variables['time'][1] + 2678400
  data_out.variables['meanMeltRate'][:] = data_in.variables['meanMeltRate'][:]
  data_out.variables['totalMeltFlux'][:] = data_in.variables['totalMeltFlux'][:]
  data_out.variables['totalOceanVolume'][:] = data_in.variables['totalOceanVolume'][:]
  data_out.variables['meanTemperature'][:] = data_in.variables['meanTemperature'][:]
  data_out.variables['meanSalinity'][:] = data_in.variables['meanSalinity'][:]

  # list of variables to be corrected
  variables = ['temperatureYZ','salinityYZ']
  for v in data_in.variables:
    if len(data_in.variables[v][:].shape) > 1:
      print('Processing variable ',v)
      if v in variables:
        tmp = data_in.variables[v][:]
        data_out.variables[v][:] = tmp
      else:
        tmp = data_in.variables[v][:]
        new_tmp = tmp[:,:,160:400]
        data_out.variables[v][:] = new_tmp

    else:
      print('Skipping.. \n')

  # mask  bathymetry
  print('Masking bathymetry...\n')
  bat =  data_in.variables['bathymetry'][:,:,160:400]
  bottomSalinity =  data_in.variables['bottomSalinity'][:,:,160:400]
  tm, jm, im = bat.shape
  for t in range(tm):
    bat[t,:] = np.ma.masked_where(bottomSalinity[t,:].mask == True, bat[t,:])

  data_out.variables['bathymetry'][:,:,:] = bat[:,:,:]

  # : mask zero values
  print('Masking iceDraft...\n')
  iceDraft = data_in.variables['iceDraft'][:,:,160:400]
  for t in range(tm):
    iceDraft[t,:] = np.ma.masked_where(bottomSalinity[t,:].mask == True, iceDraft[t,:])

  data_out.variables['iceDraft'][:,:,:] = iceDraft[:,:,:]
  # change attributes
  data_out.Author = 'Gustavo Marques ([email protected])'
  data_out.Created = datetime.now().isoformat()

  data_out.sync()
  data_out.close()
  data_in.close()
  print('Done!')
Example #2
0
    def create_nc(self, ncfile):
        """
        Create the particle netcdf file

        NetCDF variable and dimension names are consistent with partrac data.
        """

        if self.verbose:
            print '\nInitialising particle netcdf file: %s...\n' % ncfile

        # Global Attributes
        nc = Dataset(ncfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'Particle trajectory file'
        nc.Author = os.getenv('USER')
        nc.Created = datetime.now().isoformat()

        # Dimensions
        nc.createDimension('ntrac', self.N)
        nc.createDimension('nt', 0)  # Unlimited

        # Create variables
        def create_nc_var(name, dimensions, attdict, dtype='f8'):
            tmp = nc.createVariable(name, dtype, dimensions)
            for aa in attdict.keys():
                tmp.setncattr(aa, attdict[aa])

        basetimestr = 'seconds since %s'%(datetime.strftime(self.basetime,\
            '%Y-%m-%d %H:%M:%S'))
        create_nc_var('tp',('nt'),{'units':basetimestr\
            ,'long_name':"time at drifter locations"},dtype='f8')
        create_nc_var('xp',('ntrac','nt'),{'units':'m',\
            'long_name':"Easting coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('yp',('ntrac','nt'),{'units':'m',\
            'long_name':"Northing coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('zp',('ntrac','nt'),{'units':'m',\
            'long_name':"vertical position of drifter (negative is downward from surface)",'time':'tp'},dtype='f8')
        if self.has_age:
            create_nc_var('age',('ntrac','nt'),{'units':'seconds',\
                'long_name':"Particle age",'time':'tp'},dtype='f8')
            create_nc_var('agemax',('ntrac','nt'),{'units':'seconds',\
                'long_name':"Maximum particle age",'time':'tp'},dtype='f8')

        # Keep the pointer to the open file as an attribute
        self._nc = nc
Example #3
0
    def create_nc(self,ncfile):
        """
        Create the particle netcdf file

        NetCDF variable and dimension names are consistent with partrac data.
        """

        if self.verbose:
            print '\nInitialising particle netcdf file: %s...\n'%ncfile
            
        # Global Attributes
        nc = Dataset(ncfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'Particle trajectory file'
        nc.Author = os.getenv('USER')
        nc.Created = datetime.now().isoformat()

        # Dimensions
        nc.createDimension('ntrac', self.N)
        nc.createDimension('nt', 0) # Unlimited
        
        # Create variables
        def create_nc_var( name, dimensions, attdict, dtype='f8'):
            tmp=nc.createVariable(name, dtype, dimensions)
            for aa in attdict.keys():
                tmp.setncattr(aa,attdict[aa])
          
        basetimestr = 'seconds since %s'%(datetime.strftime(self.basetime,\
            '%Y-%m-%d %H:%M:%S'))
        create_nc_var('tp',('nt'),{'units':basetimestr\
            ,'long_name':"time at drifter locations"},dtype='f8')
        create_nc_var('xp',('ntrac','nt'),{'units':'m',\
            'long_name':"Easting coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('yp',('ntrac','nt'),{'units':'m',\
            'long_name':"Northing coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('zp',('ntrac','nt'),{'units':'m',\
            'long_name':"vertical position of drifter (negative is downward from surface)",'time':'tp'},dtype='f8')
        if self.has_age:
            create_nc_var('age',('ntrac','nt'),{'units':'seconds',\
                'long_name':"Particle age",'time':'tp'},dtype='f8')
            create_nc_var('agemax',('ntrac','nt'),{'units':'seconds',\
                'long_name':"Maximum particle age",'time':'tp'},dtype='f8')

        # Keep the pointer to the open file as an attribute
        self._nc = nc
Example #4
0
    def initParticleNC(self,outfile,Np,age=False):
        """
        Export the grid variables to a netcdf file
        """
        import os

        if self.verbose:
            print '\nInitialising particle netcdf file: %s...\n'%outfile
            
        # Global Attributes
        nc = Dataset(outfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'Particle trajectory file'
        nc.Author = os.getenv('USER')
        nc.Created = datetime.now().isoformat()

        #tseas = self.time_sec[1] - self.time_sec[0]
        #nsteps = np.floor(tseas/self.dt)
        #nc.nsteps = '%f (number of linear interpolation steps in time between model outputs)'%nsteps
        #nc.tseas = '%d (Time step (seconds) between model outputs'%tseas
        #nc.dt = '%f (Particle model time steps [seconds])'%self.dt
        nc.dataset_location = '%s'%self.ncfile

        # Dimensions
        nc.createDimension('ntrac', Np)
        nc.createDimension('nt', 0) # Unlimited
        
        # Create variables
        def create_nc_var( name, dimensions, attdict, dtype='f8'):
            tmp=nc.createVariable(name, dtype, dimensions)
            for aa in attdict.keys():
                tmp.setncattr(aa,attdict[aa])
          
        create_nc_var('tp',('nt'),{'units':'seconds since 1990-01-01 00:00:00','long_name':"time at drifter locations"},dtype='f8')
        create_nc_var('xp',('ntrac','nt'),{'units':'m','long_name':"Easting coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('yp',('ntrac','nt'),{'units':'m','long_name':"Northing coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('zp',('ntrac','nt'),{'units':'m','long_name':"vertical position of drifter (negative is downward from surface)",'time':'tp'},dtype='f8')
	if age:
	    create_nc_var('age',('ntrac','nt'),{'units':'seconds','long_name':"Particle age",'time':'tp'},dtype='f8')
	    create_nc_var('agemax',('ntrac','nt'),{'units':'seconds','long_name':"Maximum particle age",'time':'tp'},dtype='f8')

        nc.close()
Example #5
0
    def initParticleNC(self,outfile,Np,age=False):
        """
        Export the grid variables to a netcdf file
        """
        import os

        if self.verbose:
            print '\nInitialising particle netcdf file: %s...\n'%outfile
            
        # Global Attributes
        nc = Dataset(outfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'Particle trajectory file'
        nc.Author = os.getenv('USER')
        nc.Created = datetime.now().isoformat()

        #tseas = self.time_sec[1] - self.time_sec[0]
        #nsteps = np.floor(tseas/self.dt)
        #nc.nsteps = '%f (number of linear interpolation steps in time between model outputs)'%nsteps
        #nc.tseas = '%d (Time step (seconds) between model outputs'%tseas
        #nc.dt = '%f (Particle model time steps [seconds])'%self.dt
        nc.dataset_location = '%s'%self.ncfile

        # Dimensions
        nc.createDimension('ntrac', Np)
        nc.createDimension('nt', 0) # Unlimited
        
        # Create variables
        def create_nc_var( name, dimensions, attdict, dtype='f8'):
            tmp=nc.createVariable(name, dtype, dimensions)
            for aa in attdict.keys():
                tmp.setncattr(aa,attdict[aa])
          
        create_nc_var('tp',('nt'),{'units':'seconds since 1990-01-01 00:00:00','long_name':"time at drifter locations"},dtype='f8')
        create_nc_var('xp',('ntrac','nt'),{'units':'m','long_name':"Easting coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('yp',('ntrac','nt'),{'units':'m','long_name':"Northing coordinate of drifter",'time':'tp'},dtype='f8')
        create_nc_var('zp',('ntrac','nt'),{'units':'m','long_name':"vertical position of drifter (negative is downward from surface)",'time':'tp'},dtype='f8')
	if age:
	    create_nc_var('age',('ntrac','nt'),{'units':'seconds','long_name':"Particle age",'time':'tp'},dtype='f8')
	    create_nc_var('agemax',('ntrac','nt'),{'units':'seconds','long_name':"Maximum particle age",'time':'tp'},dtype='f8')

        nc.close()
Example #6
0
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
from netCDF4 import Dataset
from shutil import copyfile

N = 15
Nr = 4

nc = Dataset('Rivers.nc', 'w', format='NETCDF3_64BIT')
nc.Description = 'Discharges of major rivers'
nc.Author = 'Evgeny Ivanov'
nc.Created = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
nc.title = 'Discharges of major rivers'
nc.createDimension('river_time', 365 * 10)  ###
####nc.createDimension('river_time', 365)
nc.createDimension('xi_rho', 82)
nc.createDimension('xi_u', 81)
nc.createDimension('xi_v', 82)
nc.createDimension('eta_rho', 112)
nc.createDimension('eta_u', 112)
nc.createDimension('eta_v', 111)
nc.createDimension('s_rho', N)
nc.createDimension('river', Nr)

YY = []
MM = []
DD = []
QQ = []

for line in open('Maas_Dordrecht.txt', 'r').readlines():
Example #7
0
def make_remap_grid_file(grd):

    #create remap file
    remap_filename = 'remap_grid_' + grd.name + '_t.nc'
    nc = Dataset(remap_filename, 'w', format='NETCDF3_64BIT')
    nc.Description = 'remap grid file for Mecrator'
    nc.Author = 'Jheka'
    nc.Created = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    nc.title = grd.name
    print "4"

    lon_corner = grd.lon_vert
    lat_corner = grd.lat_vert
    grid_center_lon = grd.lon_t.flatten()
    grid_center_lat = grd.lat_t.flatten()
    Mp, Lp = grd.lon_t.shape
    grid_imask = grd.mask_t[0,:].flatten()

    grid_size = Lp * Mp

    grid_corner_lon = np.zeros((grid_size, 4))
    grid_corner_lat = np.zeros((grid_size, 4))
    k = 0
    for j in range(Mp-2):
        for i in range(Lp-2):
	    #print i,j
            grid_corner_lon[k,0] = lon_corner[j,i]
            grid_corner_lat[k,0] = lat_corner[j,i]
            grid_corner_lon[k,1] = lon_corner[j,i+1]
            grid_corner_lat[k,1] = lat_corner[j,i+1]
            grid_corner_lon[k,2] = lon_corner[j+1,i+1]
            grid_corner_lat[k,2] = lat_corner[j+1,i+1]
            grid_corner_lon[k,3] = lon_corner[j+1,i]
            grid_corner_lat[k,3] = lat_corner[j+1,i]
            k = k + 1


    #Write netcdf file
    nc.createDimension('grid_size', grid_size)
    nc.createDimension('grid_corners', 4)
    nc.createDimension('grid_rank', 2)

    nc.createVariable('grid_dims', 'i4', ('grid_rank'))
    nc.variables['grid_dims'].long_name = 'grid size along x and y axis'
    nc.variables['grid_dims'].units = 'None'
    nc.variables['grid_dims'][:] = [(Lp, Mp)]

    nc.createVariable('grid_center_lon', 'f8', ('grid_size'))
    nc.variables['grid_center_lon'].long_name = 'longitude of cell center'
    nc.variables['grid_center_lon'].units = 'degrees'
    nc.variables['grid_center_lon'][:] = grid_center_lon

    nc.createVariable('grid_center_lat', 'f8', ('grid_size'))
    nc.variables['grid_center_lat'].long_name = 'latitude of cell center'
    nc.variables['grid_center_lat'].units = 'degrees'
    nc.variables['grid_center_lat'][:] = grid_center_lat

    nc.createVariable('grid_imask', 'i4', ('grid_size'))
    nc.variables['grid_imask'].long_name = 'mask'
    nc.variables['grid_imask'].units = 'None'
    nc.variables['grid_imask'][:] = np.ones((Lp * Mp))

    nc.createVariable('grid_corner_lon', 'f8', ('grid_size', 'grid_corners'))
    nc.variables['grid_corner_lon'].long_name = 'longitude of cell corner'
    nc.variables['grid_corner_lon'].units = 'degrees'
    nc.variables['grid_corner_lon'][:] = grid_corner_lon

    nc.createVariable('grid_corner_lat', 'f8', ('grid_size', 'grid_corners'))
    nc.variables['grid_corner_lat'].long_name = 'latitude of cell corner'
    nc.variables['grid_corner_lat'].units = 'degrees'
    nc.variables['grid_corner_lat'][:] = grid_corner_lat


    nc.close()
Example #8
0
    def writeNC(self, outfile, tt, x, y, Uwind, Vwind, Tair, Cloud, RH, Pair,
                Rain):
        """
        SUNTANS required wind file, this function creates the netcdf file
        """
        Nstation = x.shape[0]
        Nt = len(tt)

        nc = Dataset(outfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'SUNTANS History file'
        nc.Author = ''
        nc.Created = datetime.now().isoformat()
        ####Create dimensions####
        nc.createDimension('NVwind', Nstation)
        nc.createDimension('NTair', Nstation)
        nc.createDimension('Nrain', Nstation)
        nc.createDimension('NUwind', Nstation)
        nc.createDimension('NPair', Nstation)
        nc.createDimension('NRH', Nstation)
        nc.createDimension('Ncloud', Nstation)
        nc.createDimension('nt', Nt)
        nc.close()

        def create_nc_var(outfile,
                          name,
                          dimensions,
                          attdict,
                          dtype='f8',
                          zlib=False,
                          complevel=0,
                          fill_value=None):

            nc = Dataset(outfile, 'a')
            tmp = nc.createVariable(name,
                                    dtype,
                                    dimensions,
                                    zlib=zlib,
                                    complevel=complevel,
                                    fill_value=fill_value)
            for aa in attdict.keys():
                tmp.setncattr(aa, attdict[aa])
            #nc.variables[name][:] = var
            nc.close()

        ####adding variables####
        create_nc_var(outfile, 'x_Vwind', ('NVwind'), {
            'long_name': 'Longitude at Vwind',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_Vwind', ('NVwind'), {
            'long_name': 'Latitude at Vwind',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_Vwind', ('NVwind'), {
            'long_name': 'Elevation at Vwind',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_Tair', ('NTair'), {
            'long_name': 'Longitude at Tair',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_Tair', ('NTair'), {
            'long_name': 'Latitude at Tair',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_Tair', ('NTair'), {
            'long_name': 'Elevation at Tair',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_rain', ('Nrain'), {
            'long_name': 'Longitude at rain',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_rain', ('Nrain'), {
            'long_name': 'Latitude at rain',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_rain', ('Nrain'), {
            'long_name': 'Elevation at rain',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_Uwind', ('NUwind'), {
            'long_name': 'Longitude at Uwind',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_Uwind', ('NUwind'), {
            'long_name': 'Latitude at Uwind',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_Uwind', ('NUwind'), {
            'long_name': 'Elevation at Uwind',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_Pair', ('NPair'), {
            'long_name': 'Longitude at Pair',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_Pair', ('NPair'), {
            'long_name': 'Latitude at Pair',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_Pair', ('NPair'), {
            'long_name': 'Elevation at Pair',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_RH', ('NRH'), {
            'long_name': 'Longitude at RH',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_RH', ('NRH'), {
            'long_name': 'Latitude at RH',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_RH', ('NRH'), {
            'long_name': 'Elevation at RH',
            'units': 'm'
        })

        create_nc_var(outfile, 'x_cloud', ('Ncloud'), {
            'long_name': 'Longitude at cloud',
            'units': 'degrees_north'
        })
        create_nc_var(outfile, 'y_cloud', ('Ncloud'), {
            'long_name': 'Latitude at cloud',
            'units': 'degrees_east'
        })
        create_nc_var(outfile, 'z_cloud', ('Ncloud'), {
            'long_name': 'Elevation at cloud',
            'units': 'm'
        })

        create_nc_var(outfile, 'Time', ('nt'), {
            'units': 'seconds since 1990-01-01 00:00:00',
            'long_name': 'time'
        })
        create_nc_var(
            outfile, 'Vwind', ('nt', 'NVwind'), {
                'units': 'm s-1',
                'long_name': 'Northward wind velocity component',
                'coordinates': 'x_Vwind,y_Vwind'
            })
        create_nc_var(
            outfile, 'Tair', ('nt', 'NTair'), {
                'units': 'Celsius',
                'long_name': 'Air Temperature',
                'coordinates': 'x_Tair,y_Tair'
            })
        create_nc_var(
            outfile, 'rain', ('nt', 'Nrain'), {
                'units': 'kg m2 s-1',
                'long_name': 'rain fall rate',
                'coordinates': 'x_rain,y_rain'
            })
        create_nc_var(
            outfile, 'Uwind', ('nt', 'NUwind'), {
                'long_name': 'Eastward wind velocity component',
                'coordinates': 'x_Uwind,y_Uwind',
                'units': 'm s-1'
            })
        create_nc_var(
            outfile, 'Pair', ('nt', 'NPair'), {
                'units': 'hPa',
                'long_name': 'Air Pressure',
                'coordinates': 'x_Pair,y_Pair'
            })
        create_nc_var(
            outfile, 'RH', ('nt', 'NRH'), {
                'units': 'percent',
                'long_name': 'Relative Humidity',
                'coordinates': 'x_RH,y_RH'
            })
        create_nc_var(
            outfile, 'cloud', ('nt', 'Ncloud'), {
                'units': 'dimensionless',
                'long_name': 'Cloud cover fraction',
                'coordinates': 'x_cloud,y_cloud'
            })

        z = np.ones([Nstation]) * 2
        ## change time units
        time_new = SecondsSince(tt)
        #        ##Tair, rain, Pair, RH, cloud are set to be constant due to a lack of information
        #        Tair = np.ones([Nt, Nstation])*30.0
        #        rain = np.ones([Nt, Nstation])*0.0
        #        Pair = np.ones([Nt, Nstation])*1010.0
        #        RH = np.ones([Nt, Nstation])*50.0
        #        cloud = np.ones([Nt, Nstation])*0.0
        ######Now writting the variables######
        nc = Dataset(outfile, 'a')
        nc.variables['x_Vwind'][:] = x
        nc.variables['y_Vwind'][:] = y
        nc.variables['z_Vwind'][:] = z

        nc.variables['x_Tair'][:] = x
        nc.variables['y_Tair'][:] = y
        nc.variables['z_Tair'][:] = z

        nc.variables['x_rain'][:] = x
        nc.variables['y_rain'][:] = y
        nc.variables['z_rain'][:] = z

        nc.variables['x_Uwind'][:] = x
        nc.variables['y_Uwind'][:] = y
        nc.variables['z_Uwind'][:] = z

        nc.variables['x_Pair'][:] = x
        nc.variables['y_Pair'][:] = y
        nc.variables['z_Pair'][:] = z

        nc.variables['x_RH'][:] = x
        nc.variables['y_RH'][:] = y
        nc.variables['z_RH'][:] = z

        nc.variables['x_cloud'][:] = x
        nc.variables['y_cloud'][:] = y
        nc.variables['z_cloud'][:] = z

        nc.variables['Time'][:] = time_new
        nc.variables['Vwind'][:] = Vwind
        nc.variables['Tair'][:] = Tair
        nc.variables['rain'][:] = Rain
        nc.variables['Uwind'][:] = Uwind
        nc.variables['Pair'][:] = Pair
        nc.variables['RH'][:] = RH
        nc.variables['cloud'][:] = Cloud

        print "Ending writing variables into netcdf file !!!"
        nc.close()
Example #9
0
    def writeNC(self, outfile):
        """
        This function is used to create the netcdf file
        """
        print 'under developing'
        
        ####create netcdf File####
        nc = Dataset(outfile, 'w', format='NETCDF4_CLASSIC')
        nc.Description = 'SUNTANS History file'
        nc.Author = ''
        nc.Created = datetime.now().isoformat()
        ####Create dimensions####
        nc.createDimension('NVwind', self.Nstation)
        nc.createDimension('NTair', self.Nstation)
        nc.createDimension('Nrain', self.Nstation)
        nc.createDimension('NUwind', self.Nstation)
        nc.createDimension('NPair', self.Nstation)
	nc.createDimension('NRH', self.Nstation)
	nc.createDimension('Ncloud', self.Nstation)
	nc.createDimension('nt', self.Nt)
	nc.close()

	####adding variables####
        self.create_nc_var(outfile,'x_Vwind',('NVwind'),{'long_name':'Longitude at Vwind','units':'degrees_north'})
        self.create_nc_var(outfile,'y_Vwind',('NVwind'),{'long_name':'Latitude at Vwind','units':'degrees_east'})
        self.create_nc_var(outfile,'z_Vwind',('NVwind'),{'long_name':'Elevation at Vwind','units':'m'})

	self.create_nc_var(outfile,'x_Tair',('NTair'),{'long_name':'Longitude at Tair','units':'degrees_north'})
        self.create_nc_var(outfile,'y_Tair',('NTair'),{'long_name':'Latitude at Tair','units':'degrees_east'})
        self.create_nc_var(outfile,'z_Tair',('NTair'),{'long_name':'Elevation at Tair','units':'m'})

	self.create_nc_var(outfile,'x_rain',('Nrain'),{'long_name':'Longitude at rain','units':'degrees_north'})
        self.create_nc_var(outfile,'y_rain',('Nrain'),{'long_name':'Latitude at rain','units':'degrees_east'})
        self.create_nc_var(outfile,'z_rain',('Nrain'),{'long_name':'Elevation at rain','units':'m'})

	self.create_nc_var(outfile,'x_Uwind',('NUwind'),{'long_name':'Longitude at Uwind','units':'degrees_north'})
        self.create_nc_var(outfile,'y_Uwind',('NUwind'),{'long_name':'Latitude at Uwind','units':'degrees_east'})
        self.create_nc_var(outfile,'z_Uwind',('NUwind'),{'long_name':'Elevation at Uwind','units':'m'})

	self.create_nc_var(outfile,'x_Pair',('NPair'),{'long_name':'Longitude at Pair','units':'degrees_north'})
        self.create_nc_var(outfile,'y_Pair',('NPair'),{'long_name':'Latitude at Pair','units':'degrees_east'})
        self.create_nc_var(outfile,'z_Pair',('NPair'),{'long_name':'Elevation at Pair','units':'m'})

	self.create_nc_var(outfile,'x_RH',('NRH'),{'long_name':'Longitude at RH','units':'degrees_north'})
        self.create_nc_var(outfile,'y_RH',('NRH'),{'long_name':'Latitude at RH','units':'degrees_east'})
        self.create_nc_var(outfile,'z_RH',('NRH'),{'long_name':'Elevation at RH','units':'m'})

	self.create_nc_var(outfile,'x_cloud',('Ncloud'),{'long_name':'Longitude at cloud','units':'degrees_north'})
        self.create_nc_var(outfile,'y_cloud',('Ncloud'),{'long_name':'Latitude at cloud','units':'degrees_east'})
        self.create_nc_var(outfile,'z_cloud',('Ncloud'),{'long_name':'Elevation at cloud','units':'m'})

	self.create_nc_var(outfile,'Time',('nt'),{'units':'seconds since 1990-01-01 00:00:00','long_name':'time'})
	self.create_nc_var(outfile,'Vwind',('nt','NVwind'),{'units':'m s-1','long_name':'Northward wind velocity component','coordinates':'x_Vwind,y_Vwind'})
	self.create_nc_var(outfile,'Tair',('nt','NTair'),{'units':'Celsius','long_name':'Air Temperature','coordinates':'x_Tair,y_Tair'})
	self.create_nc_var(outfile,'rain',('nt','Nrain'),{'units':'kg m2 s-1','long_name':'rain fall rate','coordinates':'x_rain,y_rain'})
	self.create_nc_var(outfile,'Uwind',('nt','NUwind'),{'long_name':'Eastward wind velocity component','coordinates':'x_Uwind,y_Uwind','units':'m s-1'})
	self.create_nc_var(outfile,'Pair',('nt','NPair'),{'units':'hPa','long_name':'Air Pressure','coordinates':'x_Pair,y_Pair'})
	self.create_nc_var(outfile,'RH',('nt','NRH'),{'units':'percent','long_name':'Relative Humidity','coordinates':'x_RH,y_RH'})
	self.create_nc_var(outfile,'cloud',('nt','Ncloud'),{'units':'dimensionless','long_name':'Cloud cover fraction','coordinates':'x_cloud,y_cloud'})
	

	######Now writting the variables######
	nc = Dataset(outfile,'a')
	nc.variables['x_Vwind'][:]=self.lat
	nc.variables['y_Vwind'][:]=self.lon
	nc.variables['z_Vwind'][:]=self.z
	
	nc.variables['x_Tair'][:]=self.lat
	nc.variables['y_Tair'][:]=self.lon
	nc.variables['z_Tair'][:]=self.z

	nc.variables['x_rain'][:]=self.lat
	nc.variables['y_rain'][:]=self.lon
	nc.variables['z_rain'][:]=self.z	
	
	nc.variables['x_Uwind'][:]=self.lat
	nc.variables['y_Uwind'][:]=self.lon
	nc.variables['z_Uwind'][:]=self.z

	nc.variables['x_Pair'][:]=self.lat
	nc.variables['y_Pair'][:]=self.lon
	nc.variables['z_Pair'][:]=self.z

	nc.variables['x_RH'][:]=self.lat
	nc.variables['y_RH'][:]=self.lon
	nc.variables['z_RH'][:]=self.z

	nc.variables['x_cloud'][:]=self.lat
	nc.variables['y_cloud'][:]=self.lon
	nc.variables['z_cloud'][:]=self.z

	nc.variables['Time'][:]=self.time
	nc.variables['Vwind'][:]=self.Vwind
	nc.variables['Tair'][:]=self.Tair
	nc.variables['rain'][:]=self.rain
	nc.variables['Uwind'][:]=self.Uwind
	nc.variables['Pair'][:]=self.Pair
	nc.variables['RH'][:]=self.RH
	nc.variables['cloud'][:]=self.cloud

	print "Ending writing variables into netcdf file !!!"
	nc.close()