Exemplo n.º 1
0
def run_modulation(mission, n_photons=10000, outpath=None,
                   pointing=mypointing, wave=wave, orders=['all']):
    energies = wave.to(u.keV, equivalencies=u.spectral())
    modulation = np.zeros((len(energies), 4, len(orders)))
    for i, e in enumerate(energies):
        print('{0}/{1}'.format(i + 1, len(energies)))
        mysource = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                               energy=e, polarization=0. * u.rad)
        mysource2 = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                                energy=e, polarization=np.pi/2 * u.rad)

        p1 = mysource.generate_photons(n_photons * u.s)
        p2 = mysource2.generate_photons(n_photons * u.s)
        photons = astropy.table.vstack([p1, p2])
        photons = pointing(photons)
        photons = mission(photons)
        if outpath is not None:
            photons.write(os.path.join(outpath,
                                       'merrit{0:05.2f}.fits'.format(wave.value[i])),
                          overwrite=True)
        for j, order in enumerate(orders):
            if order == 'all':
                phot = photons
            else:
                phot = photons[photons['order'] == order]

            modulation[i, :, j] = calculate_modulation(phot)
    return modulation
Exemplo n.º 2
0
def run_aeff(mission, n_photons=10000, outpath=None,
             pointing=mypointing, wave=wave, orders=['all']):
    '''

    Parameters
    ----------
    n_photons : int
         Number of photons for each simulation
    outpath : string or ``None``.
        Path to an existing directory where ray files will be saved.
        Set to ``None`` if not files shall be written.
    mission : marxs optical elements
        Total mission description.``
    '''
    energies = wave.to(u.keV, equivalencies=u.spectral())
    frac_aeff = np.zeros((len(energies), 4, len(orders)))

    for i, e in enumerate(energies):
        print('{0}/{1}'.format(i + 1, len(energies)))
        mysource = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                               energy=e)

        photons = mysource.generate_photons(n_photons * u.s)
        photons = pointing(photons)
        photons = mission(photons)
        if outpath is not None:
            photons.write(os.path.join(outpath,
                                       'aeff{0:05.2f}.fits'.format(wave.value[i])),
                          overwrite=True)
        for j, order in enumerate(orders):
            if order == 'all':
                filterfunc = None
            else:
                filterfunc = lambda photons: photons['order'] == order
            frac_aeff[i, :, j] = fractional_aeff(photons, filterfunc=filterfunc)
    return frac_aeff
Exemplo n.º 3
0
import sys
sys.path.append('../redsox')
import redsox
from mirror import Ageom

%matplotlib


my_source = PointSource(coords=SkyCoord(30., 30., unit='deg'), energy=0.25,
                        polarization=120.,
                        geomarea=Ageom)
my_pointing = FixedPointing(coords=SkyCoord(30., 30., unit='deg'),
                            reference_transform=redsox.xyz2zxy)

photons = my_source.generate_photons(1)
photons = my_pointing(photons)

photons = redsox.redsox(photons)


fig = mlab.figure(**kwargsfig)
redsox.mirror.display = copy.deepcopy(redsox.mirror.display)
redsox.mirror.display['color'] = (1., 0.6, 0.)
out = marxsavi.plot_object(redsox.redsox, viewer=fig)

pos_full = redsox.keeppos.format_positions()
ind = np.isfinite(photons['order']) & (photons['grating_id'] < 5000)
pos = np.empty((pos_full.shape[0], pos_full.shape[1] + 1, pos_full.shape[2]))
pos[:, 0:3, :] = pos_full[:, 0:3, :]
pos[:, 3:, :] = pos_full[:, 2:, :]
Exemplo n.º 4
0
from matplotlib import pyplot as plt
from astropy.coordinates import SkyCoord

from marxs.source import poisson_process
from marxs.missions import chandra
from marxs.source import PointSource

ngc1313_X1 = SkyCoord("3h18m19.99s -66d29m10.97s")

energies = np.arange(.3, 8., .01)
spectrum1 = 6.3e-4 * energies**(-1.9)
flux1 = (spectrum1[1:] * np.diff(energies)).sum()
flux1 = poisson_process(flux1)

aperture = chandra.Aperture()

src1 = PointSource(coords=ngc1313_X1, energy={'energy': energies, 'flux': spectrum1},
                   flux=flux1, geomarea=aperture.area)

pointing = chandra.LissajousDither(coords=ngc1313_X1)
hrma = chandra.HRMA()
acis = chandra.ACIS(chips=[4,5,6,7,8,9], aimpoint=chandra.AIMPOINTS['ACIS-S'])

photons = src1.generate_photons(5e3)  # 5 ks exposure time
photons = pointing(photons)
photons = aperture(photons)
photons = hrma(photons)
photons = acis(photons)

line = plt.plot(photons['tdetx'], photons['tdety'], '.')
Exemplo n.º 5
0
# Place an additional detector on the Rowland circle.
detcirc = marxs.optics.CircularDetector.from_rowland(rowland, width=20)
detcirc.loc_coos_name = ['detcirc_phi', 'detcirc_y']
detcirc.detpix_name = ['detcircpix_x', 'detcircpix_y']
detcirc.display['opacity'] = 0.2

uptomirror = Sequence(elements=[aper, mirror])

keeppos = marxs.simulator.KeepCol('pos')
mission = Sequence(elements=[aper, mirror, gas, catsupport, det, detfp],
                   postprocess_steps=[keeppos])

star = PointSource(coords=(23., 45.), flux=5.)
pointing = FixedPointing(coords=(23., 45.))
photons = star.generate_photons(exposuretime=2000)
photons = pointing(photons)

### Look at different energies for some orders in detail
p = uptomirror(photons.copy())

gratings = copy.deepcopy(gas)
p1 = p.copy()
p02 = p.copy()
p02['energy'] = 0.2

gratingeff = marxs.optics.constant_order_factory(0)
for elem in gratings.elements:
    elem.order_selector = gratingeff

p1o0 = gratings(p1.copy())
Exemplo n.º 6
0
    '/melkor/d1/guenther/Dropbox/REDSoX File Transfers/raytrace/inputdata/mk421_spec.txt',
    format='ascii.no_header',
    names=['wave', 'fluxperwave'])
spectrum['energy'] = 1.2398419292004202e-06 / (spectrum['wave'] * 1e-7)
spectrum['flux'] = spectrum['fluxperwave'] / 12.398419292004202 * spectrum[
    'wave']**2
spectrum.sort('energy')
# Now limit to the range where I have coefficients for gratings etc.
spectrum = spectrum[(spectrum['wave'] > 25.) & (spectrum['wave'] < 75.)]
flux = np.sum(spectrum['flux'][1:] * np.diff(spectrum['energy']))
my_sourcepol = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                           energy=spectrum,
                           flux=0.2 * flux,
                           polarization=120.,
                           geomarea=Ageom)
my_sourceunpol = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                             energy=spectrum,
                             flux=0.8 * flux,
                             geomarea=Ageom)
ppol = my_sourcepol.generate_photons(300)
punpol = my_sourceunpol.generate_photons(300)
with enable_merge_strategies(utils.MergeIdentical):
    photons = vstack([ppol, punpol])

photons = mypointing(photons)
len(photons)

photons = redsox.redsox(photons)
photons.write('/melkor/d1/guenther/projects/REDSoX/sims/photons_spectrum.fits',
              overwrite=True)
Exemplo n.º 7
0
                   flux=poisson_process(2))

# Component 2: polarization fraction 33 %
spec = table.Table.read('../inputdata/bb36.tbl', format='ascii', names=['energy','flux'])
pol2 = np.ones_like(polangle) / len(polangle)
pol2 [100:110] += .5 / 10
src2 = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                   energy={'energy': energy, 'flux': fluxdens1},
                   polarization={'angle': polangle, 'probability': pol1},
                   geomarea=Ageom,
                   flux=poisson_process(1))

my_pointing = FixedPointing(coords=SkyCoord(30., 30., unit='deg'),
                            reference_transform=redsox.xyz2zxy)

p1 = src1.generate_photons(5e3)
p2 = src2.generate_photons(5e3)
p = table.vstack([p1, p2])
p.sort(['time'])

p = my_pointing(p)

p = redsox.redsox(p)

fig = mlab.figure()
mlab.clf()
out = marxs.visualization.mayavi.plot_object(redsox.redsox, viewer=fig)
pos = format_saved_positions(redsox.keeppos)
ind = np.isfinite(p['order']) & (p['probability'] > 1e-4)
marxs.visualization.mayavi.plot_rays(pos[ind, :, :], scalar=p['energy'][ind], viewer=fig)
Exemplo n.º 8
0
from astropy.table import Table
import astropy.units as u
from astropy import table
from astropy.utils.metadata import enable_merge_strategies
from astropy.io import fits
import arcus

n_photons_list = [1e4, 1e5, 1e6, 1e7]

wave = np.arange(8., 50., 0.5) * u.Angstrom
energies = wave.to(u.keV, equivalencies=u.spectral()).value

for n_photons in n_photons_list:
    t0 = time.time()
    mysource = PointSource((0., 0.), energy=0.5, flux=1.)
    photons = mysource.generate_photons(n_photons / 2)

    mypointing = FixedPointing(coords=(0., 0.))
    photons = mypointing(photons)
    photons = arcus.arcus_joern(photons)

    photonsm = mysource.generate_photons(n_photons / 2)
    photonsm = mypointing(photonsm)
    photonsm = arcus.arcus_joernm(photonsm)
    photonsm['aperture'] += 2

    with enable_merge_strategies(utils.MergeIdentical):
        out = table.vstack([photons, photonsm])

        photons.write(tempfile.NamedTemporaryFile(), format='fits')
    runtime = time.time() - t0
Exemplo n.º 9
0
from marxs.missions import chandra
from marxs.source import PointSource

ngc1313_X1 = SkyCoord("3h18m19.99s -66d29m10.97s")

energies = np.arange(.3, 8., .01) * u.keV
fluxdensity = 6.3e-4 * energies.value**(-1.9) / u.s / u.cm**2 / u.keV
fluxperbin = fluxdensity[1:] * np.diff(energies)
flux = poisson_process(fluxperbin.sum())
energytab = QTable({'energy': energies, 'fluxdensity': fluxdensity})

aperture = chandra.Aperture()

src1 = PointSource(coords=ngc1313_X1,
                   energy=energytab,
                   flux=flux,
                   geomarea=aperture.area)

pointing = chandra.LissajousDither(coords=ngc1313_X1)
hrma = chandra.HRMA()
acis = chandra.ACIS(chips=[4, 5, 6, 7, 8, 9],
                    aimpoint=chandra.AIMPOINTS['ACIS-S'])

photons = src1.generate_photons(5 * u.ks)
photons = pointing(photons)
photons = aperture(photons)
photons = hrma(photons)
photons = acis(photons)

line = plt.plot(photons['tdetx'], photons['tdety'], '.')