Catalogs

In this example we have 3 catalogs containing different informations. We want to select data and merge these catalogs in order to plot the size-mass relation for objects with z<0.5. We will see, how to:

  1. merge 2 catalogs (Santini et al. 2015), selecting only relevant columns.
  2. cross-match, on the basis of objects coordinates, the merged catalog with a 3rd catalog (see van der Wel et al. 2012).
  3. select passive galaxies on the basis of object properties and gather galaxies in 3 separated redshift bins.
  4. select a redshift bin (z<0.5 in this case) and convert objects size in the effective radius in kpc
  5. plot the size-mass relation

Keys: Table, catalog operations (selection, match, join, sort, ...), units, sky coordinates, cosmology, matplotlib (histogram, scatter plot)

numpy.loadtxt: "low level" function

In [1]:
import numpy as np
filename = 'data/CheckPositions.dat'

#Open an homogenus table
table = np.loadtxt(filename)
table[0:5]
Out[1]:
array([[ 3.30008858e+08,  1.70849750e+01,  7.08309040e+01,
         1.34314990e+01,  7.08607000e+01,  1.33912270e+01],
       [ 2.80007053e+08,  1.62173060e+01, -2.30435670e+01,
         6.09456750e+01, -2.30128810e+01,  6.09082740e+01],
       [ 2.70005300e+08,  1.61864120e+01, -3.30905140e+01,
        -7.05857920e+01, -3.31175090e+01, -7.05944670e+01],
       [ 2.70009682e+08,  1.66147790e+01, -4.49628570e+01,
         2.19773070e+01, -4.49261170e+01,  2.18768850e+01],
       [ 2.60012292e+08,  1.72345300e+01,  2.32170960e+01,
        -7.70041830e+01,  2.31572670e+01, -7.71689770e+01]])
In [ ]:
 
In [2]:
!head -2 $filename
#objID		mag		exp_x_mm	exp_y_mm	meas_x_mm	meas_y_mm
330008858	17.084975	70.830904	13.431499	70.860700	13.391227	
In [3]:
#Select columns and define column types and names
subtable = np.loadtxt(filename, usecols=(0, 1, 2, 4), 
                      dtype={'names': ('ID', 'mag', 'expected', 'measured'), 
                             'formats':('i8', 'f4', 'f4', 'f4')})
subtable[0:5]
Out[3]:
array([(330008858, 17.084974,  70.8309  ,  70.8607  ),
       (280007053, 16.217306, -23.043568, -23.01288 ),
       (270005300, 16.186413, -33.090515, -33.117508),
       (270009682, 16.614779, -44.962856, -44.926117),
       (260012292, 17.23453 ,  23.217096,  23.157267)],
      dtype=[('ID', '<i8'), ('mag', '<f4'), ('expected', '<f4'), ('measured', '<f4')])
In [4]:
subtable[0]
Out[4]:
(330008858, 17.084974, 70.8309, 70.8607)

dtype

A data type object (numpy.dtype) describes how the bytes, in the fixed-size block of memory, corresponding to an array item, should be interpreted. It describes the following aspects:

  • type of the data: integer, float, string, etc.
  • size of the data: how many bytes are used to store each item (e.g the integer)
  • if the data type is a structured data type (e.g. catalog case), an aggregate of other data types:
    • what are the names of the “fields” of the structure, by which they can be accessed
    • what is the data-type of each field
    • which part of the memory block each field takes.

In [ ]:
 

Table

astropy.table provides functionality for storing and manipulating heterogeneous tables of data in a way that is familiar to numpy users. A few notable capabilities of this package are:

  • Modify a table by adding or removing columns, changing column names, or adding new rows of data.
  • Handle tables containing missing values.
  • Include table and column metadata as flexible data structures.
  • Specify a description, units and output formatting for columns.
  • Create a new table by selecting rows or columns from a table.
  • Perform Table operations like joins, concatenation, and binning.
  • Manipulate multidimensional columns.
  • Methods for reading and writing Table objects to files.

Open the phsys parameters catalog

In [5]:
from astropy.table import Table

# https://archive.stsci.edu/missions/hlsp/candels/uds/catalogs/v1/
filename = 'data/hlsp_candels_hst_wfc3_uds_santini_v1_physpar_cat.fits'
physpar = Table.read(filename, format='fits')
In [6]:
physpar
Out[6]:
Table length=35932
Seqage_2a_tautau_2a_tauAv_2a_tauSFR_2a_tauchi2_2a_tauage_2d_tautau_2d_tauAv_2d_taumet_2d_tauage_4bEBV_4bM_l68_6a_tauM_u68_6a_tauage_6a_tautau_6a_tauEBV_6a_tauSFR_6a_taumet_6a_tauextlw_6a_tauchi2_6a_tauL1400_6a_tauL2700_6a_tauUMag_6a_tauBMag_6a_tauVMag_6a_tauRMag_6a_tauIMag_6a_tauJMag_6a_tauKMag_6a_tauage_10cSFH_10ctau_10cmet_10cM_l99_11a_tauM_u99_11a_tauage_11a_tauSFR_11a_tauM_l68_12aM_u68_12aM_l95_12aM_u95_12aage_12atau_12aEBV_12amet_12aLbol_12achi2_12aage_13a_tautau_13a_tauAv_13a_tauSFR_13a_tauchi2_13a_tauage_14aSFH_14atau_14aEBV_14aSFR_14aq_14aage_6a_tau^NEBtau_6a_tau^NEBEBV_6a_tau^NEBSFR_6a_tau^NEBmet_6a_tau^NEBextlw_6a_tau^NEBchi2_6a_tau^NEBL1400_6a_tau^NEBL2700_6a_tau^NEBUMag_6a_tau^NEBBMag_6a_tau^NEBVMag_6a_tau^NEBRMag_6a_tau^NEBIMag_6a_tau^NEBJMag_6a_tau^NEBKMag_6a_tau^NEBage_6a_deltautau_6a_deltauEBV_6a_deltauSFR_6a_deltaumet_6a_deltauextlw_6a_deltauchi2_6a_deltauL1400_6a_deltauL2700_6a_deltauUMag_6a_deltauBMag_6a_deltauVMag_6a_deltauRMag_6a_deltauIMag_6a_deltauJMag_6a_deltauKMag_6a_deltauage_6a_invtautau_6a_invtauEBV_6a_invtauSFR_6a_invtaumet_6a_invtauextlw_6a_invtauchi2_6a_invtauL1400_6a_invtauL2700_6a_invtauUMag_6a_invtauBMag_6a_invtauVMag_6a_invtauRMag_6a_invtauIMag_6a_invtauJMag_6a_invtauKMag_6a_invtauage_10c^dustSFH_10c^dusttau_10c^dustmet_10c^dustage_12a_tautau_12a_tauEBV_12a_taumet_12a_tauLbol_12a_tauchi2_12a_tauage_14a_constEBV_14a_constSFR_14a_constq_14a_constage_14a_linEBV_14a_linSFR_14a_linq_14a_linage_14a_deltautau_14a_deltauEBV_14a_deltauSFR_14a_deltauq_14a_deltauage_14a_tautau_14a_tauEBV_14a_tauSFR_14a_tauq_14a_tau
int32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float64float32float32int16float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float64float32int16float32float64float32int16float32float32float64float32int16float32float32float64float32int16
19.10.50.421.88177.09.1460.3160.00.46.00.87.4511.699.110.30.01.782.52126.01.81e+283.17e+28-20.41-21.43-21.91-22.12-22.3-22.79-22.828.80710.12.010.1110.359.1211.0610.3510.738.9211.29.1570.40.01.010.91105.09.10.3982.252.48110.09.0711-99.00.759327.119.110.30.01.732.52126.01.82e+283.19e+28-20.44-21.42-21.9-22.11-22.27-22.76-22.799.110.20.01.92.52129.01.92e+282.84e+28-19.9-20.71-20.98-21.11-21.25-21.69-21.719.115.00.01.580.22131.02.38e+282.1e+28-19.32-19.91-20.0-20.04-20.08-20.07-19.729.10710.32.09.2070.30.02.511.04104.09.0710.759327.119.040.834567.519.1320.2640.51339.9819.1310.4190.46931.781
210.07.90.80.0069.04-99.0-99.0-99.0-99.06.480.66.297.789.71.00.00.00.225.325.11e+241.14e+25-12.2-13.19-13.77-14.02-14.24-14.47-14.28.15730.11.07.017.198.8680.06.597.796.387.959.7781.00.10.27.813.09.10.3160.00.000910.18.95540.1510.0580.019.71.00.00.00.225.315.29e+241.17e+25-12.22-13.2-13.77-14.01-14.23-14.46-14.199.91.00.00.00.225.348.73e+241.39e+25-12.24-13.21-13.76-14.0-14.23-14.46-14.1910.015.00.20.010.225.645.44e+242.18e+25-12.35-13.23-13.68-13.92-14.17-14.48-14.288.15730.11.09.6021.00.10.27.7913.09.4130.1570.00519.5440.190.00719.0250.1330.0590.018.9550.1510.0580.01
37.60.31.146.77304.06.95439.8111.35.06.960.487.79.887.015.00.113.70.022261.02.84e+283.28e+28-19.43-19.38-19.12-18.98-18.82-18.34-17.519.3811.02.08.779.299.211.228.399.557.669.769.3980.10.02.510.28116.09.41.2590.00.831870.49.3311-99.00.0491.4917.350.30.065.580.022265.02.92e+282.97e+28-19.61-19.68-19.79-19.63-19.0-18.74-18.227.41.90.118.310.022261.02.84e+283.27e+28-19.43-19.4-19.15-19.01-18.85-18.39-17.577.00.30.114.310.022261.02.84e+283.27e+28-19.42-19.38-19.12-18.98-18.82-18.35-17.529.34211.02.09.0571.00.02.510.26116.09.3310.0491.4918.9840.1042.6518.4041.0830.1454.32518.781.9450.082.0871
49.10.31.013.871.98.9030.21.30.29.30.410.611.239.230.30.061.370.2137.41.54e+286.26e+28-21.5-22.56-23.06-23.29-23.51-23.76-23.578.80710.12.010.7411.129.03214.410.6211.1910.4211.319.1570.40.1251.011.5321.59.20.3160.64.78624.29.03240.2620.25112.4919.230.30.061.360.2137.41.59e+286.32e+28-21.52-22.56-23.06-23.29-23.5-23.75-23.569.00.10.12.151.0136.81.38e+286.12e+28-21.43-22.63-23.06-23.26-23.44-23.76-23.78.99.00.55232.40.2141.61.49e+286.87e+28-21.34-22.39-23.01-23.4-23.82-24.48-24.648.80710.12.09.1570.30.151.011.5621.19.2470.502143.419.2940.543207.819.0380.2560.34648.9429.0320.2620.25112.491
57.612.60.01288.0964000.06.8450.011.12.56.60.88.6912.68.80.10.230.811.011280.09.76e+287.24e+29-24.21-25.52-25.98-26.21-26.45-26.87-26.888.80710.12.0-99.0-99.0-99.0-99.011.6711.788.7211.939.1570.40.01.012.23271.09.10.3160.030.252000.09.0431-99.00.03434.3418.80.10.230.511.011280.09.89e+287.24e+29-24.21-25.51-25.98-26.21-26.44-26.86-26.879.00.10.1536.551.011270.01.44e+297.4e+29-24.21-25.46-25.94-26.17-26.39-26.77-26.769.0515.00.51541.00.211300.01.63e+296.6e+29-23.77-24.81-25.41-25.78-26.17-26.79-26.918.80710.12.09.2070.30.02.512.37270.09.0430.03434.3418.8930.02934.919.0190.2730.06796.7419.0680.2340.134.292
69.10.30.00.00241.29.8450.0320.00.029.480.07.547.739.72.00.00.00.2212.94.8e+255.54e+25-13.36-14.21-14.62-14.82-15.0-15.18-14.98.50730.10.57.187.549.070.07.17.326.927.559.0570.00.0250.27.711.379.10.3160.00.00211.918.91240.1150.0160.019.72.00.00.00.2211.64.84e+255.69e+25-13.43-14.22-14.64-14.82-14.97-15.15-14.879.81.00.00.00.2213.04.37e+255.23e+25-13.33-14.2-14.62-14.82-15.01-15.19-14.9110.015.00.10.010.2219.73.57e+256.93e+25-13.45-14.24-14.59-14.77-14.97-15.18-14.938.40730.11.09.0570.00.0250.27.711.3110.0050.0460.006110.0240.1010.00918.9780.1080.0160.018.9120.1150.0160.01
78.30.30.60.41714.47.9030.0080.12.57.30.127.318.339.0615.00.030.182.5211.11.16e+271.81e+27-16.63-17.14-17.22-17.28-17.41-17.86-17.848.05730.12.07.647.978.4560.297.328.167.128.428.3070.30.151.09.659.827.710.01.01.12210.68.4081-99.00.1150.30419.0615.00.030.172.5210.61.11e+271.77e+27-16.73-17.15-17.27-17.31-17.35-17.79-17.779.061.50.10.312.5210.17.64e+261.92e+27-16.71-17.14-17.17-17.2-17.35-17.86-17.848.315.00.150.431.0211.56.57e+261.96e+27-16.75-17.15-17.21-17.26-17.37-17.61-17.398.00630.12.07.3980.00.1252.59.499.568.4080.1150.30418.6570.120.33818.5070.7170.1250.38418.3270.7240.1130.3131
88.50.51.13.8022.098.6990.0790.20.28.310.08.579.299.0615.00.151.832.521.392.36e+278.8e+27-18.54-19.15-19.35-19.47-19.67-20.24-20.299.00731.02.08.619.168.245.58.219.417.839.738.0040.30.1252.510.191.658.40.3161.24.3651.998.47540.5010.2693.77419.0615.00.151.722.521.472.31e+278.72e+27-18.66-19.18-19.41-19.51-19.64-20.19-20.249.110.40.151.772.521.382.32e+278.77e+27-18.55-19.18-19.37-19.49-19.69-20.24-20.289.43.00.151.711.021.522.66e+278.57e+27-18.53-19.21-19.46-19.61-19.79-20.11-19.988.05730.12.07.6990.00.1752.510.321.648.6030.2863.8318.8110.2984.45618.6230.6190.2945.13418.4750.5010.2693.7741
99.55.00.00.5133.699.3011.2590.00.49.480.08.259.319.519.00.00.52.5213.74.65e+275.96e+27-17.96-18.54-18.75-18.88-19.06-19.57-19.558.0062-99.00.27.258.097.870.567.69.046.929.39.3980.00.00.49.8220.59.52.5120.00.346714.99.4681-99.00.0220.4619.519.00.00.482.5214.04.65e+276.03e+27-18.08-18.58-18.81-18.92-19.03-19.54-19.529.510.90.00.492.5213.94.63e+276e+27-17.98-18.59-18.79-18.92-19.08-19.58-19.569.515.00.00.410.2213.96.23e+275.72e+27-18.0-18.65-18.83-18.92-19.01-19.07-18.768.0062-99.00.28.9061.00.00.29.7920.99.4680.0220.4619.4670.0310.50819.0170.440.0250.4819.0351.2570.0230.4671
108.60.50.65.1292.458.1460.0010.10.28.010.069.319.348.750.30.061.940.221.361.62e+282.4e+28-19.65-20.37-20.52-20.58-20.66-20.68-20.378.20730.10.59.039.388.3889.429.09.518.619.758.0040.00.1250.210.690.4138.60.3160.64.6771.058.37440.3340.187.32918.750.30.061.860.221.391.61e+282.45e+28-19.77-20.42-20.6-20.62-20.64-20.66-20.359.32.00.13.870.221.511.51e+282.66e+28-19.68-20.31-20.46-20.54-20.63-20.7-20.399.41.00.13.950.221.461.52e+282.64e+28-19.67-20.29-20.44-20.52-20.62-20.7-20.48.20730.10.58.0040.00.0750.210.530.48.4380.2048.24918.6790.2119.27218.5680.4710.2019.55818.3740.3340.187.3291
.....................................................................................................................................................................................................................................................................................................................................................................................................................
359238.90.30.00.0414.778.6020.010.00.0058.010.067.147.997.02.00.41.770.223.776.41e+257.69e+26-15.98-16.46-16.63-16.7-16.77-16.73-16.158.20730.11.07.727.948.640.057.587.957.298.318.3070.20.01.08.753.688.90.3160.00.03893.818.59240.1250.0350.03419.02.00.10.080.0223.894.29e+267.54e+26-15.92-16.5-16.64-16.68-16.63-16.44-15.957.052.00.57.80.223.773.25e+257.27e+26-16.01-16.47-16.66-16.74-16.82-16.71-16.047.02.00.452.260.223.724.11e+257.05e+26-15.96-16.48-16.69-16.79-16.88-16.86-16.288.20730.11.08.3070.00.00.48.753.698.5720.1660.17318.5670.2030.25418.6460.1090.0760.0618.5920.1250.0350.0341
359248.80.30.01.6222.928.1460.0320.00.48.460.08.819.69.159.00.032.180.222.032.23e+282.49e+28-19.59-20.24-20.38-20.45-20.53-20.57-20.268.45710.10.58.619.288.2925.128.329.737.599.938.9570.40.0250.410.523.258.90.5010.11.9952.368.4511-99.00.0853.85518.50.10.00.830.222.082.36e+282.48e+28-19.7-20.35-20.46-20.46-20.47-20.42-20.089.060.30.032.060.222.032.25e+282.55e+28-19.61-20.26-20.37-20.42-20.47-20.47-20.149.1515.00.032.210.222.042.24e+282.47e+28-19.56-20.19-20.32-20.38-20.45-20.49-20.178.45710.10.58.7570.30.01.010.443.248.4510.0853.85518.4290.1085.24718.4540.4730.0945.24518.4660.5810.0693.6471
359258.70.30.50.0251.317.8450.0030.12.57.30.326.597.467.015.00.50.541.021.294.56e+241.55e+26-14.38-14.8-15.01-15.12-15.3-15.62-15.438.35730.12.07.047.478.2940.086.537.796.058.068.0040.30.1252.58.391.458.70.3980.60.03091.258.3292-99.00.270.09917.415.00.350.151.021.041.23e+251.51e+26-14.49-14.73-15.07-15.18-15.03-15.43-15.329.11.50.20.051.021.343.81e+251.69e+26-14.25-14.84-15.02-15.13-15.29-15.59-15.447.03.00.50.561.021.274.64e+241.58e+26-14.39-14.81-15.02-15.12-15.29-15.57-15.358.35730.12.08.0040.00.0752.58.261.478.3450.2360.06718.3290.270.09918.3340.810.2610.09718.3430.7310.2220.0631
359268.30.50.91.2020.548.01.2591.10.28.310.227.389.058.12.00.251.661.010.4151.49e+273.17e+27-17.34-17.79-17.95-18.09-18.29-18.7-18.648.10730.12.07.988.58.1321.367.499.046.589.267.6990.10.250.410.220.5988.40.3160.80.9120.6128.3542-99.00.2491.66818.015.00.251.591.010.4041.45e+273.14e+27-17.56-17.87-18.13-18.25-18.22-18.63-18.578.61.00.251.751.010.4131.48e+273.14e+27-17.34-17.81-17.98-18.11-18.31-18.72-18.678.20.60.251.691.010.4131.48e+273.16e+27-17.34-17.8-17.97-18.1-18.3-18.72-18.668.00631.01.07.3980.00.2250.410.080.5928.3380.2161.13518.3540.2491.66818.3420.7580.2421.64918.3280.7530.2041.0741
359279.20.50.00.0480.6319.5441.9950.10.29.30.067.28.879.00.30.10.050.0210.5765.38e+268.99e+26-16.37-17.19-17.43-17.57-17.65-17.54-17.088.15730.10.27.718.438.5760.377.118.96.089.078.8570.10.00.29.070.7789.00.3160.10.05250.958.42840.9070.2660.49429.060.30.00.030.220.5835.36e+268.15e+26-16.34-17.19-17.47-17.56-17.64-17.68-17.379.160.20.00.030.220.586.16e+268.33e+26-16.27-17.13-17.39-17.5-17.61-17.66-17.389.515.00.150.170.210.6625.88e+268.55e+26-16.14-16.94-17.28-17.47-17.67-17.92-17.758.15730.10.29.0570.30.00.29.110.788.3880.290.54218.3830.3130.74918.420.7490.3070.74418.4280.9070.2660.4942
359289.41.30.50.20.6759.25525.1192.92.56.00.37.438.859.00.30.00.041.020.8915.64e+268.47e+26-16.22-17.14-17.41-17.53-17.64-17.82-17.658.00630.32.07.378.288.30.247.079.436.129.879.4771.00.0251.09.391.249.00.3160.00.04371.478.3581-99.00.2120.29817.015.00.31.360.210.7475.37e+261.01e+27-16.54-16.89-17.32-17.29-16.91-16.94-16.659.40.40.00.040.220.8937.01e+268.46e+26-16.25-17.08-17.4-17.54-17.67-17.79-17.519.415.00.150.190.210.9486.55e+269.44e+26-16.23-17.01-17.32-17.5-17.69-17.92-17.759.43930.12.09.5441.00.02.59.391.28.3580.2120.29818.3340.2320.4118.3630.7270.2340.43418.3540.8070.1930.2761
359298.72.00.00.2091.187.0790.0020.21.08.460.07.238.128.61.00.00.211.020.9822.46e+272.61e+27-16.92-17.34-17.32-17.32-17.34-17.43-17.168.35710.31.07.287.838.1360.287.018.326.628.688.7570.80.0250.29.531.268.71.5850.00.20421.288.2571-99.00.0350.2818.415.00.00.211.020.8952.47e+272.59e+27-17.05-17.24-17.27-17.21-17.07-17.15-16.868.950.50.00.221.020.9862.47e+272.6e+27-16.9-17.31-17.3-17.3-17.33-17.43-17.168.715.00.00.221.020.9832.46e+272.6e+27-16.91-17.33-17.31-17.31-17.33-17.43-17.168.35710.31.08.4560.60.0250.29.531.258.2570.0350.2818.3140.0430.33818.2980.8380.0430.34718.2281.00.0350.2841
359308.312.60.43.9810.9637.5440.0050.31.06.960.17.948.897.60.30.157.171.011.241.49e+282.24e+28-19.25-19.47-19.47-19.51-19.65-19.95-19.838.35710.12.08.248.717.7345.157.869.447.429.698.6061.00.0751.010.550.8577.710.00.67.081.298.31-99.00.0662.62318.00.10.031.851.021.651.63e+282.08e+28-19.31-19.47-19.52-19.48-19.35-19.46-19.178.00.10.157.81.011.251.49e+282.23e+28-19.25-19.48-19.48-19.52-19.64-19.91-19.777.40.10.158.452.511.181.31e+282.32e+28-19.26-19.36-19.24-19.18-19.38-20.14-20.238.10730.32.08.3070.20.052.510.460.8538.30.0662.62318.3720.0833.33718.3590.60.0783.40518.2650.7060.0632.651
359317.80.30.12.571.968.0790.0630.40.027.480.17.618.827.80.10.032.380.221.762.23e+282.06e+28-19.05-19.33-19.25-19.22-19.2-19.18-18.78.00630.10.28.028.597.7912.57.559.027.539.467.6990.20.01.010.281.97.80.3160.23.091.328.1871-99.00.0222.09517.90.10.032.020.0222.062.41e+282.1e+28-19.19-19.38-19.38-19.25-18.88-18.55-17.957.052.00.1531.470.211.792.17e+282.07e+28-19.06-19.22-19.1-19.01-18.89-18.47-17.78.015.00.032.580.221.782.24e+282.08e+28-19.08-19.38-19.31-19.27-19.24-19.2-18.78.00630.10.27.3980.00.00.410.251.768.1870.0222.09518.2810.0262.37618.2550.8380.0262.42118.1631.0270.0222.0941
359329.00.80.04.6771.458.0790.0040.00.28.460.09.319.868.750.30.03.520.220.8086.47e+286.22e+28-20.59-21.26-21.35-21.38-21.42-21.38-21.048.957-991.00.58.839.538.23213.018.679.97.9710.159.0060.40.00.210.871.18.90.5010.04.5711.158.48740.4990.0528.45418.750.30.03.40.220.8376.49e+286.41e+28-20.72-21.31-21.44-21.43-21.41-21.37-21.038.750.10.03.150.220.8026.54e+286.35e+28-20.61-21.28-21.35-21.38-21.41-21.37-21.038.915.00.067.660.210.8796.34e+286.52e+28-20.58-21.18-21.28-21.34-21.4-21.44-21.138.95711.00.58.7070.30.00.210.871.18.4930.0668.98418.4730.08812.0818.5160.360.06811.7918.4870.4990.0528.4541

Custum open

In case we have to open a custom file, not supported by Astropy/Numpy, we can create our own reader.

Open the file and browse it, looping through lines to retrieve the required informations.

In this weird example values are enclosed in ***, and we are interested in just the first value of each row.

In [7]:
!cat data/custom.dat
***1***
12	***1***	36
***2***
78	***3***
***5***	***7***
***8*** 23 7 x
7 marco esempio 14 ***13***
In [8]:
tab = []
with open('data/custom.dat', 'r') as custom:
    for line in custom:
        try:
            value = line.split('***')[1]
        except:
            continue
        tab.append(int(value))
print(tab)
[1, 1, 2, 3, 5, 8, 13]

Download files

Astropy provides facility to download files from external sites

In [ ]:
from astropy.utils.data import download_file
download_file('https://archive.stsci.edu/missions/hlsp/candels/uds/catalogs/v1/hlsp_candels_hst_wfc3_uds_santini_v1_physpar_cat.fits')
In [ ]:
 

Columns selection

columns can not be retrieved by index (it doesn't make sense in this case...).

They can be retrieved by name

physpar[:,1]

In [9]:
physpar['age_2a_tau']
Out[9]:
<Column name='age_2a_tau' dtype='float32' length=35932>
9.1
10.0
7.6
9.1
7.6
9.1
8.3
8.5
9.5
8.6
8.7
7.6
...
8.6
8.7
8.9
8.8
8.7
8.3
9.2
9.4
8.7
8.3
7.8
9.0

Subcatalog (columns selection)

Using the same syntax, we can select a sub catalog (selection by columns in this case)

In [10]:
physpar_sel=physpar[['Seq', 'UMag_6a_tau', 'VMag_6a_tau', 'JMag_6a_tau']]
physpar_sel
Out[10]:
Table length=35932
SeqUMag_6a_tauVMag_6a_tauJMag_6a_tau
int32float32float32float32
1-20.41-21.91-22.79
2-12.2-13.77-14.47
3-19.43-19.12-18.34
4-21.5-23.06-23.76
5-24.21-25.98-26.87
6-13.36-14.62-15.18
7-16.63-17.22-17.86
8-18.54-19.35-20.24
9-17.96-18.75-19.57
10-19.65-20.52-20.68
............
35923-15.98-16.63-16.73
35924-19.59-20.38-20.57
35925-14.38-15.01-15.62
35926-17.34-17.95-18.7
35927-16.37-17.43-17.54
35928-16.22-17.41-17.82
35929-16.92-17.32-17.43
35930-19.25-19.47-19.95
35931-19.05-19.25-19.18
35932-20.59-21.35-21.38
In [ ]:
 

Open the masses catalog

In [11]:
#Read coordinates and masses values
# https://archive.stsci.edu/missions/hlsp/candels/uds/catalogs/v1/
filename = 'data/hlsp_candels_hst_wfc3_uds_santini_v1_mass_cat.fits'
mass = Table.read(filename, format='fits')
mass
Out[11]:
Table length=35932
SeqRAdegDECdegHmagH_SNRPhotFlagStarFlagClass_starAGNFlagzbestzspecq_zspecr_zspeczphotzphot_l68zphot_u68zphot_l95zphot_u95M_meds_medM_neb_meds_neb_meddelta_MzM_2a_tauM_2d_tauM_4bM_6a_tauM_10cM_11a_tauM_12aM_13a_tauM_14aM_6a_tau^NEBM_6a_deltauM_6a_invtauM_10c^dustM_12a_tauM_14a_constM_14a_linM_14a_deltauM_14a_tau
int32float64float64float32float32int16int16float32int16float32float32int16bytes39float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32
134.2237625-5.278052827.344.03600.5204.137-99.0-99none4.1371.337.570.059.66137000000000.0125000000000.022000000000.0116000000000.06.28110.8911.2710.5310.3610.6510.2710.3811.4711.410.349.829.0911.3410.611.411.3311.3211.3
234.2239037-5.277948924.817.41200.600.252-99.0-99none0.2520.062.130.013.8721200000.021400000.07270000.09570000.00.6777.8-99.06.47.396.397.037.536.936.937.397.427.36.397.446.926.876.936.93
334.2234917-5.277952226.27.04400.002.378-99.0-99none2.3782.156.430.59.51940000000.01250000000.01360000000.0827000000.00.9159.229.259.488.1210.099.139.49.599.38.058.168.1110.159.229.38.948.659.0
434.2651062-5.277749199.00.0200.0102.888-99.0-99none2.8882.763.121.028.62118000000000.025800000000.0114000000000.049100000000.00.56211.1411.3511.5110.8310.8511.0211.011.1211.0910.8310.8211.0810.8511.0211.211.1211.0911.09
534.2953682-5.27764823.8924.33400.004.6-99.0-99none4.61.238.110.039.73271000000000.0453000000000.0397000000000.0552000000000.02.99510.6311.5111.5212.0811.8810.7111.711.4810.412.0712.0612.0411.8811.9310.49.9811.2611.86
634.2623291-5.277638923.529.62000.9900.12-99.0-99none0.120.050.180.010.2220500000.08010000.025200000.09010000.00.4757.368.067.737.577.147.297.177.337.237.567.587.557.397.177.517.417.237.23
734.2735214-5.277461126.346.46000.000.905-99.0-99none0.9050.850.980.772.6267600000.033500000.074500000.040400000.00.6097.938.27.818.157.847.827.837.677.768.118.07.817.847.697.767.757.737.75
834.2244873-5.277385225.277.07100.3602.379-99.0-99none2.3791.962.821.593.071090000000.0241000000.01020000000.0224000000.0-99.09.089.519.229.149.228.98.99.089.049.129.139.268.918.859.049.018.999.04
934.2892265-5.277386299.00.0200.9101.827-99.0-99none1.8271.632.091.428.1983000000.0520000000.0816000000.0492000000.00.5439.139.389.269.067.297.558.669.118.919.049.028.857.298.468.918.678.638.71
1034.2341118-5.277367124.7713.57000.002.421-99.0-99none2.4212.322.552.232.772000000000.0343000000.01820000000.0283000000.00.3069.339.419.399.349.299.269.219.419.269.329.349.369.299.179.229.219.239.26
...........................................................................................................................
3592334.4241371-5.13193726.334.58000.000.759-99.0-99none0.7590.710.810.650.8761500000.027700000.062900000.010500000.01.287.978.17.917.237.777.837.727.957.87.847.457.317.777.77.667.547.777.8
3592434.4255409-5.13037326.874.09000.5403.886-99.0-99none3.8863.784.03.674.131530000000.0711000000.01120000000.0304000000.0-99.09.339.219.399.339.338.979.39.48.99.139.269.289.339.268.98.738.839.0
3592534.3481674-5.135999227.035.61000.900.621-99.0-99none0.6210.583.370.293.5813800000.06670000.07450000.06420000.00.6827.327.26.966.717.197.257.117.326.916.517.256.77.197.087.046.916.947.08
3592634.3149147-5.133644126.445.01000.1501.703-99.0-99none1.7031.292.110.762.62182000000.042700000.0147000000.016800000.00.558.348.478.438.238.228.228.178.48.168.118.298.268.118.138.268.168.188.29
3592734.3862114-5.133107226.863.93000.9101.68-99.0-99none1.681.212.20.542.79200000000.084300000.0196000000.077400000.00.9478.518.778.698.437.378.128.218.378.048.318.278.477.378.347.997.847.928.04
3592834.3383026-5.132746227.254.63000.7702.183-99.0-99none2.1831.522.850.589.49235000000.0394000000.039400000.028100000.00.8348.9810.037.288.376.357.838.918.297.77.118.398.4310.169.057.77.537.637.72
3592934.4137039-5.130691126.644.19000.6801.396-99.0-99none1.3961.211.591.092.1259200000.021600000.039800000.04330000.0-99.07.927.367.97.877.917.557.827.927.587.67.897.887.917.797.587.437.467.59
3593034.2911873-5.133760926.616.47000.9803.357-99.0-99none3.3573.253.453.03.55441000000.0165000000.0266000000.095800000.00.4738.788.928.448.419.138.458.88.478.598.48.468.28.818.798.598.488.538.62
3593134.3882599-5.133396126.854.03000.8903.458-99.0-99none3.4583.373.563.23.73187000000.033800000.0223000000.034600000.0-99.08.168.998.678.248.138.38.278.248.398.38.058.318.138.38.398.258.268.4
3593234.4994812-5.133169226.24.64000.9305.251-99.0-99none5.2515.125.374.965.463820000000.01760000000.02740000000.0932000000.0-99.09.799.79.759.69.89.229.589.769.419.589.569.69.89.529.39.139.299.41
In [ ]:
 

again perform columns selection on this catalog

In [12]:
mass_sel=mass[['Seq', 'RAdeg', 'DECdeg', 'zbest', 'StarFlag', 'AGNFlag', 'M_med']]
mass_sel
Out[12]:
Table length=35932
SeqRAdegDECdegzbestStarFlagAGNFlagM_med
int32float64float64float32int16int16float32
134.2237625-5.27805284.13700137000000000.0
234.2239037-5.27794890.2520021200000.0
334.2234917-5.27795222.378001940000000.0
434.2651062-5.27774912.88800118000000000.0
534.2953682-5.2776484.600271000000000.0
634.2623291-5.27763890.120020500000.0
734.2735214-5.27746110.9050067600000.0
834.2244873-5.27738522.379001090000000.0
934.2892265-5.27738621.82700983000000.0
1034.2341118-5.27736712.421002000000000.0
.....................
3592334.4241371-5.1319370.7590061500000.0
3592434.4255409-5.1303733.886001530000000.0
3592534.3481674-5.13599920.6210013800000.0
3592634.3149147-5.13364411.70300182000000.0
3592734.3862114-5.13310721.6800200000000.0
3592834.3383026-5.13274622.18300235000000.0
3592934.4137039-5.13069111.3960059200000.0
3593034.2911873-5.13376093.35700441000000.0
3593134.3882599-5.13339613.45800187000000.0
3593234.4994812-5.13316925.251003820000000.0
In [ ]:
 

Join the 2 catalogs

Perform a join on the tables on specified keys (column names)

  • keys: Name(s) of column(s) used to match rows of left and right tables. Default is to use all columns which are common to both tables.
  • join_type: Join type inner, outer, left, right (default is inner)
In [13]:
from astropy.table import join
joined = join(mass_sel, physpar_sel, keys='Seq', join_type='inner')
WARNING: MergeConflictWarning: Cannot merge meta key 'DATE-HDU' types <class 'str'> and <class 'str'>, choosing DATE-HDU='2014-11-18T13:05:21' [astropy.utils.metadata]
In [14]:
joined
Out[14]:
Table length=35932
SeqRAdegDECdegzbestStarFlagAGNFlagM_medUMag_6a_tauVMag_6a_tauJMag_6a_tau
int32float64float64float32int16int16float32float32float32float32
134.2237625-5.27805284.13700137000000000.0-20.41-21.91-22.79
234.2239037-5.27794890.2520021200000.0-12.2-13.77-14.47
334.2234917-5.27795222.378001940000000.0-19.43-19.12-18.34
434.2651062-5.27774912.88800118000000000.0-21.5-23.06-23.76
534.2953682-5.2776484.600271000000000.0-24.21-25.98-26.87
634.2623291-5.27763890.120020500000.0-13.36-14.62-15.18
734.2735214-5.27746110.9050067600000.0-16.63-17.22-17.86
834.2244873-5.27738522.379001090000000.0-18.54-19.35-20.24
934.2892265-5.27738621.82700983000000.0-17.96-18.75-19.57
1034.2341118-5.27736712.421002000000000.0-19.65-20.52-20.68
..............................
3592334.4241371-5.1319370.7590061500000.0-15.98-16.63-16.73
3592434.4255409-5.1303733.886001530000000.0-19.59-20.38-20.57
3592534.3481674-5.13599920.6210013800000.0-14.38-15.01-15.62
3592634.3149147-5.13364411.70300182000000.0-17.34-17.95-18.7
3592734.3862114-5.13310721.6800200000000.0-16.37-17.43-17.54
3592834.3383026-5.13274622.18300235000000.0-16.22-17.41-17.82
3592934.4137039-5.13069111.3960059200000.0-16.92-17.32-17.43
3593034.2911873-5.13376093.35700441000000.0-19.25-19.47-19.95
3593134.3882599-5.13339613.45800187000000.0-19.05-19.25-19.18
3593234.4994812-5.13316925.251003820000000.0-20.59-21.35-21.38

stack vertically

The Table class supports stacking tables vertically with the vstack function This process is also commonly known as concatenating or appending tables in the row direction. There are 3 types of vstack: outer, inner and exact.

In [15]:
from astropy.table import Table, vstack
obs1 = Table.read("data/obs1.dat", format='ascii')
obs1
Out[15]:
Table length=3
nameobs_datemag_blogLx
str4str10float64float64
M312012-01-0217.042.5
M822012-10-2916.243.5
M1012012-10-3115.144.5
In [16]:
obs2 = Table.read("data/obs2.dat", format='ascii')
obs2
Out[16]:
Table length=3
nameobs_datelogLx
str7str10float64
NGC35162011-11-1142.1
M311999-01-0543.1
M822012-10-3045.0

outer vstack

The obs2 table is missing the mag_b column, so in the stacked output table those values are marked as missing

In [17]:
#Join type outer
v1=vstack([obs1, obs2])
v1
Out[17]:
Table masked=True length=6
nameobs_datemag_blogLx
str7str10float64float64
M312012-01-0217.042.5
M822012-10-2916.243.5
M1012012-10-3115.144.5
NGC35162011-11-11--42.1
M311999-01-05--43.1
M822012-10-30--45.0
In [18]:
v1['mag_b'].data
Out[18]:
masked_BaseColumn(data=[17.0, 16.2, 15.1, --, --, --],
                  mask=[False, False, False,  True,  True,  True],
            fill_value=1e+20)

inner vstack

In the case of join_type='inner', only the common columns (the intersection) are present in the output table.

In [19]:
#Join type inner
vstack([obs1, obs2], join_type='inner')
Out[19]:
Table length=6
nameobs_datelogLx
str7str10float64
M312012-01-0242.5
M822012-10-2943.5
M1012012-10-3144.5
NGC35162011-11-1142.1
M311999-01-0543.1
M822012-10-3045.0

exact vstack

In the case of join_type='exact', the vstack requires that all the input tables have exactly the same column names.

In [ ]:
vstack([obs1, obs2], join_type='exact') #Error!
In [20]:
obs3 = Table.read("""name    obs_date    mag_b  logLx
                     M45     2012-02-03  15.0   40.5""", format='ascii')
vstack([obs1, obs3], 'exact')
Out[20]:
Table length=4
nameobs_datemag_blogLx
str4str10float64float64
M312012-01-0217.042.5
M822012-10-2916.243.5
M1012012-10-3115.144.5
M452012-02-0315.040.5

stack-horizontally

hstack function acts like vstack, but it works on rows (instead of columns). Also in this case 3 types of join are provided: outer, inner and exact.

Join tables

The Table class supports the database join operation. This provides a flexible and powerful way to combine tables based on the values in one or more key columns.

In [21]:
from astropy.table import join
optical = Table.read("data/optical.dat", format='ascii')
optical
Out[21]:
Table length=3
nameobs_datemag_bmag_v
str4str10float64float64
M312012-01-0217.016.0
M822012-10-2916.215.2
M1012012-10-3115.115.5
In [22]:
xray = Table.read("data/xray.dat", format='ascii')
xray
Out[22]:
Table length=3
nameobs_datelogLx
str7str10float64
NGC35162011-11-1142.1
M311999-01-0543.1
M822012-10-2945.0

Inner join

Represents the strict intersection of the two tables on the key columns

In [23]:
join(optical, xray)
Out[23]:
Table length=1
nameobs_datemag_bmag_vlogLx
str7str10float64float64float64
M822012-10-2916.215.245.0
In [24]:
join(optical, xray, keys='name')
Out[24]:
Table length=2
nameobs_date_1mag_bmag_vobs_date_2logLx
str7str10float64float64str10float64
M312012-01-0217.016.01999-01-0543.1
M822012-10-2916.215.22012-10-2945.0
In [ ]:
 

Left join

The left join creates a new table which has every row from the left table and includes matching values from the right table when available

In [25]:
join(optical, xray, join_type='left')
Out[25]:
Table masked=True length=3
nameobs_datemag_bmag_vlogLx
str7str10float64float64float64
M1012012-10-3115.115.5--
M312012-01-0217.016.0--
M822012-10-2916.215.245.0
In [26]:
join(optical, xray, join_type='left', keys='name')
Out[26]:
Table masked=True length=3
nameobs_date_1mag_bmag_vobs_date_2logLx
str7str10float64float64str10float64
M1012012-10-3115.115.5----
M312012-01-0217.016.01999-01-0543.1
M822012-10-2916.215.22012-10-2945.0
In [27]:
join(optical, xray, join_type='left')
Out[27]:
Table masked=True length=3
nameobs_datemag_bmag_vlogLx
str7str10float64float64float64
M1012012-10-3115.115.5--
M312012-01-0217.016.0--
M822012-10-2916.215.245.0

right join

Likewise one can construct a new table with every row of the right table and matching left values (when available) using join_type=right.

outer join

To make a table with the union of rows from both tables do an outer join

In [28]:
join(optical, xray, join_type='outer')
Out[28]:
Table masked=True length=5
nameobs_datemag_bmag_vlogLx
str7str10float64float64float64
M1012012-10-3115.115.5--
M311999-01-05----43.1
M312012-01-0217.016.0--
M822012-10-2916.215.245.0
NGC35162011-11-11----42.1
In [29]:
join(optical, xray, join_type='outer', keys='name')
Out[29]:
Table masked=True length=4
nameobs_date_1mag_bmag_vobs_date_2logLx
str7str10float64float64str10float64
M1012012-10-3115.115.5----
M312012-01-0217.016.01999-01-0543.1
M822012-10-2916.215.22012-10-2945.0
NGC3516------2011-11-1142.1

unique rows

The unique function returns a sorted table containing the first row for each unique keys column value. If no keys are provided it returns a sorted table containing all the fully unique rows

In [30]:
from astropy.table import unique
obs = Table.read("""name    obs_date    mag_b  mag_v
                    M31     2012-01-02  17.0   17.5
                    M82     2012-02-14  16.2   14.5
                    M101    2012-01-02  15.1   13.5
                    M31     2012-01-02  17.1   17.4
                    M101    2012-01-02  15.1   13.5
                    M82     2012-02-14  16.2   14.5
                    M31     2012-02-14  16.9   17.3
                    M82     2012-02-14  15.2   15.5
                    M101    2012-02-14  15.0   13.6
                    M82     2012-03-26  15.7   16.5
                    M101    2012-03-26  15.1   13.5
                    M101    2012-03-26  14.8   14.3""", format='ascii')
unique(obs, keys='name')
Out[30]:
Table length=3
nameobs_datemag_bmag_v
str4str10float64float64
M1012012-01-0215.113.5
M312012-01-0217.017.5
M822012-02-1416.214.5
In [31]:
unique(obs, keys=['name', 'obs_date'])
Out[31]:
Table length=7
nameobs_datemag_bmag_v
str4str10float64float64
M1012012-01-0215.113.5
M1012012-02-1415.013.6
M1012012-03-2615.113.5
M312012-01-0217.017.5
M312012-02-1416.917.3
M822012-02-1416.214.5
M822012-03-2615.716.5

Sort

In [32]:
obs.sort(['name'])
obs
Out[32]:
Table length=12
nameobs_datemag_bmag_v
str4str10float64float64
M1012012-01-0215.113.5
M1012012-01-0215.113.5
M1012012-02-1415.013.6
M1012012-03-2615.113.5
M1012012-03-2614.814.3
M312012-01-0217.017.5
M312012-01-0217.117.4
M312012-02-1416.917.3
M822012-02-1416.214.5
M822012-02-1416.214.5
M822012-02-1415.215.5
M822012-03-2615.716.5
In [33]:
obs.sort(['name', 'mag_b'])
obs
Out[33]:
Table length=12
nameobs_datemag_bmag_v
str4str10float64float64
M1012012-03-2614.814.3
M1012012-02-1415.013.6
M1012012-01-0215.113.5
M1012012-01-0215.113.5
M1012012-03-2615.113.5
M312012-02-1416.917.3
M312012-01-0217.017.5
M312012-01-0217.117.4
M822012-02-1415.215.5
M822012-03-2615.716.5
M822012-02-1416.214.5
M822012-02-1416.214.5

NOTE: unlike the other methods, sort works in place (it modifies the table itself)

... back to the execise

In [34]:
joined
Out[34]:
Table length=35932
SeqRAdegDECdegzbestStarFlagAGNFlagM_medUMag_6a_tauVMag_6a_tauJMag_6a_tau
int32float64float64float32int16int16float32float32float32float32
134.2237625-5.27805284.13700137000000000.0-20.41-21.91-22.79
234.2239037-5.27794890.2520021200000.0-12.2-13.77-14.47
334.2234917-5.27795222.378001940000000.0-19.43-19.12-18.34
434.2651062-5.27774912.88800118000000000.0-21.5-23.06-23.76
534.2953682-5.2776484.600271000000000.0-24.21-25.98-26.87
634.2623291-5.27763890.120020500000.0-13.36-14.62-15.18
734.2735214-5.27746110.9050067600000.0-16.63-17.22-17.86
834.2244873-5.27738522.379001090000000.0-18.54-19.35-20.24
934.2892265-5.27738621.82700983000000.0-17.96-18.75-19.57
1034.2341118-5.27736712.421002000000000.0-19.65-20.52-20.68
..............................
3592334.4241371-5.1319370.7590061500000.0-15.98-16.63-16.73
3592434.4255409-5.1303733.886001530000000.0-19.59-20.38-20.57
3592534.3481674-5.13599920.6210013800000.0-14.38-15.01-15.62
3592634.3149147-5.13364411.70300182000000.0-17.34-17.95-18.7
3592734.3862114-5.13310721.6800200000000.0-16.37-17.43-17.54
3592834.3383026-5.13274622.18300235000000.0-16.22-17.41-17.82
3592934.4137039-5.13069111.3960059200000.0-16.92-17.32-17.43
3593034.2911873-5.13376093.35700441000000.0-19.25-19.47-19.95
3593134.3882599-5.13339613.45800187000000.0-19.05-19.25-19.18
3593234.4994812-5.13316925.251003820000000.0-20.59-21.35-21.38

Rename columns

In [35]:
joined.rename_column('M_med', 'M')
joined.rename_column('UMag_6a_tau', 'U')
joined.rename_column('VMag_6a_tau', 'V')
joined.rename_column('JMag_6a_tau', 'J')
joined.rename_column('zbest', 'z')
In [36]:
joined
Out[36]:
Table length=35932
SeqRAdegDECdegzStarFlagAGNFlagMUVJ
int32float64float64float32int16int16float32float32float32float32
134.2237625-5.27805284.13700137000000000.0-20.41-21.91-22.79
234.2239037-5.27794890.2520021200000.0-12.2-13.77-14.47
334.2234917-5.27795222.378001940000000.0-19.43-19.12-18.34
434.2651062-5.27774912.88800118000000000.0-21.5-23.06-23.76
534.2953682-5.2776484.600271000000000.0-24.21-25.98-26.87
634.2623291-5.27763890.120020500000.0-13.36-14.62-15.18
734.2735214-5.27746110.9050067600000.0-16.63-17.22-17.86
834.2244873-5.27738522.379001090000000.0-18.54-19.35-20.24
934.2892265-5.27738621.82700983000000.0-17.96-18.75-19.57
1034.2341118-5.27736712.421002000000000.0-19.65-20.52-20.68
..............................
3592334.4241371-5.1319370.7590061500000.0-15.98-16.63-16.73
3592434.4255409-5.1303733.886001530000000.0-19.59-20.38-20.57
3592534.3481674-5.13599920.6210013800000.0-14.38-15.01-15.62
3592634.3149147-5.13364411.70300182000000.0-17.34-17.95-18.7
3592734.3862114-5.13310721.6800200000000.0-16.37-17.43-17.54
3592834.3383026-5.13274622.18300235000000.0-16.22-17.41-17.82
3592934.4137039-5.13069111.3960059200000.0-16.92-17.32-17.43
3593034.2911873-5.13376093.35700441000000.0-19.25-19.47-19.95
3593134.3882599-5.13339613.45800187000000.0-19.05-19.25-19.18
3593234.4994812-5.13316925.251003820000000.0-20.59-21.35-21.38

Add units

In [37]:
from astropy import units as u

joined['DECdeg'].unit=u.deg
joined['RAdeg'].unit=u.deg
joined['U'].unit=u.ABmag
joined['V'].unit=u.ABmag
joined['J'].unit=u.ABmag
joined['M'].unit=u.solMass
In [38]:
joined
Out[38]:
Table length=35932
SeqRAdegDECdegzStarFlagAGNFlagMUVJ
degdegsolMassmag(AB)mag(AB)mag(AB)
int32float64float64float32int16int16float32float32float32float32
134.2237625-5.27805284.13700137000000000.0-20.41-21.91-22.79
234.2239037-5.27794890.2520021200000.0-12.2-13.77-14.47
334.2234917-5.27795222.378001940000000.0-19.43-19.12-18.34
434.2651062-5.27774912.88800118000000000.0-21.5-23.06-23.76
534.2953682-5.2776484.600271000000000.0-24.21-25.98-26.87
634.2623291-5.27763890.120020500000.0-13.36-14.62-15.18
734.2735214-5.27746110.9050067600000.0-16.63-17.22-17.86
834.2244873-5.27738522.379001090000000.0-18.54-19.35-20.24
934.2892265-5.27738621.82700983000000.0-17.96-18.75-19.57
..............................
3592334.4241371-5.1319370.7590061500000.0-15.98-16.63-16.73
3592434.4255409-5.1303733.886001530000000.0-19.59-20.38-20.57
3592534.3481674-5.13599920.6210013800000.0-14.38-15.01-15.62
3592634.3149147-5.13364411.70300182000000.0-17.34-17.95-18.7
3592734.3862114-5.13310721.6800200000000.0-16.37-17.43-17.54
3592834.3383026-5.13274622.18300235000000.0-16.22-17.41-17.82
3592934.4137039-5.13069111.3960059200000.0-16.92-17.32-17.43
3593034.2911873-5.13376093.35700441000000.0-19.25-19.47-19.95
3593134.3882599-5.13339613.45800187000000.0-19.05-19.25-19.18
3593234.4994812-5.13316925.251003820000000.0-20.59-21.35-21.38

Units and quantities

astropy.units handles defining, converting between, and performing arithmetic operations with physical quantities, such as meters, seconds, Hz, etc.

It also handles logarithmic units such as magnitude and decibel.

quantities are the combination of a value and a unit.

The easiest way to create a Quantity is to simply multiply or divide a value by one of the built-in units.

It works with scalars, sequences and Numpy arrays

In [39]:
v = 23563.7 * u.kilometer / (1.8 * u.second)
v
v.value
v.unit
Out[39]:
$\mathrm{\frac{km}{s}}$
In [40]:
x=2.7*u.hour*v
x
x=x.decompose()
x
Out[40]:
$1.2724398 \times 10^{11} \; \mathrm{m}$
In [41]:
x=x.to(u.lightyear)
x
Out[41]:
$1.3449699 \times 10^{-5} \; \mathrm{lyr}$
In [ ]:
 

Select rows

We want select all object that are neither stars nor AGNs

In [42]:
no_star = (joined['StarFlag'] == 0)
no_agn = (joined['AGNFlag'] == 0)
just_galaxies = no_star & no_agn
selection = joined[just_galaxies]

Syntax more compact

In [43]:
uds=joined[(joined['StarFlag'] == 0) & (joined['AGNFlag'] == 0)]
In [44]:
len(uds)
Out[44]:
35852

numpy.where

numpy.where returns elements numpy.where(condition[, x, y]) chosen from x or y depending on condition

In [45]:
a=np.arange(10)
np.where(a<5, 2*a, 3.14)
Out[45]:
array([0.  , 2.  , 4.  , 6.  , 8.  , 3.14, 3.14, 3.14, 3.14, 3.14])
In [46]:
np.where(a<5)
Out[46]:
(array([0, 1, 2, 3, 4]),)
In [47]:
a<5
Out[47]:
array([ True,  True,  True,  True,  True, False, False, False, False,
       False])

NOTE: when only condition is provided, this function is a shorthand for np.nonzero. Using nonzero directly should be preferred, as it behaves correctly for subclasses.

In [48]:
np.nonzero(a<5)
Out[48]:
(array([0, 1, 2, 3, 4]),)
In [ ]:
 

Remove columns

star and ANG flags are no more required now

In [49]:
uds.remove_columns(['StarFlag', 'AGNFlag'])
In [ ]:
 

Create and add new columns

The selection of the passive galaxies will be performed on the V-J/U-V color/color plane. We want to add these values to the catalog

In [50]:
#Compute colors (add columns like arrays)
uv = uds['U'] - uds['V']
vj = uds['V'] - uds['J']

#Add columns to table
uds.add_column(uv, name='U-V', index=4)
uds.add_column(vj, name='V-J', index=5)
In [51]:
uv = uds['U'] - uds['V']
vj
Out[51]:
<Column name='V' dtype='float32' unit='mag(AB)' length=35852>
0.88000107
0.6999998
-0.7800007
0.70000076
0.8900013
0.5600004
0.6400013
0.8899994
0.8199997
0.15999985
0.80999947
-0.7400017
...
-0.07999992
-0.22000027
0.10000038
0.19000053
0.60999966
0.75
0.11000061
0.40999985
0.11000061
0.48000145
-0.069999695
0.02999878

Define passive galaxies by redfhit bins

  • create a plot grid with 3 different redshift bins: $z<0.5$, $0.5\leq z<1.0$, $z\ge1.0$
In [52]:
#%matplotlib qt
%matplotlib notebook
In [53]:
#Import moudules
import matplotlib.pyplot as plt

How to display data: matplotlib

  • matplotlib is a Python plotting library
  • produces publication quality figures
  • can be used in Python scripts, Python/IPython shells, the Jupyter notebook, ...
  • matplotlib.pyplot provides a MATLAB-like plotting framework.
  • import pylab is no longer recommended

%matplotlib

Set up matplotlib to work interactively

This function lets you activate matplotlib interactive support at any point during an IPython session. It does not import anything into the interactive namespace.

In this case, where the matplotlib default is TkAgg: %matplotlib Using matplotlib backend: TkAgg

But you can explicitly request a different GUI backend: %matplotlib qt

You can list the available backends using the -l/–list option: %matplotlib --list

In [ ]:
 

The plot grid

Create a plot grid a 3 different redshift bins: $z<0.5$, $0.5\le z<1.0$, $z\ge1.0$

In [54]:
#Add prepare the layout 2x2
fig = plt.figure("color vs color")
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222, sharex=ax1, sharey=ax1)
ax3 = fig.add_subplot(223, sharex=ax1, sharey=ax1)
ax1.set_ylabel('U-V')
ax3.set_ylabel('U-V')
ax2.set_xlabel('V-J')
ax3.set_xlabel('V-J')
Out[54]:
Text(0.5, 0, 'V-J')

Plot z selection

In [55]:
zmask1 = uds['z'] < 0.5
gal1 = uds[zmask1]
ax1.scatter(gal1['V-J'], gal1['U-V'], alpha=0.1)

zmask2= (0.5<= uds['z']) & (uds['z'] <1.0)
gal2 = uds[zmask2]
ax2.scatter(gal2['V-J'], gal2['U-V'], alpha=0.1)

zmask3= uds['z'] >=1
gal3 = uds[zmask3]
ax3.scatter(gal3['V-J'], gal3['U-V'], alpha=0.1)
fig.show() #no interactive mode
In [56]:
gal1
Out[56]:
Table length=3684
SeqRAdegDECdegzU-VV-JMUVJ
degdegmag(AB)mag(AB)solMassmag(AB)mag(AB)mag(AB)
int32float64float64float32float32float32float32float32float32float32
234.2239037-5.27794890.2521.57000060.699999821200000.0-12.2-13.77-14.47
634.2623291-5.27763890.121.26000020.560000420500000.0-13.36-14.62-15.18
3434.3927803-5.2771330.0431.01000020.3999996221000000.0-13.33-14.34-14.74
3934.3444824-5.27691320.1271.77999970.900000621600000.0-11.66-13.44-14.34
7834.3962326-5.27652790.3621.01000020.3499994351700000.0-14.96-15.97-16.32
9334.4087143-5.2765450.2431.56999970.7100000413600000.0-12.47-14.04-14.75
9434.5502167-5.27634480.3870.68000030.05999946685300000.0-16.72-17.4-17.46
9934.3584633-5.27707480.3231.06999970.5300007447000000.0-16.84-17.91-18.44
10134.2541275-5.27653790.3011.06999970.4200000895200000.0-15.16-16.23-16.65
..............................
3576634.5426254-5.1294260.3611.26999950.550000215100000.0-12.93-14.2-14.75
3579334.3453331-5.12814710.4580.75999930.11999988621100000.0-15.02-15.78-15.9
3579734.3776741-5.13104010.1240.750.140000341320000.0-11.66-12.41-12.55
3582234.3439484-5.13067480.4830.6800003-0.1100006114700000.0-14.42-15.1-14.99
3583534.3935242-5.13121080.3561.56999970.740000727900000.0-12.58-14.15-14.89
3584834.3081474-5.13031820.4340.85000040.2399997713700000.0-13.92-14.77-15.01
3585534.4985275-5.12790490.4320.95999910.430000315800000.0-13.77-14.73-15.16
3588234.4903946-5.133110.0320.85000040.25110000.0-9.11-9.96-10.21
3590134.4618912-5.1331220.3041.61999990.739999821900000.0-12.37-13.99-14.73
3591834.5434418-5.13013410.280.710000040.38999946960000.0-13.39-14.1-14.49

Select passive galaxies

"

Williams et. al, 2009

In [57]:
#Select all passive galaxies, redshift independet
cmask = (uds['U-V'] > 1.3) & (uds['V-J'] < 1.6)

# z < 0.5 passive galaxies
pmask1 = (uds['U-V']>0.88*uds['V-J']+0.69) & cmask & zmask1
pas1 = uds[pmask1]
ax1.scatter(pas1['V-J'], pas1['U-V'], alpha=0.1, color='orange')

# 0.5 <= z < 1.0 passive galaxies
pmask2 = (uds['U-V']>0.88*uds['V-J']+0.59) & cmask & zmask2
pas2 = uds[pmask2]
ax2.scatter(pas2['V-J'], pas2['U-V'], alpha=0.1, color='orange')

# z >= 1.0 all galaxies
pmask3 = (uds['U-V']>0.88*uds['V-J']+0.49) & cmask & zmask3
pas3 = uds[pmask3]
ax3.scatter(pas3['V-J'], pas3['U-V'], alpha=0.1, color='orange')
plt.show()
In [ ]:
plt.close(fig)

Pretty plot for papers

In [58]:
fig = plt.figure("paper plot")
fig.set_figwidth(13.0)
fig.set_figheight(9.0)

fig.subplots_adjust(hspace=0, wspace=0)

#0<z<0.5
ax1=fig.add_subplot(221, ylabel='$U-V_{rest}$')
ax1.xaxis.set_visible(False)
ax1.text(2, 0.25, '$0\leq z_{best}\leq 0.5$', horizontalalignment='left', verticalalignment='bottom')
ax1.minorticks_on()
ax1.set_xlim([0.,2.6])
ax1.set_ylim([0.,2.9])
ax1.scatter(gal1['V-J'], gal1['U-V'], alpha=0.1, color='blue', label='all galaxies')
ax1.scatter(pas1['V-J'], pas1['U-V'], alpha=0.1, color='orange', label='passive galaxies')
#ax1.legend()

ax2=fig.add_subplot(222, xlabel='$V-J_{rest}$')
ax2.yaxis.set_visible(False)
ax2.text(2, 0.25, '$0.5 < z_{best} \leq 1.0$', horizontalalignment='left', verticalalignment='bottom')
ax2.minorticks_on()
ax2.set_xlim([0.,2.6])
ax2.set_ylim([0.,2.9])
ax2.scatter(gal2['V-J'], gal2['U-V'], alpha=0.1, color='blue', label='all galaxies')
ax2.scatter(pas2['V-J'], pas2['U-V'], alpha=0.1, color='orange', label='passive galaxies')
#ax2.legend()

ax3=fig.add_subplot(223, xlabel='$V-J_{rest}$', ylabel='$U-V_{rest}$')
ax3.text(2, 0.25, '$z_{best} > 1.0$', horizontalalignment='left', verticalalignment='bottom')
ax3.minorticks_on()
ax3.set_xlim([0.,2.6])
ax3.set_ylim([0.,2.9])
ax3.scatter(gal3['V-J'], gal3['U-V'], alpha=0.1, color='blue', label='all galaxies')
ax3.scatter(pas3['V-J'], pas3['U-V'], alpha=0.1, color='orange', label='passive galaxies')
leg3=ax3.legend()

for lh in leg3.legendHandles: lh.set_alpha(1)           
    
fig.savefig('tmp/paper_plot.png')
In [ ]:
plt.close(fig)

Add the passive column

In [59]:
passive = Table.Column(data=(pmask1 | pmask2 | pmask3), name="passive")
uds.add_column(passive)
In [ ]:
 

save the table

  • add the extetion name
In [60]:
uds.meta['EXTNAME']='UDS GAL'
  • write the file
In [61]:
uds.write('tmp/uds_galaxies.dat', format='ascii', overwrite=True)
In [ ]:
uds.write('tmp/uds_galaxies.fits', format='fits', overwrite=True) #ABmag raise an error

BinTableHDU.from_columns does not convert ABmag

In [62]:
for col in uds.columns:
    if uds[col].unit == u.ABmag:
        uds[col].unit = u.mag
uds.write('tmp/uds_galaxies.fits', format='fits', overwrite=True)

The 3rd catalog: morphological parameters

In [63]:
filename = 'data/uds_3dhst.v4.1_f160w.galfit'
# http://www.mpia-hd.mpg.de/homes/vdwel/allfields.tar
galfit = Table.read(filename, format='ascii')
In [64]:
galfit
Out[64]:
Table length=44102
NUMBERRADECfmagdmagredrendnqdqpadpasn
int64float64float64int64float64float64float64float64float64float64float64float64float64float64float64
134.446064-5.285457225.23350.4153770.1270380.1127756.26129.402530.050.500987-1.827558.40256.41418
234.447491-5.284816021.66930.03721330.1713240.01018162.89080.3523330.52320.0476136-86.08994.9780785.0546
334.43383-5.285184226.9870.5470640.0180.02115010.20.5007740.53770.669696-28.4017110.963.352
434.438637-5.283363121.68560.06048120.6566280.03229290.6760.1139620.47770.0350281-82.12192.5612138.4857
534.443878-5.284456023.80570.1236870.0895740.02157286.16663.254630.63970.16491868.756520.381324.6858
634.43869-5.2843383-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
734.442711-5.284338024.33390.1370390.1946820.03115160.4980.3773030.89780.11915260.019111.041314.7184
834.43681-5.284299227.94830.4114770.0180.01768781.15481.968620.12810.533146-15.000890.75974.49085
934.432861-5.284348226.16570.551780.1442880.1727634.29877.561680.0430.59804970.36583.10263.9374
1034.43959-5.282533021.56970.03669130.4754220.0213512.07050.1678540.79370.021543172.83651.7036383.1543
.............................................
4409334.363277-5.123683-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4409434.556057-5.123807226.550.8524340.3428880.5266454.40749.359240.04240.61669439.988778.24642.88182
4409534.328003-5.1227733-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4409634.368511-5.123433-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4409734.327488-5.1231423-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4409834.363106-5.1220663-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4409934.333569-5.1232193-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4410034.363682-5.1231243-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0
4410134.556389-5.123043-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.07.64875
4410234.365097-5.1219753-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.0-999.00.0

Sky coordinates match

SkyCoord provides a flexible interface for celestial coordinate representation, manipulation, and transformation between systems.

It is also possible to input coordinate values in other representations such as cartesian or cylindrical

In [65]:
from astropy.coordinates import SkyCoord
galfit_coords=SkyCoord(galfit['RA']*u.deg, galfit['DEC']*u.deg)
uds_coords=SkyCoord(uds['RAdeg'], uds['DECdeg'])
idx, d2d, _ = uds_coords.match_to_catalog_sky(galfit_coords)
In [ ]:
 
  • idx: Indexes of galfit_coords object
  • d2d: 2d separation of the matches
  • the galfit sub catalog matching with uds catalog
    match = galfit[idx]
    
In [66]:
match = galfit[idx]
In [ ]:
 

Create new columns

  • the matching ids column
In [67]:
new_col1 = Table.Column(idx, name="match_indexs")
  • the separation in match
In [68]:
new_col2 = Table.Column(data=d2d.arcsec, name="separation", unit=u.arcsec)
In [ ]:
 

Add columns to UDS table

In [69]:
match["re"].unit=u.arcsec
uds.add_columns((match["re"], match["q"], new_col1, new_col2))
In [70]:
uds
Out[70]:
Table length=35852
SeqRAdegDECdegzU-VV-JMUVJpassivereqmatch_indexsseparation
degdegmagmagsolMassmagmagmagarcsecarcsec
int32float64float64float32float32float32float32float32float32float32boolfloat64float64int64float64
134.2237625-5.27805284.1371.50.88000107137000000000.0-20.41-21.91-22.79True0.568140.15871310.20622415473116226
234.2239037-5.27794890.2521.57000060.699999821200000.0-12.2-13.77-14.47True0.568140.15871310.47447425015165035
334.2234917-5.27795222.378-0.30999947-0.78000071940000000.0-19.43-19.12-18.34False16.43830.5551320.03549758951776946
434.2651062-5.27774912.8881.55999950.70000076118000000000.0-21.5-23.06-23.76True0.239430.71451540.22590954165180346
534.2953682-5.2776484.61.77000050.8900013271000000000.0-24.21-25.98-26.87True0.3797040.95511680.19857159952291267
634.2623291-5.27763890.121.26000020.560000420500000.0-13.36-14.62-15.18False0.0180.051480.006849387088246349
734.2735214-5.27746110.9050.590000150.640001367600000.0-16.63-17.22-17.86False0.2690880.05811530.09665923828623986
834.2244873-5.27738522.3790.809999470.88999941090000000.0-18.54-19.35-20.24False24.00.01371510.3940623624551962
934.2892265-5.27738621.8270.79000090.8199997983000000.0-17.96-18.75-19.57False0.2145540.17323564.763845787896464
.............................................
3592334.4241371-5.1319370.7590.64999960.1000003861500000.0-15.98-16.63-16.73False0.3159840.1541424740.020072478348473265
3592434.4255409-5.1303733.8860.7899990.190000531530000000.0-19.59-20.38-20.57False0.1320120.0335428980.01440446332452097
3592534.3481674-5.13599920.6210.63000010.6099996613800000.0-14.38-15.01-15.62False0.0180.003878413770.037092434048780334
3592634.3149147-5.13364411.7030.61000060.75182000000.0-17.34-17.95-18.7False0.2293020.0402420560.04357327920768605
3592734.3862114-5.13310721.681.05999950.11000061200000000.0-16.37-17.43-17.54False0.1296360.0349421900.07704229624744328
3592834.3383026-5.13274622.1831.19000050.40999985235000000.0-16.22-17.41-17.82False0.5920560.1544421252.171254404698205
3592934.4137039-5.13069111.3960.399999620.1100006159200000.0-16.92-17.32-17.43False0.1767240.1628428010.02032822958840174
3593034.2911873-5.13376093.3570.219999310.48000145441000000.0-19.25-19.47-19.95False0.0180.0745420180.02134406957436333
3593134.3882599-5.13339613.4580.20000076-0.069999695187000000.0-19.05-19.25-19.18False0.0437340.0679420990.035404743677074774
3593234.4994812-5.13316925.2510.76000020.029998783820000000.0-20.59-21.35-21.38False0.0525420.2257421710.03113385501535447

Check separation values

In [71]:
fig = plt.figure("separation")
plt.clf()
_ = plt.hist(uds["separation"], color='red', bins=50)
In [ ]:
 
In [72]:
plt.clf()
_ = plt.hist(uds["separation"][uds["separation"]<0.5], color='orange', bins=50)
In [ ]:
plt.close(fig)

Final selection

  • good separation flags = uds["separation"] < 0.3

  • passive flags&= uds["passive"]

  • suitable z bin flags&= uds["z"]<=0.5

  • suitable in M flags&= uds["M"]>10**10

  • and suitable re flags&= uds["re"]>0.03

In [73]:
flags = uds["separation"] < 0.3
flags&= uds["passive"]
flags&= uds["z"]<=0.5
flags&= uds["M"]>10**10
flags&= uds["re"]>0.03
good=uds[flags]
In [74]:
good
Out[74]:
Table length=36
SeqRAdegDECdegzU-VV-JMUVJpassivereqmatch_indexsseparation
degdegmagmagsolMassmagmagmagarcsecarcsec
int32float64float64float32float32float32float32float32float32float32boolfloat64float64int64float64
251334.4621124-5.2709680.4412.0399991.159999884300000000.0-20.26-22.3-23.46True1.513990.830410020.0710198672830541
385434.4495239-5.26011610.48942.2099991.489999835400000000.0-18.76-20.97-22.46True0.798930.194648300.0075684946179961875
438434.2754097-5.25313620.4171.64999961.090000210900000000.0-18.61-20.26-21.35True0.564690.461674900.028717306350864155
456334.5523758-5.25278810.4012.19000051.329999931800000000.0-18.35-20.54-21.87True0.267330.630578150.015579713810220044
843034.3956871-5.23175620.35052.10000041.239999823700000000.0-18.65-20.75-21.99True0.4201560.3514139750.01512424948739272
845134.4872818-5.23042680.33581.90000151.28999911900000000.0-18.63-20.53-21.82True0.2812320.6697141920.024931136600014097
928634.4395332-5.22833680.20662.11000061.260000219000000000.0-17.98-20.09-21.35True0.399330.9479143260.03168811283711497
933434.3924141-5.22756580.44642.10999871.2568700000000.0-19.79-21.9-23.15True0.6471120.7371146990.004334849955685843
1074634.4451752-5.22257710.2932.12000081.239999841200000000.0-19.15-21.27-22.51True0.5671980.271155020.01874208646347688
.............................................
2015634.341362-5.16673090.44781.65999980.989999821500000000.0-19.59-21.25-22.24True0.3949740.6832333170.07036893885583605
2037134.3828239-5.1659980.4851.98999981.260000268000000000.0-19.81-21.8-23.06True0.6450180.4405335460.014438955639872382
2084034.4787636-5.1627350.4482.10000041.239999820400000000.0-18.43-20.53-21.77True0.2257560.5085344200.003875152834750343
2099134.3604546-5.16233210.44881.77000051.099998527700000000.0-19.43-21.2-22.3True0.379110.6195346480.011251773737363342
2341634.3747139-5.14561320.4692.02000051.190000521300000000.0-18.55-20.57-21.76True0.2605620.7008393800.10512061147457963
2355734.4466362-5.14621780.4341.99000171.119998910300000000.0-18.05-20.04-21.16True0.2266140.5166389110.013698782028896874
2416734.5110435-5.14998580.43182.06000141.169998256700000000.0-19.73-21.79-22.96True0.3894480.4119379030.0033923876368344924
2615534.4003983-5.13958980.1942.0399991.230001416300000000.0-18.43-20.47-21.7True0.5727240.3117399310.0012943877254266156
2645034.5186615-5.14013390.4031.87000081.030000712300000000.0-18.39-20.26-21.29True0.1157040.7856407890.014292350334453705
2679234.3735657-5.14834120.4962.01000021.139999446500000000.0-19.9-21.91-23.05True0.5737320.8767378980.04212181560913217

cosmologies

The astropy.cosmology subpackage contains classes for representing cosmologies, and utility functions for calculating commonly used quantities that depend on a cosmological model: distances, ages and lookback times corresponding to a measured redshift or the transverse separation corresponding to a measured angular separation.

cosmology.parameters.available

Compute distances

Here WMAP9 is a built-in object describing a cosmology with the parameters from the 9-year WMAP results

In [75]:
from astropy.cosmology import parameters
parameters.available
Out[75]:
['Planck15', 'Planck13', 'WMAP9', 'WMAP7', 'WMAP5']
In [76]:
from astropy.cosmology import WMAP9

Compute re in kpc

According with the README:

  • $re$ of the catalog is the semi-major axis in arcsec of the ellipse that contains half of the total light in the best fitting Sersic model
  • $q$ if the axis ratio of the best fitting Sersic model
$$ q = \frac{b}{a} $$$$ re = \sqrt{ab} = a \sqrt{q} $$
In [77]:
re_arcmin = good["re"].to(u.arcmin)*np.sqrt(good["q"])
re_kpc = WMAP9.kpc_proper_per_arcmin(good["z"])*re_arcmin
In [ ]:
 
In [78]:
#Clear the figure
fig = plt.figure()
plt.clf()

plt.title("Size mass relation")
plt.errorbar(good['M'], re_kpc, fmt='o')#re_kpc)

#Set axis scales
plt.semilogx()
plt.semilogy()

#Set axis labels
plt.xlabel("mass ($M_{\odot}$)")
plt.ylabel("size (kpc)")

#Display dashed grid
plt.grid(which="both", ls='--')
In [ ]:
 

Useless return parameters

Syntax used to ignore returned function parameters

In [79]:
lines=["2012-01-02 M31 17.0 16.0 16.3", "2012-10-29 M82 16.2 15.2", "2012-10-31 M101"]
for line in lines:
    _, name, *_ = line.split()
    print(name)
M31
M82
M101

pandas

pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

Python has long been great for data munging and preparation, but less so for data analysis and modeling. pandas helps fill this gap, enabling you to carry out your entire data analysis workflow in Python without having to switch to a more domain specific language like R.

In [80]:
pandas=physpar.to_pandas()
pandas
Out[80]:
Seq age_2a_tau tau_2a_tau Av_2a_tau SFR_2a_tau chi2_2a_tau age_2d_tau tau_2d_tau Av_2d_tau met_2d_tau ... age_14a_deltau tau_14a_deltau EBV_14a_deltau SFR_14a_deltau q_14a_deltau age_14a_tau tau_14a_tau EBV_14a_tau SFR_14a_tau q_14a_tau
0 1 9.1 0.5 0.4 21.879999 177.000000 9.146 0.316000 0.0 0.400 ... 9.132 0.264 0.513 39.980000 1 9.131 0.419 0.469 31.780001 1
1 2 10.0 7.9 0.8 0.006000 9.040000 -99.000 -99.000000 -99.0 -99.000 ... 9.025 0.133 0.059 0.000000 1 8.955 0.151 0.058 0.000000 1
2 3 7.6 0.3 1.1 46.770000 304.000000 6.954 39.811001 1.3 5.000 ... 8.404 1.083 0.145 4.325000 1 8.780 1.945 0.080 2.087000 1
3 4 9.1 0.3 1.0 13.800000 71.900002 8.903 0.200000 1.3 0.200 ... 9.038 0.256 0.346 48.939999 2 9.032 0.262 0.251 12.490000 1
4 5 7.6 12.6 0.0 1288.000000 964000.000000 6.845 0.010000 1.1 2.500 ... 9.019 0.273 0.067 96.739998 1 9.068 0.234 0.100 34.290001 2
5 6 9.1 0.3 0.0 0.002000 41.200001 9.845 0.032000 0.0 0.020 ... 8.978 0.108 0.016 0.000000 1 8.912 0.115 0.016 0.000000 1
6 7 8.3 0.3 0.6 0.417000 14.400000 7.903 0.008000 0.1 2.500 ... 8.507 0.717 0.125 0.384000 1 8.327 0.724 0.113 0.313000 1
7 8 8.5 0.5 1.1 3.802000 2.090000 8.699 0.079000 0.2 0.200 ... 8.623 0.619 0.294 5.134000 1 8.475 0.501 0.269 3.774000 1
8 9 9.5 5.0 0.0 0.513000 3.690000 9.301 1.259000 0.0 0.400 ... 9.017 0.440 0.025 0.480000 1 9.035 1.257 0.023 0.467000 1
9 10 8.6 0.5 0.6 5.129000 2.450000 8.146 0.001000 0.1 0.200 ... 8.568 0.471 0.201 9.558000 1 8.374 0.334 0.180 7.329000 1
10 11 8.7 0.3 1.2 2.884000 1.770000 8.146 0.032000 1.2 0.400 ... 8.544 0.817 0.399 8.568000 1 8.449 0.855 0.375 6.363000 1
11 12 7.6 12.6 0.0 2.399000 123.000000 7.602 0.003000 0.2 1.000 ... 8.037 1.715 0.012 1.672000 1 8.028 2.275 0.012 1.371000 1
12 13 8.6 5.0 0.2 5.248000 3.960000 7.079 0.025000 0.9 1.000 ... 8.482 0.797 0.061 6.156000 1 8.315 0.728 0.048 5.025000 1
13 14 7.6 12.6 0.9 2.239000 50.900002 7.602 0.001000 0.5 2.500 ... 8.142 0.947 0.103 0.736000 1 8.119 1.184 0.076 0.519000 1
14 15 8.0 12.6 0.6 15.140000 18.400000 7.000 0.013000 0.9 1.000 ... 8.448 0.503 0.098 8.996000 1 8.164 0.495 0.099 8.422000 1
15 16 8.8 0.8 0.2 1.445000 2.170000 6.699 0.013000 1.0 0.005 ... 8.874 0.689 0.076 2.023000 1 8.690 0.946 0.066 1.725000 1
16 17 7.6 12.6 0.0 446.700012 146000.000000 6.778 0.003000 0.1 5.000 ... 9.001 0.232 0.015 37.340000 1 8.909 0.331 0.013 37.320000 1
17 18 9.2 0.3 0.0 0.036000 2.390000 -99.000 -99.000000 -99.0 -99.000 ... 8.612 0.723 0.531 2.875000 1 8.554 0.674 0.489 1.810000 1
18 19 9.3 12.6 0.0 0.562000 7.060000 9.079 1.000000 0.1 0.005 ... 8.772 0.927 0.076 1.149000 1 8.639 1.213 0.059 0.903000 1
19 20 9.4 3.2 0.3 3.631000 81.900002 8.653 0.631000 0.6 2.500 ... 9.086 0.282 0.047 1.726000 1 9.094 0.465 0.028 1.430000 1
20 21 8.8 1.3 0.6 12.300000 4.290000 7.699 0.010000 0.8 0.200 ... 8.459 0.387 0.224 25.040001 1 8.216 0.293 0.215 21.200001 1
21 22 8.6 3.2 0.5 8.318000 12.100000 7.146 0.002000 1.0 0.200 ... 8.681 0.694 0.140 9.531000 1 8.412 0.669 0.136 8.621000 1
22 23 8.8 0.3 0.6 0.195000 1.590000 8.079 0.005000 0.8 0.020 ... 8.771 0.511 0.238 0.577000 1 8.691 0.728 0.216 0.414000 1
23 24 8.8 0.3 0.9 0.117000 1.280000 8.079 0.008000 0.5 2.500 ... 8.787 0.320 0.269 0.268000 1 8.651 0.537 0.270 0.245000 1
24 25 8.6 0.3 0.4 0.209000 1.780000 8.699 50.118999 0.8 0.005 ... 8.691 0.769 0.135 0.345000 1 8.542 0.840 0.118 0.267000 1
25 26 8.6 0.5 2.7 257.000000 11.700000 9.301 0.040000 0.7 0.020 ... 8.519 0.463 0.747 528.000000 1 8.324 0.439 0.735 435.799988 1
26 27 8.4 0.3 0.3 0.240000 2.180000 9.602 0.316000 3.5 1.000 ... 8.460 0.837 0.080 0.299000 1 8.291 0.803 0.067 0.243000 1
27 28 8.9 1.3 0.2 1.820000 2.090000 8.301 0.063000 0.4 0.005 ... 8.574 0.828 0.137 4.527000 1 8.428 0.889 0.120 3.514000 1
28 29 8.3 0.3 0.4 2.188000 1.970000 7.602 0.003000 0.2 1.000 ... 8.408 0.880 0.113 2.799000 1 8.270 0.950 0.099 2.228000 1
29 30 9.5 5.0 0.6 0.550000 1.170000 9.477 1.259000 0.3 1.000 ... 8.571 0.867 0.313 2.706000 1 8.596 0.947 0.270 1.661000 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
35902 35903 8.3 0.8 0.4 0.324000 1.750000 6.845 0.010000 1.1 2.500 ... 8.245 0.828 0.057 0.268000 1 8.171 0.971 0.043 0.209000 1
35903 35904 9.1 0.3 0.0 0.002000 1.030000 9.146 0.316000 0.0 0.400 ... 8.415 0.431 0.325 0.076000 1 8.472 0.377 0.257 0.040000 1
35904 35905 8.5 0.3 0.0 0.355000 1.790000 7.602 0.004000 0.2 0.200 ... 8.349 0.680 0.066 0.750000 1 8.289 0.719 0.051 0.578000 1
35905 35906 8.9 0.3 0.0 0.023000 5.890000 9.079 0.398000 0.1 1.000 ... 8.399 0.670 0.103 0.074000 1 8.385 0.721 0.068 0.049000 1
35906 35907 8.6 0.3 0.5 0.251000 1.160000 8.079 0.032000 0.3 2.500 ... 8.435 0.500 0.178 0.534000 1 8.408 0.576 0.147 0.366000 1
35907 35908 9.2 0.3 0.0 0.028000 0.826000 8.146 0.001000 0.1 0.005 ... 8.360 0.958 0.423 1.094000 1 8.362 0.545 0.381 0.694000 1
35908 35909 9.0 1.3 0.0 0.162000 0.430000 9.204 100.000000 0.0 0.400 ... 8.403 0.621 0.105 0.492000 1 8.374 0.773 0.082 0.351000 1
35909 35910 8.7 0.3 0.0 0.282000 1.240000 8.653 0.200000 0.0 0.400 ... 8.340 0.698 0.088 0.786000 1 8.290 0.836 0.069 0.575000 1
35910 35911 8.8 0.8 0.0 2.089000 0.950000 8.699 0.398000 0.0 0.400 ... 8.374 0.674 0.055 4.146000 1 8.351 0.838 0.040 3.175000 1
35911 35912 8.4 0.3 0.2 2.630000 0.747000 8.146 0.032000 0.0 0.400 ... 8.366 0.670 0.080 4.133000 1 8.340 0.665 0.060 3.114000 1
35912 35913 9.1 12.6 0.5 3.890000 2.170000 7.602 0.001000 0.5 2.500 ... 8.412 0.602 0.188 8.321000 1 8.397 0.586 0.155 5.611000 1
35913 35914 9.2 0.8 0.6 3.890000 14.600000 8.544 0.079000 0.0 2.500 ... 8.625 0.132 0.220 6.686000 1 8.605 0.213 0.179 5.038000 1
35914 35915 8.5 0.3 0.0 0.126000 33.000000 9.602 0.316000 3.5 1.000 ... 8.204 0.798 0.018 0.178000 1 8.099 1.095 0.016 0.149000 1
35915 35916 9.0 0.3 1.7 28.840000 47.299999 9.000 0.050000 0.2 0.400 ... 8.413 0.530 0.877 800.000000 1 8.486 0.313 0.774 350.899994 2
35916 35917 8.1 0.8 0.8 2.344000 0.758000 7.255 0.008000 1.1 0.400 ... 8.291 0.786 0.198 2.498000 1 8.232 0.872 0.173 1.799000 1
35917 35918 8.7 0.5 0.4 0.012000 2.060000 8.204 0.040000 0.3 1.000 ... 8.604 0.153 0.132 0.013000 1 8.542 0.199 0.105 0.009000 1
35918 35919 8.9 2.0 0.0 0.347000 0.997000 8.079 0.002000 0.0 0.005 ... 8.419 0.633 0.059 0.665000 1 8.373 0.857 0.043 0.506000 1
35919 35920 8.8 0.3 0.5 0.078000 0.286000 8.146 0.008000 0.3 1.000 ... 8.395 0.515 0.180 0.185000 1 8.399 0.664 0.145 0.129000 1
35920 35921 8.6 12.6 0.0 0.427000 2.090000 6.903 0.002000 0.2 5.000 ... 8.350 0.715 0.049 0.693000 1 8.267 0.832 0.038 0.552000 1
35921 35922 8.7 0.3 0.0 0.024000 1.810000 8.954 0.631000 0.0 0.020 ... 8.482 0.421 0.107 0.075000 1 8.440 0.540 0.077 0.050000 1
35922 35923 8.9 0.3 0.0 0.041000 4.770000 8.602 0.010000 0.0 0.005 ... 8.646 0.109 0.076 0.060000 1 8.592 0.125 0.035 0.034000 1
35923 35924 8.8 0.3 0.0 1.622000 2.920000 8.146 0.032000 0.0 0.400 ... 8.454 0.473 0.094 5.245000 1 8.466 0.581 0.069 3.647000 1
35924 35925 8.7 0.3 0.5 0.025000 1.310000 7.845 0.003000 0.1 2.500 ... 8.334 0.810 0.261 0.097000 1 8.343 0.731 0.222 0.063000 1
35925 35926 8.3 0.5 0.9 1.202000 0.540000 8.000 1.259000 1.1 0.200 ... 8.342 0.758 0.242 1.649000 1 8.328 0.753 0.204 1.074000 1
35926 35927 9.2 0.5 0.0 0.048000 0.631000 9.544 1.995000 0.1 0.200 ... 8.420 0.749 0.307 0.744000 1 8.428 0.907 0.266 0.494000 2
35927 35928 9.4 1.3 0.5 0.200000 0.675000 9.255 25.118999 2.9 2.500 ... 8.363 0.727 0.234 0.434000 1 8.354 0.807 0.193 0.276000 1
35928 35929 8.7 2.0 0.0 0.209000 1.180000 7.079 0.002000 0.2 1.000 ... 8.298 0.838 0.043 0.347000 1 8.228 1.000 0.035 0.284000 1
35929 35930 8.3 12.6 0.4 3.981000 0.963000 7.544 0.005000 0.3 1.000 ... 8.359 0.600 0.078 3.405000 1 8.265 0.706 0.063 2.650000 1
35930 35931 7.8 0.3 0.1 2.570000 1.960000 8.079 0.063000 0.4 0.020 ... 8.255 0.838 0.026 2.421000 1 8.163 1.027 0.022 2.094000 1
35931 35932 9.0 0.8 0.0 4.677000 1.450000 8.079 0.004000 0.0 0.200 ... 8.516 0.360 0.068 11.790000 1 8.487 0.499 0.052 8.454000 1

35932 rows × 135 columns

In [ ]:
 

astroquery

Astroquery is an Astropy affiliated package that contains a collection of tools to access online Astronomical data. Each web service has its own sub-package

Importing astroquery on its own doesn't get you much: you need to import each sub-module specifically

$ conda install -c astropy astroquery

Query results

We can obtain Tables instances

In [ ]:
from astroquery.esasky import ESASky

# Available catalogs
ESASky.list_catalogs()

#List of tables
results=ESASky.query_object_catalogs("M31","all")
results[2]

or list of HDUImages

In [ ]:
from astroquery.ukidss import Ukidss
Ukidss.get_images(SkyCoord(49.489*u.deg, -0.27*u.deg, frame='galactic'), image_width=5 * u.arcmin)