Exemplo n.º 1
0
    def make_library(self, diffuse_yaml, catalog_yaml, binning_yaml):
        """ Build up the library of all the components

        Parameters
        ----------

        diffuse_yaml : str
            Name of the yaml file with the library of diffuse component definitions
        catalog_yaml : str
            Name of the yaml file width the library of catalog split definitions
        binning_yaml : str
            Name of the yaml file with the binning definitions
        """
        ret_dict = {}
        #catalog_dict = yaml.safe_load(open(catalog_yaml))
        components_dict = Component.build_from_yamlfile(binning_yaml)
        diffuse_ret_dict = make_diffuse_comp_info_dict(
            GalpropMapManager=self._gmm,
            DiffuseModelManager=self._dmm,
            library=diffuse_yaml,
            components=components_dict)
        catalog_ret_dict = make_catalog_comp_dict(
            library=catalog_yaml, CatalogSourceManager=self._csm)
        ret_dict.update(diffuse_ret_dict['comp_info_dict'])
        ret_dict.update(catalog_ret_dict['comp_info_dict'])
        self._library.update(ret_dict)
        return ret_dict
Exemplo n.º 2
0
    def make_library(self, diffuse_yaml, catalog_yaml, binning_yaml):
        """ Build up the library of all the components

        Parameters
        ----------

        diffuse_yaml : str
            Name of the yaml file with the library of diffuse component definitions
        catalog_yaml : str
            Name of the yaml file with the library of catalog split definitions
        binning_yaml : str
            Name of the yaml file with the binning definitions
        """
        ret_dict = {}
        #catalog_dict = yaml.safe_load(open(catalog_yaml))
        components_dict = Component.build_from_yamlfile(binning_yaml)
        diffuse_ret_dict = make_diffuse_comp_info_dict(GalpropMapManager=self._gmm,
                                                       DiffuseModelManager=self._dmm,
                                                       diffuse=diffuse_yaml,
                                                       components=components_dict)
        catalog_ret_dict = make_catalog_comp_dict(sources=catalog_yaml,
                                                  CatalogSourceManager=self._csm)
        ret_dict.update(diffuse_ret_dict['comp_info_dict'])
        ret_dict.update(catalog_ret_dict['comp_info_dict'])
        self._library.update(ret_dict)
        return ret_dict
Exemplo n.º 3
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(
            components=components,
            library=args['library'],
            basedir=NAME_FACTORY.base_dict['basedir'])
        diffuse_comp_info_dict = ret_dict['comp_info_dict']

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[
                diffuse_comp_info_key]

            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')

                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(
                        comp)

                full_key = "%s_%s" % (sub_comp_info.sourcekey, key)

                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 coordsys=comp.coordsys,
                                 irf_ver=NAME_FACTORY.irf_ver(),
                                 mktime='none',
                                 fullpath=True)

                infile = NAME_FACTORY.srcmaps(**name_keys)
                outfile = infile.replace('.fits', '.png')

                logfile = make_nfs_path(outfile.replace('.png', '_png.log'))
                job_configs[full_key] = dict(
                    input=infile,
                    output=outfile,
                    extension=sub_comp_info.source_name,
                    zscale=args.get('zscale', 'log'),
                    logfile=logfile)

        return job_configs
Exemplo n.º 4
0
def test_diffuse_src_manager():
    basedir = os.path.join(PACKAGE_ROOT, 'diffuse', 'tests', 'data')
    kwargs = dict(basedir=basedir,
                  library=os.path.join(basedir, 'models', 'library.yaml'),
                  comp=os.path.join(basedir, 'binning.yaml'))
    ret_dict = make_diffuse_comp_info_dict(**kwargs)

    # spot check results
    assert(len(ret_dict['comp_info_dict'].keys()) == 29)

    # sun
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].model_type == 'MapCubeSource')
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].moving)
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].selection_dependent is False)
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].source_name == 'sun-ic')
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].sourcekey == 'sun-ic_v2r0')
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].source_ver == 'v2r0')

    assert(len(ret_dict['comp_info_dict']['sun-ic_v2r0'].components) == 4)
    assert(ret_dict['comp_info_dict']['sun-ic_v2r0'].components[
           'zmax100'].comp_key == 'zmax100')


    # isotropic
    assert(ret_dict['comp_info_dict'][
           'isotropic_P8R3_SOURCE_V2'].model_type == 'IsoSource')
    assert(ret_dict['comp_info_dict']['isotropic_P8R3_SOURCE_V2'].moving is False)
    assert(ret_dict['comp_info_dict'][
           'isotropic_P8R3_SOURCE_V2'].selection_dependent is False)
    assert(ret_dict['comp_info_dict'][
           'isotropic_P8R3_SOURCE_V2'].source_name == 'isotropic')
    assert(ret_dict['comp_info_dict'][
           'isotropic_P8R3_SOURCE_V2'].sourcekey == 'isotropic_P8R3_SOURCE_V2')
    assert(ret_dict['comp_info_dict']['isotropic_P8R3_SOURCE_V2'].source_ver == 'P8R3_SOURCE_V2')
    assert(ret_dict['comp_info_dict']['isotropic_P8R3_SOURCE_V2'].components is None)

    # galprop ring
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].model_type == 'MapCubeSource')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].moving is False)
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].selection_dependent is False)
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].source_name == 'merged_HI_5')
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].sourcekey == 'merged_HI_5_ref')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].source_ver == 'ref')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].components is None)

    assert(len(ret_dict['DiffuseModelManager'].sourcekeys()) == 8)
Exemplo n.º 5
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        input_config = {}
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(
            components=components,
            diffuse=args['diffuse'],
            basedir=NAME_FACTORY.base_dict['basedir'])
        diffuse_comp_info_dict = ret_dict['comp_info_dict']

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[
                diffuse_comp_info_key]

            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')
                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(
                        comp)
                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 mktime='none',
                                 coordsys='GAL',
                                 irf_ver=args['irf_ver'],
                                 fullpath=True)

                outfile = NAME_FACTORY.srcmaps(**name_keys)
                outfile_tokens = os.path.splitext(outfile)
                infile_regexp = "%s_*.fits*" % outfile_tokens[0]
                full_key = "%s_%s" % (sub_comp_info.sourcekey, key)

                job_configs[full_key] = dict(output=outfile,
                                             args=infile_regexp,
                                             hdu=sub_comp_info.source_name,
                                             logfile=outfile.replace(
                                                 '.fits', '.log'))

        output_config = {}
        return input_config, job_configs, output_config
Exemplo n.º 6
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        input_config = {}
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(components=components,
                                               diffuse=args['diffuse'],
                                               basedir=NAME_FACTORY.base_dict['basedir'])
        diffuse_comp_info_dict = ret_dict['comp_info_dict']

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[diffuse_comp_info_key]

            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')

                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(comp)

                full_key = "%s_%s" % (sub_comp_info.sourcekey, key)

                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 coordsys='GAL',
                                 irf_ver=args['irf_ver'],
                                 fullpath=True)

                infile = NAME_FACTORY.srcmaps(**name_keys)
                outfile = infile.replace('.fits', '.png')

                job_configs[full_key] = dict(input=infile,
                                             output=outfile,
                                             extension=sub_comp_info.source_name,
                                             zscale=args.get('zscale', 'log'),
                                             logfile=outfile.replace('.png', '_png.log'))
                                            

        output_config = {}
        return input_config, job_configs, output_config
Exemplo n.º 7
0
def test_diffuse_src_manager():
    basedir = os.path.join(PACKAGE_ROOT, 'diffuse', 'tests', 'data')
    kwargs = dict(basedir=basedir,
                  diffuse=os.path.join(basedir, 'diffuse_components.yaml'),
                  comp=os.path.join(basedir, 'binning.yaml'))
    ret_dict = make_diffuse_comp_info_dict(**kwargs)

    # spot check results
    assert(len(ret_dict['comp_info_dict'].keys()) == 28)

    # sun
    assert(ret_dict['comp_info_dict']['sun_v00'].model_type == 'MapCubeSource')
    assert(ret_dict['comp_info_dict']['sun_v00'].moving)
    assert(ret_dict['comp_info_dict']['sun_v00'].selection_dependent is False)
    assert(ret_dict['comp_info_dict']['sun_v00'].source_name == 'sun')
    assert(ret_dict['comp_info_dict']['sun_v00'].sourcekey == 'sun_v00')
    assert(ret_dict['comp_info_dict']['sun_v00'].source_ver == 'v00')

    assert(len(ret_dict['comp_info_dict']['sun_v00'].components) == 4)
    assert(ret_dict['comp_info_dict']['sun_v00'].components[
           'zmax100'].comp_key == 'zmax100')

    # residual cr
    assert(ret_dict['comp_info_dict'][
           'residual_cr_v00'].model_type == 'MapCubeSource')
    assert(ret_dict['comp_info_dict']['residual_cr_v00'].moving is False)
    assert(ret_dict['comp_info_dict']['residual_cr_v00'].selection_dependent)
    assert(ret_dict['comp_info_dict'][
           'residual_cr_v00'].source_name == 'residual_cr')
    assert(ret_dict['comp_info_dict'][
           'residual_cr_v00'].sourcekey == 'residual_cr_v00')
    assert(ret_dict['comp_info_dict']['residual_cr_v00'].source_ver == 'v00')

    assert(len(ret_dict['comp_info_dict']['residual_cr_v00'].components) == 10)
    assert(ret_dict['comp_info_dict']['residual_cr_v00'].components[
           'E0_PSF3'].comp_key == 'E0_PSF3')

    # isotropic
    assert(ret_dict['comp_info_dict'][
           'isotropic_v00'].model_type == 'IsoSource')
    assert(ret_dict['comp_info_dict']['isotropic_v00'].moving is False)
    assert(ret_dict['comp_info_dict'][
           'isotropic_v00'].selection_dependent is False)
    assert(ret_dict['comp_info_dict'][
           'isotropic_v00'].source_name == 'isotropic')
    assert(ret_dict['comp_info_dict'][
           'isotropic_v00'].sourcekey == 'isotropic_v00')
    assert(ret_dict['comp_info_dict']['isotropic_v00'].source_ver == 'v00')
    assert(ret_dict['comp_info_dict']['isotropic_v00'].components is None)

    # galprop ring
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].model_type == 'MapCubeSource')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].moving is False)
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].selection_dependent is False)
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].source_name == 'merged_HI_5')
    assert(ret_dict['comp_info_dict'][
           'merged_HI_5_ref'].sourcekey == 'merged_HI_5_ref')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].source_ver == 'ref')
    assert(ret_dict['comp_info_dict']['merged_HI_5_ref'].components is None)

    assert(len(ret_dict['DiffuseModelManager'].sourcekeys()) == 7)
Exemplo n.º 8
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(components=components,
                                               library=args['library'],
                                               basedir='.')
        diffuse_comp_info_dict = ret_dict['comp_info_dict']
        if args['make_xml']:
            SrcmapsDiffuse_SG._make_xml_files(diffuse_comp_info_dict)

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[
                diffuse_comp_info_key]
            no_psf = diffuse_comp_info_value.no_psf
            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')
                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(
                        comp)
                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 mktime='none',
                                 coordsys=comp.coordsys,
                                 irf_ver=NAME_FACTORY.irf_ver(),
                                 fullpath=True)

                kmin = 0
                kmax = comp.enumbins + 1
                outfile_base = NAME_FACTORY.srcmaps(**name_keys)
                kstep = HPX_ORDER_TO_KSTEP[comp.hpx_order]
                base_dict = dict(cmap=NAME_FACTORY.ccube(**name_keys),
                                 expcube=NAME_FACTORY.ltcube(**name_keys),
                                 irfs=NAME_FACTORY.irfs(**name_keys),
                                 bexpmap=NAME_FACTORY.bexpcube(**name_keys),
                                 srcmdl=sub_comp_info.srcmdl_name,
                                 source=sub_comp_info.source_name,
                                 no_psf=no_psf,
                                 evtype=comp.evtype)

                if kstep < 0:
                    kstep = kmax
                else:
                    pass

                for k in range(kmin, kmax, kstep):
                    full_key = "%s_%s_%02i" % (diffuse_comp_info_key, key, k)
                    khi = min(kmax, k + kstep)

                    full_dict = base_dict.copy()
                    outfile = outfile_base.replace('.fits', '_%02i.fits' % k)
                    logfile = make_nfs_path(
                        outfile_base.replace('.fits', '_%02i.log' % k))
                    full_dict.update(
                        dict(outfile=outfile,
                             kmin=k,
                             kmax=khi,
                             logfile=logfile))
                    job_configs[full_key] = full_dict

        return job_configs
Exemplo n.º 9
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(components=components,
                                               library=args['library'],
                                               basedir='.')
        diffuse_comp_info_dict = ret_dict['comp_info_dict']
        if args['make_xml']:
            SrcmapsDiffuse_SG._make_xml_files(diffuse_comp_info_dict)

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[diffuse_comp_info_key]
            no_psf = diffuse_comp_info_value.no_psf
            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')
                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(comp)
                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 mktime='none',
                                 coordsys=comp.coordsys,
                                 irf_ver=NAME_FACTORY.irf_ver(),
                                 fullpath=True)

                kmin = 0
                kmax = comp.enumbins + 1
                outfile_base = NAME_FACTORY.srcmaps(**name_keys)
                kstep = HPX_ORDER_TO_KSTEP[comp.hpx_order]
                base_dict = dict(cmap=NAME_FACTORY.ccube(**name_keys),
                                 expcube=NAME_FACTORY.ltcube(**name_keys),
                                 irfs=NAME_FACTORY.irfs(**name_keys),
                                 bexpmap=NAME_FACTORY.bexpcube(**name_keys),
                                 srcmdl=sub_comp_info.srcmdl_name,
                                 source=sub_comp_info.source_name,
                                 no_psf=no_psf,
                                 evtype=comp.evtype)

                if kstep < 0:
                    kstep = kmax
                else:
                    pass

                for k in range(kmin, kmax, kstep):
                    full_key = "%s_%s_%02i" % (diffuse_comp_info_key, key, k)
                    khi = min(kmax, k + kstep)

                    full_dict = base_dict.copy()
                    outfile = outfile_base.replace('.fits', '_%02i.fits' % k)
                    logfile = make_nfs_path(outfile_base.replace('.fits', '_%02i.log' % k))
                    full_dict.update(dict(outfile=outfile,
                                          kmin=k, kmax=khi,
                                          logfile=logfile))
                    job_configs[full_key] = full_dict

        return job_configs
Exemplo n.º 10
0
    def build_job_configs(self, args):
        """Hook to build job configurations
        """
        input_config = {}
        job_configs = {}

        components = Component.build_from_yamlfile(args['comp'])
        NAME_FACTORY.update_base_dict(args['data'])

        ret_dict = make_diffuse_comp_info_dict(components=components,
                                               diffuse=args['diffuse'],
                                               basedir='.')
        diffuse_comp_info_dict = ret_dict['comp_info_dict']
        if args['make_xml']:
            ConfigMaker_SrcmapPartial._make_xml_files(diffuse_comp_info_dict)

        for diffuse_comp_info_key in sorted(diffuse_comp_info_dict.keys()):
            diffuse_comp_info_value = diffuse_comp_info_dict[diffuse_comp_info_key]
            for comp in components:
                zcut = "zmax%i" % comp.zmax
                key = comp.make_key('{ebin_name}_{evtype_name}')
                if diffuse_comp_info_value.components is None:
                    sub_comp_info = diffuse_comp_info_value
                else:
                    sub_comp_info = diffuse_comp_info_value.get_component_info(comp)
                name_keys = dict(zcut=zcut,
                                 sourcekey=sub_comp_info.sourcekey,
                                 ebin=comp.ebin_name,
                                 psftype=comp.evtype_name,
                                 coordsys='GAL',
                                 irf_ver=args['irf_ver'])

                kmin = 0
                kmax = comp.enumbins + 1
                outfile_base = NAME_FACTORY.srcmaps(**name_keys)
                kstep = HPX_ORDER_TO_KSTEP[comp.hpx_order]
                base_dict = dict(cmap=NAME_FACTORY.ccube(**name_keys),
                                 expcube=NAME_FACTORY.ltcube(**name_keys),
                                 irfs=NAME_FACTORY.irfs(**name_keys),
                                 bexpmap=NAME_FACTORY.bexpcube(**name_keys),
                                 srcmdl=sub_comp_info.srcmdl_name,
                                 source=sub_comp_info.source_name,
                                 evtype=comp.evtype)

                if kstep < 0:
                    kstep = kmax
                else:
                    pass

                for k in range(kmin, kmax, kstep):
                    full_key = "%s_%s_%02i" % (diffuse_comp_info_key, key, k)
                    khi = min(kmax, k + kstep)
                    
                    full_dict = base_dict.copy()
                    full_dict.update(dict(outfile=\
                                              outfile_base.replace('.fits', '_%02i.fits' % k),
                                          kmin=k, kmax=khi,
                                          logfile=\
                                              outfile_base.replace('.fits', '_%02i.log' % k)))
                    job_configs[full_key] = full_dict

        output_config = {}
        return input_config, job_configs, output_config