Exemplo n.º 1
0
 def createModule(self):
     '''
     Returns a Module object based on gui input values
     '''
     # get radii and angles
     radii, angles = [], []
     for i in range(self.tableWidget.rowCount()):
         r, rvalid = self.tableWidget.item(i, 0).text().toDouble()
         a, avalid = self.tableWidget.item(i, 1).text().toDouble()
         if rvalid and avalid:
             radii.append(r)
             angles.append(a)
     # radii need to be in decending order
     import operator
     indices = [
         i for (i, j) in sorted(
             enumerate(radii), key=operator.itemgetter(1), reverse=True)
     ]  #@UnusedVariable
     radii = [radii[i] for i in indices]
     angles = [angles[i] for i in indices]
     # get other value
     seglen = self.doubleSpinBox_2.value()
     focal = self.doubleSpinBox.value()
     # return module
     try:
         return Module(seglen=seglen,
                       focal=focal,
                       radii=radii,
                       angles=angles)
     except:
         QMessageBox.warning(
             self, 'Warning',
             'Could not create module. Check input values.')
         return None
Exemplo n.º 2
0
def make_rays(angle,nrays,proc):
    fbr = 6.296              ## Front blocker radius
    rbr = 5.99               ## Rear blocker radius

    # Creating the FOXSI telescope
    module = Module(radii = [9.333,9.153,8.973,8.793,8.613,8.434,8.255,
                             8.076,7.897,7.718,7.540,7.362,7.184,7.006,
                             6.828,6.650,6.473,6.296], focal=1400.0, core_radius=(fbr,rbr))

    Sdist = -1.5e13         ## Source distance in cm
    Xs = -Sdist * np.sin(np.deg2rad(np.sqrt(2.) * angle / 120.0))
    Ys = -Sdist * np.sin(np.deg2rad(np.sqrt(2.) * angle / 120.0))
    source = Source(type='point', center=[Xs, Ys, Sdist ])
    source.loadSpectrum(spectrum)

    # Generating rays
    rays = source.generateRays(module.targetFront, nrays)
    # Passing rays
    module.passRays(rays)
    Trays = [ray for ray in rays if (ray.dead==False)] ## save only those alive rays
    save_rays(Trays,filename=f'rays_Angle_=_{angle}_{proc}.csv')
Exemplo n.º 3
0
    tstart = datetime.now()
    # spectrum = lambda x: np.exp(-x)
    max_energy = 30.0
    min_energy = 1.0
    nrays = 500

    energies = numpy.random.rand(nrays) * (max_energy - min_energy) + min_energy
    source_distance = 1e4
    source = Source(type='point', center=[0, 0, -source_distance], color=[1, 0, 0], spectrum=energies)

    radii = [5.15100, 4.90000, 4.65900, 4.42900, 4.21000, 4.00000, 3.79900]  # 7 shell radii
    seglen = 30
    base = [0, 0, 0]
    focal_length = 200
    module = Module(radii=radii, seglen=seglen, base=base, angles=None, focal=focal_length, conic=True)

    detector = Detector(center=[0, 0, 230])  # focal point is at 230 by default

    #  generate nrays from the source
    rays = source.generateRays(module.targetFront, nrays)

    plt.figure()
    plt.hist([ray.energy for ray in rays], normed=True, label='generated rays')
    plt.legend()
    plt.show()

    # pass rays through module
    module.passRays(rays, robust=True)

    # catch rays at detector
Exemplo n.º 4
0
'wrong' end of the module. The detector catches some of these, and
the generated image is displayed.

Created on Aug 15, 2011

@author: rtaylor
'''
from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
import matplotlib.pyplot as plt

if __name__ == '__main__':

    # create module using defaults
    module = Module()
    
    # create large detector facing aperture
    detector = Detector(center=[0,0,-100], normal=[0,0,1], width=50, height=50)
    
    # create a nonpoint source replacing the detector
    source = Source(center=[0,0,230], normal=[0,0,-1], width=2, height=2, type='nonpoint')
    
    #  generate 1000 rays at source and target them towards the **backend** of module
    rays = source.generateRays(module.targetBack, 1000)
    
    # simulate
    module.passRays(rays)
    detector.catchRays(rays)
    
    # plot detector pixels
Exemplo n.º 5
0
#!/usr/bin/env python
from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
from foxsisim.plotting import scatterHist
from foxsisim.plotting import plot
import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    # create module of 7 shells
    module = Module(radii=[5.151, 3.799],
                    seglen=30.0,
                    base=[0, 0, 0],
                    focal=200,
                    angles=None,
                    conic=False)

    detector = Detector(width=0.96,
                        height=0.96,
                        normal=[0, 0, 1],
                        center=[0, 0, 200.0 + 30.0],
                        reso=[128, 128])

    source_distance = -2187.5
    offaxis_angle_arcmin = 1.0
    source = Source(
        type='point',
        center=[
            source_distance * np.sin(np.deg2rad(offaxis_angle_arcmin / 60.0)),
            0.0, source_distance
Exemplo n.º 6
0
    # Reading and normalizing Flare input spectrum :
    fx, fy = pd.read_csv('../doc/util/flare_m3_spec.csv').values.T
    # choose only value above a certain limit energy e_min
    e_min = 3.5
    e_max = 20.
    fx, fy = fx[((fx >= e_min) & (fx < e_max))], fy[((fx >= e_min) &
                                                     (fx < e_max))]
    # Normalize the input spectrum
    fy = fy / fy.sum()
    # Define a 2xN array as Input to the source
    flarespectrum = np.array((fx, fy))

    # Create the FOXSI telescope
    module = Module(
        radii=[5.151, 4.9, 4.659, 4.429, 4.21, 4.0, 3.799, 3.59, 3.38, 3.17],
        core_radius=(fbr, rbr))
    Sdist = 1.496e+13  # 1AU in cm
    source = Source(type='point',
                    center=[0., 0., -Sdist],
                    spectrum=flarespectrum)
    rays = source.generateRays(module.targetFront, nrays)
    # Passing rays
    module.passRays(rays)
    # Plot the Input and output spectra
    energies = [r.energy for r in rays]
    plt.hist(energies,
             bins=20,
             density=True,
             histtype='stepfilled',
             alpha=.7,
Exemplo n.º 7
0
        x, [x < 0, ((x < max_energy) & (x > 0)),
            (x >= max_energy)], [0, 1. / max_energy, 0])


source_distance = -1e4  ##cm
source = Source(type='point', center=[0, 0, source_distance])
source.loadSpectrum(spectrum)
energies = np.arange(-10, 60, 0.1)
plt.plot(energies, source._spectrum(energies))
plt.xlabel('Energy [keV]')
plt.title('Source Spectrum')
#plt.show()
print('teo-input-spect.png')
plt.savefig('teo-input-spect.png')

module = Module(radii=[5.151, 4.9], focal=200.0)
detector = Detector(width=8,
                    height=8,
                    normal=[0, 0, 1],
                    center=[0, 0, 230],
                    reso=[1024, 1024])

rays = source.generateRays(module.targetFront, 7)

print('rays generated')

plt.figure()
plt.hist([ray.energy for ray in rays], normed=True, label='generated rays')
plt.xlabel('Energy [keV]')
plt.title('Histogram generated rays')
plt.legend()
Exemplo n.º 8
0
# June 2014, @milo & @Steven
''' Example 2 using the geometry of the Hyp and Par. This should show
perfect focusing with all rays falling in a point.'''

from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
from foxsisim.plotting import scatterHist
from foxsisim.plotting import plot

import matplotlib.pyplot as plt

if __name__ == '__main__':

    # create module/detector/source objects using defaults
    module = Module()
    detector = Detector()
    source = Source()

    # generate 1000 rays at source
    rays = source.generateRays(module.targetFront, 1000)

    # pass rays through module
    module.passRays(rays, robust=True)

    # catch rays at detector
    detector.catchRays(rays)

    # plot detector pixels
    plot(detector)
Exemplo n.º 9
0
the generated image is displayed.

Created on Aug 15, 2011

@author: rtaylor
'''
from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
from foxsisim.plotting import plot
import matplotlib.pyplot as plt

if __name__ == '__main__':

    # create module using defaults
    module = Module(conic=True)

    # create large detector facing aperture
    detector = Detector(center=[0, 0, -100],
                        normal=[0, 0, 1],
                        width=50,
                        height=50)

    # create a nonpoint source replacing the detector
    source = Source(center=[0, 0, 230],
                    normal=[0, 0, -1],
                    width=2,
                    height=2,
                    type='nonpoint')

    #  generate 1000 rays at source and target them towards the **backend** of module
Exemplo n.º 10
0
#Create Source :
source = Source(
    type='point',
    center=[0, -Sdist * np.sin(np.deg2rad(offaxisAngle / 60.0)), Sdist])

fbr = 2.8575
rbr = 0.00
offaxisAngles = np.arange(0.0, 30., 2.)  # Off-Axis Angles

F286_NR_All_Drays, F286_NR_All_Hrays, F286_NR_All_Prays = [], [], []
F286_NR_All_Dx, F286_NR_All_Dy, F286_NR_All_Hx, F286_NR_All_Hy, F286_NR_All_Px, F286_NR_All_Py = [], [], [], [], [], []

for fbr in fbrs:
    print('Front radius: %f' % fbr)
    module = Module(radii=[3.17], core_radius=(fbr, 0.))
    rays = source.generateRays(module.targetFront, n)
    module.passRays(rays)
    rays = [ray for ray in rays
            if (ray.tag != 'Source')]  #kills the passthrough rays

    # Create detector :
    detector = Detector(width=10,
                        height=10,
                        normal=[0, 0, 1],
                        center=[0, 0, 230],
                        reso=[1024, 1024])
    # Detector Catch rays:
    detector.catchRays(Brays)
    '''Defining D, H, and P rays for each blocker size: '''
    Drays = [
Exemplo n.º 11
0
Created on Aug 15, 2011

@author: rtaylor
'''
from foxsisim.module import Module
from foxsisim.plotting import get3dAxes
import matplotlib.pyplot as plt

if __name__ == '__main__':

    # module parameters for FOXSI
    focalLength = 200.0
    segmentLength = 30.0
    radii = [5.15100, 4.90000, 4.65900, 4.42900, 4.21000, 4.00000, 3.79900]  # 7 shell radii

    # create module
    module = Module(seglen=segmentLength, focal=focalLength, radii=radii, conic=True, core_radius=2.856)

    # generate cross section
    fig1 = plt.figure(figsize=(9, 3))
    axes1 = fig1.gca()
    module.plot2D(axes1, 'b')

    # generate 3d representation
    fig2 = plt.figure(figsize=(5, 5))
    axes2 = get3dAxes(fig2)
    module.plot3D(axes2, 'b')

    # show figures
    plt.show()
Exemplo n.º 12
0
from foxsisim.module import Module
from foxsisim.plotting import get3dAxes
import matplotlib.pyplot as plt

if __name__ == '__main__':

    # module parameters for FOXSI
    focalLength = 200.0
    segmentLength = 30.0
    radii = [5.15100, 4.90000, 4.65900, 4.42900, 4.21000, 4.00000,
             3.79900]  # 7 shell radii

    # create module
    module = Module(seglen=segmentLength,
                    focal=focalLength,
                    radii=radii,
                    conic=True,
                    core_radius=2.856)

    # generate cross section
    fig1 = plt.figure(figsize=(9, 3))
    axes1 = fig1.gca()
    module.plot2D(axes1, 'b')

    # generate 3d representation
    fig2 = plt.figure(figsize=(5, 5))
    axes2 = get3dAxes(fig2)
    module.plot3D(axes2, 'b')

    # show figures
    plt.show()