Example #1
0
    def createSource(self, row):
        '''
        Returns a Source object from row i in the sources table
        '''

        # get input
        type = str(self.tableWidget_2.cellWidget(row, 0).currentText())
        center = self.str2List(self.tableWidget_2.item(row, 1).text())
        normal = self.str2List(self.tableWidget_2.item(row, 2).text())
        width = self.str2Num(self.tableWidget_2.item(row, 3).text())
        height = self.str2Num(self.tableWidget_2.item(row, 4).text())
        colorText = str(self.tableWidget_2.cellWidget(row, 5).currentText())
        color = self.colorsRGB[self.colors.index(colorText)]

        try:
            if type == 'atinf' or type == 'nonpoint':
                return Source(center=center,
                              width=width,
                              height=height,
                              normal=normal,
                              type=type,
                              color=color)
            elif type == 'point':
                return Source(center=center, type=type, color=color)
        except:
            QMessageBox.warning(
                self, 'Warning', 'Could not create source at row ' +
                str(row + 1) + '. Check input values.')
            return None
Example #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')
Example #3
0
from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
from foxsisim.plotting import plot

if __name__ == '__main__':

    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()
Example #4
0
    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
        ],
        color=[0, 1, 1])

    rays = source.generateRays(module.targetFront, 2000)
    module.passRays(rays, robust=True)
    detector.catchRays(rays)

    plot(detector)
    scatterHist(rays)
    plt.show()
Example #5
0
    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,
             label='output spec')
    plt.plot(fx, 50 * fy, '-', alpha=.7, label='Input flare spec')
    plt.yscale('log')
    plt.xlim(3, 20.5)
Example #6
0
''' Defining Spectrum '''

def spectrum(z):
        if (type(z) is not type([1])) and (type(z) is not type(np.array(1))):
            x = np.array([z])
        else:
            x = np.array(z)
        return np.piecewise(x, [x < 0, ((x < max_energy) & (x > 0)), (x >= max_energy)], [0, 1./max_energy, 0])

source_distance = -1.496e+13      ## cm
offaxis_angle_arcminX = 21.0      ## 
offaxis_angle_arcminY = 0.17      ## 

source = Source(type='point', center=[source_distance * np.sin(np.deg2rad(offaxis_angle_arcminX / 60.0)),
                                      source_distance * np.sin(np.deg2rad(offaxis_angle_arcminY / 60.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')
print('teo-input-spect.png')
plt.savefig("teo-input-spect.png", dpi=100)


''' Creating the FOXSI telescope '''

module = Module(radii = [5.151,4.9,4.659,4.429,4.21,4.0,3.799], #7Shells
#module = Module(radii = [5.151,4.9,4.659,4.429,4.21,4.0,3.799,3.59,3.38,3.17], #10Shells
                core_radius=(fbr,rbr))
Example #7
0
max_energy = 30.0


def spectrum(z):
    if (type(z) is not type([1])) and (type(z) is not type(np.array(1))):
        x = np.array([z])
    else:
        x = np.array(z)
    return np.piecewise(
        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])
Example #8
0
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)

    # create scatter plot
    detectorRays = detector.rays
Example #9
0
from foxsisim.util import load_rays, save_rays
from foxsisim.detector import Detector

n = 40000  ## number of rays
fbr = 2.858  ## front blocker radius
rbr = 2.595  ## rear blocker radius
#fbr = 3.75             ## front blocker radius
#rbr = 3.135             ## rear blocker radius
Sdist = -1524.0  ## cm
#offaxisAngle = 0.0     ## arcmin
offaxisAngles = np.arange(0.0, 2., 0.2)  ## arcmin

for angle in offaxisAngles:
    #Create Source :
    Xs = -Sdist * np.sin(np.deg2rad(angle / 60.0))
    Ys = 0.0
    source = Source(type='point', center=[Xs, Ys, Sdist])
    print('Off-axis Angle: %f' % angle)
    '''This needs to be modified for each module'''
    module = Module(radii=[5.151, 4.9, 4.659, 4.429, 4.21, 4.0, 3.799],
                    core_radius=(fbr, rbr))
    rays = source.generateRays(module.targetFront, n)
    module.passRays(rays)
    Rrays = rays
    #Rrays = [ray for ray in rays if (ray.tag != 'Source')] #kills the passthrough rays
    save_rays(
        Rrays,
        filename=
        '/Users/Kamilobu/Desktop/Developer/Milo_RayTracing/Laser_Alignment/WSMR/X1/rays/rays_Angle_=_'
        + '{:.1f}'.format(angle) + '.csv')
Example #10
0

''' Creating 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))

angle = 28.0

Sdist = -1.496e+13  ## Source distance in cm
offaxis_angle_arcminX = 18.3666  ## AR1
offaxis_angle_arcminY = 16.6333  ## AR1

Xs = Sdist * np.sin(np.deg2rad(offaxis_angle_arcminX / 60.0))
Ys = Sdist * np.sin(np.deg2rad(offaxis_angle_arcminY / 60.0))
source = Source(type='point', center=[-Xs, -Ys, Sdist])
source.loadSpectrum(spectrum)
''' Generating rays '''
tstart = datetime.now()
rays = source.generateRays(module.targetFront, nrays)
tgen = datetime.now()
print('rays generated, time = ' + str((tgen - tstart).seconds) + 'seconds')

print('Pasing rays')
module.passRays(rays)

Trays = [ray for ray in rays
         if (ray.dead == False)]  ## save only those alive rays
save_rays(Trays, filename=folder + 'test_rays_Angle_=_' + str(angle) + '.csv')
print('rays saved, time = ' + str((datetime.now() - tstart).seconds) +
      'seconds')
Example #11
0
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(tag='Det')
    source = Source(tag='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)
    for ray in rays:
        print("{0} {1} {2}".format(ray.bounces, ray.dead, ray.tag))
Example #12
0
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
    rays = source.generateRays(module.targetBack, 1000)

    # simulate
    module.passRays(rays)
    detector.catchRays(rays)

    # plot detector pixels
    plot(detector)

    # show
    plt.show()
Example #13
0
import numpy as np
from foxsisim.source import Source
from foxsisim.module import Module
from foxsisim.util import load_rays, save_rays
from foxsisim.detector import Detector

n = 100  ## number of rays
Sdist = -1.5e13  ## cm
offaxisAngle = 0.0  ## arcmin

fbrs = np.arange(2.623, 3.29,
                 0.05)  # Front blocker radius ranging from 2.623 cm to 3.273

#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
Example #14
0
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime

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

if __name__ == '__main__':

    tstart = datetime.now()

    source_distance = 1e4
    source = Source(type='point', center=[0, 0, -source_distance], color=[1, 0, 0])

    # spectrum = lambda x: np.exp(-x)
    max_energy = 30.0

    def spectrum(z):
        if (type(z) is not type([1])) and (type(z) is not type(np.array(1))):
            x = np.array([z])
        else:
            x = np.array(z)
        return np.piecewise(x, [x < 0, (x < max_energy) & (x > 0), (x >= max_energy)], [0, 1 / max_energy, 0])

    source.loadSpectrum(spectrum)
    plot(source)

    radii = [5.15100, 4.90000, 4.65900, 4.42900, 4.21000, 4.00000, 3.79900]  # 7 shell radii
Example #15
0
from foxsisim.module import Module
from foxsisim.detector import Detector
from foxsisim.source import Source
import matplotlib.pyplot as plt
from foxsisim.plotting import plot

if __name__ == '__main__':

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

    # create a detector located slightly in front of focal point
    detector = Detector(center=[0, 0, 228])  # focal point is at 230 by default

    # create a few sources of different types
    source1 = Source(
    )  # a white source 'at infinity' whose rays point perpendicular to module aperture

    source2 = Source(
        type='point',  # a point source
        center=[10, 10, -35000],  # located at [x=10,y=10,z=-35000]
        color=[1, 0, 0])  # and colored red

    source3 = Source(
        width=0.0001,  # a 1 micron
        height=0.0001,  # by 1 micron
        type='nonpoint',  # non-point source (a square region)
        center=[5, -8, -20000],  # centered at [x=5,y=-8,z=20000]
        color=[0, 1, 1])  # and colored light blue

    #  generate 500 rays from each source
    rays = source1.generateRays(module.targetFront, 500)