df = df[df.BIN_PATTERN_INDEX == 'LINEAR linear_0006']
# now can drop that column
df = df.drop('BIN_PATTERN_INDEX', axis=1)

bin_tables = df.BIN_TBL.value_counts()
bin_tables

for ind in bin_tables.index:
    print(ind)
    print(df[df.BIN_TBL==ind].orbit_segment.value_counts())

"""
Explanation: Will be focusing on LINEAR linear_0006 for now, until I better understand how they compare.
End of explanation
"""


df = df[df.BIN_TBL=='LINEAR 7,8 linear_0006']
df = df.drop('BIN_TBL', axis=1)

df.orbit_segment.value_counts()

df.index

df.columns

df.CHANNEL.value_counts()

df.INT_TIME.value_counts()

df.BINNING_SET.value_counts()

df.NAXIS1.value_counts()

df.NAXIS2.value_counts()

to_drop = []
for col in df.columns:
    length = len(df[col].value_counts())
    if length == 1:
        to_drop.append(col)
df = df.drop(to_drop, axis=1)

df.columns

from iuvs import calib

df.DET_TEMP = df.DET_TEMP.map(calib.convert_det_temp_to_C) +273.15

df.CASE_TEMP = df.CASE_TEMP.map(calib.convert_case_temp_to_C) + 273.15

%matplotlib nbagg
import seaborn as sns
sns.set_context('talk')

from sklearn.preprocessing import normalize

df.index

df = df.reset_index()


df.set_index('TIME_OF_INT', inplace=True)

df['normalized_mean'] = normalize(df['mean']).T

df[['mean']].plot(style='*')

df.plot(kind='scatter', x='CASE_TEMP', y='mean')

df.plot(kind='scatter',x='DET_TEMP', y='CASE_TEMP')

df.plot(kind='scatter', x='SOLAR_LONGITUDE',y='mean')

df.plot(kind='scatter', x='SOLAR_LONGITUDE', y='DET_TEMP')

from sklearn import linear_model, decomposition, datasets

pca = decomposition.RandomizedPCA()

df.columns

Xcols = 'case_temp det_temp fov_deg lya_centroid mirror_deg mirror_dn mir_deg solar_longitude'.upper().split()
Xcols += ['mean']
Xcols

pca.fit(df[Xcols].values)

plt.close('all')

plt.figure(1, figsize=(4, 3))
plt.clf()
plt.axes([.2, .2, .7, .7])
plt.semilogy(pca.explained_variance_, linewidth=2)
plt.axis('tight')
plt.xlabel('n_components')
plt.ylabel('explained_variance_')

"""
Explanation: Focusing on one of the periapse tables for now:
End of explanation
"""


