Exemple #1
0
    def timeseries(self, x, convert=None, rmnans=False, timeslice=None, **kw):
        """Extract simple timeseries.
        
        e.g.,   depth, t = slate.timeseries('depth')
                depthCmd, t = slate.timeseries('VerticalControl/depthCmd')
                etc.

        """
        x = x.replace('.','/')
        try: v = self[x]['value'][:].squeeze()
        except KeyError:
            raise KeyError('could not read value for {0}'.format(x))
#        if x.split('/')[-1] == 'platform_orientation':
#            v[v < 0] += 2*np.pi
        if convert: 
            v = convert(v)
        t = self[x]['time'][:].squeeze() - 366
        if timeslice:
            if type(timeslice[0]) is datetime.datetime: 
                timeslice[0] = matplotlib.dates.date2num(timeslice[0])
            if type(timeslice[1]) is datetime.datetime: 
                timeslice[1] = matplotlib.dates.date2num(timeslice[1])
            v = v[np.logical_and(t > timeslice[0], t < timeslice[1])]
            t = t[np.logical_and(t > timeslice[0], t < timeslice[1])]
        if rmnans:
            v, t = oalib.rmnans(v, t)
        return v, t
Exemple #2
0
 def map_trajectory(self, mapobject, *a, **kw):
     raise DeprecationWarning("use map_track instead")
     try:
         timeslice = kw.pop('timeslice')
         lats, t = self.timeseries('latitude', timeslice=timeslice)
         lons, t = self.timeseries('longitude', timeslice=timeslice)
     except KeyError:
         lats = self['latitude/value'][:]
         lons = self['longitude/value'][:]
     # remove NaNs, since some Proj & basemap tools have trouble w/ them
     junk, lats, lons = oalib.rmnans(lats + lons, lats, lons)
     if self.units('latitude') is 'radian':
         lats, lons = np.rad2deg(lats), np.rad2deg(lons)
     x, y = mapobject(lons, lats)
     mapobject.plot(x, y, *a, **kw)
Exemple #3
0
    def meters_trajectory(self, projection):
        """
        
        Monterey Bay in UTM:
            projection = pyproj.Proj(proj='utm', zone=10, ellps='WGS84')

        """
        g = np.hstack((self['longitude/value'][:],self['latitude/value'][:]))
        lat = self['latitude/value'][:]
        lon = self['longitude/value'][:]
        dep = self['depth/value'][:]
        junk, lat, lon, dep = oalib.rmnans(lat + lon, lat, lon, dep)
#        if self.units('latitude') is 'radian':
#            lats, lons = np.rad2deg(lats), np.rad2deg(lons)
        if self.units('latitude') is 'radian': radflag = True
        else: radflag = False
        easting, northing = projection(lon, lat, radians=radflag)
        return np.vstack((northing, easting, dep))
Exemple #4
0
 def contourf_time_section(self, x, dt=60, dz=1, dv=None, **kw):
     v, t = self.timeseries(x, rmnans=True, **kw)
     z = self.interpolate_timeseries('depth', t)
     z, v, t = oalib.rmnans(z, v, t)
     t = matplotlib.dates.date2num(t)
     zmin, zmax = np.floor(z.min()), np.ceil(z.max())
     tmin, tmax = np.floor(t.min()), np.ceil(t.max())
     tg, zg = np.mgrid[tmin:tmax:(dt/86400.0), zmin:zmax:dz]
     pts = np.vstack((t, z)).T
     vg = sp.interpolate.griddata(pts, v, (tg, zg), method='cubic')
     if 'axes' in kw:
         ax = kw.pop('axes')
         cs = ax.contourf(tg, zg, vg, **kw)
     else:
         cs = plt.contourf(tg, zg, vg, **kw)
         ax = plt.gca()
     ax.invert_yaxis()
     ax.xaxis_date()
     return cs, ax
Exemple #5
0
    def draw_track(self, lat, lon, *a, **kw):
        """Draw a position track on the map (e.g., from Tethys or Daphne).

        Parameters
        ----------
        lat : array-like
            Latitude, in decimal degrees.
        lon : array-like
            Longitude, in decimal degrees.

        Returns
        -------
        track : (matplotlib line)

        TODO Add optional kwargs to perform conversions on lat/lon?

        Any additional args or kwargs are passed to self.plot

        """
        # remove NaNs, since some Proj & basemap tools have trouble w/ them
        junk, lat, lon = lib.rmnans(lat + lon, lat, lon)
        x, y = self(lon, lat) # convert to map plotting coordinates
        self.plot(x, y, *a, **kw)
Exemple #6
0
            print x
            raise e
        if convert: 
            v = convert(v)
        t = oalib.matlab_datenum_to_python_datetime(self[x]['time'][:].ravel())
        if return_epoch: # XXX does this if really slow things down?
            t = oalib.python_datetime_to_unix_epoch(t)
        t = np.array(t)
        if timeslice:
            try:
                v = v[np.logical_and(t > timeslice[0], t < timeslice[1])]
                t = t[np.logical_and(t > timeslice[0], t < timeslice[1])]
            except Exception, e: 
                raise e # TODO catch common exceptions
        if rmnans:
            v, t = oalib.rmnans(v, t)
        if return_list:
            v, t = v.tolist(), t.tolist()
        return v, t


    def plot_timeseries(self, x, *a, **kw):
        """A convenience function for plotting time-series."""
        kw.update(return_epoch=False)
        v, t = self.timeseries(x, **kw)
        for k in ('return_epoch', 'convert', 'timeslice', 'rmnans'): 
            trash = kw.pop(k, None)
        if not a: a = '-' # plot a line by default
        if 'label' not in kw: 
            kw.update({'label': x.replace('platform ','').replace('_',' ')})
        if 'axes' in kw: # deal with possible bug in plot_date?