In [1]:
pd.options.display.max_columns = 100
In [8]:
l1b = io.some_l1b()
In [9]:
Out[9]:
In [2]:
l1bdarkfnames = io.get_current_science_fnames('l1b', env='production')
In [3]:
len(l1bdarkfnames)
Out[3]:
In [4]:
def process_fname(fname):
l1b = io.L1BReader(fname)
d = dict(fname=fname)
if not hasattr(l1b, 'detector_dark'):
d['error'] = 'no dark'
return d
if l1b.dark_dn_s.ndim == 3:
dark = l1b.dark_dn_s[0]
else:
dark = l1b.dark_dn_s
if l1b.raw_dn_s.ndim == 3:
light = l1b.raw_dn_s[0]
else:
light = l1b.raw_dn_s
sub = light - dark
try:
spa_slice, spe_slice = io.find_scaling_window(sub)
except IndexError:
d['error'] = 'IndexError'
return d
window = sub[spa_slice, spe_slice]
d['mean'] = window.mean()
d['std'] = window.std()
d['nspa'] = window.shape[0]
d['nspe'] = window.shape[1]
return d
In [5]:
process_fname(l1bdarkfnames[100])
Out[5]:
In [6]:
namestats = pd.DataFrame([io.ScienceFilename(str(i)).as_series() for i in l1bdarkfnames])
In [7]:
from IPython.parallel import Client
c = Client()
In [8]:
dview = c.direct_view()
lview = c.load_balanced_view()
In [9]:
doing = namestats.sample(2000).basename
results = lview.map_async(process_fname, doing)
In [10]:
from iuvs.multitools import nb_progress_display
In [11]:
nb_progress_display(results, doing)
In [123]:
res = []
for result in results:
res.append(result)
In [125]:
res = pd.DataFrame(res)
In [130]:
merged = res.merge(namestats, left_on='fname', right_on='basename')
In [133]:
import seaborn as sns
In [134]:
sns.set_context('notebook')
In [136]:
merged.columns
Out[136]:
In [ ]:
len(res)
In [135]:
sns.stripplot(x='phase', y='mean'
In [88]:
l1b = io.L1BReader('/maven_iuvs/production/products/level1b/mvn_iuv_l1b_APP1-orbit00087-mode0002-fuv_20141014T141612_v02_r01.fits.gz')
In [89]:
l1b.detector_dark.shape
Out[89]:
In [91]:
l1b.detector_raw.ndim
Out[91]:
In [ ]:
In [16]:
def check_for_issues(p):
from iuvs import exceptions
d = {}
d['fname'] = p.name
try:
l1a = io.L1AReader(str(p))
except exceptions.DimensionsError:
d['dims'] = False
d['kind'] = l1a.img_header['BIN_TBL'][:3]
d['n_unique_spabins'] = l1a.n_unique_spabins
d['n_unique_spebins'] = l1a.n_unique_spebins
return d
In [17]:
check_for_issues(df.p[4])
Out[17]:
In [18]:
doing = df.p
results = lview.map_async(check_for_issues, doing)
In [19]:
from iuvs.multitools import nb_progress_display
results.ready()
Out[19]:
In [20]:
nb_progress_display(results, doing)
In [21]:
resultdf = pd.DataFrame(results.result)
In [22]:
for col in resultdf.columns:
if col == 'fname': continue
print(col)
print(resultdf[col].value_counts(dropna=False))
In [23]:
resultdf['phase'] = resultdf.fname.map(lambda x: io.ScienceFilename(x).phase)
In [24]:
subdf = resultdf[(resultdf.n_unique_spabins==2) | (resultdf.n_unique_spebins==2)]
In [40]:
subdf[subdf.kind=='LIN'].info()
In [271]:
def process_fname(fname):
from iuvs import exceptions
import numpy as np
l1a = io.L1AReader(fname)
d = dict(fname=fname)
try:
l1a = io.L1AReader(fname)
except exceptions.DimensionsError:
d['error'] = 'dims'
return d
if l1a.img_header['BIN_TBL'].startswith('NON LINEAR'):
d['error'] = 'nonlinear'
return d
if any([l1a.n_unique_spabins>1, l1a.n_unique_spebins>1]):
d['error'] = 'badbins'
return d
main_header = io.get_header_df(l1a.hdulist[0])
integration = l1a.Integration
if main_header.loc[0, 'NAXIS'] == 2:
main_header.loc[0, 'NAXIS3'] = np.nan
avgtuple = None
elif main_header.loc[0, 'NAXIS'] == 3:
avgtuple = (1,2)
else:
d['error'] = 'axes'
return d
try:
integration['mean'] = l1a.primary_img_dn_s.mean(axis=avgtuple)
integration['median'] = np.median(l1a.primary_img_dn_s, axis=avgtuple)
integration['std'] = l1a.primary_img_dn_s.std(axis=avgtuple)
except KeyError:
integration['mean'] = np.nan
integration['median'] = np.nan
integration['std'] = np.nan
lenint = len(integration)
if lenint > 1:
main_header = main_header.append([main_header]*(lenint-1), ignore_index=True)
joined = pd.concat([integration, main_header], axis=1)
for col in l1a.Observation.names[:-3]:
val = l1a.Observation[col][0]
if col == 'COLLECTION_ID':
val = val[0]
joined[col] = val
savepath = io.save_to_hdf(joined.sort_index(axis=1), fname, 'l1a_dark_scans')
d['success'] = True
return d
# return joined, 0
In [272]:
process_fname(l1adarkfnames[2000])
Out[272]:
In [273]:
doing = l1adarkfnames
results = lview.map_async(process_fname, doing)
In [274]:
nb_progress_display(results, doing)
In [281]:
results_df = pd.DataFrame(results.result)
In [61]:
results_df.info()
In [62]:
results_df.loc[results_df.ANC_SVN_REVISION == '', 'ANC_SVN_REVISION'] = 0
In [63]:
results_df = results_df.convert_objects(convert_numeric=True)
In [64]:
results_df.to_hdf('/home/klay6683/output/l1a_dark_scans/results_df.h5', 'df')
In [277]:
import glob
h5fnames = glob.glob("/home/klay6683/output/l1a_dark_scans/*.h5")
In [278]:
len(h5fnames)
Out[278]:
In [279]:
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
In [280]:
dfs = []
for i,chunk in enumerate(chunker(h5fnames, 200)):
print("Chunk {}".format(i))
frames = []
for fname in chunk:
frames.append(pd.read_hdf(fname, 'df'))
dfs.append(pd.concat(frames, ignore_index=True))
In [282]:
superdf = pd.concat(dfs, ignore_index=True)
In [283]:
superdf.info()
In [284]:
from iuvs import calib
In [285]:
superdf.DET_TEMP = superdf.DET_TEMP.map(calib.convert_det_temp_to_C)
superdf.CASE_TEMP = superdf.CASE_TEMP.map(calib.convert_case_temp_to_C)
In [286]:
superdf.to_hdf('/home/klay6683/to_keep/l1a_dark_scan.h5','df')
In [287]:
from iuvs import meta
In [ ]: