if cone == 0: geometry = SphereTorusGeometry(NH = nh, verbose=args.verbose) else: geometry = BNTorusGeometry(Theta_tor = cone, NH = nh, verbose=args.verbose) geometry.viz() plt.savefig(prefix + "geometry.pdf") plt.savefig(prefix + "geometry.png") plt.close() binmapfunction = lambda beta, alpha: (numpy.round(0.5 + nmu * numpy.abs(cos(beta))) - 1).astype(int) def binmapfunction(beta, alpha): mu = ((0.5 + nmu * numpy.abs(cos(beta))) - 1).astype(int) mu[mu >= nmu] = nmu - 1 return mu rdata, nphot = montecarlo.run(prefix, nphot = args.nevents, nmu = nmu, geometry=geometry, binmapfunction = binmapfunction, plot_paths=args.plot_paths, plot_interactions=args.plot_interactions, verbose=args.verbose) rdata_transmit, rdata_reflect = rdata header = dict(NH=nh, OPENING=cone) montecarlo.store(prefix + 'transmit', nphot, rdata_transmit, nmu, extra_fits_header = header, plot=False) montecarlo.store(prefix + 'reflect', nphot, rdata_reflect, nmu, extra_fits_header = header, plot=False) rdata_transmit += rdata_reflect del rdata_reflect montecarlo.store(prefix, nphot, rdata_transmit, nmu, extra_fits_header = header, plot=True)
kbin = ((log10(nh) + 2) * n_nh_bins / (4 + 2)).astype(int) kbin[kbin == n_nh_bins] = n_nh_bins - 1 mkbin = kbin * nmu + mbin bins = emission['bin'] # produce unique array bins, mbin which contains counts counts, xedges, yedges = numpy.histogram2d(bins, mkbin, bins=binrange) # record into histogram if it landed within relevant range if n_interactions < 1: rdata_transmit[i] += counts else: rdata_reflect[i] += counts del counts, emission, bins if not more: break del photons return (rdata_transmit, rdata_reflect), nphot rdata, nphot = run(prefix, nphot = args.nevents, nmu = nmu, n_nh_bins = n_nh_bins, geometry=geometry, binmapfunction = binmapfunction, verbose=args.verbose) rdata_transmit, rdata_reflect = rdata montecarlo.store(prefix + 'transmit', nphot, rdata_transmit, nmu*n_nh_bins, plot=False) montecarlo.store(prefix + 'reflect', nphot, rdata_reflect, nmu*n_nh_bins, plot=False) rdata_transmit += rdata_reflect del rdata_reflect montecarlo.store(prefix, nphot, rdata_transmit, nmu*n_nh_bins, plot=False)
action='store_true') parser.add_argument('--output', type=str, default='disk_', help='Prefix for output files. ') args = parser.parse_args() nmu = 10 # number of viewing angle bins geometry = DiskGeometry(verbose=args.verbose) prefix = args.output def binmapfunction(beta, alpha): return (numpy.round(0.5 + nmu * numpy.abs(cos(beta))) - 1).astype(int) rdata, nphot = montecarlo.run(prefix, nphot=args.nevents, nmu=nmu, geometry=geometry, binmapfunction=binmapfunction, plot_paths=args.plot_paths, plot_interactions=args.plot_interactions, verbose=args.verbose) rdata_transmit, rdata_reflect = rdata rdata_both = rdata_transmit + rdata_reflect montecarlo.store(prefix + 'transmit', nphot, rdata_transmit, nmu, plot=True) montecarlo.store(prefix + 'reflect', nphot, rdata_reflect, nmu, plot=True) montecarlo.store(prefix, nphot, rdata_both, nmu, plot=True)