Esempio n. 1
0
    def get_time_indices(self,trange):
        """
        Find the time indices
        """

        if not self.multifile:
            self.time = gettime(self._nc,self.timecoord)

        else:
            if self.MF==None:
                self.MF = MFncdap(self._ncfiles,timevar=self.timecoord)

            self.time = self.MF.time

        # Time
        if trange==None:
            self.t1=0
            self.t2 = self.time.shape[0]
        else:
            self.t1 = othertime.findNearest(trange[0],self.time)
            self.t2 = othertime.findNearest(trange[1],self.time)

        if self.t1==self.t2:
            self.t2+=1

        self.nt = self.t2 - self.t1

        print trange
Esempio n. 2
0
    def get_time_indices(self,trange):
        """
        Find the time indices
        """

        if not self.multifile:
            self.time = gettime(self._nc,self.timecoord)

        else:
            if self.MF==None:
                self.MF = MFncdap(self._ncfiles,timevar=self.timecoord)

            self.time = self.MF.time

        # Time
        if trange==None:
            self.t1=0
            self.t2 = self.time.shape[0]
        else:
            self.t1 = othertime.findNearest(trange[0],self.time)
            self.t2 = othertime.findNearest(trange[1],self.time)

        if self.t1==self.t2:
            self.t2+=1

        self.nt = self.t2 - self.t1

        print(trange)
Esempio n. 3
0
    def __init__(self,tmod,ymod,tobs,yobs, interpmodel=True, **kwargs):
        """
        Inputs:
            tmod,tobs - vector of datetime object
            ymod,yobs - vector of values
            interpmodel - [default: True] interp the model onto the observations

        Keywords:
            long_name: string containing variable's name (used for plotting)
            units: string containing variable's units (used for plotting)

        Note that tmod and tobs don't need to be the same length. yobs is
        linearly interpolated onto tmod.
        """
        self.__dict__.update(**kwargs)


        # Set the range inclusive of both observation and model result
        if isinstance(tmod,list):
            time0 = max(tmod[0],tobs[0])
            time1 = min(tmod[-1],tobs[-1])
        elif isinstance(tmod[0], np.datetime64):
            time0 = max(tmod[0],tobs[0])
            time1 = min(tmod[-1],tobs[-1])

        if time1 < time0:
            print 'Error - the two datasets have no overlapping period.'
            return None
        
        # Clip both the model and observation to this daterange
        t0m = othertime.findNearest(time0,tmod)
        t1m = othertime.findNearest(time1,tmod)
        TSmod = timeseries(tmod[t0m:t1m],ymod[...,t0m:t1m], **kwargs)

        t0 = othertime.findNearest(time0,tobs)
        t1 = othertime.findNearest(time1,tobs)
        TSobs = timeseries(tobs[t0:t1],yobs[...,t0:t1], **kwargs)

        # Interpolate the observed value onto the model step
        #tobs_i, yobs_i = TSobs.interp(tmod[t0:t1],axis=0)
        #self.TSobs = timeseries(tobs_i, yobs_i)

        # Interpolate the modeled value onto the observation time step
        if interpmodel:
            tmod_i, ymod_i = TSmod.interp(tobs[t0:t1],axis=-1,method='nearestmask')
            #self.TSmod = timeseries(tmod_i,ymod_i, **kwargs)
            self.TSmod = timeseries(tobs[t0:t1], ymod_i, **kwargs)
            self.TSobs = TSobs
        else:
            tobs_i, yobs_i = TSobs.interp(tmod[t0m:t1m],axis=-1,method='nearestmask')
            #self.TSobs = timeseries(tobs_i,yobs_i, **kwargs)
            self.TSobs = timeseries(tmod[t0m:t1m], yobs_i, **kwargs)
            self.TSmod = TSmod


        self.N = self.TSmod.t.shape[0]
        if self.N==0:
            print 'Error - zero model points detected'
            return None

        # Compute the error 
        self.error = self.TSmod.y - self.TSobs.y

        self.calcStats()

        # Calculate the data limits
        self._calc_data_lims()
Esempio n. 4
0
    def __init__(self, tmod, ymod, tobs, yobs, interpmodel=True, **kwargs):
        """
        Inputs:
            tmod,tobs - vector of datetime object
            ymod,yobs - vector of values
            interpmodel - [default: True] interp the model onto the observations

        Keywords:
            long_name: string containing variable's name (used for plotting)
            units: string containing variable's units (used for plotting)

        Note that tmod and tobs don't need to be the same length. yobs is
        linearly interpolated onto tmod.
        """
        self.__dict__.update(**kwargs)

        # Set the range inclusive of both observation and model result
        #if isinstance(tmod,list):
        #    time0 = max(tmod[0],tobs[0])
        #    time1 = min(tmod[-1],tobs[-1])
        #elif isinstance(tmod[0], np.datetime64):
        #    time0 = max(tmod[0],tobs[0])
        #    time1 = min(tmod[-1],tobs[-1])
        time0 = max(tmod[0], tobs[0])
        time1 = min(tmod[-1], tobs[-1])

        if time1 < time0:
            print('Error - the two datasets have no overlapping period.')
            return None

        if not (tmod.shape[0] == tobs.shape[0]) and\
                not (tmod[0] == tobs[0]) and not (tmod[-1] == tobs[-1]) :
            # Clip both the model and observation to this daterange
            t0m = othertime.findNearest(time0, tmod)
            t1m = othertime.findNearest(time1, tmod)
            TSmod = timeseries(tmod[t0m:t1m], ymod[..., t0m:t1m], **kwargs)

            t0 = othertime.findNearest(time0, tobs)
            t1 = othertime.findNearest(time1, tobs)
            TSobs = timeseries(tobs[t0:t1], yobs[..., t0:t1], **kwargs)

            # Interpolate the observed value onto the model step
            #tobs_i, yobs_i = TSobs.interp(tmod[t0:t1],axis=0)
            #self.TSobs = timeseries(tobs_i, yobs_i)

            ## Don't interpolate if datasets are the same
            #if np.all(tobs==tmod):
            #   self.TSobs = TSobs
            #   self.TSmod = TSmod
            # Interpolate the modeled value onto the observation time step
            if interpmodel:
                tmod_i, ymod_i = TSmod.interp(tobs[t0:t1],
                                              axis=-1,
                                              method='nearestmask')
                #self.TSmod = timeseries(tmod_i,ymod_i, **kwargs)
                self.TSmod = timeseries(tobs[t0:t1], ymod_i, **kwargs)
                self.TSobs = TSobs
            else:
                tobs_i, yobs_i = TSobs.interp(tmod[t0m:t1m],
                                              axis=-1,
                                              method='nearestmask')
                #self.TSobs = timeseries(tobs_i,yobs_i, **kwargs)
                self.TSobs = timeseries(tmod[t0m:t1m], yobs_i, **kwargs)
                self.TSmod = TSmod
        else:

            self.TSmod = timeseries(tmod, ymod, **kwargs)
            self.TSobs = timeseries(tobs, yobs, **kwargs)

        ### Check the dimension sizes
        #print self.TSmod.y.shape, self.TSobs.y.shape
        #print self.TSmod.t.shape[0], self.TSobs.t.shape[0]
        assert self.TSmod.t.shape[0] == self.TSobs.t.shape[0],\
                'Number of time records not equal'

        assert self.TSmod.y.shape == self.TSobs.y.shape,\
                'Dimensions sizes not equal'

        self.N = self.TSmod.t.shape[0]
        if self.N == 0:
            print('Error - zero model points detected')
            return None

        # Compute the error
        self.error = self.TSmod.y - self.TSobs.y

        self.calcStats()

        # Calculate the data limits
        self._calc_data_lims()