Skip to content

Commit

Permalink
Add max scattering option (#76)
Browse files Browse the repository at this point in the history
* Fixed some incorrect units in the metadata generator.
* Added a max_diameter option
* Switched to conda-forge for most software installs.
  • Loading branch information
josephhardinee authored Aug 22, 2018
1 parent 1a2e89d commit 314c8cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
5 changes: 3 additions & 2 deletions continuous_integration/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ conda create -n testenv --yes pip python=$PYTHON_VERSION
source activate testenv

# Install dependencies
conda install -c conda-forge numpy
conda install -c conda-forge pytest pytest-cov sphinx_rtd_theme numpy scipy matplotlib netcdf4 nose sphinx numpydoc hdf4=4.2.12 pytmatrix

conda install -c conda-forge pytmatrix pytest pytest-cov sphinx_rtd_theme numpy scipy matplotlib netcdf4 nose sphinx numpydoc hdf4=4.2.12

pip install sphinx-gallery nose-cov

if [[ $PYTHON_VERSION == '2.7' ]]; then
Expand Down
44 changes: 30 additions & 14 deletions pydsd/DropSizeDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def set_scattering_temperature_and_frequency(
self.scattering_temp = scattering_temp
self.m_w = dielectric.get_refractivity(scattering_freq, scattering_temp)

def calculate_radar_parameters(self, dsr_func=DSR.bc, scatter_time_range=None):
def calculate_radar_parameters(
self, dsr_func=DSR.bc, scatter_time_range=None, max_diameter=9.0
):
""" Calculates radar parameters for the Drop Size Distribution.
Calculates the radar parameters and stores them in the object.
Expand All @@ -164,7 +166,9 @@ def calculate_radar_parameters(self, dsr_func=DSR.bc, scatter_time_range=None):
Parameter to restrict the scattering to a time interval. The first element is the start time,
while the second is the end time.
"""
self._setup_scattering(SPEED_OF_LIGHT / self.scattering_freq * 1000.0, dsr_func)
self._setup_scattering(
SPEED_OF_LIGHT / self.scattering_freq * 1000.0, dsr_func, max_diameter
)
self._setup_empty_fields()

if scatter_time_range is None:
Expand Down Expand Up @@ -221,28 +225,31 @@ def _setup_empty_fields(self):
param, np.ma.zeros(self.numt)
)

def _setup_scattering(self, wavelength, dsr_func):
def _setup_scattering(self, wavelength, dsr_func, max_diameter):
""" Internal Function to create scattering tables.
This internal function sets up the scattering table. It takes a
wavelength as an argument where wavelength is one of the pytmatrix
accepted wavelengths.
Parameters:
-----------
wavelength : tmatrix wavelength
PyTmatrix wavelength.
dsr_func : function
Drop Shape Relationship function. Several built-in are available in the `DSR` module.
max_diameter: float
Maximum drop diameter to generate scattering table for.
"""
self.scatterer = Scatterer(wavelength=wavelength, m=self.m_w)
self.scatterer.psd_integrator = PSDIntegrator()
self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / dsr_func(D)
self.dsr_func = dsr_func
self.scatterer.psd_integrator.D_max = 10.0
self.scatterer.psd_integrator.D_max = max_diameter
self.scatterer.psd_integrator.geometries = (
tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw
tmatrix_aux.geom_horiz_back,
tmatrix_aux.geom_horiz_forw,
)
self.scatterer.or_pdf = orientation.gaussian_pdf(20.0)
self.scatterer.orient = orientation.orient_averaged_fixed
Expand Down Expand Up @@ -316,8 +323,12 @@ def calculate_dsd_parameterization(self, method="bringi"):
np.array(self.diameter["data"]) ** 3,
)
self.fields["D0"]["data"][t] = self._calculate_D0(self.Nd["data"][t])
self.fields["Nw"]["data"][t] = 256.0 / (np.pi * rho_w) * np.divide(
self.fields["W"]["data"][t], self.fields["Dm"]["data"][t] ** 4
self.fields["Nw"]["data"][t] = (
256.0
/ (np.pi * rho_w)
* np.divide(
self.fields["W"]["data"][t], self.fields["Dm"]["data"][t] ** 4
)
)

self.fields["Dmax"]["data"][t] = self.__get_last_nonzero(self.Nd["data"][t])
Expand Down Expand Up @@ -426,12 +437,17 @@ def calculate_RR(self):
# np.array(self.diameter['data'])**3)
velocity = 9.65 - 10.3 * np.exp(-0.6 * self.diameter["data"])
velocity[0] = 0.5
self.fields["rain_rate"]["data"][t] = 0.6 * np.pi * 1e-03 * np.sum(
self._mmultiply(
velocity,
self.Nd["data"][t],
self.spread["data"],
np.array(self.diameter["data"]) ** 3,
self.fields["rain_rate"]["data"][t] = (
0.6
* np.pi
* 1e-03
* np.sum(
self._mmultiply(
velocity,
self.Nd["data"][t],
self.spread["data"],
np.array(self.diameter["data"]) ** 3,
)
)
)

Expand Down
6 changes: 3 additions & 3 deletions pydsd/utility/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"Nw":
{
"standard_name": "normalized_intercept_parameter",
"units": "?",
"units": "mm-1 m-3",
"long_name" :"Normalized Intercept Parameter of a Normalized Gaussian Distribution"
},
"Nt":
Expand All @@ -32,7 +32,7 @@
"N0":
{
"standard_name": "intercept_parameter",
"units": "?",
"units": "mm-1 m-3",
"long_name" :"Intercept Parameter of Modeled Drop Size Distribution"
},
"W":
Expand Down Expand Up @@ -79,7 +79,7 @@
"Kdp":
{
"standard_name": "specific_differential_phase",
"units": "deg",
"units": "deg/km",
"long_name" :"Specific Differential Phase from Drop Size Distribution"
},
"Ai":
Expand Down

0 comments on commit 314c8cc

Please sign in to comment.