def create_flux_chain(analyzer, transformations, spectrum, erange = "2.0 10.0"): """ For each posterior sample, computes the flux in the given energy range. The so-created chain can be combined with redshift information to propagate the uncertainty. This is especially important if redshift is a variable parameter in the fit (with some prior). Returns erg/cm^2 energy flux (first column) and photon flux (second column) for each posterior sample. """ posterior = analyzer.get_equal_weighted_posterior() prefix = analyzer.outputfiles_basename modelnames = set([t['model'].name for t in transformations]) oldchatter = Xset.chatter, Xset.logChatter Xset.chatter, Xset.logChatter = 0, 0 # plot models flux = [] pbar = progressbar.ProgressBar( widgets=[progressbar.Percentage(), progressbar.Counter('%5d'), progressbar.Bar(), progressbar.ETA()], maxval=len(posterior)).start() for k, row in enumerate(posterior): set_parameters(parameters=row[:-1], transformations=transformations) AllModels.calcFlux(erange) f = spectrum.flux # compute flux in current energies f.append([f[0], f[3]]) pbar.update(k) pbar.finish() Xset.chatter, Xset.logChatter = oldchatter return numpy.array(flux)
def create_flux_chain(analyzer, transformations, spectrum, erange = "2.0 10.0"): """ For each posterior sample, computes the flux in the given energy range. The so-created chain can be combined with redshift information to propagate the uncertainty. This is especially important if redshift is a variable parameter in the fit (with some prior). Returns erg/cm^2 energy flux (first column) and photon flux (second column) for each posterior sample. """ posterior = analyzer.get_equal_weighted_posterior() #prefix = analyzer.outputfiles_basename #modelnames = set([t['model'].name for t in transformations]) oldchatter = Xset.chatter, Xset.logChatter Xset.chatter, Xset.logChatter = 0, 0 # plot models flux = [] for k, row in enumerate(tqdm(posterior, disable=None)): set_parameters(values=row[:-1], transformations=transformations) AllModels.calcFlux(erange) f = spectrum.flux # compute flux in current energies flux.append([f[0], f[3]]) Xset.chatter, Xset.logChatter = oldchatter return numpy.array(flux)
def create_flux_chain(self, spectrum, erange="2.0 10.0", nsamples=None): """ For each posterior sample, computes the flux in the given energy range. The so-created chain can be combined with redshift information to propagate the uncertainty. This is especially important if redshift is a variable parameter in the fit (with some prior). Returns erg/cm^2 energy flux (first column) and photon flux (second column) for each posterior sample. """ #prefix = analyzer.outputfiles_basename #modelnames = set([t['model'].name for t in transformations]) with XSilence(): # plot models flux = [] for k, row in enumerate( tqdm(self.posterior[:nsamples], disable=None)): set_parameters(values=row, transformations=self.transformations) AllModels.calcFlux(erange) f = spectrum.flux # compute flux in current energies flux.append([f[0], f[3]]) return numpy.array(flux)
def create_flux_chain(analyzer, transformations, spectrum, erange="2.0 10.0"): """ For each posterior sample, computes the flux in the given energy range. The so-created chain can be combined with redshift information to propagate the uncertainty. This is especially important if redshift is a variable parameter in the fit (with some prior). Returns erg/cm^2 energy flux (first column) and photon flux (second column) for each posterior sample. """ posterior = analyzer.get_equal_weighted_posterior() prefix = analyzer.outputfiles_basename modelnames = set([t['model'].name for t in transformations]) oldchatter = Xset.chatter, Xset.logChatter Xset.chatter, Xset.logChatter = 0, 0 # plot models flux = [] pbar = progressbar.ProgressBar(widgets=[ progressbar.Percentage(), progressbar.Counter('%5d'), progressbar.Bar(), progressbar.ETA() ], maxval=len(posterior)).start() for k, row in enumerate(posterior): set_parameters(parameters=row[:-1], transformations=transformations) AllModels.calcFlux(erange) f = spectrum.flux # compute flux in current energies f.append([f[0], f[3]]) pbar.update(k) pbar.finish() Xset.chatter, Xset.logChatter = oldchatter return numpy.array(flux)