In [2]:
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 notebook

In [4]:
from datetime import datetime

checktime = datetime.strptime('2017-05-08', "%Y-%m-%d")
tlefile = '../data/NuSTAR.tle'
mindt, line1, line2 = get_epoch_tle(checktime, tlefile)
print('Days between TLE entry and when you want to observe: ', mindt)


Days between TLE entry and when you want to observe:  15

In [55]:
from astropy.coordinates import SkyCoord
from datetime import timedelta
ra = []
dec =[]
times= []
base_ra = None
base_dec = None

step_size = timedelta(0, 2.) # 2 second steps for checking the Moon motion

# Start and stop time for the unocculted period that we're looking at:
checktime = datetime.strptime('2017-05-08T11:23:04', "%Y-%m-%dT%H:%M:%S")
end_time = datetime.strptime('2017-05-08T12:18:55', "%Y-%m-%dT%H:%M:%S")

last_pos = None
dt = []
dra = []
ddec= []

# How large a motion of the moon you can have:
limit = 2 #arcminutes

set = 0
ctr = 0
last_time = None
base_ra = None

while ( (end_time - checktime).total_seconds() ) > 0:
    checktime += step_size
    
    ra_moon, dec_moon = get_moon_j2000(checktime, line1, line2)
    this_pos = SkyCoord(ra_moon, dec_moon)
    
    # Init values:
    if base_ra is None:
        base_ra = ra_moon
        base_dec = dec_moon
    else:
        dra.extend([ra_moon - base_ra])
        ddec.extend([dec_moon - base_dec])

        
    # Check to see if you're updating the interval or not:
    if set == 0:
        last_pos = this_pos
        
        if last_time is not None:
            dt.extend([checktime - last_time])
            ctr += 1

        last_time = checktime
        set = 1
        
    else:
        
        if( this_pos.separation(last_pos).arcmin > limit):
            set = 0

In [81]:
ctr = 0
exp = 0.
all_exp = 0.
slew_rate = 0.17 # arcmin / sec
slew_time = limit / slew_rate

for t in dt:
    if (t.total_seconds() - slew_time > 0):
        ctr += 1
        exp += t.total_seconds() - slew_time
        print('Dwell time: ', t.total_seconds() - slew_time)
#        print(t.total_seconds())
    all_exp += t.total_seconds()
print()
print('Stationary exposure: ', exp)
print('Total Exposure: ', all_exp)
print('Efficiency: ', exp / all_exp)
print('Number of dwells: ', ctr, '(Used)', len(dt), '(Total)')


Dwell time:  80.23529411764706
Dwell time:  128.23529411764707
Dwell time:  348.2352941176471
Dwell time:  92.23529411764706
Dwell time:  70.23529411764706
Dwell time:  58.23529411764706
Dwell time:  50.23529411764706
Dwell time:  46.23529411764706
Dwell time:  42.23529411764706
Dwell time:  38.23529411764706
Dwell time:  36.23529411764706
Dwell time:  34.23529411764706
Dwell time:  32.23529411764706
Dwell time:  30.235294117647058
Dwell time:  30.235294117647058
Dwell time:  28.235294117647058
Dwell time:  28.235294117647058
Dwell time:  28.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  26.235294117647058
Dwell time:  28.235294117647058
Dwell time:  28.235294117647058
Dwell time:  28.235294117647058
Dwell time:  30.235294117647058
Dwell time:  30.235294117647058
Dwell time:  32.23529411764706
Dwell time:  34.23529411764706
Dwell time:  34.23529411764706
Dwell time:  38.23529411764706
Dwell time:  40.23529411764706
Dwell time:  44.23529411764706
Dwell time:  48.23529411764706
Dwell time:  54.23529411764706
Dwell time:  64.23529411764706
Dwell time:  82.23529411764706
Dwell time:  132.23529411764707
Dwell time:  384.2352941176471

Stationary exposure:  2703.5294117647063
Total Exposure:  3280.0
Efficiency:  0.8242467718794836
Number of dwells:  49 (Used) 49 (Total)

In [ ]: