-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotCorrelationMap14.py
More file actions
executable file
·1858 lines (1477 loc) · 70.5 KB
/
Copy pathplotCorrelationMap14.py
File metadata and controls
executable file
·1858 lines (1477 loc) · 70.5 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
#!/usr/bin/env python
"""
By David French (frenchd@astro.wisc.edu)
$Id: plotCorrelationMap14.py, v 14 06/13/18
This program takes in a list of AGN targets and generates an environment map (i.e. nearby
galaxies) for each.
Adapted from:
'
plotAGNCorrelationSquare9.py, v 9.0 02/12/2014
Make a square plot showing the positions of correlated galaxies around a target AGN
Starts with the older 'plotAGNCorrelationSquare6.py' and makes adjustments for the current
data.
v8: include inclinations in galaxy annotation tags
v9: plots all targets in the input file, and does everything better faster
'
v1: Removes group vs field galaxy bits
v2: Draw ellipses to denote inclination and position angle at the same time
v3: Make nicer plots for poster (09/10/14)
v4: change the labeling for individual plots (09/11/14)
v5: adopt to make plots for general correlation tables
v6: include option to make skyplot as well (plot just the ra and dec of all objects)
This was final AAS poster version, made targetmaps3
v7: More general version - 06/19/15
v7.1: Now saves into 'ambiguous' or 'associated' folders depending on the 'include' answer
- 06/25/15
7.2: Reverse PA direction. Now PA is measured clockwise from N (up) to E (on right). This
changes angle = float(PA[i]) to angle = float(-PA[i]) in plotting
Also changed the name annotation slightly, to xy=(-60, size[i]/6) from
xy=(-65, size[i]/4), and unknown type marker size increased to size[i]*4
E type galaxies now have no edge, spiral have black edges, unknown are diamonds
- 07/07/15
- unfortunately, this version was still named "plotCorrelationMap7_1.py".
7.3: Sort the map table by the quantity: abs(dif_velocity)*impact parameter/virial radius
- low means the galaxy in question close in both velocity and distance. These get
listed first.
7.4: Same as above, but tweaking the "likelihood" parameter to the following:
abs(dif_velocity) * (impact parameter - virial radius)
7.5: Now the likelihood parameter is:
abs(dif_velocity) * (impact parameter - virial radius) / (virial radius)**2
if this value is >2 times the next largest, call it associated and put it in that folder
11/6/15: (approximate date) Now use a gaussian form likelihood parameter, and take
the velocity difference into account as well (normalized to 200 km/s)
-looks like: exp((impact/virial)^2) * exp((vel_dif/200)^2) - Targetmaps12
11/11/15: continued with more tweaks to try to get satellite galaxies to be rated
lower. Targetmaps13 uses diam^1.4 instead of a virial radius
Targetmaps14 uses diam^1.5
11/15/15: Targetmaps15 uses diam^1.5, and multiplies likelihood by 2 if the virial
radius is larger than the impact parameter
Targetmaps16 requires 3* greater likelihood for associated tag
Targetmaps17 back to standard virial radius, but with the above tweaks for
multiplying likelihood *2 and requiring 3* difference
11/17/15: Targetmaps18 back to diam^1.5, and now with 5* difference required
11/19/15: Targetmaps19 uses standard r_vir, but requires a 5* difference
v8.0: Computes both standard R_vir and diam^1.5 results. Adds the results automatically to
LG_correlation_combined5.csv,
v9.0: velocity colormap in units of delta-v instead of absolute velocity units
v9.1: 'include' now requires a hard L limit (L>=0.001 etc)
v10: correlate with galaxy v_helio, not vcorr - using correlateSingle7 now
- (03/24/16 - 4/13/16)
v11: moved to .../inclination/git_inclination/ so it can be updated with git, and
now including rc tex formating for the plots (05/12/2016)
v11.1: updates for the newest round of sightlines in LG_correlation_combined5_10.csv
- Made LG_correlation_combined5_11.csv and targetmaps34 (07/06/16)
v11.2: minor formatting updates. (8/08/16)
v11.3: more minor updates - make the tick labels NOT bold (10/03/16)
- make LG_correlation_combined5_11_25cut_edit5.csv and targetmaps37/
v11.3: more minor updates - fix the colorbar bolded ticks problem (10/10/16)
- remake LG_correlation_combined5_11_25cut_edit5.csv and targetmaps37/
v11.4: removes the 'include_folder' for saving - saves everything in the same general
directory, so you don't have to fuss around when doing single correlations
(1/16/17)
v11.5: include the speed of light for converting from redshift, upgrade to
correlateSingle9.py - uses the newest galaxy table (7/21/17)
v12: this comes from plotCorrelationMap_single.py -> specifically made to plot single
galaxy maps instead of from a big list, for the metals project (Taesun?)
Adapting to make this more flexible. Now you can plot single or multiple from a file
or list. You can also include both galaxies and AGN as both center targets AND/OR
included in the environment field
v13: version12 incorrectly plots the orientation of galaxies. They need to be reflected
over the RA axis, and the axis does also. This will match east to the left standard
for astronomical images. (12/06/17)
v13.1: diamonds were plotted backwards (-PA), fixed this. (12/18/17)
v14: Fix colorbar direction (i.e., red = redshifted), update for the full and final
targetlist: correlatedTargetList_5_29_18_measurements.csv (06/13/18)
"""
import sys
import os
import csv
import string
import math
import ast
from pylab import *
import correlateSingle11 as correlateSingle
from matplotlib.patches import Ellipse
from utilities import *
import getpass
from matplotlib import rc
fontScale = 18
rc('text', usetex=True)
rc('font', size=18,family='serif',weight='medium')
rc('xtick.major',size=8,width=0.6)
rc('xtick.minor',size=5,width=0.6)
rc('ytick.major',size=8,width=0.6)
rc('ytick.minor',size=5,width=0.6)
rc('xtick',labelsize = fontScale)
rc('ytick',labelsize = fontScale)
rc('axes',labelsize = fontScale)
rc('xtick',labelsize = fontScale)
rc('ytick',labelsize = fontScale)
# rc('font', weight = 450)
# rc('axes',labelweight = 'bold')
rc('axes',linewidth = 1,labelweight='normal')
rc('axes',titlesize='small')
################################################################
def buildTargetList(file,AGNheader,velocityHeader):
# builds a list consisting of tuples: (AGNname, velocity, include)
#
# requires a column called 'galaxyName' in the file. Only includes targets for which
# 'galaxyName' != 'x'
#
# - AGN name is the name of the target
# - velocity is the velocity of the absorption feature centroid in km/s
# - include is a boolean indicating whether the results should be saved into the
# 'ambiguous' folder (False), or the 'associated' folder (True)
f = open(file,'rU')
reader = csv.DictReader(f)
targetList = []
for l in reader:
AGNname = l[AGNheader]
include = l['include']
if include == 'yes':
include = True
else:
include = False
# velocityHeader is the name of the columns containing the center velocity, or
# it can also be just a number designating the center velocity
if isNumber(velocityHeader):
vel = velocityHeader
else:
vel = l[velocityHeader]
galaxyName = l['galaxyName']
if isNumber(vel) and galaxyName !='x':
pair = (AGNname,int(vel), include)
targetList.append(pair)
f.close()
return targetList
def buildFullTargetList(file,AGNheader,velocityHeader):
# makes a targetmap for every absorption line, regardless of whether there is an
# associated galaxy name or not, so long as the line velocity entry is a number
#
# builds a list consisting of tuples: (AGNname, velocity, include)
#
# - AGN name is the name of the target
# - velocity is the velocity of the absorption feature centroid in km/s
# - include is a boolean indicating whether the results should be saved into the
# 'ambiguous' folder (False), or the 'associated' folder (True)
f = open(file,'rU')
reader = csv.DictReader(f)
targetList = []
# startT = 'QSO1500-4140'
# startV = '9757'
# goOn = False
for l in reader:
AGNname = l[AGNheader]
# include = l['include']
# if include == 'yes':
# include = True
# else:
# include = False
# velocityHeader is the name of the columns containing the center velocity, or
# it can also be just a number designating the center velocity
# added
# vel = l[velocityHeader]
# if AGNname == startT:
# if vel == startV:
# goOn = True
#
# if goOn:
# added
if isNumber(velocityHeader):
vel = velocityHeader
else:
vel = l[velocityHeader]
if isNumber(vel):
include = True
pair = (AGNname,int(vel),include)
targetList.append(pair)
f.close()
return targetList
def main():
# main function to create targetmaps around selected sightlines
nullFloat = -99.99
nullInt = -99
nullStr = 'x'
counter = 0
AGNList = []
rowList = []
masterVirList = []
masterCustomList = []
# max impact parameter to use
maxSep = 500
# +/- galaxy velocity to search within around absorption velocity
velocityWindow = 400
# minimum galaxy velocity to include (False to ignore). Usually = 500
minVcorr = 500
# minimum galaxy size to include (False to ignore)
minSize = False
# minimum separation in km/s between the redshift of the AGN and the galaxy (False to ignore)
# agnSeparation = 4000.
agnSeparation = False
# include name tags on galaxies? They don't scale very well...
includeNameTags = True
# x and y name tag offset
# yTagOffset = 6
# xTagOffset = -60
yTagOffset = 2
xTagOffset = -10
# name tag font size
nameTagFont = 10
# include a title on the plots?
includeTitle = True
# also make a plot of just real positions of galaxies on the sky in RA and Dec coords?
includeSkyPlot = False
# Save the map plots?
saveMaps = True
# Save the individual map plot tables?
saveMapTables = True
# Save the full results with "include" tags? This is the whole big correlation table
# which looks like LG_correlation_combined5_11_25cut_edit4.csv
saveResults = True
# 2nd place galaxy likelihood * rigor <= 1st place galaxy for 'include'
rigor = 5
# hard limit for likelihood
l_min = 0.01
# bypass l_min for lone galaxies? (i.e. include lone galaxies no matter what likelihood is)
loner = False
# the speed of light
c = 2.9979*10**5
# maximum number of galaxies to plot on a single window. Just set it high to ignore
maxPlotObjects = 5000
# ticks
xAxisMajorTicks = 200
xAxisMinorTicks = 100
yAxisMajorTicks = 200
yAxisMinorTicks = 100
velocityStepSize = 100
# sort results into /associated/, ~/ambiguous/, and ~/nonassociated/ folders?
# if True, these folders must already exist
# if False, puts all the files into saveDirectory as set below
sortIntoFolders = False
# include AGN background targets as well?
includeAGN = True
# include name tags for AGN?
includeAGNnameTags = True
# size of stars for AGN
AGNsize = 50
# color map:
colmap = cm.RdBu_r
# colmap = cm.inferno
# which way to plot RA axis? RAeastLeft = True puts east to the left, matching
# the standard. I.e., RA increases toward the left
RAeastLeft = True
# Location and name of targetfile, and where to save figures and tables. Set this
# even if you'll manually enter targets below
user = getpass.getuser()
if user == "David":
# targetFile = '/Users/David/Research_Documents/inclination/git_inclination/LG_correlation_combined5_11_25cut_edit4.csv'
# saveDirectory = '/Users/David/Research_Documents/iraf/NGC3633/'
# outputFile = '/Users/David/Research_Documents/iraf/NGC3633_correlation.csv'
# targetFile = '/Users/David/Research_Documents/metal_absorbers/met.dat'
# saveDirectory = '/Users/David/Research_Documents/metal_absorbers/'
# outputFile = '/Users/David/Research_Documents/metal_absorbers/metal_absorbers.csv'
sys.stdout.write("Wrong user: {0}".format(user))
sys.exit()
elif user == "frenchd":
# targetFile = '/Users/frenchd/Research/fullListMaps/LG_correlation_combined5_11_25cut_edit4.csv'
# saveDirectory = '/Users/frenchd/Research/inclination/git_inclination/rotation_paper/data/'
# outputFile = '/Users/frenchd/Research/inclination/git_inclination/rotation_paper/data/test.csv'
# saveDirectory = '/Users/frenchd/Research/fullListMaps/'
# outputFile = '/Users/frenchd/Research/fullListMaps/fullListMaps.csv'
# targetFile = '/Users/frenchd/Research/inclination/git_inclination/rotation_paper/include_maps/salt_sightlines_all.csv'
# saveDirectory = '/Users/frenchd/Research/inclination/git_inclination/rotation_paper/include_maps/'
# outputFile = '/Users/frenchd/Research/inclination/git_inclination/rotation_paper/include_maps/salt_sightlines_all_results.csv'
# saveDirectory = '/Users/frenchd/Research/test/'
# outputFile = '/Users/frenchd/Research/test/test.csv'
targetFile = '/Users/frenchd/Research/inclination/git_inclination/LG_correlation_combined5_12_edit_plusSALTcut.csv'
# saveDirectory = '/Users/frenchd/Research/inclination/git_inclination/maps/'
# outputFile = '/Users/frenchd/Research/inclination/git_inclination/maps/LG_correlation_combined5_14.csv'
# saveDirectory = '/Users/frenchd/Research/test/target_maps/'
# outputFile = '/Users/frenchd/Research/test/target_maps/target_maps.csv'
# targetFile = '/Users/frenchd/Research/inclination/git_inclination/targets/correlatedTargetList_5_29_18_measurements_copy.csv'
saveDirectory = '/Users/frenchd/Research/test/'
outputFile = '/Users/frenchd/Research/test/test.csv'
else:
print "Unknown user: ",user
sys.exit()
# what are the column names in this file for the AGN name and absorption velocity?
targetHeader = 'target'
velocityHeader = 'Lya_v'
z_targetHeader = 'z_target'
v_limitsHeader = 'v_limits'
# z_targetHeader = 'AGNredshift'
# v_limitsHeader = 'vlimits'
Lya_WHeader = 'Lya_W'
NaHeader = 'Na'
bHeader = 'b'
identifiedHeader = 'identified'
# AGN_coordsHeader = ('degreesJ2000RA_DecAGN')
AGN_coordsHeader = ('RAdeg_target')
# targets from a file, use this:
# targets = buildFullTargetList(targetFile, targetHeader, velocityHeader)
# targets = [('CGCG039-137',6918,True)]
# targets = [('NGC3633',2587,True)]
# targets = [('SDSSJ080838.80+051440.0',8738,True)]
# targets = [('HE2258-5524',1000,True)]
# targets = [('LBQS1230-0015',3279,True)]
# targets = [('LBQS1230-0015',3279,True)]
targets = [('HS1543+5921',2889,True)]
# or build up a custom list of AGN names and absorption velocities here:
# targets = [('1H0419-577',0.003678*c,True),\
# ('3C273.0',0.005277*c,True)]
# targets = [('MCG-03-58-009',9015,True)]
# targets = [('NGC0891',528,True)]
# targets = [('NGC3633',2587,True)]
# targets = [('NGC4939',3093,True)]
# targets = [('RX_J1217.2+2749',1326,True)]
# targets = [('NGC6140',910,True)]
# targets = [('CGCG039-137',6918,True),\
# ('ESO343-G014',9139,True),\
# ('IC5325',1512,True),\
# ('MCG-03-58-009',9015,True),\
# ('NGC1566',1502,True),\
# ('NGC3513',1204,True),\
# ('NGC3633',2587,True),\
# ('NGC3640',1298,True),\
# ('NGC4536',1867,True),\
# ('NGC4939',3093,True),\
# ('NGC5364',1238,True),\
# ('NGC5786',2975,True),\
# ('UGC09760',2094,True)]
# targets = [('MRK279',9294,True),\
# ('PG0838+770',721,True),\
# ('PG0838+770',2911,True),\
# ('SDSSJ104335.90+115129.0',717,True),\
# ('SDSSJ104335.90+115129.0',882,True),\
# ('SDSSJ104335.90+115129.0',1030,True),\
# ('MRK504',9706,True),\
# ('2dFGRS_S393Z082',1241,True),\
# ('US2816',2848,True),\
# ('2E1530+1511',1953,True),\
# ('2E1530+1511',1795,True),\
# ('FBQSJ1134+2555',9552,True),\
# ('FBQSJ1134+2555',6343,True),\
# ('FBQSJ1134+2555',3070,True),\
# ('RX_J2139.7+0246',9219,True),\
# ('RX_J2139.7+0246',4181,True),\
# ('RX_J2139.7+0246',4083,True),\
# ('CSO1124',1653,True),\
# ('HE0241-3043',1219,True),\
# ('HE0241-3043',1310,True),\
# ('CSO327',1812,True),\
# ('RX_J1303.7+2633',8955,True),\
# ('RX_J1303.7+2633',7853,True)]
# targets = [('RX_J2139.7+0246',9219,True),\
# ('RX_J2139.7+0246',4181,True),\
# ('RX_J2139.7+0246',4083,True),\
# ('CSO1124',1653,True),\
# ('HE0241-3043',1219,True),\
# ('HE0241-3043',1310,True),\
# ('CSO327',1812,True),\
# ('RX_J1303.7+2633',8955,True),\
# ('RX_J1303.7+2633',7853,True)]
##########################################################################################
# THINGS galaxies
# targets = [('NGC2403',133,True),\
# ('MCG-02-07-026',2102,True),\
# ('NGC4789A',374,True),\
# ('NGC0628',657,True),\
# ('NGC0925',553,True),\
# ('NGC2841',638,True),\
# ('NGC2903',550,True),\
# ('NGC2976',3,True),\
# ('NGC3077',14,True),\
# ('NGC3184',592,True),\
# ('NGC3198',660,True),\
# ('NGC3351',778,True),\
# ('NGC3521',801,True),\
# ('NGC3627',727,True),\
# ('NGC4214',291,True),\
# ('NGC4449',207,True),\
# ('NGC4736',308,True),\
# ('NGC4826',408,True),\
# ('NGC5055',484,True),\
# ('NGC5194',463,True),\
# ('NGC5236',513,True),\
# ('NGC5457',241,True),\
# ('NGC6946',40,True),\
# ('NGC7331',816,True),\
# ('NGC7793',230,True)]
# targets = [('NGC4579',1517,True)]
# targets = [('NGC3198',660,True)]
# targets = [('NGC4414',716,True)]
# targets = [('NGC5907',667,True)]
# targets = [('NGC0973',4855,True)]
# targets = [('UGC04277',5459,True)]
# targets = [('NGC5529',2875,True)]
# targets = [('NGC4157',774,True)]
# targets = [('NGC4565',1230,True)]
# targets = [('NGC3982',1109,True)]
# targets = [('NGC4527',1736,True)]
# targets = [('NGC3079',1116,True)]
# targets = [('UGC05272',513,True)]
# targets = [('UGC06399',791,True)]
# targets = [('UGC06446',645,True)]
# targets = [('NGC3972',852,True)]
# targets = [('NGC3985',948,True)]
# targets = [('UGC07089',770,True)]
# targets = [('NGC4218',975,True)]
# targets = [('NGC4455',637,True)]
# targets = [('NGC5033',875,True)]
# targets = [('UGC09211',686,True)]
# targets = [('UGC09211',686,True)]
# targets = [('NGC3877',895,True)]
# targets = [('NGC3893',967,True)]
# targets = [('NGC3718',993,True)]
# targets = [('NGC0891',528,True)]
# targets = [('NGC4529',2536,True)]
# targets = [('UGC04238',1544,True)]
# targets = [('NGC2770',1947,True),\
# ('NGC3432',616,True),\
# ('NGC3666',1060,True),\
# ('NGC3769',737,True),\
# ('NGC3949',800,True),\
# ('NGC4157',774,True),\
# ('NGC4414',716,True),\
# ('NGC4534',802,True),\
# ('NGC5951',1780,True),\
# ('NGC7741',750,True),\
# ('NGC7817',2309,True),\
# ('UGC05459',1112,True),\
# ('UGC08146',670,True)]
# targets = [('NGC4238',2762,True)]
# targets = [('NGC3351',778,True)]
# targets = [('NGC4254',2407,True)]
# targets = [('NGC4559',807,True)]
# targets = [('NGC3726',866,True)]
# targets = [('NGC3067',1476,True)]
# targets = [('PG1302-102',3447,True)]
# targets = [('RX_J1142.5+2503',550,True)]
# targets = [('2E1530+1511',1953,True)]
# targets = [('MRK335',1954,True)]
# targets = [('RX_J1236.0+2641',794,True),
# ('RX_J1236.0+2641',1009,True),
# ('RX_J1236.0+2641',1166,True),
# ('RX_J1236.0+2641',1254,True)]
# targets = [('SDSSJ112448.30+531818.0',645,True),
# ('SDSSJ112448.30+531818.0',1156,True)]
# targets = [('SBS1116+523',731,True)]
# targets = [('CSO1208',874,True)]
# targets = [('MRK876',939,True)]
# targets = [('PG0804+761',1143,True)]
# targets = [('SDSSJ112439.50+113117.0',1047,True)]
# targets = [('SDSSJ112632.90+120437.0',1060,True)]
# targets = [('MRK335',1954,True)]
# targets = [('PG1259+593',670,True)]
# targets = [('SDSSJ101622.60+470643.0',661,True)]
# targets = [('RBS1503',667,True)]
# targets = [('SBS1503+570',667,True)]
# targets = [('SDSSJ112448.30+531818.0',1019,True), ('SDSSJ112448.30+531818.0',1141,True)]
# targets = [('SDSSJ112632.90+120437.0',1060,True)]
# targets = [('2E1530+1511',1953,True)]
# targets = [('NGC2770',1947,True)]
# targets = [('MRK876',939,True),\
# ('MRK876',3478,True),\
# ('MRK876',4508,True),\
# ('MRK876',5036,True),\
# ('MRK876',6037,True),\
# ('MRK876',7005,True),\
# ('MRK876',9895,True)]
# targets = [('1H0419-577',1075,True),\
# ('1H0419-577',1123,True),\
# ('1H0419-577',1188,True),\
# ('1H0419-577',1264,True),\
# ('1H0419-577',2020,True)]
c = 0
for i in targets:
# find AGN environment using the imported version of correlateSingle
targetName,center,include = i
correlation = correlateSingle.correlateTarget(targetName, maxSep, agnSeparation, minVcorr, minSize, slow=False,searchAll=True)
galaxyInfo = correlation[targetName]
# print 'galaxyInfo: ',galaxyInfo
if includeAGN:
correlationAGN = correlateSingle.correlateGalaxy(targetName, maxSep, agnSeparation, minVcorr, minSize)
if correlationAGN:
AGNinfo = correlationAGN[targetName]
else:
AGNinfo = []
# print '{0} = {1}'.format(targetName,len(galaxyInfo))
# print
# galaxyInfo.sort()
# instantiate some lists for later
galaxyNames = []
separations = []
positions = []
plotPositionsRA = []
plotPositionsDec = []
plotRA = []
plotDec = []
plotAGNposition = []
plotSizes = []
plotVelocity = []
PA = []
inc = []
typeList = []
infoDict = {}
AGNRAs = []
AGNDecs = []
plotPositionAGNRA = []
plotPositionAGNDec = []
AGNnames = []
if includeAGN:
for r in AGNinfo:
vhel, AGNrow = r
AGNRA = AGNrow['AGNRA']
AGNRAs.append(AGNRA)
AGNDec = AGNrow['AGNDec']
AGNDecs.append(AGNDec)
galaxyDist = AGNrow['bestDist']
targetRA = float(AGNrow['galaxyRA'])
targetDec = float(AGNrow['galaxyDec'])
AGNname = AGNrow['AGNname']
AGNnames.append(AGNname)
#find plot placement
# calculate angular separations in ra and dec to determine positions on chart w.r.t. target
AGNRA,AGNDec = float(AGNRA),float(AGNDec)
# calculate separation in RA only
dRA_agn = calculateImpactParameter(AGNRA,targetDec,targetRA,targetDec,galaxyDist)
# calculate separation in Dec only
dDec_agn = calculateImpactParameter(targetRA,AGNDec,targetRA,targetDec,galaxyDist)
# add signs back into physical impact parameters
if AGNRA < targetRA:
if RAeastLeft:
dRA_agn = -dRA_agn
if AGNRA > targetRA:
if not RAeastLeft:
dRA_agn = -dRA_agn
# 'edge' effects
if AGNRA >= 359.0 and targetRA <= 1.0:
dRA_agn = -dRA_agn
if AGNDec < targetDec:
dDec_agn = -dDec_agn
plotPositionAGNRA.append(dRA_agn)
plotPositionAGNDec.append(dDec_agn)
print 'dRA_agn: ',dRA_agn
print 'dDec_agn: ',dDec_agn
print
# loop through the returned galaxy environment data, making calculations and
# populating lists as we go
counter = 0
for row in galaxyInfo:
counter+=1
vhel, galaxyRow = row
AGNposition = eval(str(galaxyRow['degreesJ2000RA_DecAGN']))
# crop off results that fall out of the 'velocityWindow' parameter
# 'velocityWindow' = a cut in velocity space
if counter <= maxPlotObjects and float(vhel)-velocityWindow <= center and float(vhel)+velocityWindow >= center:
separation = galaxyRow['impactParameter (kpc)']
galaxyName = galaxyRow['galaxyName']
galaxyPosition = eval(str(galaxyRow['degreesJ2000RA_DecGalaxy']))
AGNposition = eval(str(galaxyRow['degreesJ2000RA_DecAGN']))
galaxyDist = galaxyRow['distGalaxy (Mpc)']
group = eval(str(galaxyRow['groups_dist_std (Mpc)']))
major,minor = eval(str(galaxyRow['linDiameters (kpc)']))
galaxyVcorr = galaxyRow['vcorrGalaxy (km/s)']
galaxyVel = galaxyRow['radialVelocity (km/s)']
morphology = galaxyRow['morphology']
RC3Type = galaxyRow['RC3type']
RC3PA = galaxyRow['RC3pa (deg)']
RC3inc = galaxyRow['RC3inc (deg)']
positionAngle = galaxyRow['positionAngle (deg)']
inclination = galaxyRow['inclination (deg)']
azimuth = galaxyRow['azimuth (deg)']
# include = galaxyRow['include']
if not isNull(inclination):
inclination = round(eval(inclination),0)
if not isNull(galaxyDist):
positions.append(galaxyPosition)
separations.append(float(separation))
if not isNull(positionAngle):
pa = float(positionAngle)
elif not isNull(RC3PA):
pa = float(RC3PA)
else:
pa = 0
#find plot placement
# calculate angular separations in ra and dec to determine positions on chart w.r.t. target AGN
gRA,gDec = float(galaxyPosition[0]),float(galaxyPosition[1])
agnRA,agnDec = float(AGNposition[0]),float(AGNposition[1])
# calculate separation in RA only
# dRA = correlateSingle.calculateImpactParameter_slow(gRA,agnDec,agnRA,agnDec,galaxyDist)
dRA = calculateImpactParameter(gRA,agnDec,agnRA,agnDec,galaxyDist)
# calculate separation in Dec only
# dDec = correlateSingle.calculateImpactParameter_slow(agnRA,gDec,agnRA,agnDec,galaxyDist)
dDec = calculateImpactParameter(agnRA,gDec,agnRA,agnDec,galaxyDist)
# add signs back into physical impact parameters
# if gRA < agnRA:
# if not RAeastLeft:
# # dRA = -dRA
# dRA = dRA
if gRA < agnRA:
if RAeastLeft:
dRA = -dRA
if gRA > agnRA:
if not RAeastLeft:
dRA = -dRA
# 'edge' effects
if gRA >= 359.0 and agnRA <= 1.0:
dRA = -dRA
if gDec < agnDec:
dDec = -dDec
# calculate size by finding radius
noSize = False
if not isNull(major):
averageSize = float(major)
elif not isNull(minor) and not isNull(inclination):
averageSize = float(minor) / math.cos(float(inclination) * math.pi/180)
elif not isNull(minor) and isNull(inclination) and isNull(major):
averageSize = float(minor)
inclination = 0
else:
averageSize = 2
inclination = 0
noSize = True
# if not isNumber(galaxyVcorr):
# galaxyVcorr = 0
# galaxyVel = 0
localType = 'x'
rc3Type = RC3Type.lower()
r = rc3Type[:10]
morphology = morphology.lower()
m = morphology[:10]
print 'm vs morphology: ',m, ' vs ',morphology
if not isNull(morphology):
if bfind(m,'s'):
if not bfind(m,'s0'):
# straight spiral type
localType = 's'
else:
# lenticular or S0 type
localType = 'e'
elif bfind(m,'e') or bfind(m,'dwarf') or bfind(m,'pec'):
localType = 'e'
elif bfind(m,'len'):
localType = 'e'
elif bfind(m,'ir') or bfind(m,'im') or bfind(m,'i ') or bfind(m,'ia'):
localType = 's'
else:
localType = 'x'
# try RC3 types
elif not isNull(rc3Type):
print 'Not null rc3 morphology: ',morphology
print
if bfind(r,'s'):
if not bfind(r,'s0'):
# straight spiral type
localType = 's'
else:
# lenticular or S0 type
localType = 'e'
elif bfind(r,'e') or bfind(r,'dwarf') or bfind(r,'pec'):
localType = 'e'
elif bfind(r,'len'):
localType = 'e'
elif bfind(r,'ir') or bfind(r,'im') or bfind(r,'i ') or bfind(r,'ia'):
# irregular type
localType = 's'
else:
localType = 'x'
# Latex format galaxyName
galaxyName = r'{0}'.format(galaxyName)
galaxyName = galaxyName.replace('_','\_')
infoDict[galaxyName]=galaxyRow
galaxyType = {'s':2,'e':1,'x':3}
if noSize:
galaxyNames.append('*'+galaxyName)
else:
galaxyNames.append(galaxyName)
print 'galaxyName - morph - localType: ',galaxyName, ' - ',morphology,' - ',localType
print
plotPositionsRA.append(dRA)
plotPositionsDec.append(dDec)
plotSizes.append(averageSize)
plotVelocity.append(float(galaxyVel))
typeList.append(galaxyType[localType])
PA.append(pa)
inc.append(inclination)
plotRA.append(gRA)
plotDec.append(gDec)
plotAGNposition.append(AGNposition)
if len(galaxyNames) >=1:
##################################
print 'starting first plot...'
x = arange(len(galaxyNames))+1
fig = figure(figsize=(9,7))
ax = fig.add_subplot(111)
width = 0.30
# format the axes:
#
# x-axis
majorLocator = MultipleLocator(xAxisMajorTicks)
majorFormatter = FormatStrFormatter(r'$\rm %d$')
minorLocator = MultipleLocator(xAxisMinorTicks)
ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(majorFormatter)
ax.xaxis.set_minor_locator(minorLocator)
# y axis
majorLocator = MultipleLocator(yAxisMajorTicks)
majorFormatter = FormatStrFormatter(r'$\rm %d$')
minorLocator = MultipleLocator(yAxisMinorTicks)
ax.yaxis.set_major_locator(majorLocator)
ax.yaxis.set_major_formatter(majorFormatter)
ax.yaxis.set_minor_locator(minorLocator)
# ax.xaxis.set_tick_params(labelweight='normal')
# ax.yaxis.set_tick_params(labelweight='normal')
# scale sizes and velocities
maxSize = 300
minSize = 80
largest = float(max(plotSizes))
smallest = float(min(plotSizes))
newSizes = []
# multiply sizes of galaxies by 10
for s in plotSizes:
new = s*10
newSizes.append(new)
vmaxVal = velocityWindow
vminVal = -velocityWindow
# +/- 400 km/s around the center
largestVelocity = velocityWindow
smallestVelocity = -velocityWindow
newVelocities = []
# check if there's more than one
for v in plotVelocity:
# convert to delta-v = v_absorber - v_galaxy (neg = absorber is blueward of galaxy)
# velocity = center - v
velocity = v - center
# newVelocity = ((float(velocity) - smallestVelocity)/(largestVelocity-smallestVelocity)) * (vmaxVal-0)+0
# newVelocities.append(newVelocity)
newVelocities.append(velocity)
# rounding = -1
# step = round(((largestVelocity-smallestVelocity)/vmaxVal),rounding)
# ticks = arange(int(round(smallestVelocity,-2)),int(round(largestVelocity,-2))+int(step),int(step))
rounding = -1
step = velocityStepSize
ticks = arange(-velocityWindow,velocityWindow+step,int(step))
norm = matplotlib.colors.Normalize(vmin = vminVal, vmax = vmaxVal)
m = matplotlib.cm.ScalarMappable(norm=norm, cmap=colmap)
numberGalaxies = len(newVelocities)
galaxyIndices = range(numberGalaxies)
# make ellipses to indicate position angle and inclination at once
if len(plotVelocity) !=0:
mapping = dict((i,n) for i,n in zip(galaxyIndices,galaxyNames))
for i in range(numberGalaxies):
if typeList[i] == 1 or typeList[i] == 2:
# typeList[i] == 2 is a spiral, 1 is E type
print 'i: ',i,galaxyIndices[i]
if RAeastLeft:
e = Ellipse(xy=(plotPositionsRA[i],plotPositionsDec[i]),\
width=newSizes[i] * math.cos(float(inc[i]) * math.pi/180)/2,\
height=float(newSizes[i])/2, angle=float(-PA[i]))
print 'PA = ',PA