def section(): lon, lat = [], [] fnames = sorted(data_path.glob('CTD/g01mcan*c.cnv.gz')) section = OrderedDict() for fname in fnames: cast = proc_ctd(fname) name = Path(fname).stem section.update({name: cast}) lon.append(cast['longitude'].mean()) lat.append(cast['latitude'].mean()) # Section. section = Panel.fromDict(section) return {'section': section, 'lon': lon, 'lat': lat}
def proc_ctd(fname): """ CTD processing. """ cast = DataFrame.from_cnv(fname, below_water=True).split()[0] cast = cast[cast['pumps']] cast = cast[~cast['flag']] name = Path(fname).stem # Removed unwanted columns. keep = {'t090C', 't190C', 'longitude', 'latitude'} drop = keep.symmetric_difference(cast.columns) cast.drop(drop, axis=1, inplace=True) cast = cast.apply(Series.bindata, **{'delta': 1.}) cast = cast.apply(Series.interpolate) cast.name = name return cast
from ctd import DataFrame, Series from ctd.utilities import Path import matplotlib import matplotlib.pyplot as plt import numpy as np from pandas import Panel import pytest matplotlib.use('Agg', warn=True) data_path = Path(__file__).parent.joinpath('data') def assert_is_valid_plot_return_object(objs): if isinstance(objs, np.ndarray): for el in objs.flat: assert isinstance(el, plt.Axes), ('one of \'objs\' is not a ' 'matplotlib Axes instance, ' 'type encountered {0!r}' ''.format(el.__class__.__name__)) else: assert isinstance(objs, (plt.Artist, tuple, dict)), ( 'objs is neither an ndarray of Artist instances nor a ' 'single Artist instance, tuple, or dict, "objs" is a {0!r} ' ''.format(objs.__class__.__name__))
def proc_ctd(fname, below_water=True): """ Quick `proc_ctd` function. """ # 00-Split, clean 'bad pump' data, and apply flag. cast = DataFrame.from_cnv( fname, below_water=below_water ).split()[0] name = Path(fname).stem cast = cast[cast['pumps']] cast = cast[~cast['flag']] # True for bad values. # Smooth velocity with a 2 seconds windows. cast['dz/dtM'] = movingaverage(cast['dz/dtM'], window_size=48) # 01-Filter pressure. kw = { 'sample_rate': 24.0, 'time_constant': 0.15 } cast.index = lp_filter(cast.index, **kw) # 02-Remove pressure reversals. cast = cast.press_check() cast = cast.dropna() # 03-Loop Edit. cast = cast[cast['dz/dtM'] >= 0.25] # Threshold velocity. # 04-Remove spikes. kw = { 'n1': 2, 'n2': 20, 'block': 100 } cast = cast.apply(Series.despike, **kw) # 05-Bin-average. cast = cast.apply(Series.bindata, **{'delta': 1.}) # 06-interpolate. cast = cast.apply(Series.interpolate) if False: # 07-Smooth. pmax = max(cast.index) if pmax >= 500.: window_len = 21 elif pmax >= 100.: window_len = 11 else: window_len = 5 kw = { 'window_len': window_len, 'window': 'hanning' } cast = cast.apply(Series.smooth, **kw) # 08-Derive. cast.lat = cast['latitude'].mean() cast.lon = cast['longitude'].mean() cast = derive_cnv(cast) cast.name = name return cast