Beispiel #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))
Beispiel #2
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))
Beispiel #3
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))
Beispiel #4
0
def fit_one_cube(plt,
                 ifu,
                 drpall_file=None,
                 directory_path=None,
                 analysis_path=None):
    # Grab the required input parameters
    config_file = '{0}-{1}.cfg'.format(plt, ifu)
    get_config(plt, ifu, config_file, drpall_file=drpall_file)

    # Read the datacube
    cube = MaNGADataCube.from_config(config_file,
                                     directory_path=directory_path)

    # Define how you want to analyze the data
    plan = AnalysisPlanSet([
        AnalysisPlan(
            drpqa_key='SNRG',
            bin_key='VOR10',  #'HYB10',
            continuum_key='MILESHCMPL10',
            elmom_key='EMOMMPL10',
            elfit_key='EFITMPL10',  #'EFITMPL9DB',
            spindex_key='INDXEN')
    ])

    # Run it!
    return manga_dap(cube,
                     plan,
                     verbose=2,
                     directory_path=directory_path,
                     analysis_path=analysis_path)
Beispiel #5
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))
Beispiel #6
0
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))
Beispiel #7
0
def main(args):
    t = time.perf_counter()
    analysisplan = AnalysisPlanSet.default() if args.plan_file is None \
                        else AnalysisPlanSet.from_par_file(args.plan_file)

    # Initialize the logging objects and start the log
    init_DAP_logging(None)  #, simple_warnings=False)
    loggers = module_logging(__name__, args.verbose)

    DAPall(analysisplan,
           methods=args.methods,
           drpver=args.drpver,
           redux_path=args.redux_path,
           dapver=args.dapver,
           analysis_path=args.analysis_path,
           loggers=loggers,
           quiet=args.quiet,
           single_precision=args.single_precision)

    print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))
Beispiel #8
0
def fit_one_cube(plt, ifu, drpall_file=None, directory_path=None, analysis_path=None):
    # Grab the required input parameters
    obs = get_obsinput(plt, ifu, drpall_file='./data/drpall-v2_4_3.fits')

    # Define how you want to analyze the data
    plan = AnalysisPlanSet([ AnalysisPlan(drpqa_key='SNRG',
                                          bin_key='VOR10',
                                          continuum_key='GAU-MILESHC',
                                          elmom_key='EMOMM',
                                          elfit_key='EFITM-MIUSCATTHIN',
                                          spindex_key='INDXEN') ])
    # Run it!
    return manga_dap(obs, plan, verbose=2, directory_path='./data', analysis_path='./output')
Beispiel #9
0
def main(args):
    # Instantiate the DataCube
    #   - Try to import the module
    try:
        CubeModule = importlib.import_module(args.cube_module)
    except (ModuleNotFoundError, ImportError) as e:
        raise ImportError('Cube module {0} import failed!'.format(
            args.cube_module)) from e
    #   - Try to import the class
    UserDataCube = getattr(CubeModule, args.cube_object)
    #   - Check that the class is derived from DataCube
    if not issubclass(UserDataCube, DataCube):
        raise TypeError(
            'Defined cube object must subclass from mangadap.datacube.DataCube.'
        )
    #   - Instantiate using either the datacube file directly or a
    #     configuration file
    cube = UserDataCube(args.cubefile) if args.config is None \
                else UserDataCube.from_config(args.config, drpver=args.drpver,
                                              redux_path=args.redux_path,
                                              directory_path=args.directory_path)

    # Read the analysis plan
    analysisplan = AnalysisPlanSet.default() if args.plan is None \
                        else AnalysisPlanSet.from_par_file(args.plan)

    # Run the pipeline
    status = manga_dap(cube,
                       analysisplan,
                       dbg=args.dbg,
                       log=args.log,
                       verbose=args.verbose,
                       drpver=args.drpver,
                       redux_path=args.redux_path,
                       directory_path=args.directory_path,
                       dapver=args.dapver,
                       analysis_path=args.analysis_path)
Beispiel #10
0
#-----------------------------------------------------------------------------

if __name__ == '__main__':
    t = time.perf_counter()

    import mangadap

    path = os.path.join(os.environ['MANGADAP_DIR'], 'docs', 'tables')
    if not os.path.isdir(path):
        os.makedirs(path)

    from mangadap.par.analysisplan import AnalysisPlanSet
    from mangadap.par.parset import ParSet

    ap = AnalysisPlanSet.default()

    data = numpy.empty((ap.npar // 2 + 1, 2), dtype=object)
    data[0] = ['Key', 'Value']
    j = 0
    for n in ap.data.dtype.names:
        if 'clobber' in n:
            continue
        data[j + 1, 0] = n
        data[j + 1, 1] = str(ap[0][n])
        j += 1
    lines = ParSet._data_table_string(data, delimiter='rst')

    ofile = os.path.join(path, 'default_analysisplan.rst')
    with open(ofile, 'w') as f:
        f.write(lines)
        '--dap_src',
        type=str,
        help=
        'Top-level directory with the DAP source code; defaults to $MANGADAP_DIR',
        default=None)
    parser.add_argument(
        '-a',
        '--analysis_path',
        type=str,
        help=
        'Top-level output directory for the DAP results; defaults to $MANGA_SPECTRO_ANALYSIS/$MANGADRP_VER/$MANGADAP_VER',
        default=None)

    arg = parser.parse_args()
    obspar = ObsInputPar.from_par_file(arg.obs)
    analysisplan = AnalysisPlanSet.from_par_file(arg.plan)

    status = manga_dap(obspar,
                       analysisplan,
                       dbg=arg.dbg,
                       log=arg.log,
                       verbose=arg.verbose,
                       drpver=arg.drpver,
                       redux_path=arg.redux_path,
                       directory_path=arg.directory_path,
                       dapver=arg.dapver,
                       dapsrc=arg.dap_src,
                       analysis_path=arg.analysis_path)

    print('Elapsed time: {0} seconds'.format(clock() - t))
Beispiel #12
0
def test_default():
    plan = AnalysisPlanSet.default()
    assert len(plan) == 1, 'Default is to perform one plan.'
    assert plan[0]['drpqa_key'] == 'SNRG', 'Default DRP reduction QA key changed.'
    assert plan[0]['elfit_key'] == 'EFITMPL11HCDB', 'Default emission-line fit key changed.'
Beispiel #13
0
def test_read():
    plan = AnalysisPlanSet.from_par_file(data_test_file('plan.par'))

    assert len(plan) == 1, 'Number of example plans changed'
    assert plan[0]['bin_key'] == 'ALL', 'Binning changed'
    assert plan[0]['elfit_key'] == 'EFITMPL11HC', 'Emission-line fitting key changed'