In [1]:
    
%matplotlib inline
    
In [1]:
    
from iuvs import meta
    
    
In [2]:
    
from pathlib import Path
# root = Path('/home/klay6683/to_keep')
root = Path('/Users/klay6683/data/iuvs')
# df = pd.read_hdf('/home/klay6683/to_keep/l1a_dark_scan.h5', 'df')
df = pd.read_hdf(str(root / 'l1a_dark_scan.h5'), 'df')
    
In [3]:
    
df = meta.clean_up_dark_scan(df)
    
In [4]:
    
def check_values(col):
    return df[col.upper()].value_counts(dropna=False)
    
In [5]:
    
df = df[df.COLLECTION_ID!='cruise']
df = df[df.COLLECTION_ID!='transition']
df = df[df.INT_TIME.isin([14400, 4200, 1400])]
    
In [6]:
    
from iuvs import hk
hkdb = pd.read_hdf(str(root / 'HK_DB.h5'), 'df')
    
In [7]:
    
timeres = '1s'
    
In [8]:
    
newind = pd.DatetimeIndex(start=hkdb.index[0].replace(microsecond=0),
                 end=hkdb.index[-1], freq='1s')
    
In [9]:
    
snew=pd.Series(1, newind)
sold = pd.Series(2, hkdb.index)
smerged=pd.concat([snew,sold])
smerged = smerged.sort_index()
reindexed = hkdb.reindex(smerged.index)
reindexed.head()
    
    Out[9]:
In [10]:
    
hkfuvtemp = reindexed.FUV_DET_TEMP_C.interpolate(method='time')
hkmuvtemp = reindexed.MUV_DET_TEMP_C.interpolate(method='time')
    
In [11]:
    
hkfuvtemp.tail()
    
    Out[11]:
In [12]:
    
g = df.groupby(['CHANNEL', 'INT_TIME', 'activity', 'BINNING_SET'])
    
In [13]:
    
size = g.size()
    
In [14]:
    
i = size[size>4000].index
    
In [15]:
    
i.get_level_values('BINNING_SET')
    
    Out[15]:
In [16]:
    
size[size>4000]
    
    Out[16]:
In [31]:
    
%matplotlib inline
    
In [32]:
    
for key, content in g:
    resampled = content.resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    title = '_'.join([str(i) for i in key])
    print(title)
    fig, ax = plt.subplots(nrows=2)
    resampled.plot(kind='scatter', x='DET_TEMP', y='mean', ax=ax[0],
                 xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs DET_TEMP')
    resampled.plot(kind='scatter', x='HK_TEMP', y='mean', ax=ax[1],
                 xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs HK_TEMP')
    fig.tight_layout()
    fig.savefig('plots/'+title+'.png', dpi=150)
    plt.close(fig)
    
    
In [64]:
    
for key, content in g:
    resampled = content.resample(timeres).dropna(how='all')
    selector = (df.CHANNEL == key[0]) & (df.INT_TIME==key[1]) & (df.activity==key[2])
    subdf = df[selector]
    subdf = subdf.resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hktemps.FUV_DET_TEMP_C
        subdf['HK_TEMP'] = hktemps.FUV_DET_TEMP_C
    else:
        resampled['HK_TEMP'] = hktemps.MUV_DET_TEMP_C
        subdf['HK_TEMP'] = hktemps.MUV_DET_TEMP_C
    title = '_'.join([str(i) for i in key])
    lesser_title = '_'.join([str(i) for i in key[:-1]])
    print(title)
    fig, ax = plt.subplots(nrows=2)
    subdf.plot(kind='scatter', x='HK_TEMP', y='mean', ax=ax[0],
                 xlim=(-25, -11), ylim=(0.1, 1.5), title=lesser_title+' all BINNING SETS')
    resampled.plot(kind='scatter', x='HK_TEMP', y='mean', ax=ax[1],
                 xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' ')
    fig.tight_layout()
    fig.savefig('plots/'+title+'_vs_all_bins_'+'.png', dpi=150)
    plt.close(fig)
    
    
In [51]:
    
%matplotlib nbagg
    
In [40]:
    
from scipy.interpolate import UnivariateSpline as Spline
    
In [41]:
    
Spline?
    
In [68]:
    
for key, content in g:
    if key != ('MUV', 14400, 'apoapse', (2, 34, 101, 80)):
        continue
    print(key)
    resampled = content[['mean']].resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    both_there = resampled['HK_TEMP'].notnull() & (resampled['mean'].notnull())
    y = resampled[both_there]['mean']
    x = resampled[both_there]['HK_TEMP']
    print(len(x), len(y))
    spline = UnivariateSpline(x.values, y.values)
    xs = np.linspace(-23, -12, 1000)
    ys = spline(xs)
    
    plt.figure()
    plt.scatter(x, y)
    plt.plot(xs, ys, color='green', lw=2)
    title = '_'.join([str(i) for i in key])
    plt.title(title)
    plt.xlim(-24, -10)
    plt.ylim(0.2, 0.55)
    plt.xlabel('HK_TEMP')
    plt.ylabel('dark mean')
#     print(title)
#     fig, ax = plt.subplots(nrows=2)
#     resampled.plot(kind='scatter', x='DET_TEMP', y='mean', ax=ax[0],
#                  xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs DET_TEMP')
#     resampled.plot(kind='scatter', x='HK_TEMP', y='mean', ax=ax[1],
#                  xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs HK_TEMP')
#     fig.tight_layout()
#     fig.savefig('plots/'+title+'.png', dpi=150)
#     plt.close(fig)
    
    
    
    
In [69]:
    
for key, content in g:
    if key != ('MUV', 14400, 'apoapse', (140, 8, 101, 80)):
        continue
    print(key)
    resampled = content[['mean']].resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    y = resampled['mean'].dropna()
    x = resampled[resampled['mean'].notnull()]['HK_TEMP']
    plt.figure()
    plt.scatter(x, y)
    plt.plot(xs, ys, color='green', lw=2)
    print(len(x), len(y))
    title = '_'.join([str(i) for i in key])
    plt.title(title)
    plt.xlim(-24, -10)
    plt.ylim(0.2, 0.55)
    plt.xlabel('HK_TEMP')
    plt.ylabel('dark mean')
    
    
    
    
    
In [70]:
    
for key, content in g:
    if key != ('MUV', 14400, 'apoapse', (0, 4, 101, 80)):
        continue
    print(key)
    resampled = content[['mean']].resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    y = resampled['mean'].dropna()
    x = resampled[resampled['mean'].notnull()]['HK_TEMP']
    plt.figure()
    plt.scatter(x, y)
    plt.plot(xs, ys, color='green', lw=2)
    print(len(x), len(y))
    title = '_'.join([str(i) for i in key])
    plt.title(title)
    plt.xlim(-24, -10)
    plt.ylim(0.2, 0.55)
    plt.xlabel('HK_TEMP')
    plt.ylabel('dark mean')
    
    
    
    
    
In [83]:
    
from scipy.optimize import curve_fit
def func(x, a, b, c):
    return a * np.exp(b * x) + c
    
In [88]:
    
yexp = func(xs, 10, 1, 0.2)
    
In [89]:
    
plt.figure()
plt.plot(xs, yexp)
    
    
    
    Out[89]:
In [79]:
    
for key, content in g:
    if key != ('FUV', 14400, 'inbound', (52, 4, 89, 115)):
        continue
    print(key)
    resampled = content[['mean']].resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    both_there = resampled['HK_TEMP'].notnull() & (resampled['mean'].notnull())
    y = resampled[both_there]['mean']
    x = resampled[both_there]['HK_TEMP']
    print(len(x), len(y))
    spline = UnivariateSpline(x.values, y.values)
    xs = np.linspace(-23, -12, 1000)
    ys = spline(xs)
    popt, pcov = curve_fit(func, x, y)
    plt.figure()
    plt.scatter(x, y)
    plt.plot(xs, ys, color='green', lw=2)
    title = '_'.join([str(i) for i in key])
    plt.title(title)
    plt.xlim(-24, -10)
    plt.ylim(0.2, 0.55)
    plt.xlabel('HK_TEMP')
    plt.ylabel('dark mean')
    print(popt, pcov)
#     print(title)
#     fig, ax = plt.subplots(nrows=2)
#     resampled.plot(kind='scatter', x='DET_TEMP', y='mean', ax=ax[0],
#                  xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs DET_TEMP')
#     resampled.plot(kind='scatter', x='HK_TEMP', y='mean', ax=ax[1],
#                  xlim=(-25, -11), ylim=(0.1, 1.5), title=title+' vs HK_TEMP')
#     fig.tight_layout()
#     fig.savefig('plots/'+title+'.png', dpi=150)
#     plt.close(fig)
    
    
    
In [74]:
    
for key, content in g:
    if key != ('FUV', 14400, 'inbound', (52, 8, 89, 115)):
        continue
    print(key)
    resampled = content[['mean']].resample(timeres).dropna(how='all')
    if key[0]=='FUV':
        resampled['HK_TEMP'] = hkfuvtemp
    else:
        resampled['HK_TEMP'] = hkmuvtemp
    y = resampled['mean'].dropna()
    x = resampled[resampled['mean'].notnull()]['HK_TEMP']
    plt.figure()
    plt.scatter(x, y)
    plt.plot(xs, ys, color='green', lw=2)
    print(len(x), len(y))
    title = '_'.join([str(i) for i in key])
    plt.title(title)
    plt.xlim(-24, -10)
    plt.ylim(0.2, 0.55)
    plt.xlabel('HK_TEMP')
    plt.ylabel('dark mean')
    
    
    
    
    
In [31]:
    
type(x)
    
    Out[31]:
In [12]:
    
import seaborn as sns
sns.set_style('whitegrid')
sns.set_context('notebook')
    
    
In [57]:
    
g = sns.FacetGrid(df, row='INT_TIME', hue='CHANNEL', size=1.7, aspect=4,)
g.map(sns.distplot, 'mean')
    
    
    
    Out[57]:
In [187]:
    
g = sns.PairGrid(df, x_vars=['INT_TIME'], hue='CHANNEL',
                y_vars=['mean','std'], size=3.5)
g.map(sns.violinplot)
    
    
    
    
    Out[187]:
In [ ]:
    
    
In [33]:
    
df.sort_index(inplace=True)
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [80]:
    
df['mirdeg_delta'] = df.MIRROR_DEG - df.MIR_DEG
    
In [81]:
    
plt.figure()
df.mirdeg_delta.plot(style='.')
    
    
    
    Out[81]:
In [ ]: