%matplotlib inline
from pylab import *
import ifg.shis.rdr.valid as val
from pyfbf import Workspace
import numpy as np
W = Workspace('scatter_test/rdr20170323T170847end20170323T233859sdr20170324T194155')
L = 47000
lms = ['lw', 'mw', 'sw']
pfx = 'calibrtn'
zlw, zmw, zsw = map(lambda x: W[pfx + x.upper()][:L], lms)
smp = W.sceneMirrorPosition[:L]
s,e = 0,L
cc = W["coolerCurrent"][s:e].ravel()
det = W["detectorTemp"][s:e].ravel()
abb = W["ABBapexTemp"][s:e].ravel()
hbb = W["HBBapexTemp"][s:e].ravel()
smp = W["sceneMirrorPosition"][s:e].ravel()
sd = W['scanDirection'][s:e].ravel()
goodcal = ((zlw == 1) & (zmw == 1) & (zsw == 1))
len(np.argwhere(goodcal==True).squeeze()), L
len(np.argwhere(goodcal[30000:40000]==True).squeeze())
len(np.argwhere(goodcal[20000:30000]==True).squeeze())
notgood = ((~goodcal) & (smp==ord('E')))
len(np.argwhere(notgood==True).squeeze()), L
figure(figsize=(20,10))
hist(np.argwhere(notgood==True).squeeze(), bins=48)
notgoodlw = ((zlw!=1) & (smp==ord('E')))
figure(figsize=(20,10))
hist(np.argwhere(notgoodlw==True).squeeze(), bins=48)
notgoodmw = ((zmw!=1) & (smp==ord('E')))
figure(figsize=(20,10))
hist(np.argwhere(notgoodmw==True).squeeze(), bins=48)
notgoodsw = ((zsw!=1) & (smp==ord('E')))
figure(figsize=(20,10))
hist(np.argwhere(notgoodsw==True).squeeze(), bins=48)
notgoodf = ((~goodcal) & (smp==ord('E')) & (sd==ord('F')))
figure(figsize=(20,10))
hist(np.argwhere(notgoodf==True).squeeze(), bins=48)
title('histogram of bad ' + pfx.upper() + ' status for FWD Earth views')
xlabel('record #')
notgoodb = ((~goodcal) & (smp==ord('E')) & (sd==ord('B')))
figure(figsize=(20,10))
hist(np.argwhere(notgoodb==True).squeeze(), bins=48)
title('histogram of bad ' + pfx.upper() + ' status for BWD Earth views')
xlabel('record #')
qcim = W['qc_rad_imag_threshold'][:L]
figure(figsize=(20,10))
hist(np.argwhere((qcim!=1) & (smp==ord('E')) & (sd==ord('F'))).squeeze(), bins=48)
title('histogram fwd earth view qc_rad_imag_threshold!=1')
figure(figsize=(20,10))
hist(np.argwhere((qcim!=1) & (smp==ord('E')) & (sd==ord('B'))).squeeze(), bins=48)
title('histogram bwd earth view qc_rad_imag_threshold!=1')
lw, mw, sw = W.SpectrumLW_CalRad_Resampled, W.SpectrumMW_CalRad_Resampled, W.SpectrumSW_CalRad_Resampled
figure(figsize=(20,10))
s,e = 30032,30047
plot(lw[s:e].transpose())
zlw[s:e], ''.join(chr(int(x)) for x in smp[s:e])
figure(figsize=(20,10))
# s,e = 30032,30047
plot(sw[s:e].transpose())
zsw[s:e], ''.join(chr(int(x)) for x in smp[s:e])
nlw, nmw = W.SpectrumLW_NLC, W.SpectrumMW_NLC
s,e = 30000, 34000
rex = np.argwhere((smp[s:e]==ord("E")) & (sd[s:e]==ord("F"))).squeeze() + s
len(rex)
figure(figsize=(20,10))
plot(np.real(nlw[rex]).transpose())
len(rex)
grid()
figure(figsize=(20,10))
plot(np.imag(nlw[rex]).transpose())
len(rex)
grid()
rex = np.argwhere((smp[s:e]==ord("E")) & (sd[s:e]==ord("B"))).squeeze() + s
figure(figsize=(20,10))
plot(np.real(nlw[rex]).transpose())
len(rex)
grid()
figure(figsize=(20,10))
plot(np.imag(nlw[rex]).transpose())
len(rex)
grid()
len(np.argwhere((zlw[s:e]==1) & (smp[s:e]==ord("E")))), len(np.argwhere((smp[s:e]==ord("E"))))
len(np.argwhere((zmw[s:e]==1) & (smp[s:e]==ord("E")))), len(np.argwhere((smp[s:e]==ord("E"))))
sma, fova =W['sceneMirrorAngle'], W['FOVangle']
figure(figsize=(20,10))
badrex = np.argwhere(zlw[s:e]!=1).squeeze() + s
gudrex = np.argwhere(zlw[s:e]==1).squeeze() + s
plot(gudrex, fova[gudrex], '.', color='b')
plot(badrex, fova[badrex], '.', color='r')
s,e
figure(figsize=(20,10))
badrex = np.argwhere(zmw[s:e]!=1).squeeze() + s
gudrex = np.argwhere(zmw[s:e]==1).squeeze() + s
plot(gudrex, fova[gudrex], '.', color='b')
plot(badrex, fova[badrex], '.', color='r')
plus45rex = np.argwhere((fova[s:e]>45.0) & (fova[s:e]<50.0)).squeeze() + s
plot(plus45rex, fova[plus45rex], 'o', color='orange')
minus45rex = np.argwhere((fova[s:e]<-45.0) & (fova[s:e]>-50.0)).squeeze() + s
if len(minus45rex):
plot(minus45rex, fova[minus45rex], 'o', color='orange')
else:
print('no -45>fovangle>-50')