In [1]:
from astropy.io.fits import getdata, getheader
import astropy.units as u
from nustar_lunar_pointing.tracking import get_epoch_tle
from nustar_lunar_pointing.tracking import convert_nustar_time
from nustar_lunar_pointing.tracking import get_moon_j2000

import matplotlib.pyplot as plt
%matplotlib inline

In [4]:
tlefile = '../data/NUSTAR.tle'
att = getdata('../data/nu60160109002A.attorb')
hdr = getheader('../data/nu60160109002A.attorb', 1)
mjdref = hdr['MJDREFI']

checktime = convert_nustar_time(att[0]['TIME'])
mindt, line1, line2 = get_epoch_tle(checktime, tlefile)

In [5]:
from astropy.coordinates import SkyCoord
doff = []
dra = []
ddec =[]
dt = []

base_ra = None
base_dec = None

tcheck = min(att['Time'])
step_size = 20. 
for ind, t0 in enumerate(att['Time']):
    if (t0 - tcheck) < step_size:
        continue
    else:
        tcheck = t0

    if (t0 - min(att['Time'])) > 3000:
        break

        
    t1 = convert_nustar_time(t0)
    
    ra_moon, dec_moon = get_moon_j2000(t1, line1, line2)
    moon_skycoord = SkyCoord(ra_moon, dec_moon)

    if base_ra is None:
        base_ra = ra_moon
        base_dec = dec_moon
        base_skycoord = moon_skycoord
        base_time = min(att['Time'])
    else:
        this_skycoord = SkyCoord(ra_moon, dec_moon)
        doff.extend([this_skycoord.separation(base_skycoord).arcsec])
        dra.extend([
            (ra_moon - base_ra).to(u.arcsec).value
        ])
        ddec.extend([
            (dec_moon - base_dec).to(u.arcsec).value
        ])
        dt.extend([t0 - base_time])

In [18]:
plt.plot(dt, doff, 'g.')
plt.xlabel('Time (sec)')
plt.ylabel('Offset (arcsec)')

for ind, last in enumerate(doff):
    print( (doff[ind+1] - last)/(60 * 20.))
    if ind > 300:
        break


0.03831759610361909
0.038997426968601874
0.037721266867862674
0.041707546368796124
0.04233815984114701
0.04343649369448319
0.042371988403955216
0.045525334310381
0.046564790020186424
0.04529345441300848
0.04852918139127032
0.04950017714010992
0.04752691822153954
0.051818634769811446
0.05221719610170254
0.05308392247751612
0.05133577974888055
0.054693387486374166
0.05547392275316478
0.05352999284797098
0.05690896915744266
0.05759707818188948
0.05496315974508226
0.05934816366785412
0.05943733721860705
0.05662236294687375
0.0609941233317132
0.06098023831791408
0.06143330574985043
0.058896330274008805
0.062214146209504974
0.06256013213191314
0.05986929944173672
0.06312951336223781
0.0633659875965975
0.06002917419599081
0.06422371981399881
0.06384386677618825
0.06393056028852356
0.060931882292035194
0.06398937127111254
0.06396307054916482
0.06085748607102763
0.06380069650107355
0.06366082358402801
0.059959053453663196
0.06378233065720186
0.06302441959741183
0.05924849112093246
0.06292610488595074
0.06205635915595622
0.061654257712914384
0.05831028931259274
0.06076172423781562
0.06025018771267241
0.05687208051313481
0.05914672378498987
0.05852854759003587
0.05463085217870722
0.05772337599511843
0.056498461446592124
0.05574279065506213
0.052355009237020717
0.05417079047632266
0.05331696381657669
0.04995505517859556
0.051558076913689396
0.050610954713242035
0.04679136965075789
0.0491753999585247
0.04763898528433325
0.04388142407778559
0.046035540787706095
0.04441719796428136
0.04327222654844187
0.0401235833283954
0.04096287994038372
0.0397433763973307
0.0366951789783343
0.03729448220965575
0.03600684604311331
0.032578933194225404
0.033927957066446954
0.03208244475710368
0.030714383304183836
0.027963024463526078
0.027991096280675264
0.026571162206996634
0.023971155264547784
0.023753943219716498
0.022289610480977443
0.01936278981629054
0.019884892552453647
0.017891864972317154
0.015144229034610816
0.015421224902909217
0.01340071220519576
0.011862355257179994
0.009860633444660986
0.00883898781177019
0.007281996039972303
0.00548354723710645
0.004229933182045897
0.0026622437731134594
0.0005920156913551485
8.128523413006406e-05
-0.0019734672602802067
-0.003543110785405285
-0.004832047722530508
-0.006601651180887984
-0.008163394920503985
-0.009222543407266434
-0.011198784403598741
-0.012744687294705272
-0.0140454401231212
-0.01526442088209933
-0.01726348183119247
-0.018321917205151597
-0.019731495708479846
-0.021696271727375156
-0.023174054208072146
-0.023432074234002207
-0.026019551327845725
-0.027454883462706525
-0.02746714560059369
-0.030209677778666445
-0.03159447629703891
-0.031824690005435814
-0.033778289962968604
-0.03556896688301094
-0.0368733859419073
-0.03630941155394339
-0.03935371883060043
-0.04058820780728032
-0.039779675468338764
-0.04292341242262637
-0.044079192164275964
-0.04347939988273007
-0.04580064157975661
-0.047319265139796396
-0.046475052378491456
-0.048864011403810914
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-18-b3f14be16749> in <module>()
      4 
      5 for ind, last in enumerate(doff):
----> 6     print( (doff[ind+1] - last)/(60 * 20.))
      7     if ind > 300:
      8         break

IndexError: list index out of range

In [ ]:
from astropy.coordinates import SkyCoord
doff = []
dra = []
ddec =[]
dt = []

base_ra = None
base_dec = None

tcheck = min(att['Time'])
step_size = 1. # arcminute
last_skycoord = None
last_time = None

set = 0
for ind, t0 in enumerate(att['Time']):

    if (t0 - min(att['Time'])) < 1500:
        continue


    if (t0 - min(att['Time'])) > 1800:
        break

        
    t1 = convert_nustar_time(t0)
    
    ra_moon, dec_moon = get_moon_j2000(t1, line1, line2)
    moon_skycoord = SkyCoord(ra_moon, dec_moon)

    if set == 0:
        print(t1)
        
        if last_time is not None:
            print(t0 - last_time)
        
        last_time = t0
        last_skycoord = moon_skycoord


        set = 1
    else:
        if moon_skycoord.separation(last_skycoord).arcmin > step_size:
            set=0

In [ ]:
dra

In [17]:
200e3 / (10 * 60)


Out[17]:
333.3333333333333

In [ ]: