Exemplo n.º 1
0
 def subset(self,time1,time2):
     """
     Returns a subset of the array between time1 and time2
     """
     t0 = othertime.findNearest(time1,self.t)
     t1 = othertime.findNearest(time2,self.t)
     return self.t[t0:t1],self.y[...,t0:t1]
Exemplo n.º 2
0
 def subset(self, time1, time2):
     """
     Returns a subset of the array between time1 and time2
     """
     t0 = othertime.findNearest(time1, self.t)
     t1 = othertime.findNearest(time2, self.t)
     return self.t[t0:t1], self.y[..., t0:t1]
Exemplo n.º 3
0
def window_index_time_slow(t,windowsize,overlap):
    """
    Determines the indices for window start and end points of a time vector
    
    The window does not need to be evenly spaced
    
    Inputs:
        t - list or array of datetime objects
        windowsize - length of the window [seconds]
        overlap - number of overlap points [seconds]
        
    Returns: pt1,pt2 the start and end indices of each window
    """
    
    try:
        t=t.tolist()
    except:
        t=t
        
    t1=t[0]
    t2=t1 + timedelta(seconds=windowsize)
    pt1=[0]
    pt2=[othertime.findNearest(t2,t)]
    while t2 < t[-1]:
        t1 = t2 - timedelta(seconds=overlap)
        t2 = t1 + timedelta(seconds=windowsize)

        pt1.append(othertime.findNearest(t1,t))
        pt2.append(othertime.findNearest(t2,t))
        
    return pt1, pt2
Exemplo n.º 4
0
def window_index_time_slow(t, windowsize, overlap):
    """
    Determines the indices for window start and end points of a time vector
    
    The window does not need to be evenly spaced
    
    Inputs:
        t - list or array of datetime objects
        windowsize - length of the window [seconds]
        overlap - number of overlap points [seconds]
        
    Returns: pt1,pt2 the start and end indices of each window
    """

    try:
        t = t.tolist()
    except:
        t = t

    t1 = t[0]
    t2 = t1 + timedelta(seconds=windowsize)
    pt1 = [0]
    pt2 = [othertime.findNearest(t2, t)]
    while t2 < t[-1]:
        t1 = t2 - timedelta(seconds=overlap)
        t2 = t1 + timedelta(seconds=windowsize)

        pt1.append(othertime.findNearest(t1, t))
        pt2.append(othertime.findNearest(t2, t))

    return pt1, pt2
Exemplo n.º 5
0
 def subset(self,time1,time2):
     """
     Returns a subset of the array between time1 and time2
     """
     try:
         t0 = othertime.findNearest(time1,self.t)
         t1 = othertime.findNearest(time2,self.t)
     except:
         t0 = np.searchsorted(self.t, np.datetime64(time1))
         t1 = np.searchsorted(self.t, np.datetime64(time2))
         
     return self.t[t0:t1],self.y[...,t0:t1]
Exemplo n.º 6
0
    def __init__(self,tmod,ymod,tobs,yobs,**kwargs):
        """
        Inputs:
            tmod,tobs - vector of datetime object
            ymod,yobs - vector of values

        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
        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

        t0 = othertime.findNearest(time0,tmod)
        t1 = othertime.findNearest(time1,tmod)
        TSmod = timeseries(tmod[t0:t1],ymod[...,t0:t1])

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

        # 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
        tmod_i, ymod_i = TSmod.interp(tobs[t0:t1],axis=-1)
        self.TSmod = timeseries(tmod_i,ymod_i)

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

        self.calcStats()

        # Calculate the data limits
        self.calc_data_lims()
Exemplo n.º 7
0
    def __init__(self, tmod, ymod, tobs, yobs, **kwargs):
        """
        Inputs:
            tmod,tobs - vector of datetime object
            ymod,yobs - vector of values

        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
        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

        t0 = othertime.findNearest(time0, tmod)
        t1 = othertime.findNearest(time1, tmod)
        TSmod = timeseries(tmod[t0:t1], ymod[..., t0:t1])

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

        # 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
        tmod_i, ymod_i = TSmod.interp(tobs[t0:t1], axis=-1)
        self.TSmod = timeseries(tmod_i, ymod_i)

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

        self.calcStats()
Exemplo n.º 8
0
    def get_tslice(self,time1,time2):
        """
        Returns the time indices bounded by time1 and time2
        """
        try:
            t0 = othertime.findNearest(time1,self.t)
            t1 = othertime.findNearest(time2,self.t)
        except:
            t0 = np.searchsorted(self.t, np.datetime64(time1))
            t1 = np.searchsorted(self.t, np.datetime64(time2))

        #t1 = min( self.Nt, t1+1)
	t1+=1
	if t1 > self.Nt:
	    t1=self.Nt
	#t0-=1
	#if t0<0:
	#    t0 = 0

        return t0, t1
Exemplo n.º 9
0
    def get_time_indices(self, trange):
        """
        Find the time indices
        """

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

        else:
            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
Exemplo n.º 10
0
    def get_time_indices(self,trange):
        """
        Find the time indices
        """

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

        else:
            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