def plot(self): self.myboom.elements[0].display['color'] = 'blue' ind = (self.photons['probability'] > 0) posdat = self.keeppos.format_positions()[ind, :, :] fig = mlab.figure() obj = plot_object(self.instrument, viewer=fig) obj = plot_object(self.myboom, viewer=fig) rays = plot_rays(posdat, scalar=np.asarray(self.photons[self.plot_col_color], dtype=float)[ind]) mlab.savefig(os.path.join(self.outpath, self.filename + '.x3d'))
def make_x3dplot(instrument): keeppos = simulator.KeepCol('pos') instrument.postprocess_steps = [keeppos] target = SkyCoord(30., 30., unit='deg') star = source.PointSource(coords=target, energy=.5, flux=1.) pointing = source.FixedPointing(coords=target) photons = star.generate_photons(5000) photons = pointing(photons) photons = instrument(photons) ind = (photons['probability'] >= 0) & (photons['facet'] >= 0) posdat = keeppos.format_positions()[ind, :, :] pp = photons[ind] fig = mlab.figure() plot_object(instrument, viewer=fig) plot_rays(posdat, scalar=pp['order']) return fig
def plot(self): ind = (self.photons['probability'] > 0) posdat = self.keeppos.format_positions()[ind, :, :] fig = mlab.figure() obj = plot_object(self.instrument, viewer=fig) rays = plot_rays(posdat, scalar=self.photons[self.plot_col_color][ind]) mlab.savefig(os.path.join(self.outpath, self.filename + '.x3d'))
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:, :] col = np.zeros_like(pos[:, :, 0]) col[:, 3:] = photons['order'][:, None] # some tricks to color photons red that are 1st order and then pass through a second overlapping # grating with no direction change (order 0) col[ind, 3:] = (photons['CCD_ID'][ind, None] > 0) col = 0.5 * col # 0.5 is red in this color map kwargssurface = {'opacity': .6, 'line_width': 1, 'colormap': 'summer'} out = marxs.visualization.mayavi.plot_rays(pos[ind, :, :],
from astropy.table import Table from scipy.interpolate import interp1d from arcus.defaults import DefaultSource, DefaultPointing import astropy import astropy.units as u from mayavi import mlab from marxs.visualization.mayavi import plot_object, plot_rays %matplotlib from arcus.arcus import ArcusForPlot, Arcus 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)
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]) d = np.dstack(keeppos.data) d = np.swapaxes(d, 1, 2) d = h2e(d) marxs.visualization.mayavi.plot_rays(d, scalar=photons['order'], viewer=fig) arcus.arcus.plot(format="mayavi", viewer=fig) theta, phi = np.mgrid[-0.2 + np.pi:0.2 + np.pi:60j, -1:1:60j] arcus.rowland.plot(theta=theta, phi=phi, viewer=fig, format='mayavi') photonsm = mysource.generate_photons(n_photons)
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))) colorid.append([0, 5]) fig = mlab.figure(**kwargsfig) out = marxsavi.plot_object(instrum, viewer=fig) out = marxs.visualization.mayavi.plot_rays(np.concatenate(positions, axis=0), scalar=np.hstack(colorid), kwargssurface={'opacity': .5, 'line_width': 1, 'colormap': 'gist_rainbow', 'vmin': 0, 'vmax': 5}) # overview mlab.view(100, 60, 2800, [20, -200, 1800], roll=225) fig.scene.save('../JATIS/mayavi_overview.png') fig.scene.save('../JATIS/mayavi_overview.pdf') fig.scene.save('../JATIS/web/REDSoX.x3d') # gratings mlab.view(60, 60, 900, [-30, -60, 1600], roll=270)
# object to save intermediate photons positions after every step of the simulation pos = simulator.KeepCol('pos') instrum = simulator.Sequence(elements=[aper, mirr, gas, det, projectfp], postprocess_steps=[pos]) star = source.PointSource(coords=SkyCoord(30., 30., unit='deg'), energy=1., flux=1.) pointing = source.FixedPointing(coords=SkyCoord(30., 30., unit='deg')) photons = star.generate_photons(100) photons = pointing(photons) photons = instrum(photons) ind = (photons['probability'] > 0) & (photons['facet'] >= 0) posdat = pos.format_positions()[ind, :, :] fig = mlab.figure(bgcolor=(1, 1, 1)) obj = plot_object(instrum, viewer=fig) rays = plot_rays(posdat, scalar=photons['colorid'][ind], kwargssurface={ 'opacity': .5, 'line_width': 1, 'colormap': 'blue-red' }) mlab.view(45, 54, 15000, [7200., -400, -900]) rowland.display['coo2'] = np.linspace(-.2, .2, 60) obj = plot_object(rowland, viewer=fig) mlab.savefig('../subaper3d.png') mlab.savefig('../web/subaper.x3d')
star = source.PointSource(coords=target, energy=.5, flux=1.) pointing = source.FixedPointing(coords=target) photons = star.generate_photons(5000) photons = pointing(photons) photons = instrument(photons) ind = (photons['probability'] >= 0) & (photons['facet'] >= 0) posdat = keeppos.format_positions()[ind, :, :] pp = photons[ind] fig = mlab.figure() plot_object(instrument, viewer=fig) plot_rays(posdat, scalar=pp['order']) return fig fig = make_x3dplot(demo_onaxis_full) demo_rowland.display['coo2'] = np.linspace(-.2, .2, 60) obj = plot_object(demo_rowland, viewer=fig) mlab.savefig(os.path.join(x3dpath, 'toy_chandralike.x3d')) fig = make_x3dplot(demo_onaxis_sub) obj = plot_object(demo_rowland, viewer=fig) mlab.savefig(os.path.join(x3dpath, 'toy_subaper.x3d')) # ## CAT gratings # # - Are illuminated at an angle, thus they work better with a tilted Rowland torus. # - Diffract almost exculsively to one side. # - Diffract efficiently into higher orders. # - Need CCDs to image those high orders, but also want to see zeroth order for wavelength calibration. alpha = 0.4
from marxs.source import PointSource, FixedPointing from marxs.visualization.mayavi import plot_object, plot_rays from redsox.redsox import PerfectRedsox, xyz2zxy from redsox.gosox import PerfectGosox from redsox.mirror import Ageom %matplotlib #instrum = PerfectRedsox() instrum = PerfectGosox() fig = mlab.figure() mlab.clf() out = plot_object(instrum, viewer=fig) 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=xyz2zxy) photons = my_source.generate_photons(10) photons = my_pointing(photons) photons = instrum(photons) pos = instrum.KeepPos.format_positions() ind = np.isfinite(photons['order']) & (photons['facet'] < 2000) & (photons['CCD_ID'] >= 0) out = marxs.visualization.mayavi.plot_rays(pos[ind, :, :], scalar=photons['order'][ind], viewer=fig)
import os from mayavi import mlab import marxs.visualization.mayavi as marxsavi from settings import figureout, kwargsfig import sys sys.path.append('../redsox') import redsox %matplotlib fig = mlab.figure(**kwargsfig) for g in redsox.grat2.elements: g.display['color'] = (1.0, 1., 1.) out = marxsavi.plot_object(redsox.grat1, viewer=fig) for g in redsox.grat2.elements: g.display['color'] = (1.0, 0.5, 0.5) out = marxsavi.plot_object(redsox.grat2, viewer=fig) for g in redsox.grat3.elements: g.display['color'] = (0.5, 0.5, 1.0) out = marxsavi.plot_object(redsox.grat3, viewer=fig) mlab.plot3d([0, 0], [0, 0], [2e3, 1.1e3], color=(1., 1., 1.), opacity=0.3, tube_radius=20, tube_sides=20) mlab.view(azimuth=40, elevation=70, distance=700, focalpoint=[0, 0, 1620]) fig.scene.save(os.path.join(figureout, 'gratings_mayavi.pdf'))
opacity=0.7, color=(0., 0., 0.)) lines = np.array([[[rgx, rgy, rgz], [0, rgy, rgz]], [[0, 0, 0], [0, rgy, rgz]], [[rgx, rgy, rgz], [0, 0, 0]]]) out = marxs.visualization.mayavi.plot_rays(lines, scalar=np.zeros(3), kwargssurface={'opacity': 1., 'line_width': 3, 'colormap': 'blue-red'}) return rgx, rgy, rgz, r figcoordsys = mlab.figure(bgcolor=(1,1,1), size=(1000, 1000)) out = marxsavi.plot_object(Sequence(elements=instrum.elements[3:]), viewer=figcoordsys) out = marxsavi.plot_object(instrums[0].elements[2], viewer=figcoordsys) rgx, rgy, rgz, r = plot_correct_rg() #plot_halfplanes(r * 1, rgy, rgz) plot_axes(x=[-0.1 * r, 1.05 * r], z=[0, rgz * 1.05]) # Mark center of gratings mlab.points3d(rgx, rgy, rgz, scale_factor=3) # yz - plane mlab.triangular_mesh(np.array([0., 0, 0, 0]), rgy*2 * np.array([-1, 1, 1., -1]), r * np.array([0, 0., 1, 1]), [[0, 1, 2], [0, 2, 3]], opacity=0.3, color=(.4, .4, .4)) # mlab.view(azimuth=33, elevation=50, distance=300, focalpoint=[20, 14, 62], roll=300)
# display is usually set for all objects of a class. # To change only one mirror, make a copy of this dictionary first. m2.display = copy(m2.display) m2.display['color'] = 'blue' det = FlatDetector(position=[50, 0, 2e2], zoom=[1., 20., 20.]) # Make an object that keeps the photon position after every simulation step # for later plotting of photon paths. pos = KeepCol('pos') experiment = Sequence(elements=[m1, m2, det], postprocess_steps=[pos]) from mayavi import mlab from marxs.visualization.mayavi import plot_object, plot_rays fig = mlab.figure() for i, angle in enumerate(np.arange(0, .5, .15) * np.pi): rotmat = np.eye(4) rotmat[:3, :3] = euler.euler2mat(angle, 0, 0, 'szxy') light.position = np.dot(rotmat, light_pos) light.dir = np.dot(rotmat, light_dir) m1.pos4d = np.dot(rotmat, m1pos4d) rays = light(100) pos.data = [] pos(rays) rays = experiment(rays) # Now do the plotting obj = plot_object(experiment, viewer=fig) rout = plot_rays(pos.format_positions()) mlab.view(-60, 140., 525, [70., 60., 60.], roll=250) mlab.savefig('../3dpol.pdf') mlab.savefig('../web/3dpol.x3d')