def corr_xy_SFR(H, v, tSF__T, iT, mask_radius = False): C.debug_var(debug, corr = v) C.debug_var(debug, iT = iT) C.debug_var(debug, tSF = tSF__T[iT]) if v == 'aSFRSD': dim = 'rg' else: dim = 'g' x = H.get_data_h5('%s__T%s' % (v, dim))[iT] y = H.get_data_h5('%s_Ha__%s' % (v, dim)) xm, ym = C.ma_mask_xyz(x, y) if mask_radius is True: m = (H.zone_dist_HLR__g > 0.5) xm[~m] = np.ma.masked ym[~m] = np.ma.masked Rs, _ = st.spearmanr(xm.compressed(), ym.compressed()) Rp, _ = st.pearsonr(xm.compressed(), ym.compressed()) C.debug_var(debug, Rs = Rs) C.debug_var(debug, Rp = Rp) return Rs, Rp
def f_plot(**kwargs): args = read_kwargs(**kwargs) C.debug_var(args.debug, kwargs = kwargs) H = args.H mask = args.x.mask | args.y.mask xm = np.ma.masked_array(args.x, mask = mask) ym = np.ma.masked_array(args.y, mask = mask) zm = np.ma.masked_array(args.z, mask = mask) f = plt.figure() f.set_size_inches(10, 8) ax = f.gca() plotScatterColorAxis(f, xm, ym, zm, args.xlabel, args.ylabel, args.zlabel, args.xlim, args.ylim, args.zlim, contour = args.contour, run_stats = args.run_stats, OLS = args.OLS) ax.xaxis.set_major_locator(MultipleLocator(args.x_major_locator)) ax.xaxis.set_minor_locator(MultipleLocator(args.x_minor_locator)) ax.yaxis.set_major_locator(MultipleLocator(args.y_major_locator)) ax.yaxis.set_minor_locator(MultipleLocator(args.y_minor_locator)) txt = r'DGR = $10^{%.2f}$' % (np.log10(args.DGR)) plot_text_ax(ax, txt, 0.02, 0.98, 14, 'top', 'left') ax.grid(which = 'major') f.suptitle(r'%d galaxies - tSF:%.2fMyr $x_Y$(min):%.0f%% $\tau_V^\star$(min):%.2f $\tau_V^{neb}$(min):%.2f $\epsilon\tau_V^{neb}$(max):%.2f' % (H.N_gals, (args.tSF / 1e6), H.xOkMin * 100., H.tauVOkMin, H.tauVNebOkMin, H.tauVNebErrMax), fontsize=14) f.savefig(args.fname) plt.close(f)
Rp, _ = st.pearsonr(xm.compressed(), ym.compressed()) C.debug_var(debug, Rs = Rs) C.debug_var(debug, Rp = Rp) return Rs, Rp if __name__ == '__main__': try: h5file = sys.argv[1] except IndexError: print 'usage: %s HDF5FILE' % (sys.argv[0]) exit(1) H = C.H5SFRData(h5file) tSF__T = H.tSF__T C.debug_var(debug, tSF__T = tSF__T) iT__t = np.arange(len(tSF__T)) C.debug_var(debug, iTs = iT__t) RsSFR = np.empty(iT__t.shape, dtype = np.double) RpSFR = np.empty(iT__t.shape, dtype = np.double) RsSFRSD = np.empty(iT__t.shape, dtype = np.double) RpSFRSD = np.empty(iT__t.shape, dtype = np.double) RsaSFRSD = np.empty(iT__t.shape, dtype = np.double) RpaSFRSD = np.empty(iT__t.shape, dtype = np.double) RsaSFRSDn = np.empty(iT__t.shape, dtype = np.double) RpaSFRSDn = np.empty(iT__t.shape, dtype = np.double) RsiSFR = np.empty(iT__t.shape, dtype = np.double) RpiSFR = np.empty(iT__t.shape, dtype = np.double) RsiSFRSD = np.empty(iT__t.shape, dtype = np.double) RpiSFRSD = np.empty(iT__t.shape, dtype = np.double)
for iGal, califaID in enumerate(H.califaIDs): K = C.read_one_cube(califaID, EL = True, GP = True, debug = args.debug, v_run = args.v_run) tipos, tipo, tipo_m, tipo_p = C.get_morfologia(califaID) my_type = C.my_morf(tipos) N_zone = K.N_zone # Setup elliptical-rings geometry pa, ba = K.getEllipseParams() K.setGeometry(pa, ba) minzones = 5 for iT, tSF in enumerate(tSF__T): mask__z, where_slice = H.get_prop_gal(mask__Tg[iT], califaID, return_slice = True) N_mask = mask__z.astype(int).sum() C.debug_var(args.debug, N_mask = N_mask, N_zone = K.N_zone) if (N_mask < (K.N_zone - minzones)): mask__yx = K.zoneToYX(mask__z, extensive = False, surface_density = False) SFR__z = H.SFR__Tg[iT][where_slice] zoneArea_pc2__z = H.zone_area_pc2__g[where_slice] SFR_Ha__z = H.SFR_Ha__g[where_slice] Mcor__z = H.Mcor__Tg[iT][where_slice] at_flux__z = H.at_flux__Tg[iT][where_slice] tau_V__z = H.tau_V__Tg[iT][where_slice] tau_V_neb__z = H.tau_V_neb__g[where_slice] EW_Ha__z = H.EW_Ha__g[where_slice] EW_Hb__z = H.EW_Hb__g[where_slice] F_int_Hb__z = H.F_int_Hb__g[where_slice] F_int_O3__z = H.F_int_O3__g[where_slice] F_int_Ha__z = H.F_int_Ha__g[where_slice] F_int_N2__z = H.F_int_N2__g[where_slice]
kwargs_legend = dict(fontsize = 12, loc = 'best'), kwargs_title = dict(fontsize = 10), title = titles[i], ) if i > 0: kwargs.update({'legend' : False}) C.plot_zbins(**kwargs) i += 1 suptitle = r'NGals:%d tSF:%.2f Myr $x_Y$(min):%.0f%% $\tau_V^\star$(min):%.2f $\tau_V^{neb}$(min):%.2f $\epsilon\tau_V^{neb}$(max):%.2f' % (H.N_gals, (tSF / 1e6), H.xOkMin * 100., H.tauVOkMin, H.tauVNebOkMin, H.tauVNebErrMax) f.suptitle(suptitle, fontsize = 12) if mask_radius is True: filename = '%s_ba_maskradius_%.2fMyr.png' % (fnamepref, tSF / 1e6) else: filename = '%s_ba_%.2fMyr.png' % (fnamepref, tSF / 1e6) C.debug_var(debug, filename = filename) f.savefig(filename) plt.close(f) ########################################################################## ########################################################################## ########################################################################## ########################################################################## ########################################################################## ########################################################################## xkeys = [ 'baR' ] ykeys = [ 'tauVdiffR', 'tauVRatioR' , 'logWHaWHbR' ] for fnamepref, xv, yv in H.plot_xyz_keys_iter(iT = iT, iU = -1, xkeys = xkeys, ykeys = ykeys): if mask_radius is True: m = (H.RbinCenter__r < 0.5) xv['v'][~m] = np.ma.masked
print '<<< %s galaxy: miss gasprop file' % califaID return 2, False # Problem in FITS file return 0, True #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE if __name__ == '__main__': # Saving the initial time t_init_prog = time.clock() # Parse arguments args = parser_args(sys.argv[0]) C.debug_var(True, args = args.__dict__) Zsun = 0.019 # Creating radial bins. Rbin__r = np.arange(args.rbinini, args.rbinfin + args.rbinstep, args.rbinstep) RbinCenter__r = (Rbin__r[:-1] + Rbin__r[1:]) / 2.0 NRbins = len(RbinCenter__r) RColor = [ 'r', 'y', 'b', 'k' ] RRange = [ .5, 1., 1.5, 2. ] Rbin_oneHLR = [1. - args.rbinstep, 1. + args.rbinstep] # Reading galaxies file, gals, _ = C.sort_gals(gals = args.gals_filename, order = 1) N_gals = len(gals) maxGals = None
#EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE if __name__ == '__main__': Zsun = 0.019 t_init_gal = time.clock() args = parser_args() debug = args.debug iT = args.itSF H = C.H5SFRData(args.hdf5) paths = C.CALIFAPaths() C.debug_var(debug, args = args) if (len(np.where(H.califaIDs == args.califaID)[0]) == 0): exit('<<< plot: %s: no data in HDF5 file.' % args.califaID) K = C.read_one_cube(args.califaID, EL = True, GP = True) age = H.tSF__T[iT] ageMyr = age / 1e6 # Setup elliptical-rings geometry pa, ba = K.getEllipseParams() K.setGeometry(pa, ba) tipos, tipo, tipo_m, tipo_p = C.get_morfologia(args.califaID)
help = 'Name of the output PDF file.', metavar = 'FILENAME', type = str, default = default['output']) parser.add_argument('--bamin', '-B', help = 'min b/a', metavar = '', type = float, default = default['bamin']) return parser.parse_args() if __name__ == '__main__': args = parser_args() C.debug_var(args.debug, args = args) H = C.H5SFRData(args.hdf5) iT = args.itSF iU = -1 fnamesuffix = '.pdf' minR = args.maskradius if minR is None: maskRadiusOk__g = np.ones_like(H.zone_dist_HLR__g, dtype = np.bool) maskRadiusOk__rg = np.ones((H.NRbins, H.N_gals_all), dtype = np.bool) else: maxR = H.Rbin__r[-1] maskRadiusOk__g = (H.zone_dist_HLR__g >= minR) & (H.zone_dist_HLR__g <= maxR) maskRadiusOk__rg = (np.ones((H.NRbins, H.N_gals_all), dtype = np.bool).T * ((H.RbinCenter__r >= minR) & (H.RbinCenter__r <= maxR))).T
#rs_gaussian_smooth = True, #rs_percentiles = True, #rs_gs_fwhm = 0.4, #kwargs_plot_rs = dict(c = c_rs, lw = 2, label = 'Median (run. stats)'), #rs_errorbar = False, #x_major_locator = xv['majloc'], #x_minor_locator = xv['minloc'], #y_major_locator = yv['majloc'], #y_minor_locator = yv['minloc'], ) suptitle = r'NGals:%d tSF:%.2f Myr $x_Y$(min):%.0f%% $\tau_V^\star$(min):%.2f $\tau_V^{neb}$(min):%.2f $\epsilon\tau_V^{neb}$(max):%.2f' % (H.N_gals, (tSF / 1e6), H.xOkMin * 100., H.tauVOkMin, H.tauVNebOkMin, H.tauVNebErrMax) f.suptitle(suptitle, fontsize = 12) filename = '%s_%.2fMyr.png' % ('logSFRSD_tauV', tSF / 1e6) #filename = '%s_%.2fMyr.png' % ('logSFRSDR_tauVR', tSF / 1e6) CALIFAUtils.debug_var(True, filename = filename) f.savefig(filename) plt.close(f) ################################################################################# #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE # xkeys = [ 'logtauVR', 'logtauVNebR' ] # ykeys = [ 'alogSFRSDR', 'alogSFRSDHaR' ] #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE xkeys = [ 'logtauV', 'logtauVNeb' ] ykeys = [ 'logSFRSD', 'logSFRSDHa' ] for fnamepref, xv, yv in H.plot_xyz_keys_iter(iT = iT, iU = -1, xkeys = xkeys, ykeys = ykeys): xk = fnamepref.split('_')[0] yk = fnamepref.split('_')[1] plot_zbins(
O3_central_wl = "5007" Ha_central_wl = "6563" N2_central_wl = "6583" lines_central_wl = [Hb_central_wl, O3_central_wl, Ha_central_wl, N2_central_wl] i_Hb = K.EL.lines.index(Hb_central_wl) i_O3 = K.EL.lines.index(O3_central_wl) i_Ha = K.EL.lines.index(Ha_central_wl) i_N2 = K.EL.lines.index(N2_central_wl) minSNR = 3.0 mask_lines_dict__L = {} if args.nolinecuts is True: for l in lines_central_wl: mask_lines_dict__L = np.zeros((K.N_zone), dtype=np.bool_) else: for l in lines_central_wl: C.debug_var(args.debug, l=l) mask_lines_dict__L[l] = K.EL._setMaskLineFluxNeg(l) mask_lines_dict__L[l] |= K.EL._setMaskLineSNR(l, minSNR) if args.rgbcuts is True: for l in lines_central_wl: if args.gasprop is True: pos = K.GP._dlcons[l]["pos"] sigma = K.GP._dlcons[l]["sigma"] snr = K.GP._dlcons[l]["SN"] if snr < minSNR: snr = minSNR else: pos, sigma, snr = 3.0, 3.0, 3.0 mask_lines_dict__L[l] = K.EL._setMaskLineFluxNeg(l) mask_lines_dict__L[l] |= K.EL._setMaskLineDisplacement(l, pos) mask_lines_dict__L[l] |= K.EL._setMaskLineSigma(l, sigma)
tSF = H.tSF__T[iT] xk, xv = H.get_plot_dict(iT = iT, iU = -1, key = 'logtauVR') yk, yv = H.get_plot_dict(iT = iT, iU = -1, key = 'alogSFRSDR') xname = H.get_plot_dict(iT = iT, iU = -1)[xk[:-1]]['legendname'] yname = H.get_plot_dict(iT = iT, iU = -1)[yk[1:-1]]['legendname'] xm, ym = C.ma_mask_xyz(xv['v'], yv['v']) a, b, sig_a, sig_b = OLS_bisector(xm, ym) R = ym - (a * xm + b) Yrms = R.std() Yrms_str = r' : $y_{rms}$:%.2f' % Yrms if b > 0: txt_y = r'$y_{OLS}$ = %.2f %s + %.2f %s' % (yname, a, xname, b, Yrms_str) else: txt_y = r'$y_{OLS}\ \equiv$ %s = %.2f %s - %.2f %s' % (yname, a, xname, b * -1., Yrms_str) C.debug_var(debug, txt_y = txt_y) for xk in xkeys: fnamepref = 'SKdevOLS_%s' % xk if xk != 'RadDist': _, xv = H.get_plot_dict(iT = iT, iU = -1, key = xk) xv.update(updates.get(xk, {})) else: xv = dict(v = (np.ones_like(xv['v']).T * H.RbinCenter__r).T, lim = [0, 2], label = r'R [HLR]', legendname = 'R', minloc = 0.05, majloc = 0.4 ) kwargs_figure = dict(figsize = (10, 8), dpi = 100) f = plt.figure(**kwargs_figure)
tickpos = np.linspace(mtypes[0] + halfbinstep, mtypes[-1] - halfbinstep, Ntype) aSFRSD__Ttr = np.empty((N_T, Ntype, NRbins), dtype = np.float_) aSFRSD_Ha__Ttr = np.empty((N_T, Ntype, NRbins), dtype = np.float_) nbinelem_aSFRSD__Ttr = np.empty((N_T, Ntype, NRbins), dtype = np.int_) nbinelem_aSFRSD_Ha__Ttr = np.empty((N_T, Ntype, NRbins), dtype = np.int_) perc_aSFRSD__pTtr = np.ma.masked_all((3, N_T, Ntype, NRbins), dtype = np.float_) perc_aSFRSD_Ha__pTtr = np.ma.masked_all((3, N_T, Ntype, NRbins), dtype = np.float_) Ngals__t = np.empty((Ntype), dtype = np.int_) for it, t in enumerate(mtypes): mask_morf__g = (morf__g == t) Ngals__t[it] = np.sum(mask_morf__g) for iT in range(N_T): C.debug_var(debug, iT = iT, it = it, NGals = Ngals__t[it]) # G means masked g aSFRSD__rG = aSFRSD__Trg[iT][:, mask_morf__g] aSFRSD_Ha__rG = aSFRSD_Ha__Trg[iT][:, mask_morf__g] for ir in np.where(RbinCenter__r <= 2 + rbinstep)[0]: for ig in xrange(Ngals__t[it]): if aSFRSD__rG[ir].mask[ig]: aSFRSD__rG[ir, ig] = 0 if aSFRSD_Ha__rG[ir].mask[ig]: aSFRSD_Ha__rG[ir, ig] = 0. C.debug_var(debug, aSFRSD__rG = aSFRSD__rG) aSFRSD__Ttr[iT][it] = aSFRSD__rG.mean(axis = 1) nbinelem_aSFRSD__Ttr[iT][it] = aSFRSD__rG.count(axis = 1) aSFRSD_Ha__Ttr[iT][it] = aSFRSD_Ha__rG.mean(axis = 1)