def source(self): EQPegAspec = Table.read(os.path.join(os.path.dirname(__file__), '../inputdata/EQPegA_flux.tbl'), format='ascii', names=['energy', 'flux']) # restrict table to ARCUS energy range EQPegAspec = EQPegAspec[(EQPegAspec['energy'] > 0.25) & (EQPegAspec['energy'] < 1.5)] # define position and spectrum of source mysource = DefaultSource(energy=EQPegAspec, geomarea=self.instrument.elements[0].area, flux=(EQPegAspec['flux'][1:] * np.diff(EQPegAspec['energy'])).sum()) return mysource
arc = ArcusForPlot() fig = mlab.figure(size=(800, 640)) arc.elements[0].display['shape'] = 'None' outinstrum = plot_object(arc, viewer=fig) EQPegAspec = Table.read('../inputdata/EQPegA_flux.tbl', format='ascii', names=['energy', 'flux']) # restrict table to ARCUS energy range EQPegAspec = EQPegAspec[(EQPegAspec['energy'] > 0.25) & (EQPegAspec['energy'] < 1.5)] coord = astropy.coordinates.SkyCoord.from_name("EQ Peg A") mysource = DefaultSource(coords=coord, energy=EQPegAspec, geomarea=arc.elements[0].area, flux=(EQPegAspec['flux'][1:] * np.diff(EQPegAspec['energy'])).sum()) mypointing = DefaultPointing(coords=coord) photons = mysource.generate_photons(5e3) photons = mypointing(photons) photons = arc(photons) photons['wave'] = photons['energy'].to(u.Angstrom, equivalencies=u.spectral()) ind = (photons['probability'] > 0) & (photons['facet'] >=0) & np.isfinite(photons['detpix_x']) posdat = arc.postprocess_steps[0].format_positions(atol=1.)[ind, :, :] #rays = plot_rays(posdat, scalar=photons['energy'][ind], # kwargssurface={'opacity': .5, # 'line_width': 1, # 'colormap': 'blue-red'})
from os.path import join as pjoin import datetime import numpy as np import astropy.units as u from arcus import Arcus from arcus.defaults import DefaultSource, DefaultPointing from utils import get_path n_photons = 1e5 outdir = get_path('arcus') # define position and spectrum of source mysource = DefaultSource(energy={ 'energy': np.array([0.25, 1.7]), 'flux': np.ones(2) }) jitterpointing = DefaultPointing() fixedpointing = DefaultPointing(jitter=0. * u.rad) arc = Arcus() for i in range(10): print 'jitter: {:03d}'.format(i), ' : ', datetime.datetime.now() # Ignore geometric area and set number of photons by hand. photons = mysource.generate_photons(n_photons) photons = jitterpointing(photons) photons = arc(photons) photons.write(pjoin(outdir, 'flatspecjitter{:03d}.fits'.format(i)), overwrite=True)
from mayavi import mlab from marxs.math.utils import h2e from marxs import visualization from marxs.visualization.mayavi import plot_object, plot_rays %matplotlib from arcus.arcus import Arcus from arcus.defaults import DefaultSource, DefaultPointing n_photons = 1e4 e = 0.5 mypointing = DefaultPointing() mysource = DefaultSource(energy=e) photons = mysource.generate_photons(n_photons) photons = mypointing(photons) instrum = Arcus() photons = instrum(photons) ind = (photons['probability'] > 0) posdat = visualization.utils.format_saved_positions(arcus.arcus.keeppos4)[ind, :, :] fig = mlab.figure() obj = plot_object(arcus.arcus.arcus4, viewer=fig) rays = plot_rays(posdat, scalar=photons['energy'][ind])
# fits interface directly above hdulist = fits.open(filename, mode='update') hdulist[0].header['ENERGY'] = (photons[0]['energy'], 'energy in keV') hdulist[0].header['ORDER'] = (o, 'diffraction order') hdulist[0].header['OFFX'] = (offx.to(u.rad).value, 'offset from optical axis in radian') hdulist[0].header['OFFY'] = (offy.to(u.rad).value, 'offset from optical axis in radian') hdulist[0].header['NPHOTONS'] = (n_photons, 'Number of photons per simulation') hdulist.close() for ix, offx in enumerate(pointing_offsets): for iy, offy in enumerate(pointing_offsets): for ie, e in enumerate(energies): print('{} {} {} - {}'.format(ix, iy, ie, time.ctime())) mysource = DefaultSource(coords=SkyCoord(0. * u.rad, 0. * u.rad), energy=e) photons = mysource.generate_photons(n_photons) offsetcoord = SkyCoord(offx, offy) mypointing = DefaultPointing(coords=offsetcoord, jitter=0.) photons = mypointing(photons) photons = arc(photons) # Reformat and delete columns not required for SIXTE to save space photons['POS'] = h2e(photons['pos']) # Make sure direction is normalized photons['DIR'] = norm_vector(h2e(photons['dir'])) photons.rename_column('probability', 'weight') photons.rename_column('aperture', 'channel') photons.keep_columns(['POS', 'DIR', 'time', 'weight', 'ra', 'dec', 'channel', 'order', 'energy', 'xou', 'facet']) photons.meta['A_GEOM'] = (arc.elements[0].area.to(u.cm**2).value, 'Geometric opening area in cm') filename = '{0}_{1}_{2}.fits'.format(ie, ix, iy)
from arcus.generate_rowland import make_rowland_from_d_BF_R_f from arcus.ralfgrating import (CATL1L2Stack, RectangularGrid, InterpolateRalfTable, RalfQualityFactor, catsupport, catsupportbars) from transforms3d.axangles import axangle2aff, axangle2mat from marxs.simulator import Sequence from utils import get_path outpath = get_path('grid2designtorus') n_photons = 10000 wave = np.arange(8., 50.1, 1.) * u.Angstrom energies = wave.to(u.keV, equivalencies=u.spectral()).value mypointing = DefaultPointing() mysource = DefaultSource() # Make input photon list with grid of discrete energies photons_in = mysource.generate_photons(n_photons * len(wave)) photons_in = mypointing(photons_in) for i, e in enumerate(energies): photons_in['energy'][i * n_photons:(i + 1) * n_photons] = e arr_R = np.arange(5900., 6001., 100.) arr_d_BF = np.arange(500., 701., 50.) arr_blaze = np.arange(1.2, 2.21, 0.2) class CATGratings(Sequence): order_selector_class = InterpolateRalfTable
def source(self): return DefaultSource( energy={ 'energy': self.energies[::-1], 'flux': np.ones_like(self.energies) / self.energies**2 })
def source(self): return DefaultSource(energy=0.5, flux=1.)
energies = wave.to(u.keV, equivalencies=u.spectral()).value mypointing = DefaultPointing() for instrum, path in zip( [ #Arcus(), PerfectArcus() ], [ #'raygrid', 'raygrid-perfect' ]): outpath = get_path(path) for i in range(len(wave)): print('{0}/{1} = {2}'.format(i + 1, len(energies), time.ctime())) mysource = DefaultSource(energy=energies[i]) photons = mysource.generate_photons(n_photons) photons = mypointing(photons) photons = instrum(photons) photons.write(join(outpath, 'wave{0:05.2f}.fits'.format(wave.value[i])), overwrite=True) aeffRfromraygrid(outpath, instrum.elements[0], defaultconf, join(get_path('arcus'), path + 'RAeff.fits')) csv_per_order(join(get_path('arcus'), 'raygridRAeff.fits'), 'Aeff4', join(get_path('figures'), 'Aeff.csv')) csv_per_order(join(get_path('arcus'), 'raygridRAeff.fits'), 'R4', join(get_path('figures'), 'R.csv'))
# You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. '''A module to run full error budget simulations. ''' import logging from astropy.table import Table import astropy.units as u import numpy as np from marxs.design.tolerancing import CaptureResAeff_CCDgaps from arcus.instrument import Arcus, PerfectArcus from arcus.instrument.arcus import reformat_randall_errorbudget from arcus.defaults import DefaultSource, DefaultPointing src = DefaultSource(energy=0.5 * u.keV) pointing = DefaultPointing() wave = np.array([15., 25., 37.]) * u.Angstrom instrumfull = PerfectArcus(channels='1') analyzer = CaptureResAeff_CCDgaps(A_geom=instrumfull.elements[0].area.to( u.cm**2), dispersion_coord='circ_phi', orders=np.arange(-12, 5), aeff_filter_col='CCD') logger = logging.getLogger(__name__) def run_n_errorbudgets(align, conf,
) circdet.display['opacity'] = 0.1 circdet.detpix_name = [None, None] circdet.loc_coos_name = ['circ_phi', 'circ_y'] return [circdet] #reset = marxs.simulator.simulator.Propagator(distance=-100.) #twostrips = DetCamera(conf) #return [circdet, reset, twostrips] instrum = MyArcus(channels=[channel]) outpath = get_path('arfrmf') for i, (en, wav) in enumerate(zip(energies, wave)): print('{0}/{1} = {2}'.format(i + 1, len(energies), time.ctime())) mysource = DefaultSource(energy=en) photons = mysource.generate_photons(n_photons * u.s) photons = mypointing(photons) photons.remove_columns(['time', 'polangle', 'ra', 'dec']) photons = instrum(photons) photons.meta['ENERGY'] = (en.value, en.unit) photons.meta['WAVELEN'] = (wav.value, wav.unit) photons.meta['CHANNEL'] = channel for aper in instrum.elements_of_class(RectangleAperture): area = aper.area.to(u.cm**2) photons.meta[f'AGEOM_{aper.id_num}'] = (area.value, area.unit) aper = instrum.elements[0] area = aper.area.to(u.cm**2) photons.meta['A_GEOM'] = (area.value, area.unit) # Number of photons is saved in meta['EXPOSURE'] with this setup