def main(args): t = time.perf_counter() if args.bgagg: pyplot.switch_backend('agg') # Set the paths redux_path = defaults.drp_redux_path(drpver=args.drpver) \ if args.redux_path is None else args.redux_path analysis_path = defaults.dap_analysis_path(drpver=args.drpver, dapver=args.dapver) \ if args.analysis_path is None else args.analysis_path daptypes = [] if args.daptype is None: analysisplan = AnalysisPlanSet.default() if args.plan_file is None \ else AnalysisPlanSet.from_par_file(args.plan_file) for p in analysisplan: bin_method = SpatiallyBinnedSpectra.define_method(p['bin_key']) sc_method = StellarContinuumModel.define_method(p['continuum_key']) el_method = EmissionLineModel.define_method(p['elfit_key']) daptypes += [ defaults.dap_method( bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) ] else: daptypes = [args.daptype] for daptype in daptypes: plate_fit_qa(args.dapver, analysis_path, daptype, args.plate) print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
def main(args): import time from mangadap.config import defaults from mangadap.par.analysisplan import AnalysisPlanSet from mangadap.proc.spatiallybinnedspectra import SpatiallyBinnedSpectra from mangadap.proc.stellarcontinuummodel import StellarContinuumModel from mangadap.proc.emissionlinemodel import EmissionLineModel t = time.perf_counter() # Set the the analysis path and make sure it exists analysis_path = defaults.dap_analysis_path(drpver=args.drpver, dapver=args.dapver) \ if args.analysis_path is None else args.analysis_path analysisplan = AnalysisPlanSet.from_par_file(args.plan_file) daptypes = [] for p in analysisplan: bin_method = SpatiallyBinnedSpectra.define_method(p['bin_key']) sc_method = StellarContinuumModel.define_method(p['continuum_key']) el_method = EmissionLineModel.define_method(p['elfit_key']) daptypes += [defaults.dap_method(bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key'])] dap_status(analysis_path, daptypes, logdir=args.logdir) print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
def main(args): t = time.perf_counter() if args.bgagg: pyplot.switch_backend('agg') # Set the the analysis path and make sure it exists analysis_path = defaults.dap_analysis_path(drpver=args.drpver, dapver=args.dapver) \ if args.analysis_path is None else args.analysis_path daptypes = [] if args.daptype is None: analysisplan = AnalysisPlanSet.default() if args.plan_file is None \ else AnalysisPlanSet.from_par_file(args.plan_file) for p in analysisplan: bin_method = SpatiallyBinnedSpectra.define_method(p['bin_key']) sc_method = StellarContinuumModel.define_method(p['continuum_key']) el_method = EmissionLineModel.define_method(p['elfit_key']) daptypes += [ defaults.dap_method( bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) ] else: daptypes = [args.daptype] for daptype in daptypes: plan_qa_dir = defaults.dap_method_path(daptype, plate=args.plate, ifudesign=args.ifudesign, qa=True, drpver=args.drpver, dapver=args.dapver, analysis_path=analysis_path) ofile = os.path.join( plan_qa_dir, 'manga-{0}-{1}-MAPS-{2}-spotcheck.png'.format( args.plate, args.ifudesign, daptype)) if not os.path.isdir(plan_qa_dir): os.makedirs(plan_qa_dir) spotcheck_images(analysis_path, daptype, args.plate, args.ifudesign, ofile=ofile) print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
def main(args): t = time.perf_counter() if args.bgagg: pyplot.switch_backend('agg') # Set the paths redux_path = defaults.drp_redux_path(drpver=args.drpver) \ if args.redux_path is None else args.redux_path analysis_path = defaults.dap_analysis_path(drpver=args.drpver, dapver=args.dapver) \ if args.analysis_path is None else args.analysis_path daptypes = [] if args.daptype is None: analysisplan = AnalysisPlanSet.default() if args.plan_file is None \ else AnalysisPlanSet.from_par_file(args.plan_file) for p in analysisplan: bin_method = SpatiallyBinnedSpectra.define_method(p['bin_key']) sc_method = StellarContinuumModel.define_method(p['continuum_key']) el_method = EmissionLineModel.define_method(p['elfit_key']) daptypes += [ defaults.dap_method( bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) ] else: daptypes = [args.daptype] drpall_file = defaults.drpall_file(drpver=args.drpver, redux_path=redux_path) dapall_file = defaults.dapall_file(drpver=args.drpver, dapver=args.dapver, analysis_path=analysis_path) drpall_hdu = fits.open(drpall_file) dapall_hdu = fits.open(dapall_file) eml = channel_dictionary(dapall_hdu, 0, prefix='ELG') spi = channel_dictionary(dapall_hdu, 0, prefix='SPI') for daptype in daptypes: dapall_qa(drpall_hdu['MANGA'].data, dapall_hdu[daptype].data, analysis_path, daptype, eml, spi) print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
def main(args): t = time.perf_counter() if args.bgagg: pyplot.switch_backend('agg') # Get the DAP method types to plot analysisplan = AnalysisPlanSet.default() if args.plan_file is None \ else AnalysisPlanSet.from_par_file(args.plan_file) # Construct the plot for each analysis plan for plan in analysisplan: # Get the template library keyword tpl_renorm_file = args.template_flux_file if tpl_renorm_file is None: sc_method = StellarContinuumModel.define_method( plan['continuum_key']) tpl_key = sc_method['fitpar']['template_library_key'] library = TemplateLibrary.define_library(tpl_key) library_root = os.path.split(library['file_search'])[0] tpl_renorm_file = os.path.join( library_root, '{0}_fluxes.db'.format(tpl_key.lower())) if not os.path.isfile(tpl_renorm_file): warnings.warn( 'Could not find file: {0}'.format(tpl_renorm_file)) tpl_renorm_file = None tpl_flux_renorm = None if tpl_renorm_file is None \ else numpy.genfromtxt(tpl_renorm_file, dtype=float)[:,2] # Construct the plot ppxffit_qa_plot(args.plate, args.ifudesign, plan, drpver=args.drpver, redux_path=args.redux_path, dapver=args.dapver, analysis_path=args.analysis_path, tpl_flux_renorm=tpl_flux_renorm) print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
def generate_file_paths(obs, analysisplan, drpver=None, redux_path=None, dapver=None, directory_path=None, analysis_path=None): # Generate the paths to the MAPS and LOGCUBE files: bin_method = SpatiallyBinnedSpectra.define_method(analysisplan['bin_key']) sc_method = StellarContinuumModel.define_method( analysisplan['continuum_key']) el_method = EmissionLineModel.define_method(analysisplan['elfit_key']) method = defaults.dap_method(bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) directory_path = defaults.dap_method_path(method, plate=obs['plate'], ifudesign=obs['ifudesign'], drpver=drpver, dapver=dapver, analysis_path=analysis_path) \ if directory_path is None else str(directory_path) #------------------------------------------------------------------- # Read the maps to plot maps_file = os.path.join( directory_path, defaults.dap_file_name(obs['plate'], obs['ifudesign'], method, mode='MAPS')) print('MAP file: {0}'.format(maps_file)) model_file = os.path.join( directory_path, defaults.dap_file_name(obs['plate'], obs['ifudesign'], method, mode='LOGCUBE')) print('LOGCUBE file: {0}'.format(model_file)) return maps_file, model_file
def maps_data(plt, ifu, plan, drpver, dapver, analysis_path): bin_method = SpatiallyBinnedSpectra.define_method(plan['bin_key']) sc_method = StellarContinuumModel.define_method(plan['continuum_key']) el_method = EmissionLineModel.define_method(plan['elfit_key']) method = defaults.dap_method(bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) directory_path = defaults.dap_method_path(method, plate=plt, ifudesign=ifu, drpver=drpver, dapver=dapver, analysis_path=analysis_path) maps_file = defaults.dap_file_name(plt, ifu, method, mode='MAPS') with fits.open(os.path.join(directory_path, maps_file)) as hdu: mask = hdu['BINID'].data[1, :, :] < 0 r68_map = numpy.ma.MaskedArray(hdu['STELLAR_FOM'].data[3, :, :], mask=mask) r99_map = numpy.ma.MaskedArray(hdu['STELLAR_FOM'].data[4, :, :], mask=mask) rchi2_map = numpy.ma.MaskedArray(hdu['STELLAR_FOM'].data[2, :, :], mask=mask) svel_map = numpy.ma.MaskedArray(hdu['STELLAR_VEL'].data[:, :], mask=mask) ssigo_map = numpy.ma.MaskedArray(hdu['STELLAR_SIGMA'].data[:, :], mask=mask) ssigcor_map = numpy.ma.MaskedArray( hdu['STELLAR_SIGMACORR'].data[1, :, :], mask=mask) ssigc_map = numpy.ma.sqrt( numpy.square(ssigo_map) - numpy.square(ssigcor_map)) extent = map_extent(hdu, 'SPX_MFLUX') return r68_map, r99_map, rchi2_map, svel_map, ssigo_map, ssigcor_map, ssigc_map, extent
def ppxffit_qa_plot(plt, ifu, plan, drpver=None, redux_path=None, dapver=None, analysis_path=None, tpl_flux_renorm=None): # Set the redux and DRP directory paths _drpver = defaults.drp_version() if drpver is None else drpver _redux_path = defaults.drp_redux_path( drpver=_drpver) if redux_path is None else redux_path if not os.path.isdir(_redux_path): raise NotADirectoryError('{0} is not a directory.'.format(_redux_path)) # Set the analysis path _dapver = defaults.dap_version() if dapver is None else dapver _analysis_path = defaults.dap_analysis_path(drpver=_drpver, dapver=_dapver) \ if analysis_path is None else analysis_path if not os.path.isdir(_analysis_path): raise NotADirectoryError( '{0} is not a directory.'.format(_analysis_path)) # Get the method, it's root directory, and the qa directories bin_method = SpatiallyBinnedSpectra.define_method(plan['bin_key']) sc_method = StellarContinuumModel.define_method(plan['continuum_key']) el_method = EmissionLineModel.define_method(plan['elfit_key']) method = defaults.dap_method(bin_method['key'], sc_method['fitpar']['template_library_key'], el_method['continuum_tpl_key']) method_dir = defaults.dap_method_path(method, plate=plt, ifudesign=ifu, drpver=_drpver, dapver=_dapver, analysis_path=_analysis_path) method_qa_dir = defaults.dap_method_path(method, plate=plt, ifudesign=ifu, qa=True, drpver=_drpver, dapver=_dapver, analysis_path=_analysis_path) # Check that the paths exists if not os.path.isdir(method_dir): raise NotADirectoryError( '{0} is not a directory; run the DAP first!'.format(method_dir)) if not os.path.isdir(method_qa_dir): os.makedirs(method_qa_dir) # Get the name of the output file ofile = os.path.join( method_qa_dir, 'manga-{0}-{1}-MAPS-{2}-ppxffit.png'.format(plt, ifu, method)) # Get the g-r map gmr_map = gmr_data(plt, ifu, _drpver, _redux_path) # Get the reduction assessment data signal_map, snr_map = rdxqa_data(plt, ifu, plan, _drpver, _dapver, _analysis_path) # Get the template weights and additive-polynomial coefficients binid_map, t, dt, tn, dtn, a, da, an, dan \ = continuum_component_data(plt, ifu, plan, _drpver, _dapver, _analysis_path, signal_map=signal_map, tpl_flux_renorm=tpl_flux_renorm) # print('t:', numpy.sum(t > 0), numpy.prod(t.shape)) # print('dt:', numpy.sum(dt > 0), numpy.prod(dt.shape)) # print('tn:', numpy.sum(tn > 0), numpy.prod(tn.shape)) # print('dtn:', numpy.sum(dtn > 0), numpy.prod(dtn.shape)) # print('a:', numpy.sum(a > 0), numpy.prod(a.shape)) # print('da:', numpy.sum(da > 0), numpy.prod(da.shape)) # print('an:', numpy.sum(an > 0), numpy.prod(an.shape)) # print('dan:', numpy.sum(dan > 0), numpy.prod(dan.shape)) # Map the continuum component data t_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), t, quiet=True) t_map = numpy.ma.MaskedArray(t_map, mask=numpy.invert(t_map > 0)) dt_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), dt, quiet=True) dt_map = numpy.ma.MaskedArray(dt_map, mask=numpy.invert(dt_map > 0)) #/t_map tn_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), tn, quiet=True) tn_map = numpy.ma.MaskedArray(tn_map, mask=numpy.invert(tn_map > 0)) dtn_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), dtn, quiet=True) dtn_map = numpy.ma.MaskedArray(dtn_map, mask=numpy.invert(dtn_map > 0)) #/tn_map a_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), a, quiet=True) a_map = numpy.ma.MaskedArray(a_map, mask=numpy.invert(a_map > 0)) da_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), da, quiet=True) da_map = numpy.ma.MaskedArray(da_map, mask=numpy.invert(da_map > 0)) #/a_map an_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), an, quiet=True) an_map = numpy.ma.MaskedArray(an_map, mask=numpy.invert(an_map > 0)) dan_map = DAPFitsUtil.reconstruct_map(binid_map.shape, binid_map.ravel(), dan, quiet=True) dan_map = numpy.ma.MaskedArray(dan_map, mask=numpy.invert(dan_map > 0)) #/an_map # Get the remaining output maps from the MAPS file r68_map, r99_map, rchi2_map, svel_map, ssigo_map, ssigcor_map, ssigc_map, extent \ = maps_data(plt, ifu, plan, _drpver, _dapver, _analysis_path) # if not os.path.isfile(ofile): stellar_continuum_maps(plt, ifu, method, snr_map, r68_map, r99_map, rchi2_map, signal_map, a_map, da_map, an_map, dan_map, gmr_map, t_map, dt_map, tn_map, dtn_map, svel_map, ssigo_map, ssigcor_map, ssigc_map, extent=extent, ofile=ofile)