예제 #1
0
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))
예제 #2
0
    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))
예제 #3
0
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))
예제 #4
0
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))
예제 #5
0
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
예제 #6
0
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
예제 #7
0
#    redux_path = '/Volumes/repo/MaNGA/redux/v2_2_0'
#    analysis_path = '/Users/westfall/Work/MaNGA/testing/mpl6/emissionlines/analysis/v2_2_0/test'
#    redux_path='/Users/mac/Desktop/DRP_MPL5/'
    redux_path='/Users/mac/Desktop/DRP_220/'    # v 2_2_0 redux path
    analysis_path='/Users/mac/Volumes/External/MaNGA/DAP_Output/MPL-5/2.0.2/'
    clobber = False
    
    # Read the DRP LOGCUBE file
    print('Reading DRP fits file.')
    drpf = DRPFits(plate, ifu, 'CUBE', read=True, redux_path=redux_path)

    # Calculate the S/N and coordinates
    rdxqa = ReductionAssessment('SNRG', drpf, clobber=clobber, analysis_path=analysis_path)

    # Peform the Voronoi binning to S/N>~10
    binned_spectra = SpatiallyBinnedSpectra('VOR10', drpf, rdxqa, clobber=clobber,
                                            analysis_path=analysis_path)

    # Fit the stellar kinematics
    stellar_continuum = StellarContinuumModel('GAU-MILESHC', binned_spectra, clobber=clobber,
                                              guess_vel=vel, guess_sig=100.,
                                              analysis_path=analysis_path)

    # Get the emission-line moments
    emission_line_moments = EmissionLineMoments('EMOMF', binned_spectra, clobber=clobber,
                                                stellar_continuum=stellar_continuum,
                                                redshift=nsa_redshift,
                                                analysis_path=analysis_path)

    # Get an estimate of the redshift of each bin using the first moment
    # of the H-alpha emission line:
    el_init_redshift = numpy.full(binned_spectra.nbins, nsa_redshift, dtype=float)
예제 #8
0
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)
예제 #9
0
        'ODonnell',  # Galactic reddening function to use
        3.1,  # Rv for Galactic reddening
        0.0,  # Minimum S/N to include
        None,  # Object with binning parameters
        None,  # Binning class instance
        sqbin.bin_spaxels,  # Binning function
        stackpar,  # Object with stacking parameters
        stacker,  # Stacking class instance
        stacker.stack_DRPFits,  # Stacking function
        'spaxel',  # Type of LSF characterization to use
        True)  # Use pre-pixelized LSF (KHRR added this)

    # Bin the spectra using the new binning method
    binned_spectra = SpatiallyBinnedSpectra(
        '5x5n',  # Key for binning method
        drpf,  # DRP data to bin
        rdxqa,  # Cube coordinates and S/N assessments
        method_list=binning_method,  # Methods to select from
        analysis_path=analysis_path)

    # The rest of this is just a single execution of the remaining
    # analysis steps in
    # $MANGADAP_DIR/python/mangadap/survey/manga_dap.py , with some
    # simplifications

    stellar_continuum = StellarContinuumModel('GAU-MILESHC',
                                              binned_spectra,
                                              guess_vel=vel,
                                              guess_sig=100.,
                                              analysis_path=analysis_path)

    emission_line_moments = EmissionLineMoments(
예제 #10
0
                                               binfunc=apbin.bin_spaxels,
                                               # Object with stacking parameters
                                               stackpar=stackpar,
                                               # Stacking class instance
                                               stackclass=stacker,
                                               # Stacking function
                                               stackfunc=stacker.stack_DRPFits,
                                               # Type of LSF characterization to use
                                               spec_res='spaxel',
                                               # Use pre-pixelized LSF (KHRR added this)
                                               prepixel_sres=True)

    # Bin the spectra using the new binning method
    binned_spectra = SpatiallyBinnedSpectra('Aperture',     # Key for binning method
                                            cube,           # DRP data to bin
                                            rdxqa,          # Cube coordinates and S/N assessments
                                            method_list=binning_method, # Methods to select from
                                            output_path=output_path)

    # The rest of this is just a single execution of the remaining
    # analysis steps in
    # $MANGADAP_DIR/python/mangadap/survey/manga_dap.py , with some
    # simplifications

    stellar_continuum = StellarContinuumModel('GAU-MILESHC', binned_spectra, guess_vel=vel,
                                              guess_sig=100., output_path=output_path)

    emission_line_moments = EmissionLineMoments('EMOMM', binned_spectra,
                                                stellar_continuum=stellar_continuum,
                                                redshift=nsa_redshift, output_path=output_path)