Commit ed52ec97 authored by Martin Glatzle's avatar Martin Glatzle

Restructure.

parent 70a3bfa6
import astropy.units as _u
import numpy as _numpy
import warnings as _warnings
import os as _os
from scipy.interpolate import interp1d
from scipy import integrate
import sys
Path = _os.path.dirname(_os.path.dirname(_os.path.realpath(__file__))) + \
'//Solver//'
sys.path.insert(0, Path)
import sdist as sd
import GrainSpecies as gs
###############################################################################
###############################################################################
class Dp(object):
def __init__(self,en):
self.en = en
return
def Sigma_abs_E(en):
sizes = _np.logspace(self.sizeMin, self.sizeMax, \
num = 10000)
def func1(sizes):
if issubclass(self.__class__, sd.SizeDist):
dist_gr = self.__class__(Sizes).sdist_gr
dist_sil = self.__class__(Sizes).sdist_sil
return dist_gr , dist_sil
def func2(Sizes):
sigma_cr = gs.SpGraphite.Sigma_abs(en,sizes)[0]
sigma_ sl = gs.SpAsil.Sigma_abs(en,sizes)[0]
return sigma_cr, sigma_sl
f1_gr = interp1d(sizes, func1(sizes)[0], kind='linear')
f2_sl = interp1d(sizes, func1(sizes)[1], kind='linear')
f3_gr = interp1d(sizes, func2(sizes)[0], kind='linear')
f4_sl = interp1d(sizes, func2(sizes)[1], kind='linear')
Integ1 =integrate.quad(f1_gr(Sizes)* f3_gr(Sizes),self.sizeMin, \
self.sizeMax)
Integ2 = integrate.quad(f1_gr(Sizes), self.sizeMin,self.sizeMax)
Integ3 =integrate.quad(f2_sl(Sizes)* f4_sl(Sizes),self.sizeMin, \
self.sizeMax)
Integ4 = integrate.quad(f2_sl(Sizes), self.sizeMin,self.sizeMax)
sigma_abs_1 = Integ1/Integ2
sigma_abs_2 = Integ3/Integ4
sigma_abs_E = sigma_abs_1 + sigma_abs_2
return sigma_abs_E
\ No newline at end of file
loadFiles = { 'carbon_par_0.01': 'callindex.out_CpaD03_0.01.txt',
'carbon_par_0.1':'callindex.out_CpaD03_0.10.txt',
'carbon_per_0.01':'callindex.out_CpeD03_0.01.txt' ,
'carbon_per_0.1': 'callindex.out_CpeD03_0.10.txt',
'silica': 'callindex.out_silD03.txt' }
def Find_Interpolate(lamda,array):
w = array[0]
if lamda in w:
ind = _np.where(w == lamda)
Re_n_out = array[1][ind]
Im_n_out = array[2][ind]
else:
ind1 = _np.where(w >= lamda).min()
ind2 = _np.where(w <= lamda).max()
wght1 = (w[ind1] - lamda)/lamda
wght2= (lamda - w[ind2]) / lamda
Re_n_out = (wght1* array[1][ind1] + wght2* array[1][ind2]) / 2
Im_n_out = (wght1* array[2][ind1] + wght2* array[2][ind2]) / 2
Ref_Indx = Re_n_out + j * Im_n_out
return Ref_Indx
class Crefin(object):
def __init__(self, f):
self.f = f
return
def __call__(self, a, en):
return self.f(a, en)
class SGPAHCrefin(Crefin):
@classmethod
def loadOprops(path):
"""
Load the optical properties files in CSV format.
'path': path to Refractive Index and Material properties file
returns:
energy (1D) [eV] at which Q values where computed
Real Refractive index and Imaginary Refractive index
"""
rel_path = '\\lib\\' + path
path = os.path.dirname(os.path.realpath(__file__)) + rel_path
data = []
with open(path) as f:
for line in f:
if 'number of wavelengths' not in line:
continue
else:
line = f.next().split()
w = []
eps_1 = []
eps_2 = []
real_n = []
Im_n = []
while line:
try:
line = f.next().split()
except StopIteration:
line = []
if line:
w.append(float(line[0]))
Re_n.append(float(line['Re(n)-1']) + 1)
Im_n.append(float(line['Im(n)']))
data.append([
_np.array(w),
_np.array(Re_n),
_np.array(Im_n)])
return data
class Crefin_Asil(SGPAHCrefin):
def __init__(self):
return
class Crefin_Gra(SGPAHCrefin):
def __init__(self):
return
import astropy.units as _u
import numpy as _numpy
import warnings as _warnings
import os as _os
from scipy.interpolate import interp1d
from scipy import integrate
import sys
Path = _os.path.dirname(_os.path.dirname(_os.path.realpath(__file__))) + \
'//Solver//'
sys.path.insert(0, Path)
import sdist as sd
import GrainSpecies as gs
###############################################################################
###############################################################################
class Dp(object):
def __init__(self, en):
self.en = en
return
def Sigma_abs_E(en):
sizes = _np.logspace(self.sizeMin, self.sizeMax,
num=10000)
def func1(sizes):
if issubclass(self.__class__, sd.SizeDist):
dist_gr = self.__class__(sizes).sdist_gr
dist_sil = self.__class__(sizes).sdist_sil
return dist_gr, dist_sil
def func2(sizes):
sigma_cr = gs.SpGraphite.Sigma_abs(en, sizes)[0]
sigma_sl = gs.SpAsil.Sigma_abs(en, sizes)[0]
return sigma_cr, sigma_sl
f1_gr = interp1d(sizes, func1(sizes)[0], kind='linear')
f2_sl = interp1d(sizes, func1(sizes)[1], kind='linear')
f3_gr = interp1d(sizes, func2(sizes)[0], kind='linear')
f4_sl = interp1d(sizes, func2(sizes)[1], kind='linear')
Integ1 =integrate.quad(f1_gr(Sizes) * f3_gr(Sizes),self.sizeMin,
self.sizeMax)
Integ2 = integrate.quad(f1_gr(Sizes), self.sizeMin,self.sizeMax)
Integ3 = integrate.quad(f2_sl(Sizes) * f4_sl(Sizes),self.sizeMin,
self.sizeMax)
Integ4 = integrate.quad(f2_sl(Sizes), self.sizeMin,self.sizeMax)
sigma_abs_1 = Integ1/Integ2
sigma_abs_2 = Integ3/Integ4
sigma_abs_E = sigma_abs_1 + sigma_abs_2
return sigma_abs_E
......@@ -14,119 +14,17 @@ import Solver as sv
class GrainSpecies(object):
loadFiles = { 'carbon_par_0.01': 'callindex.out_CpaD03_0.01.txt',
'carbon_par_0.1':'callindex.out_CpaD03_0.10.txt',
'carbon_per_0.01':'callindex.out_CpeD03_0.01.txt' ,
'carbon_per_0.1': 'callindex.out_CpeD03_0.10.txt',
'silica': 'callindex.out_silD03.txt' }
def __init__(self, en, sizes):
self.en = en
self.sizes = sizes
def __init__(self):
return
def __add__(self, other):
if type(other) == self.__class__:
def s_abs(*args):
return self.s_abs(*args) + \
other.s_abs(*args)
def s_sca(*args):
return self.s_sca(*args) + \
other.s_sca(*args)
return self.__class__(s_abs, s_sca)
else:
def s_abs(*args):
return other + self.s_abs(*args)
def s_sca(*args):
return other + self.s_sca(*args)
return self.__class__(s_abs, s_sca)
__radd__ = __add__
def __mul__(self, other):
def s_abs(*args):
return other*self.s_abs(*args)
def s_sca(*args):
return other*self.s_sca(*args)
return self.__class__(s_abs, s_sca)
__rmul__ = __mul__
@staticmethod
def loadOprops(path):
"""
Load the optical properties files in CSV format.
'path': path to Refractive Index and Material properties file
returns:
energy (1D) [eV] at which Q values where computed
Real Refractive index and Imaginary Refractive index
"""
rel_path = '\\lib\\' + path
path = os.path.dirname(os.path.realpath(__file__)) + rel_path
data = []
with open(path) as f:
for line in f:
if 'number of wavelengths' not in line:
continue
else:
line = f.next().split()
w = []
eps_1 = []
eps_2 = []
real_n = []
Im_n = []
while line:
try:
line = f.next().split()
except StopIteration:
line = []
if line:
w.append(float(line[0]))
Re_n.append(float(line['Re(n)-1']) + 1)
Im_n.append(float(line['Im(n)']))
data.append([
_np.array(w),
_np.array(Re_n),
_np.array(Im_n)])
return data
def Find_Interpolate(lamda,array):
w = array[0]
if lamda in w:
ind = _np.where(w == lamda)
Re_n_out = array[1][ind]
Im_n_out = array[2][ind]
else:
ind1 = _np.where(w >= lamda).min()
ind2 = _np.where(w <= lamda).max()
wght1 = (w[ind1] - lamda)/lamda
wght2= (lamda - w[ind2]) / lamda
Re_n_out = (wght1* array[1][ind1] + wght2* array[1][ind2]) / 2
Im_n_out = (wght1* array[2][ind1] + wght2* array[2][ind2]) / 2
Ref_Indx = Re_n_out + j * Im_n_out
return Ref_Indx
class SpAsil(Grainspecies):
def getSilica_props(en):
en = en.to(u.micron, equivalencies=u.spectral())
if en.unit != _u.eV or en.unit != en.J :
raise('The unit of Energy should be in eV or Joule')
elif en.unit == en.J:
......@@ -253,4 +151,4 @@ class SpAsil(Grainspecies):
sigma_sca_0.1_ = ( 2 * _np.array(sigma_par_0.1_) + \
_np.array(sigma_per_0.1_) ) / 3
#
return sigma_sca_0.01_ , sigma_sca_0.1_
\ No newline at end of file
return sigma_sca_0.01_ , sigma_sca_0.1_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment