Tables - solutions

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

To start with, read in the two data files representing the master source list and observations source list. The fields for the two tables are respectively documented in:

In [2]:
from astropy.table import Table
In [3]:
master_sources = Table.read('data/cdfs_master_sources.fits')
obs_sources = Table.read('data/cdfs_obs_sources.fits')

Exploring the data

Do the following to explore the two tables:

  • Display the data for each table in IPython notebook using the normal way of showing the value of a variable.
  • Get a list of the column names for each table. Hint: use <TAB> completion to easily discover all the attributes and methods, e.g. type master_sources. and then hit the <TAB> key.
  • Find the length of each table.
  • Find the column datatypes for each table.
In [4]:
master_sources
Out[4]:
msidnameradec
11567CXO J033206.1-27544903 32 06.10-27 54 49.73
11570CXO J033151.1-27505103 31 51.15-27 50 51.66
11574CXO J033236.1-27512603 32 36.19-27 51 26.87
11576CXO J033253.0-27513803 32 53.09-27 51 38.28
11580CXO J033213.4-27485603 32 13.44-27 48 56.20
11586CXO J033218.8-27513603 32 18.86-27 51 36.08
11595CXO J033244.3-27514103 32 44.32-27 51 41.71
11600CXO J033234.7-27553503 32 34.74-27 55 35.82
11692CXO J033153.4-27484303 31 53.49-27 48 43.92
11788CXO J033202.2-27523403 32 02.29-27 52 34.42
11791CXO J033228.0-27433203 32 28.09-27 43 32.02
............
33232CXO J033225.9-27451403 32 25.96-27 45 14.82
33233CXO J033230.0-27440403 32 30.01-27 44 04.50
33234CXO J033237.4-27400003 32 37.44-27 40 00.74
33235CXO J033149.4-27503403 31 49.46-27 50 34.20
33236CXO J033149.4-27463403 31 49.45-27 46 34.46
33239CXO J033222.7-27522403 32 22.76-27 52 24.10
33240CXO J033226.5-27480103 32 26.57-27 48 01.82
37759CXO J033309.5-27460303 33 09.52-27 46 03.30
148105CXO J033234.2-27390603 32 34.21-27 39 06.46
148106CXO J033234.4-27391303 32 34.44-27 39 13.28
148107CXO J033247.9-27414803 32 47.91-27 41 48.03
In [5]:
obs_sources
Out[5]:
obsidobitargnamegti_obsflux_aper_bsrc_cnts_aper_bra_bdec_blivetimeposidthetamsid
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:521.016e-1453.49203 32 50.25-27 52 52.6055967.0149836.88333150
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:521.64e-14112.2903 32 37.77-27 52 12.6355967.0149844.56933164
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:526.472e-1543.24703 32 43.22-27 49 14.7755967.0149853.72333183
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:521.304e-1469.77403 32 59.85-27 47 48.7255967.0149867.30233198
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:528.389e-14594.6103 32 08.67-27 47 34.8355970.2149874.10133202
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:521.58e-1490.88803 32 29.98-27 45 30.4055967.0149882.89733140
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:523.81e-1524.61703 32 30.22-27 45 05.3455967.0149893.31533142
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:529.992e-1573.29503 32 10.93-27 44 15.5055967.0149905.38633143
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:521.427e-14100.4503 32 36.71-27 44 06.8355967.0149914.73533144
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:526.375e-1559.91903 32 10.52-27 43 09.6755967.0149926.30833145
4410AXAF Southern Deep Field - ACIS-I2000-05-27T01:32:523.141e-14172.7403 32 47.89-27 42 33.0155967.0149937.40733148
....................................
85941Chandra Deep Field-South2007-11-01T12:10:521.837e-14114.4703 32 26.97-27 34 55.19141416.04458213.37431730
85941Chandra Deep Field-South2007-11-01T12:10:522.264e-1523.45803 32 58.54-27 50 07.08141397.4445906.60731719
85941Chandra Deep Field-South2007-11-01T12:10:521.223e-1532.50903 32 02.48-27 46 00.78141400.5445986.46233132
85941Chandra Deep Field-South2007-11-01T12:10:522.136e-1523.91303 32 32.06-27 41 55.25141381.9446006.37733210
85941Chandra Deep Field-South2007-11-01T12:10:523.604e-1612.81403 32 14.53-27 54 22.92141400.5446016.97933178
85941Chandra Deep Field-South2007-11-01T12:10:529.348e-1564.37903 31 52.61-27 46 40.60141400.5446028.38933226
85941Chandra Deep Field-South2007-11-01T12:10:523.648e-1610.54603 33 04.26-27 48 58.38141397.4446037.64231739
85941Chandra Deep Field-South2007-11-01T12:10:527.651e-15105.9103 32 39.83-27 35 11.70141416.04460713.26931732
85941Chandra Deep Field-South2007-11-01T12:10:524.949e-1532.44303 32 46.32-27 46 32.31141381.9446094.03933227
85941Chandra Deep Field-South2007-11-01T12:10:524.653e-1535.69303 32 40.84-27 55 45.44141400.5446117.86433197
85941Chandra Deep Field-South2007-11-01T12:10:525.546e-1579.04603 32 18.43-27 37 04.62141416.04462911.48331734
In [6]:
master_sources.colnames
Out[6]:
['msid', 'name', 'ra', 'dec']
In [7]:
obs_sources.colnames
Out[7]:
['obsid',
 'obi',
 'targname',
 'gti_obs',
 'flux_aper_b',
 'src_cnts_aper_b',
 'ra_b',
 'dec_b',
 'livetime',
 'posid',
 'theta',
 'msid']
In [8]:
len(master_sources)
Out[8]:
209
In [9]:
len(obs_sources)
Out[9]:
1637
In [10]:
master_sources.dtype
Out[10]:
dtype([('msid', '>i8'), ('name', 'S20'), ('ra', 'S12'), ('dec', 'S12')])
In [11]:
obs_sources.dtype
Out[11]:
dtype([('obsid', '>i8'), ('obi', '>i8'), ('targname', 'S50'), ('gti_obs', 'S19'), ('flux_aper_b', '>f8'), ('src_cnts_aper_b', '>f8'), ('ra_b', 'S12'), ('dec_b', 'S12'), ('livetime', '>f8'), ('posid', '>i8'), ('theta', '>f8'), ('msid', '>i8')])

Normally one displays a table in IPython notebook by entering the variable name in a cell and pressing shift-Enter. In a terminal session the default method is using something like print(my_table). In both cases the Table object prefers to display only a screenful of data to prevent having a zillion lines of output if the table is huge. If you really want to see all the data you can use the Table.pprint method.

  • Display all the rows of the master_sources table using its pprint() method.
  • If you are working in a regular terminal window (not IPython notebook), try the more() method as well.
In [12]:
master_sources.pprint(max_lines=-1)
 msid          name              ra          dec     
------ -------------------- ------------ ------------
 11567 CXO J033206.1-275449  03 32 06.10 -27 54 49.73
 11570 CXO J033151.1-275051  03 31 51.15 -27 50 51.66
 11574 CXO J033236.1-275126  03 32 36.19 -27 51 26.87
 11576 CXO J033253.0-275138  03 32 53.09 -27 51 38.28
 11580 CXO J033213.4-274856  03 32 13.44 -27 48 56.20
 11586 CXO J033218.8-275136  03 32 18.86 -27 51 36.08
 11595 CXO J033244.3-275141  03 32 44.32 -27 51 41.71
 11600 CXO J033234.7-275535  03 32 34.74 -27 55 35.82
 11692 CXO J033153.4-274843  03 31 53.49 -27 48 43.92
 11788 CXO J033202.2-275234  03 32 02.29 -27 52 34.42
 11791 CXO J033228.0-274332  03 32 28.09 -27 43 32.02
 11792 CXO J033233.7-274912  03 32 33.78 -27 49 12.12
 11797 CXO J033159.5-275018  03 31 59.58 -27 50 18.30
 11802 CXO J033243.4-274612  03 32 43.48 -27 46 12.33
 11807 CXO J033243.5-274633  03 32 43.50 -27 46 33.03
 11818 CXO J033244.3-275251  03 32 44.31 -27 52 51.25
 12009 CXO J033159.6-274948  03 31 59.65 -27 49 48.84
 12013 CXO J033309.9-274620  03 33 09.95 -27 46 20.51
 12072 CXO J033258.7-274635  03 32 58.70 -27 46 35.06
 12113 CXO J033303.6-274331  03 33 03.65 -27 43 31.08
 12118 CXO J033250.1-274135  03 32 50.17 -27 41 35.03
 12190 CXO J033304.9-274729  03 33 04.96 -27 47 29.26
 12219 CXO J033251.8-274229  03 32 51.88 -27 42 29.50
 12224 CXO J033309.2-274449  03 33 09.24 -27 44 49.67
 12232 CXO J033259.7-274325  03 32 59.75 -27 43 25.77
 12267 CXO J033157.4-274216  03 31 57.40 -27 42 16.39
 12281 CXO J033202.5-274430  03 32 02.59 -27 44 30.60
 12282 CXO J033208.4-274047  03 32 08.40 -27 40 47.07
 12285 CXO J033217.1-274137  03 32 17.13 -27 41 37.67
 12289 CXO J033210.9-274343  03 32 10.92 -27 43 43.98
 12301 CXO J033204.8-274128  03 32 04.86 -27 41 28.23
 12307 CXO J033153.9-274226  03 31 53.92 -27 42 26.27
 12312 CXO J033206.3-274023  03 32 06.31 -27 40 23.88
 12331 CXO J033144.9-274540  03 31 44.99 -27 45 40.72
 12337 CXO J033204.3-274245  03 32 04.30 -27 42 45.29
 12338 CXO J033208.0-274239  03 32 08.00 -27 42 39.62
 12339 CXO J033200.6-274216  03 32 00.68 -27 42 16.11
 12340 CXO J033208.2-274154  03 32 08.29 -27 41 54.06
 12342 CXO J033204.3-274026  03 32 04.31 -27 40 26.27
 12385 CXO J033157.7-274208  03 31 57.75 -27 42 08.68
 12399 CXO J033154.4-274159  03 31 54.42 -27 41 59.43
 12429 CXO J033205.8-274447  03 32 05.80 -27 44 47.51
 12430 CXO J033154.9-274310  03 31 54.92 -27 43 10.82
 12456 CXO J033215.8-273955  03 32 15.84 -27 39 55.15
 12461 CXO J033216.1-275645  03 32 16.17 -27 56 45.72
 12511 CXO J033200.8-275334  03 32 00.84 -27 53 34.05
 12518 CXO J033204.3-275648  03 32 04.33 -27 56 48.09
 12571 CXO J033158.4-275436  03 31 58.43 -27 54 36.43
 12578 CXO J033155.3-275448  03 31 55.37 -27 54 48.37
 12581 CXO J033225.0-274101  03 32 25.06 -27 41 01.46
 12619 CXO J033151.9-275326  03 31 51.97 -27 53 26.90
 12654 CXO J033213.1-275528  03 32 13.17 -27 55 28.48
 12730 CXO J033246.4-275413  03 32 46.48 -27 54 13.78
 12741 CXO J033303.0-275146  03 33 03.04 -27 51 46.85
 12821 CXO J033236.6-275808  03 32 36.69 -27 58 08.96
 12928 CXO J033221.4-275550  03 32 21.44 -27 55 50.52
 12936 CXO J033206.5-274642  03 32 06.54 -27 46 42.54
 13154 CXO J033231.3-273917  03 32 31.31 -27 39 17.81
 13169 CXO J033225.0-275514  03 32 25.02 -27 55 14.76
 13251 CXO J033249.2-274050  03 32 49.23 -27 40 50.23
 13258 CXO J033156.3-275131  03 31 56.39 -27 51 31.72
 13263 CXO J033147.7-274829  03 31 47.76 -27 48 29.56
 13264 CXO J033245.6-274213  03 32 45.66 -27 42 13.00
 13265 CXO J033230.3-273933  03 32 30.39 -27 39 33.84
 13267 CXO J033207.1-275229  03 32 07.10 -27 52 29.98
 13268 CXO J033229.7-274240  03 32 29.70 -27 42 40.99
 13416 CXO J033243.9-275454  03 32 43.97 -27 54 54.29
 13418 CXO J033247.5-274300  03 32 47.55 -27 43 00.56
 13462 CXO J033242.6-274340  03 32 42.65 -27 43 40.91
 13512 CXO J033201.4-274139  03 32 01.49 -27 41 39.28
 13515 CXO J033220.7-274528  03 32 20.76 -27 45 28.65
 13589 CXO J033240.1-273934  03 32 40.15 -27 39 34.93
 13593 CXO J033300.7-275520  03 33 00.75 -27 55 20.72
 13596 CXO J033218.3-274537  03 32 18.36 -27 45 37.10
 31695 CXO J033259.0-274339  03 32 59.05 -27 43 39.80
 31719 CXO J033258.4-275007  03 32 58.48 -27 50 07.48
 31720 CXO J033214.8-275103  03 32 14.85 -27 51 03.71
 31722 CXO J033232.7-275151  03 32 32.73 -27 51 51.16
 31725 CXO J033238.1-273945  03 32 38.12 -27 39 45.27
 31735 CXO J033146.6-274552  03 31 46.64 -27 45 52.75
 31736 CXO J033248.1-275256  03 32 48.18 -27 52 56.89
 31738 CXO J033231.3-275726  03 32 31.37 -27 57 26.33
 31739 CXO J033304.2-274857  03 33 04.24 -27 48 57.71
 31740 CXO J033220.8-275223  03 32 20.82 -27 52 23.25
 31741 CXO J033244.3-274819  03 32 44.38 -27 48 19.15
 31742 CXO J033243.0-274621  03 32 43.02 -27 46 21.20
 31743 CXO J033219.8-274519  03 32 19.86 -27 45 19.55
 31744 CXO J033235.9-274058  03 32 35.94 -27 40 58.65
 33022 CXO J033238.0-274626  03 32 38.03 -27 46 26.55
 33028 CXO J033207.6-275213  03 32 07.64 -27 52 13.60
 33044 CXO J033241.8-275202  03 32 41.85 -27 52 02.57
 33102 CXO J033257.5-274549  03 32 57.58 -27 45 49.08
 33104 CXO J033229.0-275730  03 32 29.01 -27 57 30.34
 33106 CXO J033218.9-274755  03 32 18.99 -27 47 55.73
 33107 CXO J033218.2-275241  03 32 18.21 -27 52 41.31
 33112 CXO J033229.7-275145  03 32 29.73 -27 51 45.69
 33114 CXO J033233.5-275418  03 32 33.58 -27 54 18.78
 33115 CXO J033225.4-275109  03 32 25.40 -27 51 09.86
 33123 CXO J033205.3-274643  03 32 05.34 -27 46 43.95
 33126 CXO J033259.3-274858  03 32 59.31 -27 48 58.82
 33127 CXO J033310.1-274842  03 33 10.19 -27 48 42.26
 33128 CXO J033244.5-274835  03 32 44.59 -27 48 35.77
 33129 CXO J033226.9-274105  03 32 26.99 -27 41 05.37
 33130 CXO J033226.4-274035  03 32 26.48 -27 40 35.91
 33131 CXO J033222.5-274604  03 32 22.53 -27 46 04.11
 33132 CXO J033202.4-274600  03 32 02.45 -27 46 00.55
 33133 CXO J033203.6-274604  03 32 03.67 -27 46 04.01
 33134 CXO J033157.0-275108  03 31 57.04 -27 51 08.37
 33136 CXO J033242.0-275702  03 32 42.03 -27 57 02.12
 33137 CXO J033233.0-274547  03 32 33.01 -27 45 47.69
 33140 CXO J033229.9-274530  03 32 29.97 -27 45 30.16
 33141 CXO J033230.0-274523  03 32 30.05 -27 45 23.81
 33142 CXO J033230.2-274504  03 32 30.21 -27 45 04.88
 33143 CXO J033210.9-274415  03 32 10.92 -27 44 15.22
 33144 CXO J033236.7-274406  03 32 36.71 -27 44 06.69
 33145 CXO J033210.5-274309  03 32 10.51 -27 43 09.39
 33146 CXO J033217.1-274303  03 32 17.15 -27 43 03.62
 33147 CXO J033217.1-275220  03 32 17.17 -27 52 20.83
 33148 CXO J033247.8-274232  03 32 47.88 -27 42 32.97
 33149 CXO J033238.9-275700  03 32 38.90 -27 57 00.52
 33150 CXO J033250.2-275252  03 32 50.24 -27 52 52.16
 33151 CXO J033212.9-275236  03 32 12.94 -27 52 36.76
 33152 CXO J033214.9-275127  03 32 14.98 -27 51 27.31
 33153 CXO J033252.8-275119  03 32 52.88 -27 51 19.86
 33154 CXO J033211.3-275213  03 32 11.39 -27 52 13.76
 33155 CXO J033229.8-275106  03 32 29.85 -27 51 06.09
 33156 CXO J033214.0-275100  03 32 14.00 -27 51 00.79
 33157 CXO J033218.3-275055  03 32 18.34 -27 50 55.29
 33158 CXO J033158.2-275041  03 31 58.27 -27 50 41.96
 33159 CXO J033259.6-275030  03 32 59.67 -27 50 30.30
 33160 CXO J033152.4-275017  03 31 52.47 -27 50 17.71
 33161 CXO J033206.1-274927  03 32 06.12 -27 49 27.96
 33162 CXO J033210.9-274856  03 32 10.96 -27 48 56.33
 33163 CXO J033239.6-274850  03 32 39.66 -27 48 50.92
 33164 CXO J033237.7-275212  03 32 37.76 -27 52 12.44
 33165 CXO J033158.0-274834  03 31 58.09 -27 48 34.11
 33166 CXO J033302.6-274823  03 33 02.62 -27 48 23.01
 33167 CXO J033208.0-274657  03 32 08.00 -27 46 57.53
 33168 CXO J033201.4-274647  03 32 01.41 -27 46 47.36
 33169 CXO J033211.7-274628  03 32 11.77 -27 46 28.37
 33170 CXO J033239.7-274611  03 32 39.72 -27 46 11.63
 33171 CXO J033303.6-274518  03 33 03.62 -27 45 18.66
 33172 CXO J033239.0-274439  03 32 39.03 -27 44 39.57
 33173 CXO J033241.8-274400  03 32 41.87 -27 44 00.20
 33174 CXO J033244.4-274940  03 32 44.45 -27 49 40.28
 33175 CXO J033213.2-274241  03 32 13.23 -27 42 41.20
 33176 CXO J033225.1-274219  03 32 25.15 -27 42 19.07
 33177 CXO J033234.9-275511  03 32 34.95 -27 55 11.36
 33178 CXO J033214.5-275421  03 32 14.57 -27 54 21.45
 33179 CXO J033205.1-275355  03 32 05.17 -27 53 55.09
 33180 CXO J033200.5-275353  03 32 00.55 -27 53 53.13
 33181 CXO J033203.8-275329  03 32 03.89 -27 53 29.21
 33182 CXO J033235.2-275317  03 32 35.21 -27 53 17.93
 33183 CXO J033243.2-274914  03 32 43.22 -27 49 14.39
 33184 CXO J033259.7-274626  03 32 59.77 -27 46 26.42
 33185 CXO J033301.5-274542  03 33 01.57 -27 45 42.57
 33186 CXO J033254.7-274503  03 32 54.72 -27 45 03.34
 33187 CXO J033209.4-274807  03 32 09.45 -27 48 07.02
 33188 CXO J033201.6-274327  03 32 01.60 -27 43 27.42
 33189 CXO J033200.3-274320  03 32 00.38 -27 43 20.06
 33190 CXO J033225.6-274306  03 32 25.67 -27 43 06.05
 33191 CXO J033214.9-274225  03 32 14.98 -27 42 25.23
 33192 CXO J033227.6-274145  03 32 27.62 -27 41 45.26
 33193 CXO J033226.7-274146  03 32 26.76 -27 41 46.05
 33194 CXO J033224.2-274126  03 32 24.25 -27 41 26.81
 33195 CXO J033211.0-274054  03 32 11.01 -27 40 54.29
 33196 CXO J033224.8-275600  03 32 24.85 -27 56 00.17
 33197 CXO J033240.8-275546  03 32 40.85 -27 55 46.61
 33198 CXO J033259.8-274748  03 32 59.85 -27 47 48.17
 33199 CXO J033249.6-275453  03 32 49.66 -27 54 53.98
 33200 CXO J033249.1-275504  03 32 49.14 -27 55 04.31
 33201 CXO J033203.0-274450  03 32 03.07 -27 44 50.30
 33202 CXO J033208.6-274734  03 32 08.66 -27 47 34.62
 33203 CXO J033226.6-274014  03 32 26.65 -27 40 13.99
 33204 CXO J033216.2-273930  03 32 16.21 -27 39 30.78
 33205 CXO J033150.4-275152  03 31 50.41 -27 51 52.06
 33206 CXO J033307.6-275127  03 33 07.60 -27 51 27.13
 33207 CXO J033147.9-275045  03 31 47.96 -27 50 45.97
 33208 CXO J033242.8-274702  03 32 42.82 -27 47 02.69
 33209 CXO J033229.8-274424  03 32 29.83 -27 44 24.43
 33210 CXO J033232.1-274155  03 32 32.10 -27 41 55.49
 33211 CXO J033247.0-275334  03 32 47.07 -27 53 34.51
 33212 CXO J033152.3-274753  03 31 52.30 -27 47 53.05
 33213 CXO J033243.0-274845  03 32 43.02 -27 48 45.26
 33214 CXO J033246.8-274212  03 32 46.80 -27 42 12.96
 33218 CXO J033220.4-274732  03 32 20.47 -27 47 32.59
 33219 CXO J033255.4-274751  03 32 55.49 -27 47 51.70
 33220 CXO J033204.4-274643  03 32 04.49 -27 46 43.23
 33221 CXO J033244.0-274635  03 32 44.01 -27 46 35.78
 33222 CXO J033228.8-274355  03 32 28.81 -27 43 55.97
 33223 CXO J033233.3-274236  03 32 33.33 -27 42 36.22
 33225 CXO J033305.8-274649  03 33 05.89 -27 46 49.79
 33226 CXO J033152.5-274642  03 31 52.54 -27 46 42.85
 33227 CXO J033246.3-274632  03 32 46.33 -27 46 32.30
 33228 CXO J033239.0-274602  03 32 39.08 -27 46 02.08
 33229 CXO J033220.0-274447  03 32 20.05 -27 44 47.25
 33230 CXO J033238.3-275552  03 32 38.33 -27 55 52.82
 33231 CXO J033201.1-275033  03 32 01.12 -27 50 33.13
 33232 CXO J033225.9-274514  03 32 25.96 -27 45 14.82
 33233 CXO J033230.0-274404  03 32 30.01 -27 44 04.50
 33234 CXO J033237.4-274000  03 32 37.44 -27 40 00.74
 33235 CXO J033149.4-275034  03 31 49.46 -27 50 34.20
 33236 CXO J033149.4-274634  03 31 49.45 -27 46 34.46
 33239 CXO J033222.7-275224  03 32 22.76 -27 52 24.10
 33240 CXO J033226.5-274801  03 32 26.57 -27 48 01.82
 37759 CXO J033309.5-274603  03 33 09.52 -27 46 03.30
148105 CXO J033234.2-273906  03 32 34.21 -27 39 06.46
148106 CXO J033234.4-273913  03 32 34.44 -27 39 13.28
148107 CXO J033247.9-274148  03 32 47.91 -27 41 48.03

Modifying tables

For our analysis we don't actually need the obi (observation interval) column in the obs_sources table.

  • Remove the obi column from the obs_sources table.

The gti_obs column name is a bit obscure (GTI is a good time interval, FWIW).

  • Rename the gti_obs column to obs_date.

It would be nice to have a count rate in addition to the source counts.

  • Add a new column src_rate_aper_b which is the source counts divided by observation duration in sec.

Some of the sources have a negative net flux in the broad band

In [13]:
obs_sources.remove_column('obi')
In [14]:
obs_sources.rename_column('gti_obs', 'obs_date')
In [15]:
obs_sources['src_rate_aper_b'] = obs_sources['src_cnts_aper_b'] / obs_sources['livetime']
In [16]:
obs_sources.colnames
Out[16]:
['obsid',
 'targname',
 'obs_date',
 'flux_aper_b',
 'src_cnts_aper_b',
 'ra_b',
 'dec_b',
 'livetime',
 'posid',
 'theta',
 'msid',
 'src_rate_aper_b']

Looking at the observation source data

For each source detected in an individual observation (in the obs_sources table), let's look at the source flux values.

  • Use the matplotlib hist() function to make a histogram of the source fluxes. Since the fluxes vary by orders of magnitude, use the numpy.log10 to put the fluxes in log space.

HINT: if you did not start notebook with --pylab=inline then try:

import matplotlib.pyplot as plt
%matplotlib inline
  • Also make the same plot but using only sources within 4 arcmin of the center. HINT: use a boolean mask to select values of theta that are less than 4.0.
In [17]:
vals, bins, patches = plt.hist(np.log10(obs_sources['flux_aper_b']), bins=50)
ok = obs_sources['theta'] < 4
out = plt.hist(np.log10(obs_sources['flux_aper_b'][ok]), bins=bins)

Join the master_sources and obs_sources tables

The master_sources and obs_sources tables share a common msid column. What we now want is to join the master RA and Dec positions and master source names with the individual observations table.

  • Use the table.join() function to make a single table called sources that has the master RA, Dec, and name included for each observation source.

HINT: the defaults for keys and join_type='inner' are correct in this case, so the simplest possible call to join() will work!

  • Intermediate: Is the length of the new sources the same as obs_sources? What happened?

  • Advanced: Make a scatter plot of the RA (x-axis) and Dec (y-axis) difference between the master source position and the observation source position. You'll need to use coordinates!

In [18]:
from astropy.table import join
In [19]:
sources = join(master_sources, obs_sources)
In [20]:
print(len(sources), len(obs_sources))
(1555, 1637)

In [21]:
# Some of the obs_sources had an `msid` value that is not in the `master_sources` table
In [22]:
from astropy.coordinates import SkyCoord
In [23]:
master_c = SkyCoord(sources['ra'], sources['dec'], unit='hourangle,deg', frame='icrs')
obs_c = SkyCoord(sources['ra_b'], sources['dec_b'], unit='hourangle,deg', frame='icrs')
In [24]:
plt.plot((master_c.ra - obs_c.ra).value, (master_c.dec - obs_c.dec).value, '.')
Out[24]:
[<matplotlib.lines.Line2D at 0x110c462d0>]

Grouped properties of sources

Finally, we can look at the variability properties of sources in the CDFS using the group_by() functionality.

This method makes a new table in which all the sources with identical master ID are next to each other.

  • Make a new table g_sources which is the sources table grouped by the msid key using the group_by() method.

The g_sources table is just a regular table with all the sources in a particular order. The attribute g_sources.groups is an object that provides access to the msid sub-groups. You can access the \(i^{th}\) group with g_sources.groups[i].

In addition the g_sources.groups.indices attribute is an array with the indicies of the group boundaries.

  • Using np.diff() find the number of repeat observations of each master sources. HINT: use the indices, Luke.
  • Print the 50th group and note which columns are the same for all group members and which are different. Does this make sense? In these few observations how many different target names were provided by observers?
In [25]:
g_sources = sources.group_by('msid')
In [26]:
np.diff(g_sources.groups.indices)
Out[26]:
array([ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  3,  1,
        1,  1,  1,  1,  1,  1,  1,  1,  1,  5,  3,  1,  1,  2,  1,  1,  1,
        1,  3,  2,  1,  1,  1,  1,  2,  1,  1,  2,  1,  4,  2,  1, 18,  5,
        4,  9, 11,  3,  7,  2,  2,  1,  1,  1,  2,  1, 14,  7, 15,  1, 10,
       12,  2,  2,  1,  1,  2, 17, 18,  5, 21, 21, 14, 15, 18,  4, 12, 16,
       21, 16, 21, 21, 21, 21, 20, 19, 21, 21, 21, 18, 21, 21, 20, 11, 20,
       14, 21,  8, 13,  6, 16, 18, 21, 11, 20, 14, 21, 11, 14, 21,  7,  7,
       13, 21, 21, 14,  5, 11,  6, 14,  7, 20, 18, 13,  6, 19, 20, 20, 21,
       11, 17,  6, 17,  9, 17, 10, 21,  8,  4,  7, 21, 20, 13,  6, 12,  8,
       10,  4,  5,  5,  2,  4,  4, 11,  3,  4,  6,  6,  5,  3, 14,  9, 16,
        3,  2,  1,  5,  5,  7,  1,  5,  1,  1,  3, 15])
In [27]:
g_sources.groups[50]
Out[27]:
msidnameradecobsidtargnameobs_dateflux_aper_bsrc_cnts_aper_bra_bdec_blivetimeposidthetasrc_rate_aper_b
31719CXO J033258.4-27500703 32 58.48-27 50 07.488595Chandra Deep Field-South2007-10-19T14:33:541.342e-1522.47503 32 58.50-27 50 07.45115413.1176336.7310.000194735259689
31719CXO J033258.4-27500703 32 58.48-27 50 07.48582AXAF Southern Deep Field2000-06-03T02:59:504.272e-1524.84403 32 58.48-27 50 09.86130584.4154617.2090.000190252434441
31719CXO J033258.4-27500703 32 58.48-27 50 07.488596Chandra Deep Field-South2007-10-24T13:44:486.401e-1615.74903 32 58.29-27 50 04.95115110.3178636.6050.000136816601121
31719CXO J033258.4-27500703 32 58.48-27 50 07.488594Chandra Deep Field-South2007-11-01T12:10:522.264e-1523.45803 32 58.54-27 50 07.08141397.4445906.6070.000165901211762
31719CXO J033258.4-27500703 32 58.48-27 50 07.482405AXAF SOUTHERN DEEP F2000-12-11T08:24:191.994e-1517.25503 32 58.51-27 50 07.2859629.5151196.7120.000289370194283

Aggregation

The real power of grouping comes in the ability to create aggregate values for each of the groups, for instance the mean flux for each unique source. This is done with the aggregate() method, which takes a function reference as its input. This function must take as input an array of values and return a single value.

Aggregate returns a new table that has a length equal to the number of groups.

  • Compute the mean of all columns for each unique source (i.e. each group) using aggregate and the np.mean function. Call this table g_sources_mean.
  • Notice that aggregation cannot form a mean for certain columns and these are dropped from the output. Use the join() function to restore the master_sources information to g_sources_mean.
In [28]:
g_sources_mean = g_sources.groups.aggregate(np.mean)
WARNING: Cannot aggregate column 'name' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'name'
WARNING: Cannot aggregate column 'ra' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'ra'
WARNING: Cannot aggregate column 'dec' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'dec'
WARNING: Cannot aggregate column 'targname' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'targname'
WARNING: Cannot aggregate column 'obs_date' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'obs_date'
WARNING: Cannot aggregate column 'ra_b' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'ra_b'
WARNING: Cannot aggregate column 'dec_b' [astropy.table.groups]
WARNING:astropy:Cannot aggregate column 'dec_b'

In [29]:
g_sources_mean
Out[29]:
msidobsidflux_aper_bsrc_cnts_aper_blivetimeposidthetasrc_rate_aper_b
11567582.04.84e-1535.507130584.415460.07.9870.00027190843623
11570582.05.134e-1555.591130584.415468.08.3210.000425709349662
11574582.01.371e-1517.829130584.415498.03.7430.000136532388249
11576582.01.136e-1510.197130584.415502.06.6667.80874285137e-05
11580582.02.37e-1516.011130584.415509.03.0570.000122610357746
11586582.02.092e-1515.765130584.415382.03.750.000120726518635
11595582.09.126e-1625.018130584.415418.05.1170.000191584906007
11600582.03.446e-1523.171130584.415431.07.4880.00017744079691
116921672.02.476e-1517.30395138.115596.07.7920.000181872456986
117882312.02.024e-1620.78123689.215863.06.9780.000168001733377
117912312.02.085e-1517.554123686.115871.05.0810.000141923789334
........................
332302312.52.2935e-1521.924127047.030128.57.58650.000173165944648
332312313.01.486e-1514.39130401.744388.06.2590.000110351322107
332324105.01.802e-1516.0434114748.9827344.23.15360.00015063014691
332335932.21.91088e-1524.2146120034.5222973.84.25680.000201076953671
332346971.571428575.16657142857e-1540.445285714384860.617128.28571438.479857142860.000491974762848
332352313.01.115e-1537.418130401.744398.08.7440.000286944111925
332364694.86.7688e-1543.9302110817.6822787.08.8040.000398015585979
332392313.01.776e-1513.234130407.944316.03.9380.000101481582021
332402313.08.431e-1611.136130398.644286.00.6978.5399689874e-05
377592074.333333334.34966666667e-1532.363116558.625248.09.447666666670.000284364926452
1481077432.01.79882666667e-14145.46313333385670.473333320396.06666677.700333333330.00168226262547
In [30]:
g_sources_mean = join(master_sources, g_sources_mean)
In [31]:
g_sources_mean
Out[31]:
msidnameradecobsidflux_aper_bsrc_cnts_aper_blivetimeposidthetasrc_rate_aper_b
11567CXO J033206.1-27544903 32 06.10-27 54 49.73582.04.84e-1535.507130584.415460.07.9870.00027190843623
11570CXO J033151.1-27505103 31 51.15-27 50 51.66582.05.134e-1555.591130584.415468.08.3210.000425709349662
11574CXO J033236.1-27512603 32 36.19-27 51 26.87582.01.371e-1517.829130584.415498.03.7430.000136532388249
11576CXO J033253.0-27513803 32 53.09-27 51 38.28582.01.136e-1510.197130584.415502.06.6667.80874285137e-05
11580CXO J033213.4-27485603 32 13.44-27 48 56.20582.02.37e-1516.011130584.415509.03.0570.000122610357746
11586CXO J033218.8-27513603 32 18.86-27 51 36.08582.02.092e-1515.765130584.415382.03.750.000120726518635
11595CXO J033244.3-27514103 32 44.32-27 51 41.71582.09.126e-1625.018130584.415418.05.1170.000191584906007
11600CXO J033234.7-27553503 32 34.74-27 55 35.82582.03.446e-1523.171130584.415431.07.4880.00017744079691
11692CXO J033153.4-27484303 31 53.49-27 48 43.921672.02.476e-1517.30395138.115596.07.7920.000181872456986
11788CXO J033202.2-27523403 32 02.29-27 52 34.422312.02.024e-1620.78123689.215863.06.9780.000168001733377
11791CXO J033228.0-27433203 32 28.09-27 43 32.022312.02.085e-1517.554123686.115871.05.0810.000141923789334
.................................
33230CXO J033238.3-27555203 32 38.33-27 55 52.822312.52.2935e-1521.924127047.030128.57.58650.000173165944648
33231CXO J033201.1-27503303 32 01.12-27 50 33.132313.01.486e-1514.39130401.744388.06.2590.000110351322107
33232CXO J033225.9-27451403 32 25.96-27 45 14.824105.01.802e-1516.0434114748.9827344.23.15360.00015063014691
33233CXO J033230.0-27440403 32 30.01-27 44 04.505932.21.91088e-1524.2146120034.5222973.84.25680.000201076953671
33234CXO J033237.4-27400003 32 37.44-27 40 00.746971.571428575.16657142857e-1540.445285714384860.617128.28571438.479857142860.000491974762848
33235CXO J033149.4-27503403 31 49.46-27 50 34.202313.01.115e-1537.418130401.744398.08.7440.000286944111925
33236CXO J033149.4-27463403 31 49.45-27 46 34.464694.86.7688e-1543.9302110817.6822787.08.8040.000398015585979
33239CXO J033222.7-27522403 32 22.76-27 52 24.102313.01.776e-1513.234130407.944316.03.9380.000101481582021
33240CXO J033226.5-27480103 32 26.57-27 48 01.822313.08.431e-1611.136130398.644286.00.6978.5399689874e-05
37759CXO J033309.5-27460303 33 09.52-27 46 03.302074.333333334.34966666667e-1532.363116558.625248.09.447666666670.000284364926452
148107CXO J033247.9-27414803 32 47.91-27 41 48.037432.01.79882666667e-14145.46313333385670.473333320396.06666677.700333333330.00168226262547