-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_mu69_lorri_occs.py
1154 lines (844 loc) · 42.7 KB
/
plot_mu69_lorri_occs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 25 22:45:55 2016
@author: throop
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import astropy
from astropy.table import Table
import astropy.table as table
from astropy.coordinates import SkyCoord
import astropy.coordinates as coord
import math
import hbt
import spiceypy as sp
import astropy.units as u
import astropy.constants as c
import pickle
from astroquery.vo_conesearch import conesearch
import astroquery
from astroquery.vizier import Vizier
from matplotlib.patches import Ellipse
import os.path # For expanduser
# NB: In future, conesearch will move from astropy to astroquery -- see mailing list 17-Mar-2017.
# But it hasn't happened yet, so even if I wanted to be pro-active, I can't.
#==============================================================================
# A quick wrapper to query the Gaia catalog using Vizier
# From https://michaelmommert.wordpress.com/2017/02/13/accessing-the-gaia-and-pan-starrs-catalogs-using-python/
#==============================================================================
def gaia_query(ra_deg, dec_deg, rad_deg, maxmag=20,
maxsources=10000):
"""
Query Gaia DR1 @ VizieR using astroquery.vizier
parameters: ra_deg, dec_deg, rad_deg: RA, Dec, field
radius in degrees
maxmag: upper limit G magnitude (optional)
maxsources: maximum number of sources
returns: astropy.table object
"""
vquery = Vizier(columns=['Source', 'RA_ICRS', 'DE_ICRS',
'phot_g_mean_mag'],
column_filters={"phot_g_mean_mag":
("<%f" % maxmag)},
row_limit = maxsources)
field = coord.SkyCoord(ra=ra_deg, dec=dec_deg,
unit=(u.deg, u.deg),
frame='icrs')
return vquery.query_region(field,
width=("%fd" % rad_deg),
catalog="I/337/gaia")[0]
#==============================================================================
# Return a list of NH MegaCam Gaia stars that match a given position and mag limit
#==============================================================================
# NB: After I finished this function, I realized that RA of catalog excerpt is
# different than RA of MU69 KEM encounter. So maybe this section is just academic.
def nh_gaia_query(ra_deg, dec_deg, rad_deg, maxmag=20, maxsources=10000):
"""
Return a list of NH MegaCam Gaia stars that match a given position and mag limit
"""
# Load the catalog into an array.
# In an ideal world we would not load this if it was already loaded.
# But I don't know how to do that. Function only gets called 1x per execution, so
# maybe not a big deal?
nh_gaia = load_nh_gaia()
# Do a set of boolean matches to extract and return the proper stars.
# This logic here is simplistic: square box, ignore cos(dec), ignore 360->0 crossing, etc.
# But for the case of NH KEM, that is sufficient.
is_ra = np.logical_and( nh_gaia['RA'] < (ra_deg + rad_deg),
nh_gaia['RA'] > (ra_deg - rad_deg) )
is_dec = np.logical_and(nh_gaia['Dec'] < (dec_deg + rad_deg),
nh_gaia['Dec'] > (dec_deg - rad_deg) )
is_mag_g = np.logical_and( nh_gaia['g'] < maxmag,
nh_gaia['g'] > 0)
is_mag_r = np.logical_and( nh_gaia['r'] < maxmag,
nh_gaia['r'] > 0)
# Combine all these bitmasks
is_good = np.logical_and(
np.logical_or(is_mag_g, is_mag_r),
np.logical_and(is_ra, is_dec) )
# Return the selected values
return nh_gaia[is_good]
#==============================================================================
# Read the NH MegaCam-Gaia star catalog from disk. Use a pickle file if available.
#==============================================================================
# NB: After I finished this function, I realized that RA of catalog excerpt is
# different than RA of MU69 KEM encounter. So maybe this section is just academic.
def load_nh_gaia():
"""
Read the NH MegaCam-Gaia star catalog from disk.
Use a pickle file if available. If not, read text file
and then create a pickle file.
"""
dir_gaia = os.path.expanduser('~') + '/Data/Catalogs/Gaia/'
# file_txt = 'nh16.mega.gaia.rdmpm.txt' # Original catalog, but covers MU69 area as seen from Earth
file_txt = 'mu69.mega.gaia.rdmspm.txt' # Smaller area, covers MU69 as seen from NH.
file_pickle = file_txt.replace('.txt', '.pkl')
if os.path.isfile(dir_gaia + file_pickle):
lun = open(dir_gaia + file_pickle, 'rb')
gaia = pickle.load(lun)
lun.close()
print("Loaded: " + file_pickle)
else:
# Read the NH MegaCam-Gaia catalog from disk
gaia = astropy.io.ascii.read(dir_gaia + file_txt, format = 'basic')
# Make a plot of the Gaia stars
plt.plot(gaia['RA'], gaia['Dec'], linestyle='none', marker = '.', ms=0.005)
plt.xlabel('RA [deg]')
plt.ylabel('Dec [deg]')
plt.title('NH MegaCam-Gaia catalog')
plt.show()
# Save it as a pickle file
lun = open(dir_gaia + file_pickle, 'wb')
pickle.dump(gaia, lun)
print("Wrote: " + dir_gaia + file_pickle)
lun.close()
return gaia
#==============================================================================
# Start of main program
#==============================================================================
#==============================================================================
# Define kernels and files
#==============================================================================
#file_tm = '/Users/throop/git/NH_rings/kernels_nh_pluto_mu69.tm' # C/A time 11:00:00 (??) - older
file_tm_dayside = '/Users/throop/git/NH_rings/kernels_nh_pluto_mu69_tcm22.tm' # C/A time 07:00:00 - newer version
file_tm_nightside = '/Users/throop/git/NH_rings/kernels_nh_pluto_mu69_nightside.tm' # Sort of hacked this together
file_hd_pickle = '/Users/throop/git/NH_rings/cat_hd.pkl'
DO_FLYBY_DAYSIDE = True # For this plot, do night-side (testing) or day-side (default) flyby?
#==============================================================================
# Initialize setting
#==============================================================================
if (DO_FLYBY_DAYSIDE): # Dayside flyby works as intended
file_tm = file_tm_dayside
side_str = 'dayside'
else:
file_tm = file_tm_nightside # I have not really validated that nightside works. Results look dfft than expected.
side_str = 'nightside'
sp.furnsh(file_tm) # Start up SPICE
hour = 3600
day = 24 * hour
fs = 15 # General font size
if ('tcm22' in file_tm):
utc_ca = '2019 1 jan 07:00:00'
else:
utc_ca = '2019 1 jan 03:09:00' # MU69 C/A time. I got this from GV.
et_ca = sp.utc2et(utc_ca)
dt_tof = 180 # Time-of-flight uncertainty (halfwidth, seconds)
# Define the dates of the OpNavs. I have no time for these, but it probably doens't matter.
# Taken from MOL = Master Obs List spreadsheet 27-Mar-2017
utc_opnav = np.array(
[
# '16 Aug 2018',
'15 Sep 2018', '16 Sep 2018', '17 Sep 2018',
'24 Sep 2018', '25 Sep 2018', '26 Sep 2018',
'05 Oct 2018', '06 Oct 2018', '07 Oct 2018',
'15 Oct 2018', '16 Oct 2018', '17 Oct 2018',
'25 Oct 2018', '26 Oct 2018', '27 Oct 2018',
'04 Nov 2018', '05 Nov 2018', '06 Nov 2018',
'12 Nov 2018', '13 Nov 2018', '14 Nov 2018',
'15 Nov 2018', '16 Nov 2018', '17 Nov 2018',
'24 Nov 2018', '25 Nov 2018', '26 Nov 2018',
'27 Nov 2018', '28 Nov 2018', '28 Nov 2018', '30 Nov 2018', '01 Dec 2018',
'03 Dec 2018', '04 Dec 2018',
'05 Dec 2018', '06 Dec 2018', '07 Dec 2018', '08 Dec 2018', '09 Dec 2018',
'13 Dec 2018', '14 Dec 2018', '15 Dec 2018', '16 Dec 2018',
# '19 Dec 2018', '20 Dec 2018', '21 Dec 2018',
# '23 Dec 2018', '24 Dec 2018',
# '25 Dec 2018',
# '26 Dec 2018',
# '27 Dec 2018',
# '28 Dec 2018',
# '29 Dec 2018',
# '30 Dec 2018',
# '31 Dec 2018'
#
] )
et_opnav = np.zeros(np.size(utc_opnav))
for i in range(np.size(utc_opnav)):
et_opnav[i] = sp.utc2et(utc_opnav[i])
hbt.figsize((15,10))
mag_limit = 8 # Plot stars brighter than this.
plot_tick_every = 360 # Plot a time-tick every __ seconds
DO_PLOT_TOF = False # In general, plotting TOF is not necessary -- it
# is a translation in position along track,
# and changes the occultation times but not positions.
DO_PLOT_LORRI = True # Plot limits of LORRI FOV?
DO_SCALEBAR_ARCSEC = False
DO_UNITS_TITLE_DAYS = False # Flag: Use Days or Hours for the units in the plot title
DO_UNITS_TICKS_DAYS = False
DO_PLOT_UNCERTAINTY_MU69 = False # Make a plot of errorbars in MU69 position?
DO_TIMES_OPNAV = False # Plot times just for OpNavs?
DO_PLOT_WIDE = False # Make the plot extra-wide (cover full range of RA), or zoom on a narrow RA?
DO_PLOT_USNO = False
DO_LABEL_USNO = False
DO_PLOT_GAIA = False
DO_LABEL_GAIA = False
DO_PLOT_NH_GAIA = False
DO_LABEL_NH_GAIA = False
maglimit_plot = 100 # Plot stars brighter than this
# Define the start and end time for the plot. This is the main control to use.
case = 7
if (case == 1): # Outbound, 0.3 .. 96 hour
et_start = et_ca + 0.3*hour
et_end = et_ca + 96*hour
pad_ra_deg = 1 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 1
DO_LABEL_HD = True # Plot star IDs on chart
DO_PLOT_HD = True
hbt.figsize((15,10))
mag_limit = 8 # Plot stars brighter than this.
if (case == 2): # Inbound, -96h .. -0.1h
et_start = et_ca -96*hour
et_end = et_ca -0.1*hour
pad_ra_deg = 2 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 2
DO_PLOT_HD = True
DO_LABEL_HD = True
hbt.figsize((25,10))
mag_limit = 8 # Plot stars brighter than this.
if (case == 3): # Outbound, 2 .. 200 hour
et_start = et_ca + 2*hour
et_end = et_ca + 200*hour
pad_ra_deg = 0.5 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.5
DO_PLOT_HD = True
DO_LABEL_HD = True # Plot star IDs on chart
hbt.figsize((15,10))
mag_limit = 10 # Plot stars brighter than this.
if (case == 4): # Outbound, 2d .. 10 *** This one is key!! It has one good occultation.
et_start = et_ca + 2*day
et_end = et_ca + 20*day
pad_ra_deg = 0.01 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.01
DO_PLOT_HD = False
DO_LABEL_HD = DO_PLOT_HD # Plot star IDs on chart
DO_PLOT_USNO = True
DO_LABEL_USNO = DO_PLOT_USNO
plot_tick_every = 7200*5
hbt.figsize((15,10))
mag_limit = 12 # Plot stars brighter than this. HD is probably complete to 10 or so.
DO_PLOT_LORRI = False
if (case == 4.5): # Outbound, zoom on the good one!
et_start = et_ca + 3.0*day
et_end = et_ca + 20*day
pad_ra_deg = 0.005 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.005
DO_PLOT_HD = False
DO_LABEL_HD = DO_PLOT_HD # Plot star IDs on chart
DO_PLOT_USNO = True
DO_LABEL_USNO = DO_PLOT_USNO
plot_tick_every = 7200*5
hbt.figsize((15,10))
mag_limit = 12 # Plot stars brighter than this. HD is probably complete to 10 or so.
DO_PLOT_LORRI = False
if (case == 5): # Inbound, 2d .. 10
et_start = et_ca - 20*day
et_end = et_ca - 2*day
pad_ra_deg = 0.01 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.01
DO_PLOT_HD = False
DO_LABEL_HD = DO_PLOT_HD # Plot star IDs on chart
DO_PLOT_USNO = True
DO_LABEL_USNO = DO_PLOT_USNO
plot_tick_every = 7200*5
hbt.figsize((15,10))
mag_limit = 12 # Plot stars brighter than this. HD is probably complete to 10 or so.
DO_PLOT_LORRI = False
if (case == 6): # Inbound, K-40d .. K-14 (for Spencer one-off project on LORRI OpNav inbound occs, not for an MT)
# Using K-40 since it is one that JS did calculations for in his 22-Mar-2017 email.
# This is the routine I am using for search for LORRI inbound stellar occultations that would happen
# by serendipity during OpNav. The idea is to use USNO and/or the 'NH_GAIA' catalog. The latter is
# the special catalog prepared for me by Stephen Gwyn y JJ Kavalers.
# et_start = et_ca - 40*day
# et_end = et_ca - 14*day
et_start = np.amin(et_opnav)
et_end = np.amax(et_opnav)
pad_ra_deg = 0.003 # 0.019 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.0035
if (DO_PLOT_WIDE):
pad_ra_deg = 0.030
pad_dec_deg = 0.019
# Set the flags for which stars to plot. In general the code just supports one at a time.
DO_PLOT_HD = False
DO_LABEL_HD = DO_PLOT_HD # Plot star IDs on chart
DO_PLOT_USNO = False
DO_LABEL_USNO = DO_PLOT_USNO
DO_PLOT_GAIA = False
DO_LABEL_GAIA = False # DO_PLOT_GAIA
DO_PLOT_NH_GAIA = True
DO_LABEL_NH_GAIA = DO_PLOT_NH_GAIA
DO_TIMES_OPNAV = True # If True, set the plot time limits based on OpNav times.
# If False, uset them based on ET values that are defined in the code header.
plot_tick_every = 24*60*60
hbt.figsize((15,10))
mag_limit = 12 # Plot stars brighter than this. XXX This parameter is not really used.
maglimit_plot = 100 # Plot only stars brighter than this XXX This one is the one to use.
DO_PLOT_LORRI = False
DO_SCALEBAR_ARCSEC = True
DO_UNITS_TITLE_DAYS = True
DO_UNITS_TICKS_DAYS = True
DO_PLOT_UNCERTAINTY_MU69 = True
if (case == 7): # Inbound, Outer core. For checking whether it is worth doing a the LORRI
# Using K-40 since it is one that JS did calculations for in his 22-Mar-2017 email.
# This is the routine I am using for search for LORRI inbound stellar occultations that would happen
# by serendipity during OpNav. The idea is to use USNO and/or the 'NH_GAIA' catalog. The latter is
# the special catalog prepared for me by Stephen Gwyn y JJ Kavalers.
# et_start = et_ca - 40*day
# et_end = et_ca - 14*day
et_start = et_ca - 14*day
et_end = et_ca - 7*day
pad_ra_deg = 0.003 # 0.019 # Add additional padding at edge of plots, RA = x dir. Degrees.
pad_dec_deg = 0.0035
if (DO_PLOT_WIDE):
pad_ra_deg = 0.030
pad_dec_deg = 0.019
# Set the flags for which stars to plot. In general the code just supports one at a time.
DO_PLOT_HD = False
DO_LABEL_HD = DO_PLOT_HD # Plot star IDs on chart
DO_PLOT_USNO = False
DO_LABEL_USNO = DO_PLOT_USNO
DO_PLOT_GAIA = False
DO_LABEL_GAIA = False # DO_PLOT_GAIA
DO_PLOT_NH_GAIA = True
DO_LABEL_NH_GAIA = DO_PLOT_NH_GAIA
DO_TIMES_OPNAV = False # If True, set the plot time limits based on OpNav times.
# If False, uset them based on ET values that are defined in the code header.
plot_tick_every = 24*60*60
hbt.figsize((15,10))
mag_limit = 12 # Plot stars brighter than this. XXX This parameter is not really used.
maglimit_plot = 100 # Plot only stars brighter than this XXX This one is the one to use.
DO_PLOT_LORRI = False
DO_SCALEBAR_ARCSEC = True
DO_UNITS_TITLE_DAYS = True
DO_UNITS_TICKS_DAYS = True
DO_PLOT_UNCERTAINTY_MU69 = True
# DO_LABEL_USNO = False
# DO_LABEL_GAIA = False
fov_lorri = 0.3*hbt.d2r # Radians. LORRI width.
num_dt = 21 # Number of timesteps. 4000 is way too many -- 200 should be fine.
# Define plot colors
color_kbo = 'purple'
color_kbo_radius = 'pink'
color_kbo_center = 'red'
color_lorri = 'lightgreen'
color_roche = 'yellow'
color_stars = 'green'
color_gaia = 'crimson'
color_tof = 'blue'
color_uncertainty_mu69 = 'blue'
hbt.set_fontsize(fs)
try:
lun = open(file_hd_pickle, 'rb')
print("Loading file: " + file_hd_pickle)
hd = pickle.load(lun)
lun.close()
except IOError: # If Pickle file not found, then go ahead and read the catalog from scratch
# Read HD into a table. Its positions are 1900. Coords are radians.
print ("Reading HD catalog...")
hd = read_hd_all()
num_stars = np.size(ra_1950)
# Precess stars from 1900 to 2000
print("Precessing to J2000")
mx = sp.pxform('B1950', 'J2000', et[0]) # SPICE knows about 1950, but not 1900!
ra_1950 = t['RA']
dec_1950 = t['Dec']
ra_2000 = []
dec_2000 = []
pt_1950 = []
# Loop over every star and precess it individually. This loop is a real bottleneck.
for i in range(num_stars):
pt_1900 = sp.radrec(1, ra_1950[i], dec_1950[i])
pt_1950 = sp.mxv(mx, pt_1900)
pt_2000 = sp.mxv(mx, pt_1950) # SPICE will not precess 1900 -> 2000. So we apply 1950 -> 2000, do it 2x.
d, ra_2000_i, dec_2000_i = sp.recrad(pt_2000)
dec_2000.append(dec_2000_i)
ra_2000.append(ra_2000_i)
hd['RA_2000'] = ra_2000
hd['Dec_2000'] = dec_2000
# Now save this pickle file, so we never have to run this routine again
lun = open(file_hd_pickle, 'wb')
pickle.dump(hd, lun)
lun.close()
print("Wrote: " + file_hd_pickle)
# Use the virtual observatory to get some UCAC2 stellar positions
# crval is a two-element array of [RA, Dec], in degrees
# Use conesearch.list_catalogs() to get list
encounter_phase = 'Inbound' if (et_start < et_ca) else 'Outbound'
# Set up the ET array
if DO_TIMES_OPNAV:
et = et_opnav
else:
et = hbt.frange(et_start, et_end, num_dt)
index_asymptote = 0 if (encounter_phase == 'Outbound') else 1
# We make one call to SPICE to look up the asymptote position
# Most SPICE calls are later, but we need to do this one now, ahead of order.
(st,lt) = sp.spkezr('MU69', et[index_asymptote], 'J2000', 'LT', 'New Horizons')
(junk, ra_asymptote, dec_asymptote) = sp.recrad(st[0:3])
crval = np.array([ra_asymptote, dec_asymptote]) * hbt.r2d
radius_search = 0.15 # degrees # We only use these catalog for very fine searches, so narrow is OK.
DO_PLOT_GSC = False # Goes to about v=12
if DO_PLOT_GSC:
name_cat = u'The HST Guide Star Catalog, Version 1.1 (Lasker+ 1992) 1' # works, but 1' errors; investigating
stars = conesearch.conesearch(crval, radius_search, cache=False, catalog_db = name_cat)
ra_stars = np.array(stars.array['RAJ2000'])*hbt.d2r # Convert to radians
dec_stars = np.array(stars.array['DEJ2000'])*hbt.d2r # Convert to radians
mag_stars = np.array(stars.array['Pmag'])
if DO_PLOT_USNO:
name_cat = u'The USNO-A2.0 Catalogue (Monet+ 1998) 1'
stars = conesearch.conesearch(crval, radius_search, cache=False, catalog_db = name_cat)
ra_stars = np.array(stars.array['RAJ2000'])*hbt.d2r # Convert to radians
id_stars = np.array(stars.array['USNO-A2.0']) # ID
id_stars = id_stars.astype('U') # Convert from byte string to Unicode, ugh.
dec_stars = np.array(stars.array['DEJ2000'])*hbt.d2r # Convert to radians
mag_b_stars = np.array(stars.array['Bmag'])
mag_r_stars = np.array(stars.array['Rmag'])
usno = Table([id_stars, ra_stars, dec_stars, mag_b_stars, mag_r_stars],
names = ['ID', 'RA_2000', 'Dec_2000', 'Bmag', 'Rmag'])
if DO_PLOT_GAIA:
stars = gaia_query(crval[0], crval[1], radius_search, maxmag=20, maxsources=10000)
ra_stars = np.array(stars['RA_ICRS'])*hbt.d2r # Convert to radians
id_stars = np.array(stars['Source'])
dec_stars = np.array(stars['DE_ICRS'])*hbt.d2r # Convert to radians
mag_stars = np.array(stars['__Gmag_'])
gaia = Table([id_stars, ra_stars, dec_stars, mag_stars],
names = ['ID', 'RA_2000', 'Dec_2000', 'mag'])
if DO_PLOT_NH_GAIA:
stars = nh_gaia_query(crval[0], crval[1], radius_search, maxmag=20, maxsources=10000)
ra_stars = np.array(stars['RA'])*hbt.d2r # Convert to radians
# id_stars = np.array(stars['Source'])
dec_stars = np.array(stars['Dec'])*hbt.d2r # Convert to radians
# Do a bit of maniplation to take G mag, or B mag, or mean, depending on what we have
mag_stars = np.array(stars['g'] + stars['r'])
is_both = (stars['r'] * stars['g']) > 0.0
mag_stars[is_both] /= 2
# Remove a very small number of stars that have clearly spurious magnitudes
is_error = (mag_stars > 50)
mag_stars[is_error] = 20
nh_gaia = Table([ra_stars, dec_stars, mag_stars],
names = ['RA', 'Dec', 'mag'])
#==============================================================================
# Look up NH position (ie, KBO position)
#==============================================================================
print("Looking up NH position...")
dt = et[1] - et[0] # Timestep
ra_kbo = []
dec_kbo = []
dist_kbo = []
ra_kbo_tof_minus = []
ra_kbo_tof_plus = []
dec_kbo_tof_minus = []
dec_kbo_tof_plus = []
for et_i in et:
# Nominal position
(st,lt) = sp.spkezr('MU69', et_i, 'J2000', 'LT', 'New Horizons')
(dist_i, ra_i, dec_i) = sp.recrad(st[0:3])
ra_kbo.append(ra_i) # MU69 RA/Dec, in radians
dec_kbo.append(dec_i)
dist_kbo.append(dist_i)
# TOF uncertainty -- negative
(st,lt) = sp.spkezr('MU69', et_i-dt_tof, 'J2000', 'LT+S', 'New Horizons')
(dist_i, ra_i, dec_i) = sp.recrad(st[0:3])
ra_kbo_tof_minus.append(ra_i) # MU69 RA/Dec, in radians
dec_kbo_tof_minus.append(dec_i)
# TOF uncertainty -- positive
(st,lt) = sp.spkezr('MU69', et_i+dt_tof, 'J2000', 'LT+S', 'New Horizons')
(dist_i, ra_i, dec_i) = sp.recrad(st[0:3])
ra_kbo_tof_plus.append(ra_i)
dec_kbo_tof_plus.append(dec_i)
# Convert all of these from lists to NP arrays
dec_kbo = np.array(dec_kbo)
ra_kbo = np.array(ra_kbo)
dec_kbo_tof_plus = np.array(dec_kbo_tof_plus)
dec_kbo_tof_minus = np.array(dec_kbo_tof_minus)
ra_kbo_tof_plus = np.array(ra_kbo_tof_plus)
ra_kbo_tof_minus = np.array(ra_kbo_tof_minus)
ra = hd['RA_2000']*hbt.r2d # Look up stellar coordinates - be sure to use J2000
dec = hd['Dec_2000']*hbt.r2d
dist_kbo = np.array(dist_kbo)*u.km # NH-MU69 distance
# Compute the size of the Hill sphere
rho_kbo = 2.5*u.gram/u.cm**3
r_kbo = 16.5 * u.km
m_kbo = 4/3 * math.pi * r_kbo**3 * rho_kbo
a_kbo = 43*u.au
a_hill = (a_kbo * (m_kbo / c.M_sun/3)**(1/3)).to('km')
# Compute angular size of Hill sphere
# In general the Hill sphere is just too large to plot... LORRI covers it only a couple days after C/A
angle_hill = (a_hill / dist_kbo).to('').value # Convert to radians, and drop the units
angle_hill = np.clip(angle_hill, -math.pi, math.pi) # Clip it (same as IDL > or < operator)
# Compute angular size of KBO itself
angle_kbo = (r_kbo / dist_kbo).to('').value # Radians
# Compute angular size of Roche limit
r_roche = 2.5 * r_kbo
angle_roche = (r_roche / dist_kbo).to('').value # Radians
# Set the x and y limits for the plot
xlim = hbt.mm(ra_kbo*hbt.r2d) # Plotting limits, in deg
ylim = hbt.mm(dec_kbo*hbt.r2d)
xlim = np.array(xlim) + pad_ra_deg * np.array([-1,1]) # Pad the plot by the specified amount
ylim = np.array(ylim) + pad_dec_deg * np.array([-1,1])
# Filter the stars. Set a flag for each one we want to plot, based on mag and position.
is_good = np.logical_and(
hd['Ptg'] < mag_limit,
np.logical_and(
np.logical_and(xlim[0] < ra,
ra < xlim[1]),
np.logical_and(ylim[0] < dec,
dec < ylim[1]) ) )
# Generate human-readable strings for the plot
if (DO_UNITS_TITLE_DAYS):
t_start_relative_str = "K{:+.0f}d".format((et_start - et_ca)/day)
t_end_relative_str = "K{:+.0f}d".format((et_end - et_ca)/day)
else:
t_start_relative_str = "K{:+}h".format((et_start - et_ca)/hour)
t_end_relative_str = "K{:+}h".format((et_end - et_ca)/hour)
#%%
#==============================================================================
# Make plot #1, which is in a fixed star field, with MU69 moving across it.
#==============================================================================
# Draw the main trajectory
hbt.figsize((21,12)) # Medium-sized figure
fig, ax = plt.subplots()
DO_PLOT_TRAJECTORY = True
if DO_PLOT_TRAJECTORY:
ax.plot(ra_kbo*hbt.r2d, dec_kbo*hbt.r2d, color=color_kbo_center)
# Plot the time-of-flight uncertainty.
# Concl: TOF error does not change the position of any of these occultations. It just changes the time
# at which we see them. This wasn't obvious to me, but these two curves lay over each other identically.
if DO_PLOT_TOF:
ax.plot(ra_kbo_tof_minus*hbt.r2d, dec_kbo_tof_minus*hbt.r2d, color=color_tof, marker = '+', ms=5)
ax.plot(ra_kbo_tof_plus*hbt.r2d, dec_kbo_tof_plus*hbt.r2d, color=color_tof, marker = '+', ms=10)
# Draw the LORRI FOVs -- 0.3 x 0.3 deg square
if DO_PLOT_LORRI:
dec_kbo_plus_lorri = dec_kbo + (fov_lorri/2) * np.sqrt(2) # All radians
dec_kbo_minus_lorri = dec_kbo - (fov_lorri/2) * np.sqrt(2)
ax.fill_between(ra_kbo*hbt.r2d, (dec_kbo_plus_lorri)*hbt.r2d, (dec_kbo_minus_lorri)*hbt.r2d,
color=color_lorri, alpha=0.5, label = 'LORRI FOV')
# Draw the Hill sphere
ax.plot(ra_kbo*hbt.r2d, (dec_kbo - angle_hill)*hbt.r2d, linestyle = '--')
ax.plot(ra_kbo*hbt.r2d, (dec_kbo + angle_hill)*hbt.r2d, linestyle = '--')
# Draw the Roche radius
ax.fill_between(ra_kbo*hbt.r2d, (dec_kbo+angle_roche)*hbt.r2d, (dec_kbo-angle_roche)*hbt.r2d,
color=color_roche, alpha=0.5, label = 'MU69 Roche radius = {} km'.format(r_roche.to('km').value))
# Draw the MU69 radius
ax.fill_between(ra_kbo*hbt.r2d, (dec_kbo+angle_kbo)*hbt.r2d, (dec_kbo-angle_kbo)*hbt.r2d,
color=color_kbo_radius, alpha=1, label = 'MU69 radius = {} km'.format(r_kbo.to('km').value))
# Draw '+' symbols every hour
for i,et_i in enumerate(et):
if (np.mod(et_i - et[0], plot_tick_every)) < dt:
if (i == 0): # Pass the info for this to plt.label()... but only for the first call!
kwargs = {'label' : 'MU69 position, SPICE, tcm22'}
else:
kwargs = {}
ax.plot(ra_kbo[i]*hbt.r2d, dec_kbo[i]*hbt.r2d, marker='+',
markersize=20, color='black', **kwargs )
ax.text(ra_kbo[0]*hbt.r2d, dec_kbo[0]*hbt.r2d, t_start_relative_str + ' ' ,
fontsize=12, clip_on=True, horizontalalignment='center') # Why does plt.text() kill my plot??
ax.text(ra_kbo[-1]*hbt.r2d, dec_kbo[-1]*hbt.r2d, ' ' + t_end_relative_str,
fontsize=12, clip_on=True, horizontalalignment='center') # Why does plt.text() kill my plot??
# Plot the HD stars
if DO_PLOT_HD:
ax.plot(hd['RA_2000'][is_good]*hbt.r2d, hd['Dec_2000'][is_good]*hbt.r2d, linestyle='none', marker='.',
label = 'HD, V < {}'.format(mag_limit), color=color_stars, clip_on = True)
# Label the HD stars
if (DO_LABEL_HD):
for i in range(np.size(is_good)):
if (is_good[i]):
string_hd = hd['ID'][i]
else:
string_hd = ''
ax.text(hd['RA_2000'][i]*hbt.r2d, hd['Dec_2000'][i]*hbt.r2d,
' {} {:.1f} {}'.format(hd['Type'][i], hd['Ptg'][i], string_hd),
fontsize = 8, clip_on = True)
# Plot the USNO stars
#plt.plot(usno['RA_2000'][is_good]*hbt.r2d, hd['Dec_2000'][is_good]*hbt.r2d, linestyle='none', marker='.',
# label = 'HD star', color=color_stars)
if DO_PLOT_USNO:
ax.plot(usno['RA_2000']*hbt.r2d, usno['Dec_2000']*hbt.r2d, linestyle='none', marker='.',
label = 'USNO positions', color=color_stars)
name_catalog = 'USNO'
if DO_LABEL_USNO:
for i in range(np.size(usno)):
ax.text(usno['RA_2000'][i]*hbt.r2d, usno['Dec_2000'][i]*hbt.r2d,
' B={:.1f}, R={:.1f} {}'.format(usno['Bmag'][i], usno['Rmag'][i], usno['ID'][i]),
fontsize = 8, clip_on = True)
# Plot the Gaia stars
if DO_PLOT_GAIA:
ax.plot(gaia['RA_2000']*hbt.r2d, gaia['Dec_2000']*hbt.r2d, linestyle='none', marker='.',
label = 'Gaia positions', color=color_gaia, alpha = 0.5)
name_catalog = 'Gaia'
if DO_LABEL_GAIA:
for i in range(np.size(gaia)):
ax.text(gaia['RA_2000'][i]*hbt.r2d, gaia['Dec_2000'][i]*hbt.r2d,
' {:.1f} {}'.format(gaia['mag'][i], gaia['ID'][i]),
fontsize = 8, clip_on = True)
if DO_PLOT_NH_GAIA:
ax.plot(nh_gaia['RA']*hbt.r2d, nh_gaia['Dec']*hbt.r2d, linestyle='none', marker='.',
label = 'Gaia-MegaCam positions', color=color_gaia, alpha = 0.5)
name_catalog = 'Gaia-MegaCam'
if DO_LABEL_NH_GAIA:
for i in range(np.size(nh_gaia)):
ax.text(nh_gaia['RA'][i]*hbt.r2d, nh_gaia['Dec'][i]*hbt.r2d,
' {:.1f}'.format(nh_gaia['mag'][i]),
fontsize = 8, clip_on = True)
# Plot a scalebar if requested
if (DO_SCALEBAR_ARCSEC):
d2as = 60. * 60.
as2d = 1/d2as
y0 = ylim[0]
dy = ylim[1] - ylim[0]
delta_pos_usno_as = 0.2
delta_pos_mu69_as = 0.5 # This is positional uncertainty now, from Earth. I want to map this into
# Get the distance to Pluto for start and end times
y0_scalebar = ylim[0] + 0.1*(ylim[1]-ylim[0])
x0_scalebar = xlim[0] + 0.1*(xlim[1]-xlim[0])
x1_scalebar = x0_scalebar + 1 * as2d
ax.hlines(y0 + dy * 0.1, x0_scalebar, x0_scalebar + 1*as2d)
ax.hlines(y0 + dy * 0.15, x0_scalebar, x0_scalebar + delta_pos_usno_as*as2d)
# plt.hlines(y0 + dy * 0.2, x0_scalebar, x0_scalebar + delta_pos_mu69_as*as2d)
ax.text(x0_scalebar, y0_scalebar, " = 1\" = {:.0f} km (at {}) = {:.0f} km (at {})".format(
(dist_kbo[ 0].value)*1*hbt.as2r,
t_start_relative_str,
(dist_kbo[-1].value)*1*hbt.as2r,
t_end_relative_str ),
bbox={'facecolor':'white', 'alpha':0.5, 'pad':10})
# ax.figtext(0.23, 0.23, "USNO accuracy = {}\"".format(delta_pos_usno_as))
# plt.figtext(0.23, 0.265, "MU69 uncertainty = {}\"".format(delta_pos_mu69_as))
# Plot error ellipses for the position of MU69. These are from JS's email to me, which are in turn from Marc Buie's
# slides as of 2-Mar-2017. I am assuming that everything is equatorial.
if (DO_PLOT_UNCERTAINTY_MU69):
dpos_x = 6413*u.km # Uncertainty in X position, km, from JS email 22-Mar-17. Halfwidth
dpos_y = 366*u.km # Uncertainty in Y position, km
angle = 3 # Rotation angle of ellipse, in degrees. This is a guess, just to make
# it vaguely align with what is in plots of Buie (from JS email).
# Plot at start of period
width = (dpos_x/dist_kbo[0]).value*hbt.r2d*2/math.cos(dec_kbo[0])
height = (dpos_y/dist_kbo[0]).value*hbt.r2d*2
xy = (ra_kbo[0]*hbt.r2d, dec_kbo[0]*hbt.r2d) # Get uncertainty in x and y, and convert to deg
ell = matplotlib.patches.Ellipse(xy=xy, width=width, height=height, angle = angle, alpha=0.1,
color=color_uncertainty_mu69, label = 'MU69 3$\sigma$ pos, Buie')
ax.add_patch(ell)
# Plot at end of period
width = (dpos_x/dist_kbo[-1]).value*hbt.r2d*2/math.cos(dec_kbo[-1])
height = (dpos_y/dist_kbo[-1]).value*hbt.r2d*2
xy = (ra_kbo[-1]*hbt.r2d, dec_kbo[-1]*hbt.r2d) # Get uncertainty in x and y, and convert to deg
ell = matplotlib.patches.Ellipse(xy=xy, width=width, height=height, angle = angle, alpha=0.1,
color=color_uncertainty_mu69)
ax.add_patch(ell)
#==============================================================================
# Plot a circle showing where rings would be, if they were there
#==============================================================================
# NB: There is a small bug here somewhere. Some stars are plotted *outside* the ring
# on this plot, but inside the ring on the other plot, or v/v.
# My guess is that this has to do with cos(dec)
DO_PLOT_RING_MU69 = True
if DO_PLOT_RING_MU69:
dpos_x = 3000*u.km # Radius of the rings to draw
dpos_y = 3000*u.km
angle = 0 # Rotation angle of ellipse, in degrees
# Plot ring at start of period
width = (dpos_y/dist_kbo[0]).value*hbt.r2d*2/math.cos(dec_kbo[0])
height = (dpos_y/dist_kbo[0]).value*hbt.r2d*2
xy = (ra_kbo[0]*hbt.r2d, dec_kbo[0]*hbt.r2d) # Get uncertainty in x and y, and convert to deg
ell = matplotlib.patches.Ellipse(xy=xy, width=width, height=height, angle = angle, alpha=0.5,
facecolor='none', edgecolor = 'grey', linewidth=3)
ax.add_patch(ell)
# Plot ring at end of period
width = (dpos_y/dist_kbo[-1]).value*hbt.r2d*2/math.cos(dec_kbo[-1])
height = (dpos_y/dist_kbo[-1]).value*hbt.r2d*2
xy = (ra_kbo[-1]*hbt.r2d, dec_kbo[-1]*hbt.r2d) # Get uncertainty in x and y, and convert to deg
ell = matplotlib.patches.Ellipse(xy=xy, width=width, height=height, angle = angle, alpha=0.5,
edgecolor='grey', facecolor='none', linewidth=3,
label = 'MU69 ring, radius = {:.0f} km'.format(dpos_x.to('km').value))
ax.add_patch(ell)
#==============================================================================
# Finalize and display the plot
#==============================================================================
if (DO_TIMES_OPNAV):
title_str = '{} .. {}, {} OpNav visits, {} flyby'.format(
t_start_relative_str, t_end_relative_str, np.size(et_opnav),
side_str)
else:
title_str = '{} .. {}, {} flyby'.format(t_start_relative_str, t_end_relative_str, side_str)
plt.title(title_str)
plt.xlim(xlim)
plt.ylim(ylim)
# Write the image to disk
dir_out = os.path.expanduser('~') + '/git/NH_rings/out/'
file_out = ('LORRI_occs_MU69_inbound_' + name_catalog +
(['', '_wide'][DO_PLOT_WIDE]) + '_' + side_str + '.png' )
plt.legend(loc = 'upper left')
plt.savefig(dir_out + file_out)
print("Wrote: " + dir_out + file_out)
plt.show()
#%%
#==============================================================================
# Make plot #2, which is with MU69 at center, and rings at a fixed scale, and stars moving across / into the ring.
#==============================================================================
# Stars pass from the outside toward the inside... that is, at the end,
# more and more stars are inside the ring, which makes sense.
hbt.figsize((18,18)) # Make a large figure here
radius_ring = 3000*u.km
radius_plot = 3400 # Radius, in km
color_stars = 'blue'
fig, ax = plt.subplots()
# Plot ring around MU69
if (DO_FLYBY_DAYSIDE): # Dayside flyby (nominal)
ax.set_xlim(radius_plot * np.array([-3,1.1])) # Set x range of plot. 0 is the x position of MU69
ax.set_ylim(radius_plot * np.array([-1.5,1.5]))
else: # Nightside flyby
ax.set_xlim(radius_plot * np.array([-1.1,3]))
ax.set_ylim(radius_plot * np.array([-1.5,1.5]))
# Grab RA and Dec for all stars
if (DO_PLOT_GAIA):
ra_stars = gaia['RA_2000']
dec_stars = gaia['Dec_2000']
mag_stars = gaia['mag']
name_catalog = 'Gaia'
if (DO_PLOT_NH_GAIA):
ra_stars = nh_gaia['RA']
dec_stars = nh_gaia['Dec']
mag_stars = nh_gaia['mag']
if (DO_PLOT_USNO):
ra_stars = usno['RA_2000']
dec_stars = usno['Dec_2000']
mag_stars = usno['Bmag']
name_catalog = 'USNO'
for i,et_i in enumerate(et): # Plot for every timestep
d_ra_ang = (ra_stars - ra_kbo[i])/np.cos(dec_stars)
d_dec_ang = dec_stars - dec_kbo[i]
d_ra_km_proj = d_ra_ang * dist_kbo[i]
d_dec_km_proj = d_dec_ang * dist_kbo[i]
ax.plot(d_ra_km_proj[mag_stars < maglimit_plot],
d_dec_km_proj[mag_stars < maglimit_plot],
marker = '.', linestyle='none', color = color_stars, markersize=1)
# Label each star at its final position (at inner edge)