fname = io.download_occultation_times(outdir='../data/')
print(fname)

"""
Explanation: Download the list of occultation periods from the MOC at Berkeley.
Note that the occultation periods typically only are stored at Berkeley for the future and not for the past. So this is only really useful for observation planning.
End of explanation
"""


tlefile = io.download_tle(outdir='../data')
print(tlefile)
times, line1, line2 = io.read_tle_file(tlefile)

"""
Explanation: Download the NuSTAR TLE archive.
This contains every two-line element (TLE) that we've received for the whole mission. We'll expand on how to use this later.
The times, line1, and line2 elements are now the TLE elements for each epoch.
End of explanation
"""


tstart = '2019-04-25T22:00:00'
tend = '2019-04-26T23:00:00'
orbits = planning.sunlight_periods(fname, tstart, tend)

"""
Explanation: Here is where we define the observing window that we want to use.
Note that tstart and tend must be in the future otherwise you won't find any occultation times and sunlight_periods will return an error.
End of explanation
"""


pa = planning.get_nustar_roll(tstart, 0)
print(tstart)
print("NuSTAR Roll angle for Det0 in NE quadrant: {}".format(pa))

"""
Explanation: We want to know how to orient NuSTAR for the Sun.
We can more or less pick any angle that we want. But this angle has to be specified a little in advance so that the NuSTAR SOC can plan the "slew in" maneuvers. Below puts DET0 in the top left corner (north-east with respect to RA/Dec coordinates).
This is what you tell the SOC you want the "Sky PA angle" to be.
End of explanation
"""


# Just use the first orbit...or choose one. This may download a ton of deltat.preds, which is a known 
# bug to be fixed.
orbit = orbits[0].copy()
print(orbit)
#...adjust the index above to get the correct orbit. Then uncomment below.

planning.make_mosaic(orbit, make_regions=True, outfile='orbit1_mosaic.txt', write_output=True)



"""
Explanation: This is where you actually make the Mosaic for Orbit 1
End of explanation
"""


# Just use the first orbit...or choose one. This may download a ton of deltat.preds, which is a known 
# bug to be fixed.
orbit = orbits[1].copy()
print(orbit)
#...adjust the index above to get the correct orbit. Then uncomment below.

planning.make_mosaic(orbit, make_regions=True, outfile='orbit2_mosaic.txt', write_output=True)



"""
Explanation: This is where you actually make the Mosaic for Orbit 2
End of explanation
"""


# Just use the first orbit...or choose one. This may download a ton of deltat.preds, which is a known 
# bug to be fixed.
orbit = orbits[2].copy()
print(orbit)
#...adjust the index above to get the correct orbit. Then uncomment below.

planning.make_mosaic(orbit, make_regions=True, outfile='orbit3_mosaic.txt', write_output=True)




"""
Explanation: This is where you actually make the Mosaic for Orbit 3
End of explanation
"""


# Just use the first orbit...or choose one. This may download a ton of deltat.preds, which is a known 
# bug to be fixed.
orbit = orbits[3].copy()
print(orbit)
#...adjust the index above to get the correct orbit. Then uncomment below.

planning.make_mosaic(orbit, make_regions=True, outfile='orbit4_mosaic.txt', write_output=True)



"""
Explanation: This is where you actually make the Mosaic for Orbit 4
End of explanation
"""


