def __init__(self,cls, History, debug=False):
        if debug:
            print 'Loading variables...'
        # Pointer to History
        setattr(self, '_History', History)

        self.matlabTime = cls.Data['velocity'].vel_time[:]
        #Sorting values with increasing time step
        sortedInd = self.matlabTime.argsort()
        self.matlabTime.sort()
        self.lat = cls.Data['velocity'].vel_lat[sortedInd]
        self.lon = cls.Data['velocity'].vel_lon[sortedInd]
        self.u = cls.Data['velocity'].u[sortedInd]
        self.v = cls.Data['velocity'].v[sortedInd]

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        if debug: print '...Passed'

        return
示例#2
0
    def __init__(self, cls, History, debug=False):
        if debug:
            print 'Loading variables...'
        # Pointer to History
        setattr(self, '_History', History)

        self.matlabTime = cls.Data['velocity'].vel_time[:]
        #Sorting values with increasing time step
        sortedInd = self.matlabTime.argsort()
        self.matlabTime.sort()
        self.lat = cls.Data['velocity'].vel_lat[sortedInd]
        self.lon = cls.Data['velocity'].vel_lon[sortedInd]
        self.u = cls.Data['velocity'].u[sortedInd]
        self.v = cls.Data['velocity'].v[sortedInd]

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        if debug: print '...Passed'

        return
示例#3
0
    def mattime2datetime(self, mattime, debug=False):
        """
        Description:
        Output the time (yyyy-mm-dd, hh:mm:ss) corresponding to
        a given matlab time

        Inputs:
          - mattime = matlab time (floats)
        """
        time = mattime_to_datetime(mattime, debug=debug)
        return time
    def mattime2datetime(self, mattime, debug=False):
        """
        Description:
        Output the time (yyyy-mm-dd, hh:mm:ss) corresponding to
        a given matlab time

        Inputs:
          - mattime = matlab time (floats)
        """  
        time = mattime_to_datetime(mattime, debug=debug)   
        return time
    def __init__(self, cls, History, debug=False):
        if debug: print 'Loading variables...'

        # Pointer to History
        setattr(self, '_History', History)

        self.RBR = cls['RBR']
        data = self.RBR.data
        self.matlabTime = self.RBR.date_num_Z
        self.lat = self.RBR.lat
        self.lon = self.RBR.lon
        self.el = data - np.mean(data)

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        if debug: print '...Done'
示例#6
0
    def __init__(self, cls, History, debug=False):
        if debug: print 'Loading variables...'

        # Pointer to History
        setattr(self, '_History', History)

        self.RBR = cls['RBR']
        data = self.RBR.data
        self.matlabTime = self.RBR.date_num_Z
        self.lat = self.RBR.lat
        self.lon = self.RBR.lon
        self.el = data - np.mean(data)

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        if debug: print '...Done'
示例#7
0
    def __init__(self, cls, History, debug=False):
        if debug:
            print 'Loading variables...'
        # Pointer to History
        setattr(self, '_History', History)

        # TR: fudge factor, squeeze out the 5 top % of the water column
        self.percent_of_depth = 0.95

        #Test if load with h5py or scipy
        if not type(cls.Data) == h5py._hl.files.File:
            self.lat = cls.Data['lat']
            self.lon = cls.Data['lon']
            self.bins = cls.Data['data'].bins[:].ravel()
            self.north_vel = cls.Data['data'].north_vel[:]
            self.east_vel = cls.Data['data'].east_vel[:]
            self.vert_vel = cls.Data['data'].vert_vel[:]
            self.dir_vel = cls.Data['data'].dir_vel[:]
            self.mag_signed_vel = cls.Data['data'].mag_signed_vel[:]
            self.pressure = cls.Data['pres']
            self.surf = self.pressure.surf[:].ravel()
            self.el = self.surf
            self.time = cls.Data['time']
            self.matlabTime = self.time.mtime[:].ravel()
            try:
                self.ucross = cls.Data['data'].ucross[:]
                self.ualong = cls.Data['data'].ualong[:]
            except AttributeError:
                pass

        else:
            self.lat = cls.Data['lat'][0][0]
            self.lon = cls.Data['lon'][0][0]
            self.bins = cls.Data['data']['bins'][:].ravel()
            self.north_vel = cls.Data['data']['north_vel'][:].T
            self.east_vel = cls.Data['data']['east_vel'][:].T
            self.vert_vel = cls.Data['data']['vert_vel'][:].T
            self.dir_vel = cls.Data['data']['dir_vel'][:].T
            self.mag_signed_vel = cls.Data['data']['mag_signed_vel'][:].T
            self.pressure = cls.Data['pres']
            self.surf = self.pressure['surf'][:].ravel()
            self.el = self.surf
            self.time = cls.Data['time']
            self.matlabTime = self.time['mtime'][:].ravel()
            try:
                self.ucross = cls.Data['data']['Ucross'][:].T
                self.ualong = cls.Data['data']['Ualong'][:].T
            except KeyError:
                pass

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        #Find the depth average of a variable based on percent_of_depth
        #choosen by the user. Currently only working for east_vel (u) and
        #north_vel (v)
        #TR: alaternative with percent of the depth
        ind = np.argwhere(
            self.bins < self.percent_of_depth * self.surf[:, np.newaxis])
        #ind = np.argwhere(self.bins < self.surf[:,np.newaxis])
        index = ind[np.r_[ind[1:, 0] != ind[:-1, 0], True]]
        try:
            data_ma_u = np.ma.array(self.east_vel,
                                    mask=np.arange(self.east_vel.shape[1]) >
                                    index[:, 1, np.newaxis])
            data_ma_u = np.ma.masked_array(data_ma_u, np.isnan(data_ma_u))
        except MaskError:
            data_ma_u = np.ma.masked_array(self.east_vel,
                                           np.isnan(self.east_vel))

        try:
            data_ma_v = np.ma.array(self.north_vel,
                                    mask=np.arange(self.north_vel.shape[1]) >
                                    index[:, 1, np.newaxis])
            data_ma_v = np.ma.masked_array(data_ma_v, np.isnan(data_ma_v))
        except MaskError:
            data_ma_v = np.ma.masked_array(self.north_vel,
                                           np.isnan(self.north_vel))

        self.ua = np.array(data_ma_u.mean(axis=1))
        self.va = np.array(data_ma_v.mean(axis=1))

        # Compute depth with fvcom convention, negative from surface down
        self.depth = np.ones(self.north_vel.shape) * np.nan
        for t in range(self.matlabTime.shape[0]):
            #i = np.where(np.isnan(self.north_vel[t,:]))[0][0]
            #z = self.bins[i]
            self.depth[t, :] = self.bins[:] - self.surf[t]
        self.depth[np.where(self.depth > 0.0)] = np.nan

        if debug:
            print '...Passed'

        return
示例#8
0
    def __init__(self,cls, History, debug=False):
        if debug:
            print 'Loading variables...'
        # Pointer to History
        setattr(self, '_History', History)


        # TR: fudge factor, squeeze out the 5 top % of the water column
        self.percent_of_depth=0.95

        #Test if load with h5py or scipy
        if not type(cls.Data)==h5py._hl.files.File:
            self.lat = cls.Data['lat']
            self.lon = cls.Data['lon']
            #self.bins = cls.Data['data'].bins[:].ravel()
            self.north_vel = cls.Data['data'].north_vel[:]
            self.east_vel = cls.Data['data'].east_vel[:]
            #self.vert_vel = cls.Data['data'].vert_vel[:]
            #self.dir_vel = cls.Data['data'].dir_vel[:]
            #self.mag_signed_vel = cls.Data['data'].mag_signed_vel[:]
            #self.pressure = cls.Data['pres']
            #self.surf = self.pressure.surf[:].ravel()
            #self.el = self.surf
            self.time = cls.Data['time']
            self.matlabTime = self.time.mtime[:].ravel()
            #try:
            #    self.ucross = cls.Data['data'].ucross[:]
            #    self.ualong = cls.Data['data'].ualong[:]
            #except AttributeError:
            #    pass

        else:
            self.lat = cls.Data['lat'][0][0]
            self.lon = cls.Data['lon'][0][0]
            #self.bins = cls.Data['data']['bins'][:].ravel()
            self.north_vel = cls.Data['data']['north_vel'][:].T
            self.east_vel = cls.Data['data']['east_vel'][:].T
            #self.vert_vel = cls.Data['data']['vert_vel'][:].T
            #self.dir_vel = cls.Data['data']['dir_vel'][:].T
            #self.mag_signed_vel = cls.Data['data']['mag_signed_vel'][:].T
            #self.pressure = cls.Data['pres']
            #self.surf = self.pressure['surf'][:].ravel()
            #self.el = self.surf
            self.time = cls.Data['time']
            self.matlabTime = self.time['mtime'][:].ravel()
            #try:
            #    self.ucross = cls.Data['data']['Ucross'][:].T
            #    self.ualong = cls.Data['data']['Ualong'][:].T
            #except KeyError:
            #    pass

        #-Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Temporal domain from ' + str(start) +\
                ' to ' + str(end)
        self._History.append(text)

        #Find the depth average of a variable based on percent_of_depth
        #choosen by the user. Currently only working for east_vel (u) and
        #north_vel (v)
        #TR: alaternative with percent of the depth
        #ind = np.argwhere(self.bins < self.percent_of_depth * self.surf[:,np.newaxis])
        #ind = np.argwhere(self.bins < self.surf[:,np.newaxis])
        #index = ind[np.r_[ind[1:,0] != ind[:-1,0], True]]
        #try:
        #    data_ma_u = np.ma.array(self.east_vel,
        #                mask=np.arange(self.east_vel.shape[1]) > index[:, 1, np.newaxis])
        #    data_ma_u=np.ma.masked_array(data_ma_u,np.isnan(data_ma_u))
        #except MaskError:
        data_ma_u=np.ma.masked_array(self.east_vel,np.isnan(self.east_vel))

        #try:
            #data_ma_v = np.ma.array(self.north_vel,
                        #mask=np.arange(self.north_vel.shape[1]) > index[:, 1, np.newaxis])
            #data_ma_v=np.ma.masked_array(data_ma_v,np.isnan(data_ma_v))
        #except MaskError:
        data_ma_v=np.ma.masked_array(self.north_vel,np.isnan(self.north_vel))
        
        self.ua = data_ma_u
        self.va = data_ma_v

        # Compute depth with fvcom convention, negative from surface down
        #self.depth = np.ones(self.north_vel.shape) * np.nan
        #for t in range(self.matlabTime.shape[0]):
            ##i = np.where(np.isnan(self.north_vel[t,:]))[0][0]
            ##z = self.bins[i]
            #self.depth[t, :] = self.bins[:] - self.surf[t]
        #self.depth[np.where(self.depth>0.0)] = np.nan

        #if debug:
            #print '...Passed'

        return
示例#9
0
    def __init__(self, data, elements, grid, History, debug=False):
        if debug: print 'Loading variables...'

        #Pointer to History
        setattr(self, '_grid', grid)
        setattr(self, '_History', History)

        #List of keywords
        kwl2D = ['ua', 'va', 'zeta']
        kwl3D = ['ww', 'u', 'v', 'gls', 'tke']
        #List of aliaSes
        al2D = ['ua', 'va', 'el']
        al3D = ['w', 'u', 'v', 'gls', 'tke']

        if debug: print '...time variables...'
        self.julianTime = data.variables['time_JD'][:]
        self.secondTime = data.variables['time_second'][:]
        self.matlabTime = self.julianTime[:] + 678942.0 + self.secondTime[:] / (24*3600)
        # Append message to History field
        start = mattime_to_datetime(self.matlabTime[0])
        end = mattime_to_datetime(self.matlabTime[-1])
        text = 'Full temporal domain from ' + str(start) +\
               ' to ' + str(end)
        self._History.append(text)
        # Add time dimension to grid variables
        self._grid.ntime = self.matlabTime.shape[0]

        if debug: print '...hydro variables...'

        region_e = elements
        region_n = elements
        #Redefine variables in bounding box
        #Check if OpenDap variables or not
        if type(data.variables).__name__=='DatasetType':
            # TR: fix for issue wih elements = slice(none)
            if elements == slice(None):
                region_e = np.arange(self._grid.nele)
                region_n = np.arange(self._grid.nnode)
            #loading hori data
            keyCount = 0
            for key, aliaS in zip(kwl2D, al2D):
                #Special loading for zeta
                H = 0 #local counter
                if key == 'zeta':
                    for k, g in groupby(enumerate(region_n), lambda (i,x):i-x):
                        ID = map(itemgetter(1), g)
                        if debug: print 'Index bound: ' +\
                            str(ID[0]) + '-' + str(ID[-1]+1)
                        if H==0:
                            try:
                                setattr(self, aliaS, data.variables[key].data[:,ID[0]:(ID[-1]+1)])
                            except AttributeError: #exeception due nc.Dataset
                                setattr(self, aliaS, data.variables[key][:,ID[0]:(ID[-1]+1)])
                            H=1
                        else:
                            try:
                                setattr(self, aliaS,
                                np.hstack((getattr(self, aliaS),
                                data.variables[key].data[:,ID[0]:(ID[-1]+1)])))
                            except AttributeError: #exeception due nc.Dataset
                                setattr(self, aliaS,
                                np.hstack((getattr(self, aliaS),
                                data.variables[key][:,ID[0]:(ID[-1]+1)])))
                else:
                    try:                        
                        for k, g in groupby(enumerate(region_e), lambda (i,x):i-x):
                            ID = map(itemgetter(1), g)
                            if debug: print 'Index bound: ' + str(ID[0]) + '-' + str(ID[-1]+1)
                            if H==0:
                                setattr(self, aliaS,
                                        data.variables[key].\
                                        data[:,ID[0]:(ID[-1]+1)])
                                H=1
                            else:
                                try:
                                    setattr(self, aliaS,
                                    np.hstack((getattr(self, aliaS),
                                    data.variables[key].data[:,ID[0]:(ID[-1]+1)])))
                                except AttributeError: #exeception due nc.Dataset
                                    setattr(self, aliaS,
                                    np.hstack((getattr(self, aliaS),
                                    data.variables[key][:,ID[0]:(ID[-1]+1)])))
                            keyCount +=1
                    except KeyError:
                        if debug: print key, " is missing !"
                        continue
            if keyCount==0:
                print "---Horizontal variables are missing---"
            self._3D = False 
                    
            #loading verti data
            keyCount = 0
            for key, aliaS in zip(kwl3D, al3D):
                try:
                    H = 0 #local counter
                    for k, g in groupby(enumerate(region_e), lambda (i,x):i-x):
                        ID = map(itemgetter(1), g)
                        if debug: print 'Index bound: ' + str(ID[0]) + '-' + str(ID[-1]+1)
                        if H==0:
                            try:
                                setattr(self, aliaS,
                                data.variables[key].data[:,:,ID[0]:(ID[-1]+1)])
                            except AttributeError: #exeception due nc.Dataset
                                setattr(self, aliaS,
                                data.variables[key][:,:,ID[0]:(ID[-1]+1)])
                            H=1
                        else:
                            try:
                                setattr(self, aliaS,
                                np.dstack((getattr(self, aliaS),
                                data.variables[key].data[:,:,ID[0]:(ID[-1]+1)])))
                            except AttributeError: #exeception due nc.Dataset
                                setattr(self, aliaS,
                                np.dstack((getattr(self, aliaS),
                                data.variables[key][:,:,ID[0]:(ID[-1]+1)])))
                    keyCount +=1
                except KeyError:
                    if debug: print key, " is missing !"
                    continue
示例#10
0
    def __init__(self, data, grid, tx, History, debug=False):
        self._debug = debug
        self._3D = False
        self._opendap = type(data.variables).__name__=='DatasetType'

        # Pointer to History
        setattr(self, '_History', History)

        # Parallel computing attributs
        #self._cpus = mp.cpu_count()

        #List of keywords
        kwl2D = ['ua', 'va', 'zeta','depth_av_flow_dir', 'hori_velo_norm',
                 'depth_av_vorticity', 'depth_av_power_density',
                 'depth_av_power_assessment', 'tauc']
        kwl3D = ['ww', 'u', 'v', 'gls', 'tke', 'flow_dir', 'velo_norm',
                 'verti_shear', 'vorticity', 'power_density']
        #List of aliaSes
        al2D = ['ua', 'va', 'el','depth_av_flow_dir', 'hori_velo_norm',
               'depth_av_vorticity', 'depth_av_power_density',
               'depth_av_power_assessment', 'tauc']
        al3D = ['w', 'u', 'v', 'gls', 'tke', 'flow_dir', 'velo_norm',
                 'verti_shear', 'vorticity', 'power_density']

        # Figure out which quantity to treat
        self._kwl2D = []
        self._al2D = []
        for key, aliaS in zip(kwl2D, al2D):
            if key in data.variables.keys():
                self._kwl2D.append(key)
                self._al2D.append(aliaS)
            else:
                if debug: print key, " is missing !"

        self._kwl3D = []
        self._al3D = []
        for key, aliaS in zip(kwl3D, al3D):
            if key in data.variables.keys():
                self._kwl3D.append(key)
                self._al3D.append(aliaS)
            else:
                if debug: print key, " is missing !"

        if not len(self._kwl3D)==0: self._3D = True

        #Loading time stamps
        try:
            self.julianTime = data.variables['time']
        except KeyError: #exeception due to Save_as(netcdf)
            self.julianTime = data.variables['julianTime']      
        if tx==[]:
            # get time and adjust it to matlab datenum
            try:
                self.julianTime = data.variables['time'].data
            except (KeyError, AttributeError) as e:
                #exeception due to Save_as(netcdf)
                if e==KeyError: self.julianTime=data.variables['julianTime']
                #exception for nc.dataset type data
                if e==AttributeError: self.julianTime = data.variables['time'][:]
            self.matlabTime = self.julianTime[:] + 678942.0
            #-Append message to History field
            start = mattime_to_datetime(self.matlabTime[0])
            end = mattime_to_datetime(self.matlabTime[-1])
            text = 'Full temporal domain from ' + str(start) +\
                   ' to ' + str(end)
            self._History.append(text)
            #Add time dimension to grid variables
            grid.ntime = self.julianTime.shape[0]
            if debug: print 'Full temporal domain'
        else:
            #Time period           
            region_t = self._t_region(tx, debug=debug)
            self._region_time = region_t
            ts = self._region_time[0]
            te = self._region_time[-1] + 1
            # get time and adjust it to matlab datenum
            self.julianTime = data.variables['time'][ts:te]
            self.matlabTime = self.julianTime + 678942.0
            #-Append message to History field
            start = mattime_to_datetime(self.matlabTime[0])
            end = mattime_to_datetime(self.matlabTime[-1])
            text = 'Temporal domain from ' + str(start) +\
                   ' to ' + str(end)
            self._History.append(text)
            #Add time dimension to grid variables
            grid.ntime = self.julianTime.shape[0]
            if debug: print "ntime: ", grid.ntime
            if debug: print "region_t shape: ", region_t.shape

        # Define which loading function to use
        if grid._ax==[] and tx==[]:
            loadVar = self._load_full_time_full_region
            for key, aliaS in zip(self._kwl2D, self._al2D):
                loadVar(data, key, aliaS, debug=debug)
            for key, aliaS in zip(self._kwl3D, self._al3D):
                loadVar(data, key, aliaS, debug=debug)
        else:

            if grid._ax!=[] and tx!=[]:
                loadVar = self._load_partial_time_partial_region
            elif grid._ax==[] and tx!=[]:
                loadVar = self._load_partial_time_full_region
            else:
                loadVar = self._load_full_time_partial_region

            # Loading 2D variables
            for key, aliaS in zip(self._kwl2D, self._al2D):
                loadVar(data, grid, key, aliaS, debug=debug)

            # Loading 3D variables
            for key, aliaS in zip(self._kwl3D, self._al3D):
                loadVar(data, grid, key, aliaS, debug=debug)

            ##-------Parallelized loading block-------
            # if debug: startT = time.time()
            #
            # divisor = len(self._kwl2D)//self._cpus
            # remainder = len(self._kwl2D)%self._cpus
            #
            # if debug: print "Parallel loading 2D vars..."
            # if debug: start2D = time.time()
            #
            # for i in range(divisor):
            #     start = self._cpus * i
            #     end = start + (self._cpus-1)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl2D[start:end], self._al2D[start:end])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # # Remaining vars
            # if remainder != 0:
            #     start = int(-1 * remainder)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl2D[start:], self._al2D[start:])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # if debug: end2D = time.time()
            # if debug: print "...processing time: ", (end2D - start2D)
            #
            # if debug: print "Parallel loading 3D vars..."
            # if debug: start3D = time.time()
            #
            # for i in range(divisor):
            #     start = self._cpus * i
            #     end = start + (self._cpus-1)
            #     processes = [mp.Process(target=loadVar, args=(data, grid,key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl3D[start:end], self._al3D[start:end])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # # Remaining vars
            # if remainder != 0:
            #     start = int(-1 * remainder)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl3D[start:], self._al3D[start:])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # if debug: end3D = time.time()
            # if debug: endT = time.time()
            # if debug: print "...-loading 3D- processing time: ", (end3D - start3D)
            # if debug: print "...-loading 2D & 3D- processing time: ", (endT - startT)
            # #-------end-------

        if debug: print '...Passed'
        return
示例#11
0
    def __init__(self, data, grid, tx, History, debug=False):
        self._debug = debug
        self._3D = False
        self._opendap = type(data.variables).__name__ == 'DatasetType'

        # Pointer to History
        setattr(self, '_History', History)

        # Parallel computing attributs
        #self._cpus = mp.cpu_count()

        #List of keywords
        kwl2D = [
            'ua', 'va', 'zeta', 'depth_av_flow_dir', 'hori_velo_norm',
            'depth_av_vorticity', 'depth_av_power_density',
            'depth_av_power_assessment', 'tauc'
        ]
        kwl3D = [
            'ww', 'u', 'v', 'gls', 'tke', 'flow_dir', 'velo_norm',
            'verti_shear', 'vorticity', 'power_density'
        ]
        #List of aliaSes
        al2D = [
            'ua', 'va', 'el', 'depth_av_flow_dir', 'hori_velo_norm',
            'depth_av_vorticity', 'depth_av_power_density',
            'depth_av_power_assessment', 'tauc'
        ]
        al3D = [
            'w', 'u', 'v', 'gls', 'tke', 'flow_dir', 'velo_norm',
            'verti_shear', 'vorticity', 'power_density'
        ]

        # Figure out which quantity to treat
        self._kwl2D = []
        self._al2D = []
        for key, aliaS in zip(kwl2D, al2D):
            if key in data.variables.keys():
                self._kwl2D.append(key)
                self._al2D.append(aliaS)
            else:
                if debug: print key, " is missing !"

        self._kwl3D = []
        self._al3D = []
        for key, aliaS in zip(kwl3D, al3D):
            if key in data.variables.keys():
                self._kwl3D.append(key)
                self._al3D.append(aliaS)
            else:
                if debug: print key, " is missing !"

        if not len(self._kwl3D) == 0: self._3D = True

        #Loading time stamps
        try:
            self.julianTime = data.variables['time']
        except KeyError:  #exeception due to Save_as(netcdf)
            self.julianTime = data.variables['julianTime']
        if tx == []:
            # get time and adjust it to matlab datenum
            try:
                self.julianTime = data.variables['time'].data
            except (KeyError, AttributeError) as e:
                #exeception due to Save_as(netcdf)
                if e == KeyError:
                    self.julianTime = data.variables['julianTime']
                #exception for nc.dataset type data
                if e == AttributeError:
                    self.julianTime = data.variables['time'][:]
            self.matlabTime = self.julianTime[:] + 678942.0
            #-Append message to History field
            start = mattime_to_datetime(self.matlabTime[0])
            end = mattime_to_datetime(self.matlabTime[-1])
            text = 'Full temporal domain from ' + str(start) +\
                   ' to ' + str(end)
            self._History.append(text)
            #Add time dimension to grid variables
            grid.ntime = self.julianTime.shape[0]
            if debug: print 'Full temporal domain'
        else:
            #Time period
            region_t = self._t_region(tx, debug=debug)
            self._region_time = region_t
            ts = self._region_time[0]
            te = self._region_time[-1] + 1
            # get time and adjust it to matlab datenum
            self.julianTime = data.variables['time'][ts:te]
            self.matlabTime = self.julianTime + 678942.0
            #-Append message to History field
            start = mattime_to_datetime(self.matlabTime[0])
            end = mattime_to_datetime(self.matlabTime[-1])
            text = 'Temporal domain from ' + str(start) +\
                   ' to ' + str(end)
            self._History.append(text)
            #Add time dimension to grid variables
            grid.ntime = self.julianTime.shape[0]
            if debug: print "ntime: ", grid.ntime
            if debug: print "region_t shape: ", region_t.shape

        # Define which loading function to use
        if grid._ax == [] and tx == []:
            loadVar = self._load_full_time_full_region
            for key, aliaS in zip(self._kwl2D, self._al2D):
                loadVar(data, key, aliaS, debug=debug)
            for key, aliaS in zip(self._kwl3D, self._al3D):
                loadVar(data, key, aliaS, debug=debug)
        else:

            if grid._ax != [] and tx != []:
                loadVar = self._load_partial_time_partial_region
            elif grid._ax == [] and tx != []:
                loadVar = self._load_partial_time_full_region
            else:
                loadVar = self._load_full_time_partial_region

            # Loading 2D variables
            for key, aliaS in zip(self._kwl2D, self._al2D):
                loadVar(data, grid, key, aliaS, debug=debug)

            # Loading 3D variables
            for key, aliaS in zip(self._kwl3D, self._al3D):
                loadVar(data, grid, key, aliaS, debug=debug)

            ##-------Parallelized loading block-------
            # if debug: startT = time.time()
            #
            # divisor = len(self._kwl2D)//self._cpus
            # remainder = len(self._kwl2D)%self._cpus
            #
            # if debug: print "Parallel loading 2D vars..."
            # if debug: start2D = time.time()
            #
            # for i in range(divisor):
            #     start = self._cpus * i
            #     end = start + (self._cpus-1)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl2D[start:end], self._al2D[start:end])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # # Remaining vars
            # if remainder != 0:
            #     start = int(-1 * remainder)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl2D[start:], self._al2D[start:])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # if debug: end2D = time.time()
            # if debug: print "...processing time: ", (end2D - start2D)
            #
            # if debug: print "Parallel loading 3D vars..."
            # if debug: start3D = time.time()
            #
            # for i in range(divisor):
            #     start = self._cpus * i
            #     end = start + (self._cpus-1)
            #     processes = [mp.Process(target=loadVar, args=(data, grid,key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl3D[start:end], self._al3D[start:end])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # # Remaining vars
            # if remainder != 0:
            #     start = int(-1 * remainder)
            #     processes = [mp.Process(target=loadVar, args=(data, grid, key, aliaS, debug))\
            #                  for key, aliaS in zip(self._kwl3D[start:], self._al3D[start:])]
            #     # Run processes
            #     for p in processes:
            #         p.start()
            #     # Exit the completed processes
            #     for p in processes:
            #         p.join()
            #
            # if debug: end3D = time.time()
            # if debug: endT = time.time()
            # if debug: print "...-loading 3D- processing time: ", (end3D - start3D)
            # if debug: print "...-loading 2D & 3D- processing time: ", (endT - startT)
            # #-------end-------

        if debug: print '...Passed'
        return