Advertisement
bolverk

line of sight intensity image calculator

Sep 18th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. def calc_emissivity(point):
  2.  
  3.     x = point[0]
  4.     y = point[1]
  5.     z = point[2]
  6.  
  7.     if x**2 + y**2 + z**2 < 0.7**2:
  8.         return 1
  9.     else:
  10.         return 0
  11.  
  12. def calc_emissivity_2(point):
  13.  
  14.     x = float(point[0])
  15.     y = float(point[1])
  16.     z = float(point[2][0])
  17.  
  18.     r2 = x**2 + y**2 + z**2
  19.     if r2< 0.7**2:
  20.         return r2**2
  21.     else:
  22.         return 0
  23.  
  24. def los_integrate(emiss_func, x, y, zmin, zmax):
  25.  
  26.     import scipy.integrate
  27.  
  28.     return (scipy.integrate.quadrature
  29.             (lambda z: emiss_func([x,y,z]),
  30.              zmin, zmax)[0])
  31.  
  32. class RichBremsstrahlung:
  33.  
  34.     def __init__(self, fname, inclination=0):
  35.  
  36.         import h5py
  37.         import numpy
  38.         import scipy.interpolate
  39.  
  40.         self.q = inclination
  41.         with h5py.File(fname,'r+') as f:
  42.             x_list = numpy.array(f['x_coordinate'])
  43.             y_list = numpy.array(f['y_coordinate'])
  44.             t_list = numpy.array(f['temperature'])
  45.             d_list = numpy.array(f['density'])
  46.         self.z_min = numpy.min(y_list)
  47.         self.z_max = numpy.max(y_list)
  48.         self.temperature_func = (
  49.             scipy.interpolate.LinearNDInterpolator
  50.             (numpy.array([x_list, y_list]).T,
  51.              t_list,
  52.              fill_value=0))
  53.         self.density_func = (
  54.             scipy.interpolate.LinearNDInterpolator
  55.             (numpy.array([x_list,y_list]).T,
  56.              d_list,
  57.              fill_value=0))
  58.  
  59.     def __call__(self, p):
  60.  
  61.         import numpy
  62.  
  63.         x = p[0]
  64.         y = p[1]*numpy.cos(self.q)+p[2]*numpy.sin(self.q)
  65.         z = p[2]*numpy.cos(self.q)-p[1]*numpy.sin(self.q)
  66.  
  67.         r = numpy.sqrt(x**2 + y**2)
  68.         t = self.temperature_func(r,z)
  69.         d = self.temperature_func(r,z)
  70.         return numpy.sqrt(t)*d**2
  71.  
  72. def main():
  73.  
  74.     import numpy
  75.     import pylab
  76.     import matplotlib as plt
  77.     import scipy.integrate
  78.  
  79.     q = numpy.pi/3
  80.     x_list = numpy.linspace(-10,10,num=100)
  81.     y_list = numpy.linspace(-10,10,num=101)
  82.     rbs = RichBremsstrahlung('snapshot_575.h5',q)
  83.     I_list = [[los_integrate(rbs,x,y,rbs.z_min,rbs.z_max)
  84.                for x in x_list]
  85.               for y in y_list]
  86.     X_list, Y_list = numpy.meshgrid(x_list, y_list)
  87.     pylab.contourf(X_list, Y_list, I_list, 20,
  88.                    cmap=plt.cm.bone)
  89.     pylab.axis('equal')
  90.     pylab.xlabel('x [pc]')
  91.     pylab.ylabel('y [pc]')
  92.     pylab.title(r'$i = '+str(180*q/numpy.pi)+'^O$')
  93.     pylab.show()
  94.  
  95. if __name__ == '__main__':
  96.  
  97.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement