A look at GAMA single-sersic colour profiles

Code collected from BD_analysis.ipynb and plot_illustrations.py


In [1]:
%matplotlib inline
import matplotlib
from matplotlib import pyplot as plt
# better-looking plots
plt.rcParams['font.family'] = 'serif'
plt.rcParams['figure.figsize'] = (10.0*1.3, 8*1.3)
plt.rcParams['font.size'] = 18*1.3

In [2]:
import numpy as np

In [3]:
import pandas as pd
#from galapagos_to_pandas import galapagos_to_pandas
## convert the GALAPAGOS data
#galapagos_to_pandas()
## convert the SIGMA data
#galapagos_to_pandas('/home/ppzsb1/projects/gama/qc/raw/StructureCat_SersicExp.fits',
#                    '/home/ppzsb1/quickdata/StructureCat_SersicExp.h5')

In [4]:
from astropy.io import fits as pyfits

In [5]:
data_all = pyfits.getdata('/Users/spb/Work/projects/MegaMorph/benedetta/gama_verylast.fits', 1)

In [6]:
len(data_all)


Out[6]:
38132

In [7]:
data_all = pd.DataFrame(data_all)

In [8]:
data_all = data_all+0
data_all


Out[8]:
id ALPHA_J2000 DELTA_J2000 Z MAG_GALFIT_BAND_1 u_abs g_abs r_abs i_abs z_abs ... N_GALFIT_RFBAND_2 N_GALFIT_RFBAND_3 N_GALFIT_RFBAND_4 N_GALFIT_RFBAND_5 N_GALFIT_RFBAND_6 N_GALFIT_RFBAND_7 N_GALFIT_RFBAND_8 N_GALFIT_RFBAND_9 PA_GALFIT_BAND_1 Q_GALFIT_BAND_1
0 44155 137.087892 2.808739 3.50607 16.502104 -30.350000 -30.250000 -30.120001 -29.780001 -29.870001 ... 4.141272 3.455191 -0.725040 -4.394518 -7.937863 -16.145496 -35.680294 -76.771110 -70.687460 0.551713
1 13182 139.719800 -1.926369 0.65413 12.779469 -29.520000 -30.350000 -30.510000 -29.549999 -29.629999 ... 5.966017 4.487763 1.945422 1.108694 0.701009 0.504329 1.930119 8.229734 1.703880 0.927935
2 15915 139.750905 2.807855 0.65813 13.278530 -29.059999 -29.450001 -29.719999 -29.620001 -29.680000 ... 5.243079 3.822163 1.771064 1.396175 1.443239 2.316327 6.329815 18.145018 -3.865433 0.798828
3 39758 137.350046 0.036409 1.86626 16.652788 -28.100000 -28.139999 -28.160000 -28.230000 -28.330000 ... 0.932062 0.954582 1.723231 2.534222 3.356436 5.334000 10.225748 20.837769 -50.131756 0.146471
4 52701 136.468366 2.992078 1.82550 16.925505 -27.870001 -28.209999 -28.040001 -28.110001 -28.209999 ... 2.245641 2.359882 0.441501 -1.806657 -4.139424 -9.845304 -24.191692 -55.703680 57.545220 0.897901
5 97903 132.395096 -1.066533 0.55431 14.181681 -27.820000 -28.120001 -28.360001 -28.299999 -28.549999 ... 6.100164 4.671523 2.103139 1.172701 0.654197 0.162848 0.791112 5.245525 -89.995710 0.778953
6 131966 129.931057 -1.470815 0.55351 14.074463 -27.670000 -27.959999 -27.969999 -27.950001 -28.160000 ... 4.837561 2.792238 0.302423 0.268714 0.853637 3.361862 12.253154 36.047060 -89.962820 0.944978
7 111059 131.590482 0.673698 3.01713 19.102112 -27.360001 -27.180000 -27.000000 -26.590000 -26.680000 ... 1.318288 1.985772 4.509677 6.392237 8.114543 11.925549 20.543987 37.884796 33.126312 0.304337
8 71456 134.733372 1.872066 2.15660 17.675577 -27.330000 -27.430000 -27.660000 -27.809999 -27.969999 ... 0.311761 0.296417 2.243945 4.393949 6.596430 11.934201 25.236464 54.259410 84.206580 0.095338
9 86684 133.252365 2.073570 1.08192 16.064173 -27.320000 -25.830000 -23.680000 -24.120001 -24.799999 ... 2.368952 2.996990 4.322438 4.946219 5.393690 6.140917 7.186623 8.109259 -10.606851 0.638213
10 102382 132.048009 -0.238316 4.12406 19.238909 -27.260000 -27.170000 -27.070000 -26.740000 -26.840000 ... 3.256770 1.484857 -9.813786 -19.840366 -29.553425 -52.110382 -105.944910 -219.440660 -39.696236 0.437284
11 18738 139.352988 2.876797 0.80525 15.925768 -27.030001 -27.330000 -27.480000 -27.600000 -27.709999 ... 0.979456 1.134095 1.365564 1.415380 1.419476 1.346761 0.965470 -0.199435 51.050312 0.176153
12 8567 140.149183 0.391852 2.49102 18.586226 -27.020000 -26.790001 -27.250000 -27.420000 -27.600000 ... 2.688061 2.130160 -2.544061 -6.922299 -11.228989 -21.352255 -45.819927 -97.937874 -26.000414 0.970316
13 29416 138.544739 1.902543 3.13458 19.235964 -26.920000 -27.320000 -27.480000 -27.490000 -27.590000 ... 0.820415 1.745358 8.245133 14.137227 19.880302 33.283226 65.436386 133.510790 -31.599203 0.092731
14 34320 138.036465 0.982592 2.18906 18.538130 -26.900000 -27.020000 -27.340000 -27.530001 -27.709999 ... 1.165887 1.205450 1.299489 1.350314 1.390290 1.465884 1.602734 1.815536 65.481155 0.658460
15 53450 136.182965 0.106234 2.13423 18.668710 -26.889999 -26.990000 -26.950001 -26.629999 -26.719999 ... 7.633919 7.374536 -1.129714 -10.088984 -19.169010 -41.002342 -94.995800 -212.104340 -63.835796 0.918229
16 50628 136.383965 -0.241759 4.26176 19.940268 -26.879999 -26.900000 -26.830000 -26.549999 -26.650000 ... 3.405566 3.797199 3.311574 2.265575 1.077711 -2.005944 -10.186627 -28.860662 -15.758721 0.199698
17 58746 135.675344 -0.357171 4.45120 20.453274 -26.850000 -26.690001 -26.559999 -26.200001 -26.299999 ... 3.136164 0.928248 -12.131132 -23.510021 -34.473430 -59.823036 -120.041824 -246.509430 19.229982 0.608232
18 82698 133.625730 0.703798 4.08325 20.298388 -26.840000 -26.790001 -26.700001 -26.389999 -26.490000 ... 2.179387 5.919951 25.394243 41.773403 57.384197 93.160680 177.339770 352.714630 43.955750 0.412167
19 71750 134.612162 2.434500 1.50928 17.561800 -26.799999 -26.930000 -27.110001 -27.010000 -27.100000 ... 1.350905 0.814240 3.840046 7.854690 12.121164 22.731937 49.830822 110.046800 74.776370 0.808347
20 123762 130.669306 1.859491 1.49260 17.668250 -26.780001 -26.820000 -26.770000 -26.690001 -26.790001 ... 3.047957 2.802161 1.259804 -0.103759 -1.423223 -4.484739 -11.784492 -27.162132 -89.979576 0.798262
21 70523 134.607136 0.835202 2.85500 18.717676 -26.690001 -26.940001 -26.760000 -26.360001 -26.450001 ... 2.042399 2.678563 3.845742 4.285755 4.542908 4.825266 4.703673 3.064856 22.475853 0.098241
22 1274 140.942129 2.496226 2.09173 18.427029 -26.660000 -26.660000 -26.910000 -27.120001 -27.330000 ... 1.111114 1.808921 10.064322 18.175020 26.254833 45.433575 92.253420 192.781600 89.999825 0.831361
23 59558 135.516026 0.990784 3.23366 19.302511 -26.639999 -26.860001 -26.910000 -26.809999 -26.900000 ... 0.229981 1.423001 10.505121 18.868820 27.057295 46.234390 92.408554 190.460130 -38.026764 0.744075
24 92216 132.786303 1.649745 0.59087 17.172297 -26.629999 -27.400000 -29.799999 -28.100000 -28.610001 ... 2.316168 3.551745 4.868016 4.682977 4.119654 2.096348 -4.539190 -21.668407 -89.998600 0.819317
25 100197 132.303052 2.190311 0.34706 14.285802 -26.590000 -26.730000 -27.000000 -26.920000 -26.990000 ... 3.531113 2.766909 1.360645 0.827513 0.513943 0.163482 0.281495 2.189023 20.931770 0.939681
26 3810 140.869487 2.437709 1.82746 18.146292 -26.570000 -26.670000 -26.370001 -26.629999 -26.879999 ... 1.235988 0.179595 2.618085 6.673769 11.139587 22.510426 52.173996 119.101570 89.605194 0.840523
27 36833 137.659305 0.006890 2.25110 18.728870 -26.540001 -26.600000 -27.090000 -27.379999 -27.650000 ... 2.527025 2.244490 -1.258626 -4.718181 -8.169140 -16.368826 -36.406685 -79.465320 -40.896297 0.359831
28 914 140.958927 1.672601 2.05747 18.560732 -26.490000 -26.180000 -26.430000 -26.670000 -26.900000 ... 0.204272 0.837457 6.616033 12.103016 17.520320 30.290836 61.248306 127.347000 -41.635017 0.663179
29 20632 139.177931 1.707571 1.46657 17.681324 -26.469999 -25.990000 -26.320000 -26.150000 -26.250000 ... 0.574956 0.510892 3.100338 6.016405 9.016744 16.311213 34.545597 74.422390 -44.008870 0.067617
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
38102 21555 138.928160 -1.900250 0.05624 19.852343 -13.280000 -16.840000 -17.180000 -17.410000 -17.600000 ... 0.630375 0.611619 0.581585 0.573399 0.570711 0.574227 0.607277 0.719808 -20.507786 0.417315
38103 148270 129.117600 -1.925241 0.03200 19.213423 -13.210000 -15.740000 -16.620001 -17.240000 -17.719999 ... 0.423354 1.012122 2.048159 2.407071 2.595672 2.737469 2.327516 0.162623 -33.305320 0.754141
38104 53595 136.033917 0.009463 0.03308 19.638414 -13.200000 -14.690000 -16.280001 -16.930000 -17.270000 ... 5.095991 5.337958 5.797911 5.982782 6.098492 6.249202 6.310737 5.922297 89.107350 0.978087
38105 66647 134.764921 -1.784711 0.02822 17.632480 -13.180000 -17.459999 -17.820000 -17.959999 -18.160000 ... 1.430041 1.376369 1.258468 1.200098 1.156683 1.080304 0.959780 0.813029 6.651928 0.553404
38106 122527 130.734045 0.015916 0.01020 18.953129 -13.170000 -14.020000 -14.240000 -14.350000 -14.460000 ... 0.741594 0.715338 0.719734 0.759064 0.807220 0.937777 1.296671 2.135516 -87.793010 0.903742
38107 91775 132.858979 0.818082 0.01110 18.807236 -13.110000 -14.150000 -14.580000 -14.860000 -15.050000 ... 1.193279 0.939357 0.583396 0.527969 0.548203 0.732838 1.521256 3.787824 -80.260880 0.473137
38108 46896 136.833695 2.872027 0.01222 19.663153 -13.100000 -13.820000 -13.940000 -13.920000 -13.910000 ... 1.972519 1.587225 0.925258 0.707910 0.602403 0.552964 0.929122 2.580953 -3.358891 0.526856
38109 87608 132.991189 -1.684356 0.04777 18.618216 -13.040000 -17.690001 -18.010000 -18.160000 -18.350000 ... 0.817083 0.860483 1.005853 1.107767 1.198806 1.395914 1.830164 2.682805 55.843420 0.271008
38110 107832 131.730965 1.826584 0.02047 19.393295 -13.030000 -14.810000 -15.360000 -15.520000 -15.580000 ... 5.457237 4.371225 2.363348 1.595398 1.139239 0.615685 0.719906 3.292339 89.612335 0.723883
38111 49 140.959652 -1.935587 0.02259 18.258696 -12.980000 -16.340000 -16.700001 -16.879999 -17.219999 ... 0.339608 0.606772 1.150883 1.394663 1.562961 1.827464 2.139514 2.242613 47.452420 0.630116
38112 81139 133.916407 2.673124 0.01529 19.808342 -12.980000 -13.910000 -14.300000 -14.470000 -14.560000 ... 0.487040 0.736433 1.165765 1.307384 1.376630 1.410940 1.173207 0.116532 19.784615 0.539122
38113 75206 134.283698 2.931834 0.01394 18.480629 -12.940000 -14.540000 -15.420000 -15.810000 -16.000000 ... 0.910698 0.957284 1.054321 1.099190 1.130949 1.182911 1.251853 1.301495 -86.981420 0.859903
38114 71005 134.533328 1.446884 0.07026 19.821112 -12.910000 -17.240000 -17.719999 -17.950001 -18.160000 ... 1.229903 1.095093 0.877975 0.817782 0.797075 0.818997 1.048206 1.838857 -16.198275 0.546041
38115 65 140.889141 -1.925774 0.09853 19.603786 -12.890000 -18.170000 -18.809999 -19.270000 -19.540001 ... 0.664698 1.409015 2.681860 3.095231 3.292398 3.371811 2.605094 -0.673218 -82.090850 0.279741
38116 144231 129.311570 -1.596032 0.01403 15.817058 -12.860000 -17.650000 -18.090000 -18.320000 -18.459999 ... 0.566875 0.812484 1.259785 1.426032 1.521601 1.621628 1.552325 0.870888 58.717697 0.147817
38117 69294 134.546115 -1.776867 0.05329 18.766615 -12.810000 -17.309999 -18.190001 -18.650000 -18.980000 ... 1.942990 2.559247 3.637314 4.006046 4.196362 4.327618 3.855820 1.496783 -49.788506 0.376355
38118 6422 140.401707 1.860832 0.02570 22.106117 -12.660000 -13.220000 -13.320000 -14.270000 -16.320000 ... 2.461775 1.953226 1.012736 0.652846 0.438952 0.193092 0.240167 1.441000 89.890350 0.998881
38119 24630 138.635656 -1.713075 0.01205 19.326760 -12.650000 -13.880000 -14.250000 -14.490000 -14.550000 ... 0.296350 0.390568 0.562443 0.626532 0.663515 0.702665 0.678019 0.420842 -86.802740 0.518354
38120 17223 139.375118 0.256203 0.01704 19.133366 -12.640000 -14.750000 -15.210000 -15.440000 -15.550000 ... 2.265639 2.061155 1.689696 1.552320 1.473811 1.393094 1.457164 2.038391 -85.256160 0.928526
38121 21583 138.940192 -1.930078 0.05351 16.891434 -12.380000 -19.540001 -20.040001 -20.360001 -20.540001 ... 1.754981 1.939937 2.263870 2.374945 2.432481 2.472884 2.333794 1.631250 -27.112589 0.244687
38122 14218 139.713249 0.326479 0.01531 19.362543 -12.340000 -13.740000 -14.780000 -15.210000 -15.510000 ... 2.334425 2.397436 2.456667 2.438597 2.401044 2.276505 1.884968 0.895611 -59.770430 0.858313
38123 41650 137.255464 -1.859570 0.02774 17.155527 -12.220000 -17.860001 -18.280001 -18.520000 -18.670000 ... 1.145589 1.239122 1.406582 1.466740 1.499913 1.530210 1.484420 1.182639 -46.172110 0.742345
38124 38789 137.381264 -1.869051 0.02797 17.975931 -11.940000 -17.090000 -17.480000 -17.709999 -17.900000 ... 2.104629 2.207763 2.419691 2.515858 2.582932 2.690133 2.823272 2.890702 40.949623 0.758358
38125 41700 137.274351 -1.880182 0.02770 15.855060 -11.910000 -18.840000 -19.600000 -19.990000 -20.250000 ... 2.027088 2.143654 2.459959 2.652612 2.814252 3.143105 3.810396 5.012901 -62.867004 0.723061
38126 30091 138.245218 -1.859128 0.05396 19.550781 -11.650000 -17.059999 -17.590000 -17.370001 -17.580000 ... 5.075201 4.561838 3.496669 3.006756 2.661406 2.100017 1.368174 0.881891 86.918640 0.580859
38127 27137 138.421074 -1.899130 0.03979 17.549614 -11.260000 -18.450001 -18.670000 -18.860001 -19.059999 ... 1.012558 1.026499 1.047044 1.051184 1.051195 1.043771 1.007237 0.897512 45.285656 0.376257
38128 8947 140.172188 0.895889 0.05564 19.374275 -10.970000 -16.350000 -17.700001 -18.160000 -18.490000 ... 1.791767 1.793703 1.873981 1.959228 2.045785 2.254202 2.770311 3.890896 -30.519210 0.784264
38129 139530 129.651864 2.621891 0.02609 19.508135 -10.970000 -14.580000 -15.840000 -16.330000 -16.629999 ... 1.456549 1.996711 2.953501 3.289654 3.469708 3.616792 3.282967 1.388947 -59.956284 0.326629
38130 41606 137.120820 -1.805445 0.01207 18.654802 -10.500000 -14.370000 -14.930000 -15.210000 -15.410000 ... 0.216880 0.643817 1.469800 1.811770 2.032058 2.336999 2.542675 2.068914 58.452100 0.381344
38131 41765 137.047311 -1.867027 0.03030 19.520811 -10.050000 -15.730000 -16.110001 -16.379999 -16.660000 ... 0.218376 0.410423 0.770859 0.912533 0.999200 1.106307 1.124014 0.747865 87.354220 0.255841

38132 rows × 34 columns


In [9]:
## band information
allbands = list('ugrizYJHK')
#band_wl = pd.Series([3543,4770,6231,7625,9134,10395,12483,16313,22010], index=allbands)
normband = 'r'
bands = list('ugrizYJH')
band_labels = ['${}$'.format(i) for i in bands]
band_wl = pd.Series([3543,4770,6231,7625,9134,10395,12483,16313], index=bands)
#normband = 'Z'
#bands = list('ugriYJHK')
#band_wl = numpy.array([3543,4770,6231,7625,10395,12483,16313,22010])

In [10]:
## restrict to Vulcani selection objects
#data = data_all[(data_all.r_abs < -21.2) & (data_all.r_abs > -50) &
#                (data_all.Z < 0.3) & (data_all.N_GALFIT_RFBAND_1 < 7.75)]
#len(data)

In [11]:
## restrict to low-z selection objects
data = data_all[(data_all.r_abs < -19.48) & (data_all.r_abs > -50) &
                (data_all.Z < 0.15) & (data_all.N_GALFIT_RFBAND_1 < 7.75)]
len(data)


Out[11]:
5317

In [12]:
## extract magnitudes and use consistent column labels
mag_s = pd.DataFrame(data[['{}_abs'.format(b) for b in list('rugizYJHK')]])
mag_s.columns = list('rugizYJHK')

In [13]:
re_s = pd.DataFrame(data[['RE_GALFIT_RFBAND_{}_corr'.format(i) for i in range(1, 10)]])
re_s.columns = list('rugizYJHK')
n_s = pd.DataFrame(data[['N_GALFIT_RFBAND_{}'.format(i) for i in range(1, 10)]])
n_s.columns = list('rugizYJHK')

In [14]:
from scipy.special import gamma, gammaincinv
from numpy import log, log10, exp, power, pi

class Sersic:
    # currently doesn't handle uncertainties
    def __init__(self, mag, re, n, ar=1.0, pa=0.0,
                 mag_err=None, re_err=None, n_err=None, ar_err=None, pa_err=None, xc_err=None, yc_err=None):
        self.mag = mag
        self.re = re
        self.n = n
        self.ar = ar
        self.pa = pa
        self.mag_err = mag_err
        self.re_err = re_err
        self.n_err = n_err
        self.ar_err = ar_err
        self.pa_err = pa_err
    def __call__(self, r):
        return self.mu_r(r)
    def mu_r(self, r):
        # Returns the surface brightess at specified major axis radius,
        # within annular ellipses corresponding to the shape of each component individualy 
        # Taking, e.g. colours, this currently assumes major axes of components align
        # to be more generally correct need to account for AR, PA, XC, YC,
        # and either select specific vector, or properly compute azimuthal average
        mag = self.mag
        re = self.re
        n = self.n
        bn = self.bn()
        mue = mag + 5.0*log10(re) + 2.5*log10(2.0*pi*n*gamma(2.0*n)*exp(bn)/power(bn, 2.0*n))
        mu = mue + 2.5 * bn / log(10) * (power(r/re, 1.0/n) - 1.0)
        return mu
    def bn(self):
        return gammaincinv(2.0*self.n, 0.5)
    # These need testing
    def I_el(self, r_m, ar_m, pa_m=0):
        return quad(self.I_el_theta, 0, 2*pi, args=(r_m, ar_m, pa_m))[0] / (2*pi)
    def mu_el(self, r_m, ar_m, pa_m=0):
        return -2.5*numpy.log10(self.I_el(r_m, ar_m, pa_m))
    def mu_el_theta(self, theta, r_m, ar_m, pa_m=0):
        x = r_m * numpy.cos(theta - pa_m)
        y = ar_m * r_m * numpy.sin(theta - pa_m)
        r_c = numpy.sqrt(x**2 + self.ar**2 * y**2)
        return self.mu_r(r_c)
    def I_el_theta(self, theta, r_m, ar_m, pa_m=0):
        return 10**(-0.4*self.mu_el_theta(theta, r_m, ar_m, pa_m))

In [15]:
def make_funcs(ids):
    func = {}
    for i in ids:
        func[i] = {}
        remax = 0
        for band in bands:
            func[i][band] = Sersic(mag_s[band].iloc[i], re_s[band].iloc[i]/re_s[normband].iloc[i], n_s[band].iloc[i])
    return func

In [16]:
f = make_funcs(np.arange(len(data)))

In [17]:
def plot_colour_profile(prof, band1='g', band2='r', *args, **kwargs):
    lograd = np.arange(-2, log10(5)+0.1, 0.1)
    rad = 10**lograd
    b1 = prof[band1](rad)
    b2 = prof[band2](rad)
    col = b1 - b2
    plt.plot(rad, col, *args, **kwargs)
    plt.semilogx()
    plt.gca().set_xticks([0.01, 0.03, 0.1, 0.3, 1.0, 3.0])
    plt.gca().xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
    plt.xlim((0.01, 5))
    plt.ylim((-2, 5))

In [18]:
from scipy.odr import *

def gradfit(rad, col):
    # use orthogonal regression a la La Barbera
    def f(B, x):
        return B[0]*x + B[1]
    linear = Model(f)
    mydata = RealData(rad, col, sx=0.00001, sy=0.01)
    myodr = ODR(mydata, linear, beta0=[0., col.mean()])
    myoutput = myodr.run()
    return myoutput.beta

In [19]:
def colour_gradient(prof, band1='g', band2='r', rad1=0.1, rad2=1.0, fit=True):
    if not fit:
        rad = [rad1, rad2]
    else:
        rad = np.arange(rad1, rad2+0.00001, 0.01)
    b1 = prof[band1](rad)
    b2 = prof[band2](rad)
    col = b1 - b2
    if not fit:
        grad = col[1] - col[0]
    else:
        grad = gradfit(rad, col)
    return grad

In [20]:
def plot_colour_gradient_distribs(profs, hsel=None, lsel=None, fit=False):
    fig, ax = plt.subplots(len(bands[2:]), 1, sharex=True, sharey=True)
    for i, b in enumerate(bands[2:]):
        g = np.array([colour_gradient(profs[id], 'g', b, fit=fit) for id in profs.keys()])
        g = g[~np.isnan(g)].clip(-4, 4)
        w = 1.0/len(g)
        label = '${}\quad all:\quad \mu={:.2f}\quad \sigma={:.2f}$'.format(b, g.mean(), g.std())
        ax[i].hist(g, range=(-4, 4), bins=100, histtype='step', label=label,
                   weights=np.ones_like(g)*w)
        if hsel is not None:
            g = np.array([colour_gradient(profs[id], 'g', b, fit=fit) for id in profs.keys() if hsel[id]])
            g = g[~np.isnan(g)].clip(-4, 4)
            label = '${}\ high-n:\quad \mu={:.2f}\quad \sigma={:.2f}$'.format(b, g.mean(), g.std())
            ax[i].hist(g, range=(-4, 4), bins=100, histtype='step', label=label,
                       weights=np.ones_like(g)*w)
        if lsel is not None:
            g = np.array([colour_gradient(profs[id], 'g', b, fit=fit) for id in profs.keys() if lsel[id]])
            g = g[~np.isnan(g)].clip(-4, 4)
            label = '${}\ \ \ low-n:\quad \mu={:.2f}\quad \sigma={:.2f}$'.format(b, g.mean(), g.std())
            ax[i].hist(g, range=(-4, 4), bins=100, histtype='step', label=label,
                       weights=np.ones_like(g)*w)
        ax[i].legend(fontsize='x-small',loc='upper right')
    plt.xlim((-2.5, 3.5))
    plt.ylim((0, 0.16))
    ax[0].set_yticks((0.0, 0.1))
    ax[-1].set_xlabel('$\\nabla(g-x)$')
    fig.text(0.05, 0.5, 'norm. freq.', va='center', rotation='vertical')
    plt.subplots_adjust(hspace=0)

In [21]:
plot_colour_gradient_distribs(f, hsel=(n_s.r >= 2.5).values, lsel=(n_s.r < 2.5).values)



In [22]:
ids = np.random.choice(len(data), 2000, replace=False)

In [23]:
coltot = (mag_s.u - mag_s.r)

plt.subplot(211)

for id in ids:
    if n_s.r.iloc[id] < 2.5:
        if coltot.iloc[id] > 2.1:
            c = 'r'
        elif coltot.iloc[id] > 1.6:
            c = 'g'
        else:
            c = 'b'
        plot_colour_profile(f[id], 'g', 'r', c=c, alpha=0.05)
        plot_colour_profile(f[id], 'g', 'J', c=c, alpha=0.05)
plt.hlines([1.0], 0.01, 5.0)
plt.ylim((-0.5, 5))    
plt.subplot(212)
for id in ids:
    if n_s.r.iloc[id] > 2.5:
        if coltot.iloc[id] > 2.1:
            c = 'r'
        elif coltot.iloc[id] > 1.6:
            c = 'g'
        else:
            c = 'b'
        plot_colour_profile(f[id], 'g', 'r', c=c, alpha=0.05)
        plot_colour_profile(f[id], 'g', 'J', c=c, alpha=0.05)
plt.hlines([1.0], 0.01, 5.0)
_=plt.ylim((-0.5, 5))



In [24]:
def colour_at_rad(profs, rad=1.0, band1='g', band2='r'):
    return np.array([f[id][band1](rad) - f[id][band2](rad) for id in f.keys()])

In [25]:
def colour_at_rad_hist(profs, band1='g', band2='r'):
    col1re = colour_at_rad(profs, 1.0, band1, band2)
    col0p1re = colour_at_rad(profs, 0.1, band1, band2)
    col2re = colour_at_rad(profs, 2.0, band1, band2)
    col3re = colour_at_rad(profs, 3.0, band1, band2)
    coltot = (mag_s[band1] - mag_s[band2]).values
    plt.hist((coltot, col0p1re, col1re, col2re, col3re), range=(-1, 4), bins=50, histtype='step',
             label=('total', '0.1Re', '1Re', '2Re', '3Re'), normed=True)
    plt.legend()
    plt.xlabel('${}-{}$'.format(band1, band2))
    plt.ylabel('norm. freq.')

In [26]:
colour_at_rad_hist(f, 'g', 'r')



In [27]:
from scipy.stats import binned_statistic

In [28]:
def plot_colour_gradient_vs_mag(profs, ax=None, sel=None, fit=False,
                                labellines=False, labeloffset={}, label=None):
    if ax is None:
        fig, ax = plt.subplots()
    for i, b in enumerate(bands[2:]):
        if sel is None:
            g = np.array([colour_gradient(profs[id], 'g', b, fit=fit) for id in profs.keys()])
            m = mag_s['r']
        else:
            g = np.array([colour_gradient(profs[id], 'g', b, fit=fit) for id in profs.keys() if sel[id]])
            m = mag_s['r'][sel]
        ok = ~np.isnan(g) & (g > -4) & (g < 4)
        g = g[ok]
        m = m[ok]
        # HALF-MAGNITUDE BINS
        counts, edges, bins = binned_statistic(m, g, bins=8, statistic='count', range=(-23.5,-19.5))
        meds, edges, bins = binned_statistic(m, g, bins=8, statistic='median', range=(-23.5,-19.5))
        centres = (edges[:-1]+edges[1:])/2.0
        ok = counts > 10
        centres = centres[ok]
        meds = meds[ok]
        #offset = -0.1*(i+1) - np.median(meds)
        offset = 0  # NO OFFSETS
        meds += offset
        g += offset
        col = plt.cm.jet((0.8*i/5.0 + 0.1))
        ax.plot(m, g, '.', alpha=0.1, c=col, zorder=1)
        ax.plot(centres, meds, c='w', lw=6, zorder=2)
        ax.plot(centres, meds, c=col, lw=2, zorder=3)
        if labellines:
            y = meds[0]
            if labeloffset.get(b) is not None:
                y += labeloffset[b]
            ax.text(centres[0]-0.1, y, 'g-{}'.format(b), horizontalalignment='right', color=col,
                   fontsize='x-small')
        if label is not None:
            ax.text(0.05, 0.95, label, verticalalignment='top',
                    transform=ax.transAxes, fontsize='small')

In [29]:
# all types
plot_colour_gradient_vs_mag(f, labellines=True, label='all galaxies')
plt.xlim((-23.99, -19.51))
plt.ylim((-1.75, 0.49))
plt.xlabel('$M_r$')
plt.ylabel('$\\nabla_{g-x}$')
plt.locator_params(nbins=6)



In [30]:
highn = (n_s.r >= 2.5).values
lown = ~highn
red = (coltot >= 2.1).values
green = (coltot < 2.1).values & (coltot >= 1.6).values
blue = (coltot < 1.6).values

fig, ax = plt.subplots(2, 3, sharex=True, sharey=True)

plot_colour_gradient_vs_mag(f, ax[0,0], sel=red & highn, label='red, high-$n$')
plot_colour_gradient_vs_mag(f, ax[0,1], sel=green & highn, label='green, high-$n$')
plot_colour_gradient_vs_mag(f, ax[0,2], sel=blue & highn, label='blue, high-$n$')
plot_colour_gradient_vs_mag(f, ax[1,0], sel=red & lown, label='red, low-$n$')
plot_colour_gradient_vs_mag(f, ax[1,1], sel=green & lown, label='green, low-$n$',
                            labellines=True, labeloffset={'z':0.01, 'H':-0.05})
plot_colour_gradient_vs_mag(f, ax[1,2], sel=blue & lown, label='blue, low-$n$')

plt.xlim((-23.49, -19.51))
plt.ylim((-1.75, 0.49))
ax[1,1].set_xlabel('$M_r$')
fig.text(0.02, 0.5, '$\\nabla_{g-x}$', va='center', rotation='vertical')
plt.locator_params(nbins=6)

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