Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:48

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 material.py : optical properties access
0023 ==================================================
0024 
0025 Geocache materials are accessible by name, usage example: 
0026 
0027 .. code-block:: py
0028 
0029     In [2]: mat = Material("GlassSchottF2")
0030 
0031     In [3]: wl = np.linspace(100.,730.,10, dtype=np.float32)
0032 
0033     In [4]: ri = mat.refractive_index(wl)
0034 
0035     In [8]: al = mat.absorption_length(wl)
0036 
0037     In [9]: sl = mat.scattering_length(wl)
0038 
0039     In [10]: rp = mat.reemission_prob(wl)
0040 
0041     In [11]: np.dstack([wl,ri,al,sl,rp])
0042     Out[11]: 
0043     array([[[     100.   ,        1.685,  1000000.   ,  1000000.   ,        0.   ],
0044             [     170.   ,        1.685,  1000000.   ,  1000000.   ,        0.   ],
0045             [     240.   ,        1.685,  1000000.   ,  1000000.   ,        0.   ],
0046             [     310.   ,        1.685,  1000000.   ,  1000000.   ,        0.   ],
0047             [     380.   ,        1.658,  1000000.   ,  1000000.   ,        0.   ],
0048             [     450.   ,        1.638,  1000000.   ,  1000000.   ,        0.   ],
0049             [     520.   ,        1.626,  1000000.   ,  1000000.   ,        0.   ],
0050             [     590.   ,        1.619,  1000000.   ,  1000000.   ,        0.   ],
0051             [     660.   ,        1.614,  1000000.   ,  1000000.   ,        0.   ],
0052             [     730.   ,        1.611,  1000000.   ,  1000000.   ,        0.   ]]])
0053 
0054 
0055 
0056 ::
0057 
0058     In [1]: np.dstack([w, a[0,:,0], a[0,:,1],a[0,:,2],a[0,:,3],a[1,:,0]])    ## Water
0059     ///
0060     ///                                     absorption     scattering
0061     ///                                     length (mm)    length
0062     ///
0063     ///                                     ~ 27m @ 440nm    1000m !!
0064     ///                                                     (placeholder value?)
0065     ///
0066     ///     water looks blue, 
0067     ///          more absorption (lower absorption lengths) at red high wavelength end
0068     ///          of the visible
0069     ///
0070     ///     scattering length 
0071     ///           1000m looks like a do-not scatter placeholder
0072     ///  
0073     ///
0074     Out[1]: 
0075     array([[[      60.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0076             [      80.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0077             [     100.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0078             [     120.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0079             [     140.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0080             [     160.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0081             [     180.    ,        1.39  ,      273.208 ,  1000000.    ,        0.    ,      300.    ],
0082             [     200.    ,        1.39  ,      691.5562,  1000000.    ,        0.    ,      300.    ],
0083             [     220.    ,        1.3841,     1507.1183,  1000000.    ,        0.    ,      300.    ],
0084             [     240.    ,        1.3783,     2228.2798,  1000000.    ,        0.    ,      300.    ],
0085             [     260.    ,        1.3724,     3164.6375,  1000000.    ,        0.    ,      300.    ],
0086             [     280.    ,        1.3666,     4286.0454,  1000000.    ,        0.    ,      300.    ],
0087             [     300.    ,        1.3608,     5992.6128,  1000000.    ,        0.    ,      300.    ],
0088             [     320.    ,        1.3595,     7703.5034,  1000000.    ,        0.    ,      300.    ],
0089             [     340.    ,        1.3585,    10257.2852,  1000000.    ,        0.    ,      300.    ],
0090             [     360.    ,        1.3572,    12811.0684,  1000000.    ,        0.    ,      300.    ],
0091             [     380.    ,        1.356 ,    15364.8496,  1000000.    ,        0.    ,      300.    ],
0092             [     400.    ,        1.355 ,    19848.9316,  1000000.    ,        0.    ,      300.    ],
0093             [     420.    ,        1.354 ,    24670.9512,  1000000.    ,        0.    ,      300.    ],
0094             [     440.    ,        1.353 ,    27599.9746,  1000000.    ,        0.    ,      300.    ],
0095             [     460.    ,        1.3518,    28732.2051,  1000000.    ,        0.    ,      300.    ],
0096             [     480.    ,        1.3505,    29587.0527,  1000000.    ,        0.    ,      300.    ],
0097             [     500.    ,        1.3492,    26096.2637,  1000000.    ,        0.    ,      300.    ],
0098             [     520.    ,        1.348 ,    17787.9492,  1000000.    ,        0.    ,      300.    ],
0099             [     540.    ,        1.347 ,    16509.3672,  1000000.    ,        0.    ,      300.    ],
0100             [     560.    ,        1.346 ,    13644.791 ,  1000000.    ,        0.    ,      300.    ],
0101             [     580.    ,        1.345 ,    10050.459 ,  1000000.    ,        0.    ,      300.    ],
0102             [     600.    ,        1.344 ,     4328.5166,  1000000.    ,        0.    ,      300.    ],
0103             [     620.    ,        1.3429,     3532.6135,  1000000.    ,        0.    ,      300.    ],
0104             [     640.    ,        1.3419,     3149.8655,  1000000.    ,        0.    ,      300.    ],
0105             [     660.    ,        1.3408,     2404.4004,  1000000.    ,        0.    ,      300.    ],
0106             [     680.    ,        1.3397,     2126.562 ,  1000000.    ,        0.    ,      300.    ],
0107             [     700.    ,        1.3387,     1590.72  ,  1000000.    ,        0.    ,      300.    ],
0108             [     720.    ,        1.3376,      809.6543,  1000000.    ,        0.    ,      300.    ],
0109             [     740.    ,        1.3365,      370.1322,  1000000.    ,        0.    ,      300.    ],
0110             [     760.    ,        1.3354,      371.9737,  1000000.    ,        0.    ,      300.    ],
0111             [     780.    ,        1.3344,      425.7059,  1000000.    ,        0.    ,      300.    ],
0112             [     800.    ,        1.3333,      486.681 ,  1000000.    ,        0.    ,      300.    ],
0113             [     820.    ,        1.3333,      486.681 ,  1000000.    ,        0.    ,      300.    ]]])
0114 
0115 
0116 ::
0117 
0118    ipython -i $(which material.py) -- --mat Water 
0119    ipython -i $(which material.py) -- --mat GdDopedLS
0120 
0121 
0122 
0123 """
0124 import os, logging, numpy as np
0125 log = logging.getLogger(__name__)
0126 
0127 from opticks.ana.main import opticks_main
0128 from opticks.ana.proplib import PropLib
0129    
0130 mlib = PropLib("GMaterialLib")
0131 
0132 
0133 class Material(object):
0134     def __init__(self, name):
0135         self.name = name
0136         self.mlib = mlib
0137 
0138     def lookup(self, prop, wavelength):
0139         return self.mlib.interp(self.name,wavelength,prop)
0140 
0141     def data(self):
0142         return self.mlib(self.name)
0143 
0144     def refractive_index(self, wavelength):
0145         return self.lookup(PropLib.M_REFRACTIVE_INDEX, wavelength)
0146 
0147     def absorption_length(self, wavelength):
0148         return self.lookup(PropLib.M_ABSORPTION_LENGTH, wavelength)
0149 
0150     def scattering_length(self, wavelength):
0151         return self.lookup(PropLib.M_SCATTERING_LENGTH, wavelength)
0152  
0153     def reemission_prob(self, wavelength):
0154         return self.lookup(PropLib.M_REEMISSION_PROB, wavelength)
0155 
0156     def group_velocity(self, wavelength):
0157         return self.lookup(PropLib.L_GROUP_VELOCITY, wavelength)
0158 
0159     def table(self, wl):
0160         """
0161         :param wl: array of wavelengths OR string "FINE_DOMAIN" or "COARSE_DOMAIN" to use standard sets
0162         :return tab: array of shape (num_wavelengths, 6) with wavelength and property values 
0163         """
0164         if type(wl) is str:
0165             if wl in "FINE_DOMAIN COARSE_DOMAIN".split():
0166                 wl = getattr(PropLib, wl)
0167             pass  
0168         pass
0169         ri = self.refractive_index(wl)
0170         al = self.absorption_length(wl)
0171         sl = self.scattering_length(wl)
0172         rp = self.reemission_prob(wl)
0173         gv = self.group_velocity(wl)
0174         tab = np.dstack([wl,ri,al,sl,rp,gv])
0175         return tab 
0176 
0177     def table_qwn(self):
0178         qwn = "wavelen rindex abslen scatlen reemprob groupvel".split()
0179         return qwn 
0180  
0181 
0182     def dump(self):
0183         w = self.mlib.domain
0184         a = self.data()
0185         aa = np.dstack([w, a[0,:,0], a[0,:,1],a[0,:,2],a[0,:,3],a[1,:,0]])
0186         print("aa")
0187         print(aa)
0188 
0189     @classmethod
0190     def Hdr(cls):
0191         labels = "wavelen rindex abslen scatlen reemprob groupvel" 
0192         hdr = "   " + "".join(list(map(lambda _:"%12s" % _, labels.split())))
0193         return hdr 
0194 
0195     def hdr(self):
0196         return self.Hdr() + " " + self.name 
0197 
0198 
0199 
0200 if __name__ == '__main__':
0201 
0202     logging.basicConfig(level=logging.INFO)
0203     dmat = "Water"
0204     args = opticks_main(mat=dmat)    
0205     log.info("mat %s " % args.mat)
0206 
0207     wl = np.linspace(300.,600.,4)
0208     for name in list(map(lambda _:_.decode("utf-8"),mlib._names)):
0209         mat = Material(name)
0210         tab = mat.table(wl)
0211         print(mat.hdr())
0212         print(tab)
0213     pass        
0214 
0215 
0216 
0217 if 0:
0218     import matplotlib.pyplot as plt 
0219     plt.ion()
0220     plt.plot( wl, al, "*", label="Absorption Length")
0221     plt.plot( wl, sl, "+", label="Scattering Length")
0222     plt.show()
0223 
0224 
0225 
0226