OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
tmatrix.py
Go to the documentation of this file.
1 """
2 Sam Anderson
3 October 2017
4 """
5 
6 import warnings
7 import numpy as np
8 from pytmatrix.fortran_tm import pytmatrixf
9 
10 
11 class tmatrix(object):
12 
13  """T-Matrix scattering from nonspherical particles.
14 
15  Class for simulating scattering from nonspherical particles with the
16  T-Matrix method. Uses a wrapper to the Fortran code by M. Mishchenko.
17 
18  Usage instructions:
19 
20  First, the class should be be initialized. Any attributes (see below)
21  can be passed as keyword arguments to the constructor. For example:
22  sca = tmatrix.tmatrix(wavelength=2.0, m=complex(0,2))
23 
24  The properties of the scattering and the radiation should then be set
25  as attributes of this object.
26 
27  Attributes:
28  radius: Equivalent radius.
29  radius_type: If radius_type==tmatrix.RADIUS_EQUAL_VOLUME (default),
30  radius is the equivalent volume radius.
31  If radius_type==tmatrix.RADIUS_MAXIMUM, radius is the maximum
32  radius.
33  If radius_type==tmatrix.RADIUS_EQUAL_AREA,
34  radius is the equivalent area radius.
35  wavelength: The wavelength of incident light (same units as axi).
36  m: The complex refractive index.
37  axis_ratio: The horizontal-to-rotational axis ratio.
38  shape: Particle shape.
39  tmatrix.SHAPE_SPHEROID: spheroid
40  tmatrix.SHAPE_CYLINDER: cylinders;
41  tmatrix.SHAPE_CHEBYSHEV: Chebyshev particles (not yet
42  supported).
43  """
44 
45  _attr_list = set(["radius_num","radius_max", "radius_type", "wavelength",
46  "m", "axial_ratio", "shape", "ddelt", "ndgs", "ndistr", "gpoints",
47  "ncoeff", "angles", "b_coeff", "gamma" ])
48 
49  _deprecated_aliases = {"axi": "radius",
50  "lam": "wavelength",
51  "eps": "axial_ratio",
52  "rat": "radius_type",
53  "np": "shape",
54  "scatter": "orient"
55  }
56 
57  RADIUS_EQUAL_VOLUME = 1.0
58  RADIUS_EQUAL_AREA = 0.5
59  RADIUS_MAXIMUM = 2.0
60 
61  SHAPE_SPHEROID = -1
62  SHAPE_CYLINDER = -2
63  SHAPE_CHEBYSHEV = 1
64 
65  DISTRIBUTION_MODIFIED_GAMMA = 1
66  DISTRIBUTION_LOGNORMAL = 2
67  DISTRIBUTION_POWERLAW = 3
68  DISTRIBUTION_GAMMA = 4
69  DISTRIBUTION_MODIFIED_POWERLAW = 5
70 
71  def __init__(self, **kwargs):
72  self.radii = 1
73  self.radius_max = 1.0
74  self.radius_type = RADIUS_EQUAL_VOLUME
75  self.wavelength = 1.0
76  self.m = complex(1.53,0.008)
77  self.axial_ratio = 1.0
78  self.shape = SHAPE_SPHEROID
79  self.ddelt = 1e-3
80  self.distr = DISTRIBUTION_LOGNORMAL
81  self.dvpoints = 2
82  self.gqpoints = 5
83  self.ncoeff = 60
84  self.angles = 180
85  self.bcoeff = 0.1
86  self.gamma = 0.5
87 
88  self.reff = 0
89  self.veff = 0
90  self.cext = 0
91  self.csca = 0
92  self.albedo = 0
93  self.asym = 0
94  self.f = 0
95 
96  for attr in self._attr_list:
97  if attr in kwargs:
98  self.__dict__[attr] = kwargs[attr]
99 
100 
101  def generate_tables(self):
102  """
103  Generate aerosol tables using tmatrix.
104 
105  Args:
106  """
107  (self.reff, self.veff, self.cext, self.csca, self.albedo, self.asym, self.f) =\
108  pytmatrixf.calcrand(self.radius_type, self.wavelength, self.m.real, \
109  self.m.imag, self.axis_ratio, self.shape, self.ddelt, self.dvpoints, \
110  self.radii, self.radius_max, self.bcoeff, self.gamma, \
111  self.distr, self.gqpoints, self.angles, self.ncoeff)
112 
113  return (self.reff, self.veff, self.cext, self.csca, self.albedo, self.asym, self.f)
114 
115 
116  def mie(self, wl, m, sz, sig, nang ):
117  """
118  Generate Mie scattering values using lognormal distribution
119 
120  """
121  B = 2 * sig**2
122 
123  (reff, veff, cext, csca, albedo, asym, f) =\
124  pytmatrixf.calcrand(self.radius_type, wl, m.real, \
125  m.imag, 1, SHAPE_SPHEROID, self.ddelt, self.dvpoints, \
126  1, sz, B, 0, DISTRIBUTION_LOGNORMAL, self.gqpoints, nangs, self.ncoeff)
127 
128  qext = cext/(2*math.pi*reff**2)
129  qsca = csca/(2*math.pi*reff**2)
130  return (reff, veff, qext, qsca, albedo, asym, f)
131 
132 
133  def __getattr__(self, name):
134  name = self._deprecated_aliases.get(name, name)
135  return object.__getattribute__(self, name)
136 
137 
138  def __setattr__(self, name, value):
139  object.__setattr__(self, name, value)
140 
141 
142  def _init_tmat(self):
143  """Initialize the scatter_random T-matrix.
144  """
145 
146  if self.radius_type == Scatterer.RADIUS_MAXIMUM:
147  # Maximum radius is not directly supported in the original
148  # so we convert it to equal volume radius
149  radius_type = Scatterer.RADIUS_EQUAL_VOLUME
150  radius = self.equal_volume_from_maximum()
151  else:
152  radius_type = self.radius_type
153  radius = self.radius
154 
dictionary _deprecated_aliases
Definition: tmatrix.py:49
def __setattr__(self, name, value)
Definition: tmatrix.py:138
def generate_tables(self)
Definition: tmatrix.py:101
def __init__(self, **kwargs)
Definition: tmatrix.py:71
def mie(self, wl, m, sz, sig, nang)
Definition: tmatrix.py:116
def __getattr__(self, name)
Definition: tmatrix.py:133