In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
import pandas as pd
from iuvs import meta, io
In [3]:
l1b_metadata = meta.l1b_summary()
In [4]:
!head -n 28 {meta.stagel1bsummary}
In [5]:
cruisecals = l1b_metadata[l1b_metadata.filename.str.contains('cruisecal')]
In [6]:
cruisecals.columns
Out[6]:
In [8]:
%matplotlib inline
import matplotlib.pylab as plt
plt.rcParams['figure.figsize'] = (10,10)
In [9]:
from iuvs import plotting
In [10]:
import pickle
with open('two_or_more.pck', 'rb') as f:
two_or_more = pickle.load(f)
In [11]:
df = cruisecals[cruisecals.filename.isin(two_or_more)].copy()
df.head()
Out[11]:
In [12]:
from IPython.parallel import Client
c = Client()
In [13]:
lbview = c.load_balanced_view()
In [27]:
def do_dark_fit(dark_tuple):
from iuvs import scaling, io
fname1, fname2 = dark_tuple
darkin = io.L1AReader(str(io.stagelevel1apath / fname1)).img
darkout = io.L1AReader(str(io.stagelevel1apath / fname2)).img
scaler = scaling.PolyScaler(darkin, darkout)
scaler.do_fit()
return (fname1, scaler.p)
In [28]:
res = lbview.map_async(do_dark_fit, set(muv_dark_fnames))
In [26]:
for item in res:
print(item)
In [33]:
resultdf = pd.DataFrame()
for item in res:
p = item[1]
print(p[0])
resultdf.loc[item[0], 'n2coeffs'] = p[0]
resultdf.loc[item[0], 'n1coeffs'] = p[1]
resultdf.loc[item[0], 'n0coeffs'] = p[2]
In [35]:
resultdf = resultdf.reset_index()
In [41]:
resultdf.index = resultdf['index'].map(lambda x: io.Filename(x).time)
In [44]:
resultdf
Out[44]:
In [45]:
resultdf.sort_index(inplace=True)
In [46]:
resultdf
Out[46]:
In [89]:
fig, axes = plt.subplots(nrows=4)
for ax, coeff in zip(axes, resultdf.columns[1:]):
resultdf['20140402'][coeff].plot(ax=ax, legend=True)
resultdf['20140402'][['det_temp','case_temp']].plot(ax=axes[3], secondary_y=['case_temp'])
fig.suptitle("Unique MUV darks fitting parameters, temperature effect")
plt.savefig('temp_effect.png',dpi=150)
In [86]:
pwd
Out[86]:
In [82]:
resultdf
Out[82]:
In [73]:
def grep_temp(s):
return s[0]
In [76]:
resultdf.case_temp = resultdf.case_temp.map(grep_temp)
In [77]:
resultdf.det_temp = resultdf.det_temp.map(grep_temp)
In [60]:
det_temp = []
case_temp = []
for dark in set(muv_dark_fnames):
l1a = io.L1AReader(dark[0])
det_t0 = l1a.Engineering.loc['CASE_TEMP']
case_t0 = l1a.Engineering.loc['DET_TEMP']
# l1a = io.L1AReader(dark[1])
# det_t1 = l1a.Engineering.loc['CASE_TEMP']
# case_t1 = l1a.Engineering.loc['DET_TEMP']
det_temp.append(det_t0)
case_temp.append(case_t0)
In [61]:
resultdf['det_temp'] = det_temp
In [62]:
resultdf['case_temp'] = case_temp
In [ ]:
In [58]:
l1a.Engineering.loc['CASE_TEMP']
Out[58]:
In [14]:
df.drop('TARGET PURPOSE SHUT_STATE MODE'.split(), axis=1, inplace=True)
In [15]:
muv = df[df.XUV == 'MUV']
fuv = df[df.XUV == 'FUV']
In [17]:
muv_dark_fnames = []
for fname in muv.filename:
print(fname)
l1b = io.L1BReader(fname)
dark_tuple = []
for line in l1b.DarkIntegration_header['COMMENT']:
if not line.startswith('mvn_iuv'):
continue
dark_tuple.append(line)
muv_dark_fnames.append(tuple(dark_tuple))
# muv.loc[muv.filename == fname, 'darktime'] = io.Filename(muv_dark_fnames[-1]).time
In [23]:
set(muv_dark_fnames)
Out[23]:
In [22]:
muv_dark_fnames
Out[22]:
In [ ]:
In [ ]:
In [24]:
%pylab inline
In [27]:
plot n2coeffs
Out[27]:
In [28]:
plot n1coeffs
Out[28]:
In [29]:
plot n0coeffs
Out[29]:
In [108]:
df = pd.DataFrame.from_items(res).T
In [109]:
df = df.reset_index()
In [110]:
df.head()
Out[110]:
In [111]:
df.columns = ['filename', 'coeff_2','coeff_1','coeff_0']
In [112]:
df.head()
Out[112]:
In [113]:
def get_time(fname):
return io.Filename(fname).time
In [114]:
df['time'] = df.filename.map(get_time)
In [115]:
df.set_index('time', inplace=True)
In [116]:
df.iloc[:10]
Out[116]:
In [120]:
same_p_fnames = df.filename.iloc[:2].values
In [121]:
import os
In [122]:
os.path.isabs(same_p_fnames[0])
Out[122]:
In [ ]:
f1 = io.L1BReader(same_p_fnames[0]
In [106]:
t = '20140402 19'
muv[t1].plot('coeff_1', 'coeff_2', kind='scatter')
Out[106]:
In [87]:
muv = df[df.filename.str.contains('-muv_')]
fuv = df[df.filename.str.contains('-fuv_')]
In [93]:
rcParams['figure.figsize'] = (11,8)
In [104]:
t1 = '20140402'
fig, axes = subplots(nrows=3)
fig.suptitle('2014-04-02, MUV')
for ax,i in zip(axes, range(3)):
muv[t1]['coeff_'+str(i)].plot(ax=ax,style='*')
muv[t1]['coeff_'+str(i)].plot(ax=ax)
savefig('t1_muv.png', dpi=150)
In [101]:
t1 = '20140402'
fig, axes = subplots(nrows=3)
for ax,i in zip(axes, range(3)):
fuv[t1]['coeff_'+str(i)].plot(ax=ax)
fuv[t1]['coeff_'+str(i)].plot(ax=ax,style='*')
In [102]:
t2 = '20140521'
fig, axes = subplots(nrows=3)
fig
for ax,i in zip(axes, range(3)):
muv[t1]['coeff_'+str(i)].plot(ax=ax, style='*')
muv[t1]['coeff_'+str(i)].plot(ax=ax,)
In [97]:
t2 = '20140521'
fig, axes = subplots(nrows=3)
for ax,i in zip(axes, range(3)):
fuv[t1]['coeff_'+str(i)].plot(ax=ax, style='*')
In [ ]: