-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscStars.py
More file actions
2058 lines (1838 loc) · 104 KB
/
scStars.py
File metadata and controls
2058 lines (1838 loc) · 104 KB
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
import scipy
import pyfits
from scipy import stats
from scipy import special
from scipy import integrate
from gcwork import starTables
import nmpfit_sy
import asciidata, os, sys, pickle
import nmpfit_sy#2 as nmpfit_sy
import numpy as np
import math
import pdb
import time
import scipy.optimize as opter
from scipy.optimize import fsolve
from scipy.optimize import minimize
from matplotlib.ticker import ScalarFormatter
import datetime
import time
import threading
from astropy.stats import LombScargle
import pylab as py
import mysql.connector
import scYoung
homeRoot = '/u/schappell/'
plotRoot = homeRoot+'plots/'
tableRoot = homeRoot+'tables/'
cRoot = homeRoot+'code/c/'
mnoutRoot = homeRoot+'pmnOld/'
pi = math.pi
#constants and dimensional analysis
mass = 3.960e6 #mass of Sgr A*, in solar masses, according to my align
masse = 0.164e6
dist = 7828.0 #distance to Sgr A*, in pc, according to my align
G = 6.6726e-8
msun = 1.99e33
GM = G * mass * msun
GMe = G * masse * msun
mass_g = mass * msun
masse_g = masse * msun
sec_in_yr = 3.1557e7
cm_in_au = 1.496e13
cm_in_pc = 3.086e18
km_in_pc = 3.086e13
au_in_pc = 206265.0
asy_to_kms = dist * cm_in_au / (1e5 * sec_in_yr)
as_to_km = dist * cm_in_au / (1e5)
density0 = 3.2e4
density0_g = 3.2e4 * msun
density0e = 1.3e4
density0e_g = density0e * msun
GM_as_yr = GM * sec_in_yr**2 * 1e-15 / as_to_km**3
'''one_star - class of object for one star in databse
Required input:
-sname = name of star in str format
-align = home directory of align
-points = points directory within align home directory
Optional input:
-ak_correct = if set to True, star's magnitude will be Ak corrected, if False, this will not happen,
set to True unless otherwise changed
Attributes:
- name = sname, name of star
- align = align home directory
- points = points subdirectory
- years = time of observations, in units of years, in array
- x = observed x/RA positions of star, in array
- y = observed y/Dec positions of star, in array
- xe/ye = errors in positions of star, in arrays
- epoch = number of observations for star, integer number
- fit = current polynomial fit for star, every star stars with just 'Point', can be updated with
set_vel, set_acc, and set_jerk class functions
- mag = magnitude in K' filter, of ak_correct is set to True, ak correction is applied, if False
no ak correction
- pOld = probability of being late-type, from 0 to 1, confirmed early-type stars are set to 0.0,
confirmed late-type stars are set to 1.0
- pYng = probability of being early-type, from 0 to 1, confirmed late-type stars are set to 0.0,
confirmed early-type stars are set to 1.0
Functions:
- set_vz() = get line-of-sight velocities for star. No input needed. Returns to database and if
any viable radial velocity measurements are recorded (ie both the radial velocity
and it's error are non-zero) will be attributed to star in array form
- Added Attributes:
+ vz_date = array of radial velocity dates, in years
+ vz = array of radial velocities, in km/s
+ vz_err = array of error in radial velocity measurements, in km/s
- set_gcows(gcows_status) = sets attribute in_gcows, or whether star is in GCOWS footprint
- Required Input:
+ gcows_status = 0/1, whether star is in GCOWS footprint
- Added Attributes:
+ in_gcows = either 0 for not or 1 for in GCOWS footprint
- set_vel(xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xchi2, ychi2) = sets attributes for velocity
fit for star in both x/RA and y/Dec directions, attributes are only set if star is measured
in 3 or more epochs, attributes 'fit' set to 'Vel' to designate that star is currently
best fit with velocity fit
-Required Input: **Units are not specified, but need to be consistent between all inputs)
+ x/yt0 = t0 or time which is set to 0 for velocity fit in x/RA and y/Dec direction
+ x/y0 = positions in x/RA and y/Dec at t0 or time is 0 for velocity fit
+ x/y0e = error in x/y0
+ x/yv = velocity term for velocity fit in x/RA and y/Dec directions
+ x/yve = error in x/yv
+ x/ychi2 = chi squared for x/RA and y/Dec velocity fit
-Added Attributes:
+ v_xt0, v_yt0, v_x0, v_y0, v_x0e, v_y0e, v_xv, v_yv, v_xve, v_yve, v_xchi2, v_ychi2
= set to corresponding terms from input, 'v_' denotes from the velocity fit
+ xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xchi2, ychi2 = set to corresponding
terms from input
+ v_R and R = projected position, calculated from x0 and y0
+ v_chix/yr and chix/yr = reduced chi^2 in x and y directions for velocity fit
- set_acc(self, xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xa, ya, xae, yae, xchi2, ychi2) =
sets attributes for acceleration fit for star in both x/RA and y/Dec directions, attributes
are only set if star is measured in 4 or more epochs, calculates projected and tangential
accelerations (ar, at) and respective errors (radial and tangential in relation to Sgr A*),
F Test run to compare chi^2 between velocity and acceleration fits (whole function does not
run if star does not have velocity attributes, so run set_vel before this function), if passes
F Test, star's values for its orbit are set to those for the accel fit (denoted by a_*) and
fit attribute set to 'Acc'
-Required Input: **Units are not specified, but need to be consistent between all inputs)
+ x/yt0 = t0 or time which is set to 0 for accel fit in x/RA and y/Dec direction
+ x/y0 = positions in x/RA and y/Dec at t0 or time is 0 for accel fit
+ x/y0e = error in x/y0
+ x/yv = velocity term for accel fit in x/RA and y/Dec directions
+ x/yve = error in x/yv
+ x/ya = acceleration term for accel fit in x/RA and y/Dec directions
+ x/yae = error in x/ya
+ x/ychi2 = chi squared for x/RA and y/Dec accel fit
-Optional Input:
+ pval = P value used for F Test comparison between velocity and acceleration fit, unless
otherwise stated, is set to 4.0
-Added Attributes:
+ a_xt0, a_yt0, a_x0, a_y0, a_x0e, a_y0e, a_xv, a_yv, a_xve, a_yve, a_xa, a_ya, a_xae, a_yae,
a_xchi2, a_ychi2 = set to corresponding terms from input, 'a_' denotes from the accel fit
+ a_R = projected position, calculated from x0 and y0 for accel fit
+ a_chix/yr = reduced chi^2 in x and y directions for accel fit
+ va_x/yFval = F ratio for x/RA and y/Dec between velocity and acceleration fits
+ va_x/yFprob = F distribution value corresponding to F ratio, to compare to corresponding P value
- set_jerk(self, xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xa, ya, xae, yae, xj, yj, xje, yje, xchi2, ychi2) =
sets attributes for jerk (derivative of acceleration) fit for star in both x/RA and y/Dec directions,
attributes are only set if star is measured in 5 or more epochs, calculates projected and tangential
accelerations (ar, at) and respective errors (radial and tangential in relation to Sgr A*), F Test run to
compare chi^2 between acceleration and jerk fits, only when star passed F Test between vel and accel
(whole function does not run if star does not have velocity and accel attributes, so run set_vel and
set_acc before this function), if passes F Test, star's values for its orbit are set to those for the jerk
fit (denoted by j_*) and fit attribute set to 'Jerk'
-Required Input: **Units are not specified, but need to be consistent between all inputs)
+ x/yt0 = t0 or time which is set to 0 for accel fit in x/RA and y/Dec direction
+ x/y0 = positions in x/RA and y/Dec at t0 or time is 0 for jerk fit
+ x/y0e = error in x/y0
+ x/yv = velocity term for jerk fit in x/RA and y/Dec directions
+ x/yve = error in x/yv
+ x/ya = acceleration term for jerk fit in x/RA and y/Dec directions
+ x/yae = error in x/ya
+ x/yj = jerk term for jerk fit in x/RA and y/Dec directions
+ x/yje = errors in x/yj
+ x/ychi2 = chi squared for x/RA and y/Dec accel fit
-Optional Input:
+ pval = P value used for F Test comparison between acceleration and jerk fit, unless
otherwise stated, is set to 4.0
-Added Attributes:
+ j_xt0, j_yt0, j_x0, j_y0, j_x0e, j_y0e, j_xv, j_yv, j_xve, j_yve, j_xa, j_ya, j_xae, j_yae,
j_xy, j_yj, j_xje, j_yje, j_xchi2, j_ychi2 = set to corresponding terms from input, j_' denotes
from the jerk fit
+ j_R = projected position, calculated from x0 and y0 for jerk fit
+ j_chix/yr = reduced chi^2 in x and y directions for jerk fit
+ aj_x/yFval = F ratio for x/RA and y/Dec between acceleration and jerk fits
+ aj_x/yFprob = F distribution value corresponding to F ratio, to compare to corresponding P value
'''
class one_star():
def __init__(self,sname,align,points,ak_correct=True):
self.name = sname
self.align = align
self.points = points
pointsFile = np.loadtxt(align+points+sname+'.points')
self.years = pointsFile[:,0]
self.x = pointsFile[:,1]
self.y = pointsFile[:,2]
#self.path_length = np.array([math.sqrt((self.x[i]-self.x[i+1])**2 +(self.y[i]-self.y[i+1])**2) for i in range(len(self.x)-1)])
#self.totpl = np.sum(self.path_length)
self.xe = pointsFile[:,3]
self.ye = pointsFile[:,4]
self.epoch = len(pointsFile[:,0])
self.fit = 'Point'
#search database for this star, save info about stars designated as late/early type and magnitude
database = mysql.connector.connect(host="galaxy1.astro.ucla.edu",user="dbread",passwd="t36fCEtw",db="gcg")
cur = database.cursor()
cur.execute("SELECT young, old, kp, Ak_sch FROM stars WHERE name='{0}'".format(sname))
for row in cur:
if (ak_correct==True):
self.mag = row[2] + (2.7 - row[3])
else:
self.mag = row[2]
if (row[0] == 'T'):
self.pOld = 0.0
self.pYng = 1.0
elif (row[1] == 'T'):
self.pOld = 1.0
self.pYng = 0.0
#search different table for prob of being late/early type from Do et al 2013
cur.execute("SELECT probYngSimPrior, probOldSimPrior FROM unknownSims WHERE name='{0}'".format(sname))
for row in cur:
self.pYng = row[0]
self.pOld = row[1]
#hard code certain stars as certain spectral types
if ((sname == 'S0-38') | (sname == 'S0-49') | (sname == 'S0-35') | (sname == 'S1-32')):
self.pOld = 1.0
self.pYng = 0.0
if (sname == 'S0-61'):
self.pOld = 0.0
self.pYng = 1.0
#get radial velocity information from another table in database
def get_vz(self):
database = mysql.connector.connect(host="galaxy1.astro.ucla.edu",user="dbread",passwd="t36fCEtw",db="gcg")
cur = database.cursor()
cur.execute("SELECT ddate, vlsr, vz_err FROM spectra WHERE name='{0}'".format(self.name))
tmp_date = np.array([])
tmp_vz = np.array([])
tmp_vzerr = np.array([])
for row in cur:
if ((row[1] !=0) & (row[2] != 0) & (row[2] != None)):
tmp_date = np.append(tmp_date,row[0])
tmp_vz = np.append(tmp_vz, row[1])
tmp_vzerr = np.append(tmp_vzerr, row[2])
self.vz_date = tmp_date
self.vz = tmp_vz
self.vz_err = tmp_vzerr
def set_gcows(self,gcows_status):
self.in_gcows = gcows_status
def set_vel(self, xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xchi2, ychi2):
if (self.epoch > 2):
#Set values for velocity fit
self.fit = 'Vel'
self.v_xt0 = xt0
self.v_yt0 = yt0
self.v_x0 = x0
self.v_y0 = y0
self.v_R = np.hypot(x0, y0)
self.v_x0e = x0e
self.v_y0e = y0e
self.v_xv = xv
self.v_yv = yv
self.v_xve = xve
self.v_yve = yve
self.v_xchi2 = xchi2
self.v_ychi2 = ychi2
self.v_xchi2r = self.v_xchi2 / (self.epoch - 2.0)
self.v_ychi2r = self.v_ychi2 / (self.epoch - 2.0)
vmod_xdiff = self.v_xv*(self.years[0] - self.v_xt0) - self.v_xv*(self.years[-1] - self.v_xt0)
vmod_ydiff = self.v_yv*(self.years[0] - self.v_yt0) - self.v_yv*(self.years[-1] - self.v_yt0)
self.v_modelPL = math.sqrt(vmod_xdiff**2 + vmod_ydiff**2)
self.v_xres = self.x - (self.v_x0 + self.v_xv*(self.years - self.v_xt0))
self.v_yres = self.y - (self.v_y0 + self.v_yv*(self.years - self.v_yt0))
self.v_xres_sig = self.v_xres / self.xe
self.v_yres_sig = self.v_yres / self.ye
#For now, as no other kinematic fits tested, set the star's overall kinematic constants
#to that from velocity fit
self.xt0 = xt0
self.yt0 = yt0
self.x0 = x0
self.y0 = y0
self.R = np.hypot(x0, y0)
self.x0e = x0e
self.y0e = y0e
self.xv = xv
self.yv = yv
self.xve = xve
self.yve = yve
self.xchi2 = xchi2
self.ychi2 = ychi2
self.xchi2r = self.xchi2 / (self.epoch - 2.0)
self.ychi2r = self.ychi2 / (self.epoch - 2.0)
self.modelPL = math.sqrt(vmod_xdiff**2 + vmod_ydiff**2)
self.xres = self.x - (self.v_x0 + self.v_xv*(self.years - self.v_xt0))
self.yres = self.y - (self.v_y0 + self.v_yv*(self.years - self.v_yt0))
self.xres_sig = self.v_xres / self.xe
self.yres_sig = self.v_yres / self.ye
else:
print self.name+' has less than 3 epochs, no velocity fit'
def set_acc(self, xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xa, ya, xae, yae, xchi2, ychi2,pval=4.0):
if ((self.epoch > 3) & hasattr(self, 'v_xv')):
#set values from acceleration fit
self.a_xt0 = xt0
self.a_yt0 = yt0
self.a_x0 = x0
self.a_y0 = y0
self.a_R = np.hypot(x0, y0)
self.a_x0e = x0e
self.a_y0e = y0e
self.a_xv = xv
self.a_yv = yv
self.a_xve = xve
self.a_yve = yve
self.a_xa = xa
self.a_ya = ya
self.a_xae = xae
self.a_yae = yae
#Calculate radial and tangential acceleration components in the plane of the sky
ar = ((xa*x0) + (ya*y0)) / self.a_R
at = ((xa*y0) - (ya*x0)) / self.a_R
are = (xae*x0/self.a_R)**2 + (yae*y0/self.a_R)**2
are += (y0*x0e*at/self.a_R**2)**2 + (x0*y0e*at/self.a_R**2)**2
are = np.sqrt(are)
ate = (xae*y0/self.a_R)**2 + (yae*x0/self.a_R)**2
ate += (y0*x0e*ar/self.a_R**2)**2 + (x0*y0e*ar/self.a_R**2)**2
ate = np.sqrt(ate)
self.a_ar = ar
self.a_at = at
self.a_are = are
self.a_ate = ate
self.a_xchi2 = xchi2
self.a_ychi2 = ychi2
self.a_xchi2r = self.a_xchi2 / (self.epoch - 3.0)
self.a_ychi2r = self.a_ychi2 / (self.epoch - 3.0)
amod_xdiff = self.a_xv*(self.years[0] - self.a_xt0) - self.a_xv*(self.years[-1] - self.a_xt0) + 0.5*self.a_xa*(self.years[0] - self.a_xt0)**2 - 0.5*self.a_xa*(self.years[-1] - self.a_xt0)**2
amod_ydiff = self.a_yv*(self.years[0] - self.a_yt0) - self.a_yv*(self.years[-1] - self.a_yt0) + 0.5*self.a_ya*(self.years[0] - self.a_yt0)**2 - 0.5*self.a_ya*(self.years[-1] - self.a_yt0)**2
self.a_modelPL = math.sqrt(amod_xdiff**2 + amod_ydiff**2)
self.a_xres = self.x - (self.a_x0 + self.a_xv*(self.years - self.a_xt0) + 0.5*self.a_xa*(self.years - self.a_xt0)**2)
self.a_yres = self.y - (self.a_y0 + self.a_yv*(self.years - self.a_yt0) + 0.5*self.a_ya*(self.years - self.a_yt0)**2)
self.a_xres_sig = self.a_xres / self.xe
self.a_yres_sig = self.a_yres / self.ye
#Calculating value corresponding to input P Value
signif = scipy.special.erfc(pval/math.sqrt(2.0))
#F ratio
self.va_xFval = (self.v_xchi2 - self.a_xchi2) / (self.a_xchi2/(self.epoch - 3.0))
self.va_yFval = (self.v_ychi2 - self.a_ychi2) / (self.a_ychi2/(self.epoch - 3.0))
#Corresponding values on F distribution
self.va_xFprob = stats.f.sf(self.va_xFval, 1, (self.epoch - 3.0))
self.va_yFprob = stats.f.sf(self.va_yFval, 1, (self.epoch - 3.0))
#If passes F Test, set the overall kinematic values of th star to that from the accel fit; force F test for S0-16 and S0-17
if ((self.va_xFprob < signif) | (self.va_yFprob < signif) | (self.name == 'S0-16') | (self.name == 'S0-17')):
self.fit ='Acc'
self.xt0 = xt0
self.yt0 = yt0
self.x0 = x0
self.y0 = y0
self.R = np.hypot(x0, y0)
self.x0e = x0e
self.y0e = y0e
self.xv = xv
self.yv = yv
self.xve = xve
self.yve = yve
self.xa = xa
self.ya = ya
self.xae = xae
self.yae = yae
self.ar = ar
self.at = at
self.are = are
self.ate = ate
self.xchi2 = xchi2
self.ychi2 = ychi2
self.xchi2r = self.xchi2 / (self.epoch - 3.0)
self.ychi2r = self.ychi2 / (self.epoch - 3.0)
self.modelPL = math.sqrt(amod_xdiff**2 + amod_ydiff**2)
self.xres = self.x - (self.a_x0 + self.a_xv*(self.years - self.a_xt0) + 0.5*self.a_xa*(self.years - self.a_xt0)**2)
self.yres = self.y - (self.a_y0 + self.a_yv*(self.years - self.a_yt0) + 0.5*self.a_ya*(self.years - self.a_yt0)**2)
self.xres_sig = self.a_xres / self.xe
self.yres_sig = self.a_yres / self.ye
elif ( hasattr(self, 'v_xv')==False):
print 'Need to run set_vel for '+self.name
else:
print self.name+' has less than 4 epochs, no accel fit'
def set_jerk(self, xt0, yt0, x0, y0, x0e, y0e, xv, yv, xve, yve, xa, ya, xae, yae, xj, yj, xje, yje, xchi2, ychi2,pval=4.0):
if ((self.epoch > 4) & hasattr(self, 'a_xa')):
#Set values from jerk fit
self.j_xt0 = xt0
self.j_yt0 = yt0
self.j_x0 = x0
self.j_y0 = y0
self.j_R = np.hypot(x0, y0)
self.j_x0e = x0e
self.j_y0e = y0e
self.j_xv = xv
self.j_yv = yv
self.j_xve = xve
self.j_yve = yve
self.j_xa = xa
self.j_ya = ya
self.j_xae = xae
self.j_yae = yae
#Calculate radial and tangential accelerations in the plane of the sky and errors
ar = ((xa*x0) + (ya*y0)) / self.a_R
at = ((xa*y0) - (ya*x0)) / self.a_R
are = (xae*x0/self.a_R)**2 + (yae*y0/self.a_R)**2
are += (y0*x0e*at/self.a_R**2)**2 + (x0*y0e*at/self.a_R**2)**2
are = np.sqrt(are)
ate = (xae*y0/self.a_R)**2 + (yae*x0/self.a_R)**2
ate += (y0*x0e*ar/self.a_R**2)**2 + (x0*y0e*ar/self.a_R**2)**2
ate = np.sqrt(ate)
self.j_ar = ar
self.j_at = at
self.j_are = are
self.j_ate = ate
self.j_xj = xj
self.j_yj = yj
self.j_xje = xje
self.j_yje = yje
self.j_xchi2 = xchi2
self.j_ychi2 = ychi2
self.j_xchi2r = self.j_xchi2 / (self.epoch - 4.0)
self.j_ychi2r = self.j_ychi2 / (self.epoch - 4.0)
jmod_xdiff = self.j_xv*(self.years[0] - self.j_xt0) - self.j_xv*(self.years[-1] - self.j_xt0) + 0.5*self.j_xa*(self.years[0] - self.j_xt0)**2 - 0.5*self.j_xa*(self.years[-1] - self.j_xt0)**2 + self.j_xj*(self.years[0] - self.j_xt0)**3/6.0 - self.j_xj*(self.years[-1] - self.j_xt0)**3/6.0
jmod_ydiff = self.j_yv*(self.years[0] - self.j_yt0) - self.j_yv*(self.years[-1] - self.j_yt0) + 0.5*self.j_ya*(self.years[0] - self.j_yt0)**2 - 0.5*self.j_ya*(self.years[-1] - self.j_yt0)**2 + self.j_yj*(self.years[0] - self.j_yt0)**3/6.0 - self.j_yj*(self.years[-1] - self.j_yt0)**3/6.0
self.j_modelPL = math.sqrt(jmod_xdiff**2 + jmod_ydiff**2)
self.j_xres = self.x - (self.j_x0 + self.j_xv*(self.years - self.j_xt0) + 0.5*self.j_xa*(self.years - self.j_xt0)**2 + self.j_xj*(self.years - self.j_xt0)**3/6.0)
self.j_yres = self.y - (self.j_y0 + self.j_yv*(self.years - self.j_yt0) + 0.5*self.j_ya*(self.years - self.j_yt0)**2 + self.j_yj*(self.years - self.j_yt0)**3/6.0)
self.j_xres_sig = self.j_xres / self.xe
self.j_yres_sig = self.j_yres / self.ye
#Run F test between accel and jerk, only if passes F Test between velocity and accel
if (self.fit == 'Acc'):
signif = scipy.special.erfc(pval/math.sqrt(2.0))
#Calculate corresponding value for input P value, F ratios in x and y directions, and the corresponding value on the F distribution
self.aj_xFval = (self.a_xchi2 - self.j_xchi2) / (self.j_xchi2/(self.epoch - 4.0))
self.aj_yFval = (self.a_ychi2 - self.j_ychi2) / (self.j_ychi2/(self.epoch - 4.0))
self.aj_xFprob = stats.f.sf(self.aj_xFval, 1, (self.epoch - 4.0))
self.aj_yFprob = stats.f.sf(self.aj_yFval, 1, (self.epoch - 4.0))
#If star passes F Test, set overall kinematic values for star to that from jerk fit; force F test for S0-16 and S0-17
if ((self.aj_xFprob < signif) | (self.aj_yFprob < signif) | (self.name == 'S0-16') | (self.name == 'S0-17')):
self.fit ='Jerk'
self.xt0 = xt0
self.yt0 = yt0
self.x0 = x0
self.y0 = y0
self.R = np.hypot(x0, y0)
self.x0e = x0e
self.y0e = y0e
self.xv = xv
self.yv = yv
self.xve = xve
self.yve = yve
self.xa = xa
self.ya = ya
self.xae = xae
self.yae = yae
self.ar = ar
self.at = at
self.are = are
self.ate = ate
self.xj = xj
self.yj = yj
self.xje = xje
self.yje = yje
self.xchi2 = xchi2
self.ychi2 = ychi2
self.xchi2r = self.xchi2 / (self.epoch - 4.0)
self.ychi2r = self.ychi2 / (self.epoch - 4.0)
self.modelPL = math.sqrt(jmod_xdiff**2 + jmod_ydiff**2)
self.xres = self.x - (self.j_x0 + self.j_xv*(self.years - self.j_xt0) + 0.5*self.j_xa*(self.years - self.j_xt0)**2 + self.j_xj*(self.years - self.j_xt0)**3/6.0)
self.yres = self.y - (self.j_y0 + self.j_yv*(self.years - self.j_yt0) + 0.5*self.j_ya*(self.years - self.j_yt0)**2 + self.j_yj*(self.years - self.j_yt0)**3/6.0)
self.xres_sig = self.j_xres / self.xe
self.yres_sig = self.j_yres / self.ye
elif ( hasattr(self, 'a_xa')==False):
print 'Need to run set_accel for '+self.name
else:
print self.name+' has less than 5 epochs, no jerk fit'
'''stars - class of object for set of stars in database, goes through velocity and acceleration fits
for each star (and jerk if parameter polyj is set) and sets those values for each star by using
one_star class
Required input:
- root = path of root directory
- poly = directory of polyfit results in root directory
Optional input:
- pval = corresponding P Value, set to 4 unless otherwise set
- polyj = directory of polyfit for jerk fit, if not stated, jerk values not set for star sample
Attributes:
- root = root directory set by root parameter
- poly = polyfit subdirectory
- stars = array of stars of class one_star, with attributes for velocity, acceleration, and potentially
jerk fit applied
Functions:
- sample_Like(in_GCfield=True,chainsDir='efit/chains_lessrv/',addErr=True,file='/u/schappell/Downloads/NIRC2 radial mask/nirc2_gcows_2010_all_mask.fits',
savefile='/u/schappell/code/c/gcows_field.dat',magCut=15.5,Rcut=5.0,epochs=3,sigmaCut = 3.0,chiCut=10.0,label='') = function for determining
sample of stars used in primary sample for Bayesian analysis, cuts to determine sample made in K' magnitude, number of epochs detected, projected
distance, significance of unphysical acceleration (accelerations not in the direction towards Sgr A*), non-zero probability of being late-type,
and reduced chi^2 from best kinematic fit, outputs table in .tex form with stars and their info listed (hard coded path as
/u/schappell/tables/mn_sample_table.tex), and outputs .dat file with R, acceleration in the radial direction, acceleration error, and probability
of being late type for this sample in cgs units
-Optional Input:
+ in_GCfield = select out stars which are not in designated field, defined by file parameter, set to True unless otherwise set
+ chainsDir = directory for chains from likelihood fit to S0-2/S0-38's orbit and Sgr A* parameters such as position and velocity, will be used
only if addErr is set to True
+ addErr = whether error in position is updated with uncertainty in position and velocity of Sgr A* from S0-2 and/or S0-38 orbital fit and
if error will be updated with empirically additive error to account for uncertainty from source confusion by stars below detection limit,
set to True unless otherwise stated
+ file = file path for mask, fits file, of GCOWS footprint in form of pixels
+ savefile = file path of resulting output file with list of x and y positions, in pixels, which are in GCOWS field
+ magCut = limit in K' magnitude of stars considered for sample, set to 15.5 unless otherwise stated
+ Rcut = cut in projected distance, in arcsec, 5.0 unless otherwise stated
+ epochs = cut in number of epochs detected, 3 unless otherwise stated
+ sigmaCut = cut in sigma used to cut out stars with significant unphysical accelerations, or accelerations not in direction towards Sgr A*, set to
3.0 unless otherwise stated
+ chiCut = cut to reduced chi^2 in x and y direction, applied to best kinematic fit (velocity, acceleration, or jerk), set to 10.0 unless otherwise
stated
+ label = string value of flag added to outputted .dat files with sample information
- schodel_samp(label='',innerCut=5.0,outerCut=15.0,magCut=17.75,lmagCut=0.0) = determines sample from Schodel et al 2010 work, stored in database and outputs
a .dat file with projected positions listed (in cm) and probability of being late-type all set to 1 (assumed to be late-type), cuts in outer
and inner projected distance used, as well as magnitude cuts
-Optional Input:
+ label = label for .dat file, string value, blank unless otherwise stated
+ innerCut = inner radius cut, in arcsec, set to 5 unless changed
+ outerCut = outer radius cut, in arcsec, set to 15 unless otherwise stated
+ magCut = higher magnitude cut in K', 17.75 unless changed
+ lmagCut = lower magnitude cut in K', 0.0 unless changed
- run_MN(,label_in='',label_out='',innerCut=5.0,Rcut=5.0,outerCut=15.0,mnAlpha=6.0,mnDelta=4.0,mnBreak=0.5,max_r=5.0,situation=3,nonRadial=1) = compiles C++ code for
likelihood analysis using MultiNest and runs it with inputted star samples
-Optional Input:
+ label_in = string value, label of GCOWS and Schodel samples (.dat files) to be used for likelihood analysis, should be same label for both
+ label_out = label of resulting files from MultiNest, such as the posterior
+ innerCut = inner cut, in projected radius, arcsec, for Schodel sample, should be equal to or greater than Rcut to avoid stars being double counted
+ Rcut = outer radius cut for GCOWS sample
+ outerCut = outer radius cut for Schodel sample, make sure value is consistent with values used for Schodel sample construction
+ mnAlpha/Delta/Break = values for set Alpha, Delta, and Break radius for broken power law fit in likelihood analysis, if situation is set to 1 or 2
then these values are set and only gamma is left as free parameter, break radius is in pc
+ max_r = maximum radius, in pc, integrated to in likelihood analysis, set to 5 pc unless otherwise stated
+ situation = value between 1 and 4, even numbers only use GCOWS sample, no Schodel, odd values use both GCOWS and Schodel sample, situations 1 and 2
only leave gamma as free parameter, Alpha, Delta, and break radius are set to input values, while all 4 parameters are left free for situations
3 and 4, situation set to 3 or use both GCOWS and Schodel samples and leave all 4 parameters free in broken power law
+ nonRadial = whether it is required that GCOWS sample be in GCOWS footprint, if set to 1, this is required, as well as sample be within projected radius
cut and footprint is used in likelihood analysis if set to 0 only requirement is being within projected radius
- in_gcows(file='/u/schappell/Downloads/NIRC2 radial mask/nirc2_gcows_2010_all_mask.fits',savefile='/u/schappell/code/c/gcows_field.dat') = cycles through stars in
sample and determines which are in GCOWS footprint by turning their arcsec positions into pixels in mask, sets set_gcows values for stars
-Optional Input:
+ file = path for mask used
+ savefile = path for file to be outputted with list of pixels that are within mask
- updateErr_all(chainsDir=None,addErr=False) = controls updating error for both the uncertainty in position and velocity of Sgr A* from star orbital fit and from
empirically found additive error to account for source confusion caused by stars below detection limit, each update in error can only be done once,
attributes are checked to make sure not run twice or more, plot showing additive error as a function of magnitude is created, as well as comparison
between distribution of tangential acceleration before and after additive error is applied to sample
-Optional Input:
+ chainsDir = directory which contains chains with proper motion fit and errors to Sgr A*, if left as None, this error will not be added in quadrature
to stellar errors in position
+ addErr = determines if empirical additive error is added in quadrature to acceleration uncertainties
- all_vz = cycles through stars and runs get_vz function in one_star class to load radial velocity information for all stars which have it
- plot_V_vs_R(inner=1.0) = plots combined velocity vs projected radius for early and late-type stars, only consider stars outside of given inner radius (inner), stars with
radial velocity measurements and with reduced chi^2 less than 10 in both X and Y directions. For every star, total velocity is calculated from proper motion
in the plane of the sky and the RV measurement with the smallest error. Plots show stars binned in phase space and scatter plots separated by early and late type stars.
-Optional Input:
+ inner = inner projected radius cut (in arcsec) only stars outside of this radius are considered and plotted
-plot_chi2r = creates and sabes various plots for chi^2 (reduced) diagnostics, including histograms of reduced chi^2 in X and Y directions, chi^2_reduced vs projected R,
vs magnitude (K'), vs number of epochs, histograms of chi^2_reduded with the limits of K' < 15.5, R < 5arcsec, and non-zero probability of being late type,
and plot of average reduced chi^2 vs epoch number
'''
class stars():
def __init__(self,root,poly,points,pointsj=None,polyj=None,pval=4.0):
self.root = root
self.poly = poly
#call in velocity info
vel_fit = asciidata.open(self.root + self.poly + 'fit.linearFormal')
vel_t0 = asciidata.open(self.root + self.poly + 'fit.lt0')
v_xt0 = vel_t0[1].tonumpy()
v_yt0 = vel_t0[2].tonumpy()
v_names = vel_fit[0].tonumpy()
v_x0 = vel_fit[1].tonumpy()
v_xv = vel_fit[2].tonumpy()
v_x0e = vel_fit[3].tonumpy()
v_xve = vel_fit[4].tonumpy()
v_xchi2 = vel_fit[5].tonumpy()
v_y0 = vel_fit[7].tonumpy()
v_yv = vel_fit[8].tonumpy()
v_y0e = vel_fit[9].tonumpy()
v_yve = vel_fit[10].tonumpy()
v_ychi2 = vel_fit[11].tonumpy()
#call in acceleration info
acc_fit = asciidata.open(self.root + self.poly + 'fit.accelFormal')
acc_t0 = asciidata.open(self.root + self.poly + 'fit.t0')
a_xt0 = acc_t0[1].tonumpy()
a_yt0 = acc_t0[2].tonumpy()
a_names = acc_fit[0].tonumpy()
a_x0 = acc_fit[1].tonumpy()
a_xv = acc_fit[2].tonumpy()
a_xa = acc_fit[3].tonumpy()
a_x0e = acc_fit[4].tonumpy()
a_xve = acc_fit[5].tonumpy()
a_xae = acc_fit[6].tonumpy()
a_xchi2 = acc_fit[7].tonumpy()
a_y0 = acc_fit[9].tonumpy()
a_yv = acc_fit[10].tonumpy()
a_ya = acc_fit[11].tonumpy()
a_y0e = acc_fit[12].tonumpy()
a_yve = acc_fit[13].tonumpy()
a_yae = acc_fit[14].tonumpy()
a_ychi2 = acc_fit[15].tonumpy()
#call in jerk fit if polyfit for jerk directory given
if (polyj!=None):
jerk_fit = asciidata.open(self.root + polyj + 'fit.accelFormal')
jerk_t0 = asciidata.open(self.root + polyj + 'fit.t0')
j_xt0 = jerk_t0[1].tonumpy()
j_yt0 = jerk_t0[2].tonumpy()
j_names = jerk_fit[0].tonumpy()
j_x0 = jerk_fit[1].tonumpy()
j_xv = jerk_fit[2].tonumpy()
j_xa= jerk_fit[3].tonumpy()
j_xj = jerk_fit[4].tonumpy()
j_x0e = jerk_fit[5].tonumpy()
j_xve = jerk_fit[6].tonumpy()
j_xae = jerk_fit[7].tonumpy()
j_xje = jerk_fit[8].tonumpy()
j_xchi2 = jerk_fit[9].tonumpy()
j_y0 = jerk_fit[11].tonumpy()
j_yv = jerk_fit[12].tonumpy()
j_ya = jerk_fit[13].tonumpy()
j_yj = jerk_fit[14].tonumpy()
j_y0e = jerk_fit[15].tonumpy()
j_yve = jerk_fit[16].tonumpy()
j_yae = jerk_fit[17].tonumpy()
j_yje = jerk_fit[18].tonumpy()
j_ychi2 = jerk_fit[19].tonumpy()
self.stars = np.array([])
#cycle through stars in database
for i in range(len(v_x0)):
tmpname = str(v_names[i])
tmpStar = one_star(tmpname,self.root,points)
#set velocity terms
tmpStar.set_vel(v_xt0[i], v_yt0[i], v_x0[i], v_y0[i], v_x0e[i], v_y0e[i], v_xv[i], v_yv[i], v_xve[i], v_yve[i], v_xchi2[i], v_ychi2[i])
for j in range(len(a_x0)):
accname = str(a_names[j])
if (tmpname == accname):
#if has acceleration term, set it using one_star class
tmpStar.set_acc(a_xt0[j], a_yt0[j], a_x0[j], a_y0[j], a_x0e[j], a_y0e[j], a_xv[j], a_yv[j], a_xve[j], a_yve[j], a_xa[j], a_ya[j], a_xae[j], a_yae[j], a_xchi2[j], a_ychi2[j],pval=pval)
if (polyj!=None):
for k in range(len(j_x0)):
jerkname = str(j_names[k])
if (tmpname == jerkname):
#if star has jerk terms, set it using one_star class
tmpStar.set_jerk(j_xt0[k], j_yt0[k], j_x0[k], j_y0[k], j_x0e[k], j_y0e[k], j_xv[k], j_yv[k], j_xve[k], j_yve[k], j_xa[k], j_ya[k], j_xae[k], j_yae[k], j_xj[k], j_yj[k], j_xje[k], j_yje[k], j_xchi2[k], j_ychi2[k],pval=pval)
self.stars = np.append(self.stars, tmpStar)
def sample_Like(self,in_GCfield=True, chainsDir='efit/chains_lessrv/', addErr=True,file='/u/schappell/Downloads/NIRC2 radial mask/nirc2_gcows_2010_all_mask.fits',savefile='/u/schappell/code/c/gcows_field.dat',magCut=15.5, lmagCut=0.0, Rcut=5.0, accelRcut=2.5,epochs=3,sigmaCut = 3.0, chiCut = 7.0,label=''):
#if param set, find which stars are in GCOWS footprint, and update errors
if (in_GCfield == True):
self.in_gcows(file=file, savefile=savefile)
self.updateErr_all(chainsDir=chainsDir,addErr=addErr)
samp_name = np.array([])
samp_epoch = np.array([])
samp_mag = np.array([])
samp_pOld = np.array([])
samp_R = np.array([])
samp_x = np.array([])
samp_xe = np.array([])
samp_y = np.array([])
samp_ye = np.array([])
samp_xv = np.array([])
samp_yv = np.array([])
samp_xve = np.array([])
samp_yve = np.array([])
samp_fit = np.array([])
samp_ar = np.array([])
samp_are = np.array([])
samp_at = np.array([])
samp_ate = np.array([])
samp_xchi2r = np.array([])
samp_ychi2r = np.array([])
samp_xchi2r_a = np.array([])
samp_ychi2r_a = np.array([])
samp_modelPL = np.array([])
samp_xres = np.array([])
samp_yres = np.array([])
samp_xres_quad = np.array([])
samp_yres_quad = np.array([])
samp_t0 = np.array([])
#begin tex file for output table
out = open(tableRoot+'mn_accel_sample_table.tex','w')
#out.write('\\documentclass{aastex} \n')
out.write('\\setlength{\\tabcolsep}{4pt} \n')
#out.write('\\usepackage{graphicx,longtable,pdflscape,threeparttablex} \n')
#out.write('\\usepackage[labelsep=space]{caption} \n')
#out.write('\\begin{document} \n')
out.write('\\scriptsize \n')
#out.write('\\begin{landscape} \n')
out.write('\\begin{ThreePartTable} \n')
out.write('\\begin{TableNotes} \n')
out.write('\\item [a] Corrected for differential extinction to a mean extinction of 2.7 magnitudes \n')
out.write('\\item [b] Number of epochs \n')
#out.write('\\item [b] Only reported for stars with trusted measured accelerations, see section \\ref{sec:sample} \n')
out.write('\\item [c] Probability of being late-type, reported in \\citet{do13l} \n')
#out.write('\\item [d] Best kinematic fit, determined by F Tests \n')
out.write('\\item [d] Average $\chi^2_r$ between $X$ and $Y$ direction for the best kinematic fit \n')
out.write("\\item [e] Radial acceleration at a star's given projected radius, assuming line-of-sight distance is zero, divided by the star's error in radial acceleration \n")
out.write('\\end{TableNotes} \n')
out.write('\\begin{longtable}{*{14}{c}} \n')
out.write("\\caption{Stars in Inner Sample}\\label{tab:like_accel_samp_data} \n")
#out.write('\\hline \n')
out.write('\\hline \n')
#out.write("Star & K' & R$_{2D}$ & n\\tnote{a} & T$_0$ & X & Y & $v_x$ & $v_y$ & $a_r$ & $a_t$ & $j_x$ & $j_y$ & $p_{old}$\\tnote{b} & Fit\\tnote{c} & $\chi^2_r$\\tnote{d} & $a_r(R,z=0)/\sigma_R}$\\tnote{e} \\\\ \n")
#out.write("& & (arcsec) & & (yrs) & \\multicolumn{3}{c}{(arcsec)} & \\multicolumn{2}{c}{(mas/yr)} & \\multicolumn{2}{c}{($\mu$as/yr$^2$)} & \\multicolumn{2}{c}{($\mu$as/yr$^3$)} & & & \\\\\ \n")
out.write("Star & K'\\tnote{a} & n\\tnote{b} & X & Y & R$_{2D}$ & t_0 & $v_x$ & $v_y$ & $a_r$ & $a_t$ & $p_{old}$\\tnote{c} & $\chi^2_r$\\tnote{d} & $a_{r,min}/\sigma_r$\\tnote{e} \n")
out.write(" & & & & \\multicolumn{3}{c}{(arcsec)} & (years) & \\multicolumn{2}{c}{($\mu$as/yr)} & \\multicolumn{2}{c}{($\mu$as/yr$^2$)} & & & & \n")
#out.write('\\\\ \n')
out.write('\\hline \n')
out.write('\\midrule\\endhead \n')
out.write('\\bottomrule\\endfoot \n')
#format for output data to table
#fmt_wj = '%15s %1s %5.1f %1s %5.1f %1s %5.1f %1s %5.1f %1s %2d %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.1f %5s %6.1f %1s %6.1f %5s %6.1f %1s %6.2f %1s %5s %1s %6.2f %4s\n'
# fmt_noj = '%15s %1s %5.1f %1s %5.1f %1s %5.1f %1s %5.1f %1s %2d %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %5s %1s %5s %1s %6.2f %1s %5s %1s %6.2f %4s\n'
fmt_wa = '%15s %1s %5.1f %1s %2d %1s %6.2f %5s %6.2f %1s %6.2f %5s %6.2f %1s %6.2f %1s %6.2f %1s %6.1f %5s %6d %1s %6.1f %5s %6d %1s %6.1f %5s %6d %1s %6.1f %5s %6d %1s %6.2f %1s %6.1f %1s %6.2f %4s\n'
fmt_noa = '%15s %1s %5.1f %1s %2d %1s %6.1f %5s %6.1f %1s %6.1f %5s %6.1f %1s %6.1f %1s %6.2f %1s %6.1f %5s %6d %1s %6.1f %5s %6d %1s %5s %1s %5s %1s %6.2f %1s %6.1f %1s %5s %4s\n'
for tmpStar in self.stars:
if (hasattr(tmpStar,'a_ar') & hasattr(tmpStar,'pOld')):
if ((tmpStar.mag < magCut) & (tmpStar.mag >= lmagCut) & (tmpStar.R < Rcut) & (tmpStar.epoch > epochs) & (tmpStar.pOld > 0.0)):
#cycle through stars in inner sample
if (hasattr(tmpStar,'ar')):
tmp_ar = tmpStar.ar
tmp_are = tmpStar.are
tmp_at = tmpStar.at
tmp_ate = tmpStar.ate
else:
tmp_ar = tmpStar.a_ar
tmp_are = tmpStar.a_are
tmp_at = tmpStar.a_at
tmp_ate = tmpStar.a_ate
if (in_GCfield==True):
if (tmpStar.in_gcows==1):
#for 5sig cut, be careful to only do this once and not to run it multiple times
#sig5dex = np.where((tmpStar.xres_sig >= 5.0) | (tmpStar.yres_sig >= 5.0))[0]
#if len(sig5dex) >= 1:
# use5dex = np.where((np.abs(tmpStar.xres_sig) < 5.0) & (np.abs(tmpStar.yres_sig) < 5.0))[0]
# np.savetxt('/g/ghez/align/schappell_14_06_18/points_5sig/'+str(tmpStar.name)+'.points',np.transpose([tmpStar.years[use5dex],tmpStar.x[use5dex],tmpStar.y[use5dex],tmpStar.xe[use5dex],tmpStar.ye[use5dex]]),delimiter=' ')
samp_name = np.append(samp_name,tmpStar.name)
samp_epoch = np.append(samp_epoch,tmpStar.epoch)
samp_mag = np.append(samp_mag,tmpStar.mag)
samp_pOld = np.append(samp_pOld,tmpStar.pOld)
samp_R = np.append(samp_R,tmpStar.R)
if (str(tmpStar.fit) == 'Vel'):
samp_fit = np.append(samp_fit,1.0)
elif (str(tmpStar.fit) == 'Acc'):
samp_fit = np.append(samp_fit,2.0)
elif (str(tmpStar.fit) == 'Jerk'):
samp_fit = np.append(samp_fit,3.0)
#add to array of eventual output radial acceleration, error, etc
samp_ar = np.append(samp_ar,tmp_ar)
samp_are = np.append(samp_are,tmp_are)
samp_at = np.append(samp_at,tmp_at)
samp_ate = np.append(samp_ate,tmp_ate)
samp_xchi2r = np.append(samp_xchi2r,tmpStar.xchi2r)
samp_ychi2r = np.append(samp_ychi2r,tmpStar.ychi2r)
samp_xv = np.append(samp_xv,tmpStar.xv)
samp_yv = np.append(samp_yv,tmpStar.yv)
samp_xe = np.append(samp_xe,tmpStar.x0e)
samp_ye = np.append(samp_ye,tmpStar.y0e)
samp_xve = np.append(samp_xve,tmpStar.xve)
samp_yve = np.append(samp_yve,tmpStar.yve)
samp_x = np.append(samp_x,tmpStar.x0)
samp_y = np.append(samp_y,tmpStar.y0)
samp_t0 = np.append(samp_t0,tmpStar.xt0)
samp_modelPL = np.append(samp_modelPL,tmpStar.modelPL)
samp_xres = np.append(samp_xres, tmpStar.xres_sig)
samp_yres = np.append(samp_yres, tmpStar.yres_sig)
samp_xres_quad = np.append(samp_xres_quad, math.sqrt(np.sum(tmpStar.xres_sig**2)))
samp_yres_quad = np.append(samp_yres_quad, math.sqrt(np.sum(tmpStar.yres_sig**2)))
#write to tex file row of desired info for each star
samp_arz0 = GM_as_yr / samp_R**2
tmpsort = np.argsort(samp_R)#-samp_arz0/samp_are)
for i in tmpsort:
if ((samp_epoch[i] > 27) & (samp_name[i] != 'S3-327') & (samp_name[i] != 'S5-53') & (samp_name[i] != 'S6-68') & (samp_name[i] != 'S6-61') & (samp_name[i] != 'S6-74') & (samp_name[i] != 'S6-53') & (samp_name[i] != 'S5-69') & (samp_name[i] != 'S3-136') & (samp_name[i] != 'S3-279') & (samp_name[i] != 'S3-125') & (samp_name[i] != 'S3-200') & (samp_name[i] != 'S3-15') & (samp_name[i] != 'S2-117') & (samp_name[i] != 'S1-45')):
out.write(fmt_wa % (samp_name[i],'&',samp_mag[i],'&',samp_epoch[i],'&',samp_x[i],'$\pm$',samp_xe[i],'&',samp_y[i],'$\pm$',samp_ye[i],'&',samp_R[i],'&',samp_t0[i],'&',samp_xv[i]*1e6,'$\pm$',samp_xve[i]*1e6,'&',samp_yv[i]*1e6,'$\pm$',samp_yve[i]*1e6,'&',samp_ar[i]*1e6,'$\pm$',samp_are[i]*1e6,'&',samp_at[i]*1e6,'$\pm$',samp_ate[i]*1e6,'&',samp_pOld[i],'&',(samp_xchi2r[i]+samp_ychi2r[i])/2.0,'&',samp_arz0[i]/samp_are[i],'\\\\'))
else:
out.write(fmt_noa % (samp_name[i],'&',samp_mag[i],'&',samp_epoch[i],'&',samp_x[i],'$\pm$',samp_xe[i],'&',samp_y[i],'$\pm$',samp_ye[i],'&',samp_R[i],'&',samp_t0[i],'&',samp_xv[i]*1e6,'$\pm$',samp_xve[i]*1e6,'&',samp_yv[i]*1e6,'$\pm$',samp_yve[i]*1e6,'&','-','&','-','&',samp_pOld[i],'&',(samp_xchi2r[i]+samp_ychi2r[i])/2.0,'&','-','\\\\'))
out.write('\\hline \n')
out.write('\\insertTableNotes \n')
out.write('\\end{longtable} \n')
out.write('\\end{ThreePartTable} \n')
out.write('\\end{landscape} \n')
out.write('\\end{document} \n')
out.close()
#close tex table file
#begin tex file for output table
#out = open(tableRoot+'mn_inner_sample_table.tex','w')
#out.write('\\begin{ThreePartTable} \n')
#out.write('\\begin{TableNotes} \n')
#out.write('\\item [a] Number of epochs \n')
#out.write('\\item [b] Probability of being late-type, reported in \\citet{do13l} \n')
#out.write('\\item [c] Best kinematic fit, determined by F Tests \n')
#out.write('\\item [d] Average $\chi^2_r$ between $X$ and $Y$ direction for the best kinematic fit \n')
#out.write('\\end{TableNotes} \n')
#out.write('\\begin{longtable}{*{13}{c}} \n')
#out.write("\\caption{Stars in Primary Sample}\\label{tab:like_samp_data} \n")
#out.write('\\hline \n')
#out.write("Star & K' & X & Y & R$_{2D}$ & n\\tnote{a} & $v_x$ & $v_y$ & $p_{old}$\\tnote{b} & Fit\\tnote{c} & $\chi^2_r$\\tnote{d} \n")
#out.write("&& & \\multicolumn{3}{c}{(arcsec)} & & \\multicolumn{2}{c}{($\mu$as/yr)} & & & \n")
#out.write('\\hline \n')
#out.write('\\midrule\\endhead \n')
#out.write('\\bottomrule\\endfoot \n')
#fmt_noa = '%15s %1s %5.1f %1s %5.1f %1s %5.1f %1s %5.1f %1s %2d %1s %6.1f %5s %6.1f %1s %6.1f %5s %6.1f %1s %6.2f %1s %5s %1s %6.2f %4s\n'
#out.write(fmt_noa % (tmpStar.name,'&',tmpStar.mag,'&',tmpStar.x0,'&',tmpStar.y0,'&',tmpStar.R,'&',tmpStar.epoch,'&',tmpStar.xv*1e6,'$\pm$',tmpStar.xve*1e6,'&',tmpStar.yv*1e6,'$\pm$',tmpStar.yve*1e6,'&',tmpStar.pOld,'&',tmpStar.fit,'&',(tmpStar.xchi2r+tmpStar.ychi2r)/2.0,'\\\\'))
#out.write('\\hline \n')
#out.write('\\insertTableNotes \n')
#out.write('\\end{longtable} \n')
#out.write('\\end{ThreePartTable} \n')
#out.write('\\end{landscape} \n')
#out.write('\\end{document} \n')
#out.close()
#close tex table file
#selects stars with reduced chi^2 and unphysical accelerations with significance below set cuts
#flagdex = np.where((samp_xchi2r < chiCut) & (samp_ychi2r < chiCut) & ((samp_ar/samp_are) < sigmaCut) & (np.abs(samp_at/samp_ate) < sigmaCut) & (samp_fit > 1.0))[0]
forAG = np.where((samp_xchi2r < chiCut) & (samp_ychi2r < chiCut) & ((samp_ar/samp_are) < sigmaCut) & (np.abs(samp_at/samp_ate) < sigmaCut))[0]
AG37 = np.where((samp_xchi2r < chiCut) & (samp_ychi2r < chiCut) & ((samp_ar/samp_are) < sigmaCut) & (np.abs(samp_at/samp_ate) < sigmaCut) & (samp_epoch > 37))[0]
nonphys = np.where(((samp_ar/samp_are) >= sigmaCut) | (np.abs(samp_at/samp_ate) >= sigmaCut))[0]
grt_chi2r = np.maximum(samp_xchi2r,samp_ychi2r)
resdex = np.where((samp_name == 'S3-327') | (samp_name == 'S5-53') | (samp_name == 'S6-68') | (samp_name == 'S6-61') | (samp_name == 'S6-74') | (samp_name == 'S6-53') | (samp_name == 'S5-69') | (samp_name == 'S3-136') | (samp_name == 'S3-279') | (samp_name == 'S3-125') | (samp_name == 'S3-200') | (samp_name == 'S3-15') | (samp_name == 'S2-117') | (samp_name == 'S1-45'))[0]
flagdex = np.where((samp_epoch > 27) & (samp_name != 'S3-327') & (samp_name != 'S5-53') & (samp_name != 'S6-68') & (samp_name != 'S6-61') & (samp_name != 'S6-74') & (samp_name != 'S6-53') & (samp_name != 'S5-69') & (samp_name != 'S3-136') & (samp_name != 'S3-279') & (samp_name != 'S3-125') & (samp_name != 'S3-200') & (samp_name != 'S3-15') & (samp_name != 'S2-117') & (samp_name != 'S1-45'))[0] #samp_modelPL > 0.128)[0]
upLim = np.where((samp_ar + 3.0*samp_are) <= 0.0)[0]
#accel_names = np.array([samp_name[ii] for ii in flagdex])
#percent accel sample by radius
perc_hist = np.zeros(5)
perc_bins = np.array([0.0,1.0,2.0,3.0,4.0,5.0])
for i in range(5):
tmpdex_acc = np.where((samp_R[flagdex] >= perc_bins[i]) & (samp_R[flagdex] < perc_bins[i+1]))[0]
tmpdex = np.where((samp_R >= perc_bins[i]) & (samp_R < perc_bins[i+1]))[0]
perc_hist[i] = float(len(tmpdex_acc))/len(tmpdex)
pdb.set_trace()
py.close()
py.bar([0.5,1.5,2.5,3.5,4.5],perc_hist,width=1.0)
py.xlabel('Radius (arcsec)')
py.ylabel('Percent in accel sample')
py.savefig(plotRoot+'perc_accel_samp_R_hist.png')
py.close()
pass_ft = np.where(samp_fit > 1.0)[0]
py.clf()
py.plot(samp_R,samp_arz0/samp_are,'.',label='Inner Sample')
py.plot(samp_R[pass_ft],samp_arz0[pass_ft]/samp_are[pass_ft],'.',label='Pass F-Test')
py.xlabel('R$_{2D}$ (as)')
py.ylabel(r'|a$_R$(z=0)| / $\sigma_R$')
py.legend()
py.savefig(plotRoot+'arz0_are_R2d.png')
py.clf()
py.errorbar(samp_at[flagdex]*1e6,samp_ar[flagdex]*1e6,xerr=samp_ate[flagdex]*1e6,yerr=samp_are[flagdex]*1e6,fmt='.')
py.xlabel(r'a$_T$ ($\mu$as/yr$^2$)')
py.ylabel(r'a$_R$ ($\mu$as/yr$^2$)')
py.savefig(plotRoot+'at_ar_sample.png')
py.clf()
py.Circle((0,0),3)
#py.plot(samp_at/samp_ate,samp_ar/samp_are,'.',label='Inner Sample')
py.plot(samp_at[flagdex]/samp_ate[flagdex],samp_ar[flagdex]/samp_are[flagdex],'o',label='Accel Sample')
py.xlabel(r'a$_T$ / $\sigma_T$')
py.ylabel(r'a$_R$ / $\sigma_R$')
#py.legend()
py.savefig(plotRoot+'at_ar_sigma.png')
py.clf()
py.hist(samp_ar[flagdex]*1e6,bins=10)
py.xlabel(r'a$_R$ ($\mu$as/yr$^2$)')
py.savefig(plotRoot+'ar_hist_sample.png')
py.clf()
py.hist(samp_at[flagdex]*1e6,bins=10)
py.xlabel(r'a$_T$ ($\mu$as/yr$^2$)')
py.savefig(plotRoot+'at_hist_sample.png')
py.clf()
py.errorbar(samp_R[flagdex],samp_ar[flagdex]*1e6,yerr=samp_are[flagdex]*1e6,fmt='.')
py.xlabel(r'R$_2D$ (as)')
py.ylabel(r'a$_R$ ($\mu$as/yr$^2$)')
py.savefig(plotRoot+'ar_R_samp.png')
py.clf()
py.errorbar(samp_R[flagdex],samp_at[flagdex]*1e6,yerr=samp_ate[flagdex]*1e6,fmt='.')
py.xlabel(r'R$_2D$ (as)')
py.ylabel(r'a$_T$ ($\mu$as/yr$^2$)')
py.savefig(plotRoot+'at_R_samp.png')
py.clf()
rbins = np.arange(0.0,5.1,0.5)
rmid = np.zeros(len(rbins)-1)
ave_epoch = np.zeros(len(rbins)-1)
for i in range(len(rbins)-1):
rtdex = np.where((samp_R > rbins[i]) & (samp_R <= rbins[i+1]))[0]
ave_epoch[i] = np.average(samp_epoch[rtdex])
rmid[i] = (rbins[i] + rbins[i+1])/2.0
py.clf()
py.plot(rmid,ave_epoch)
py.xlabel('R (as)')
py.ylabel('Average epoch')
py.savefig(plotRoot+'ave_epoch.png')
py.clf()
py.plot(samp_epoch,grt_chi2r,'.',label='Inner Sample')
py.plot(samp_epoch[nonphys],grt_chi2r[nonphys],'o',label='Sig Non-phys')
py.legend(numpoints=1)