Example #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
Example #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
Example #3
0
from astropy.coordinates import SkyCoord
import marxs.visualization.mayavi
from marxs.source import PointSource, FixedPointing


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)
Example #4
0
from marxs.source import PointSource, FixedPointing
from marxs.optics import FlatOpticalElement, FlatDetector

import sys
sys.path.append('../redsox')
import redsox


%matplotlib
conf = copy.deepcopy(redsox.conf)
conf['gratingzoom'] = [.5, 15., 5.]
instrum = redsox.PerfectRedsox(conf=conf)

instrum3 = redsox.PerfectRedsox(conf=conf, channels='3')
my_source = PointSource(coords=SkyCoord(30., 30., unit='deg'), energy=0.25,
                        polarization=120.,
                        geomarea=instrum.elements[0].area)
my_pointing = FixedPointing(coords=SkyCoord(30., 30., unit='deg'),
                            reference_transform=redsox.xyz2zxy)

photons = my_source.generate_photons(.2)
photons = my_pointing(photons)
photons = instrum3(photons)


ind = (photons['facet'] >= 0) & (photons['CCD_ID'] >= 0)
positions = [instrum3.KeepPos.format_positions()[ind, :, :]]
colorid = [photons['colorindex'][ind]]
# saving to x3d resets color scale form in to max, ignoring vmin and vmax
# Thus, add a non-visible line here with color 5 to prevent that
positions.append(np.zeros((2, 5, 3)))
Example #5
0
detfp.detpix_name = ['detfppix_x', 'detfppix_y']
detfp.display['opacity'] = 0.2

# 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
Example #6
0
import numpy as np

from marxs.source import PointSource, FixedPointing
import astropy.units as u
from astropy.coordinates import SkyCoord
from ..constants import xyz2zxy
from .. import Arcus

import pytest

e = 0.5 * u.keV

mysource = PointSource(coords=SkyCoord(30. * u.deg, 30. * u.deg),
                       energy=e)
mypointing = FixedPointing(coords=SkyCoord(30 * u.deg, 30. * u.deg),
                           reference_transform=xyz2zxy)


@pytest.mark.parametrize("instrument", [Arcus(channels=['1']),
                                        Arcus(channels=['2m'])])
def test_orders_are_focussed(instrument):
    '''Check that the orders look reasonable.

    This test tries to be generic so that coordinate system etc. can be
    changed later, but still check that all light is focused to
    one point to detect error in setting up the mirrors.
    '''
    photons = mysource.generate_photons(2e4 * u.s)
    photons = mypointing(photons)
    photons = instrument(photons)
Example #7
0
    n = len(time)
    pol = np.random.uniform(0, 2 * np.pi, n) * u.rad
    pol[n // 3:(n // 3) * 2] = 0 * u.rad
    pol[(n // 3) * 2:] = np.pi / 2 * u.rad
    return pol


def analyzer(photons):
    aeff = instrumfull.elements[0].area.to(u.cm**2) * fractional_aeff(
        photons[:len(photons) // 3])
    modulation = calculate_modulation(photons[len(photons) // 3:])
    return {'aeff': aeff, 'modulation': modulation, 'Aeff_channel': aeff[1]}


my_source = PointSource(coords=SkyCoord(30., 0., unit='deg'),
                        energy=0.25 * u.keV,
                        polarization=polfuncinthirds)

## Here starts the list parameters ###
outpath = f'../run_results/{args.mission}/'

changeglobal, changeindividual = generate_6d_wigglelist(
    [0., 0.01, .02, .1, .2, .4, .7, 1., 2., 5., 10.] * u.mm,
    [0., .05, 2., 5., 10., 15., 20., 25., 30., 40., 50., 60., 120., 180.] *
    u.arcmin)

# in arcsec, conversion is a few lines below
scatter = np.array([0, 1., 4., 8., 16., 30., 60., 120., 180., 300, 600])
scatter = np.hstack([
    np.vstack([scatter, np.zeros_like(scatter)]),
    np.vstack([np.zeros_like(scatter[1:]), scatter[1:]])
Example #8
0
#            'flux': 0.02 * energies[::-1]**(-2)}

spectrum = Table.read(
    '/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)
Example #9
0
from mirror import Ageom

from mayavi import mlab
%matplotlib

# Make two components with different polarization directions
energy = np.arange(.1, .9, .01)
polangle = np.arange(0, 360., 1.)

# Component 1: Powerlaw gamma = 1.5, polangle = 50 deg, polarization fraction 50 %
fluxdens1 = energy ** (-1.5)
pol1 = np.ones_like(polangle) / len(polangle)
pol1[45:55] += 1.  / 10
src1 = PointSource(coords=SkyCoord(30., 30., unit='deg'),
                   energy={'energy': energy, 'flux': fluxdens1},
                   polarization={'angle': polangle, 'probability': pol1},
                   geomarea=Ageom,
                   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)
Example #10
0
from marxs import utils
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')
Example #11
0
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) * 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'], '.')