def bulk_scatter(wavelength, temp, dist, diameters, canting_width=None):
    csec_units = 'mm**2'

    scatt = scattering.scatterer(wavelength, temp, 'water',
            diameters=diameters, shape='oblate')
    if canting_width is not None:
        scatt.angle_width = canting_width
    scatt.set_scattering_model('tmatrix')

    z = to_dBz(scatt.get_reflectivity_factor(dist, polar='h'))
    zdr = (z - to_dBz(scatt.get_reflectivity_factor(dist,
        polar='v'))).rescale('dB')
    atten = (scatt.get_attenuation(dist, polar='h').rescale('1/km') * exp_to_dB)
    diff_atten = (atten -
            scatt.get_attenuation(dist, polar='v').rescale('1/km') * exp_to_dB)
    kdp = ((scatt.get_propagation_wavenumber(dist, polar='h') -
            scatt.get_propagation_wavenumber(dist, polar='v')) * pq.rad).rescale(
                    'deg/km')
    delta = (scatt.get_backscatter_differential_phase(dist) * pq.rad).rescale('deg')

    return ScatterResults(z, zdr, atten, diff_atten, kdp, delta)
import matplotlib.pyplot as plt
import numpy as np
import scattering, dsd
import scipy.constants as consts

d = np.linspace(0.01, 1.0, 200).reshape(200, 1) * consts.centi
l = np.linspace(0.01, 25.0, 100).reshape(1, 100) / consts.kilo
dist = dsd.mp_from_lwc(d, l)
#lam = 0.1
lam = 0.0321
temp = 10.0

db_factor = 10.0 * np.log10(np.e)
ref_adjust = 180

mie = scattering.scatterer(lam, temp, 'water', diameters=d)
mie.set_scattering_model('mie')

ray = scattering.scatterer(lam, temp, 'water', diameters=d)
ray.set_scattering_model('rayleigh')

oblate_rg = scattering.scatterer(
    lam, temp, 'water', diameters=d, shape='oblate')
oblate_rg.set_scattering_model('gans')

sphere_rg = scattering.scatterer(
    lam, temp, 'water', diameters=d, shape='sphere')
sphere_rg.set_scattering_model('gans')

oblate = scattering.scatterer(lam, temp, 'water', diameters=d, shape='oblate')
oblate.set_scattering_model('tmatrix')
import matplotlib.pyplot as plt
import numpy as np
import scattering, dsd
import scipy.constants as consts

d = np.linspace(0.01, 1.0, 200).reshape(200,1) * consts.centi
l = np.linspace(0.01, 15.0, 100).reshape(1,100) / consts.kilo
dist = dsd.mp_from_lwc(d, l)
#lam = 0.1
lam = 0.0321
temp = 10.0

db_factor = 10.0 * np.log10(np.e)
ref_adjust = 180

rg_brandes = scattering.scatterer(lam, temp, 'water', diameters=d,
    shape='oblate', axis_ratio_func=scattering.brandes_axis_ratios)
rg_brandes.set_scattering_model('gans')

rg_prup = scattering.scatterer(lam, temp, 'water', diameters=d,
    shape='oblate', axis_ratio_func=scattering.pruppacher_axis_ratios)
rg_prup.set_scattering_model('gans')

tmat_brandes = scattering.scatterer(lam, temp, 'water', diameters=d,
    shape='oblate', axis_ratio_func=scattering.brandes_axis_ratios)
tmat_brandes.set_scattering_model('tmatrix')

tmat_prup = scattering.scatterer(lam, temp, 'water', diameters=d,
    shape='oblate', axis_ratio_func=scattering.pruppacher_axis_ratios)
tmat_prup.set_scattering_model('tmatrix')

d = d.squeeze() / consts.centi
import numpy as N
import matplotlib.pyplot as P
import scattering, dsd

d = N.linspace(0.01, 2.0, 200).reshape(200,1)
l = N.linspace(0.01, 25.0, 100).reshape(1,100)
mp = dsd.mp_from_lwc(d*10.0, l)
sband = 10.0

s_ray = scattering.scatterer(sband, 10.0, 'water', diameters = d)
s_ray.set_scattering_model('rayleigh')
s_ray_ref = 10.0 * N.log10(s_ray.get_reflectivity(mp))
s_ray_atten = s_ray.get_attenuation(mp) * (10.0 * N.log10(N.e))
m = scattering.refractive_index('water', sband, 10.0)
Kw = (m**2 - 1)/(m**2 + 2)
lam = dsd.mp_slope_3rd(l)
s_ray_atten_mp = ((2/3.) * (N.pi**5 * N.abs(Kw)**2 / (sband**4) * 720./lam**7
    * dsd.mp_N0) + 6 * N.pi / (1e6 * sband) * N.imag(Kw) * l).squeeze()

d = d.squeeze()
l = l.squeeze()

f = P.figure()

ax = f.add_subplot(1,2,2)
ax.semilogy(l, s_ray_atten_mp, 'b--')
ax.semilogy(l, s_ray_atten, 'b-')
ax.set_xlabel('LWC (g/kg)')
ax.set_ylabel('Attenuation')
ax.set_title('Comparison of Attenuation')
ax.grid()
def plot_csecs(scatterers):
    for s in scatterers:
        plt.subplot(2,2,1)
        plot_csec(s, s.sigma_s, '\sigma_{s}')
        plt.subplot(2,2,2)
        plot_csec(s, s.sigma_a, '\sigma_{a}')
        plt.subplot(2,2,3)
        plot_csec(s, s.sigma_e, '\sigma_{e}')
        plt.subplot(2,2,4)
        plot_csec(s, s.sigma_b, '\sigma_{b}')
  
d = np.linspace(0.01, 2.0, 200).reshape(200,1) * consts.centi
sband = .1 
xband = .0321

temp = 0.0

x_mie = scattering.scatterer(xband, temp, 'water', diameters=d)
x_mie.set_scattering_model('mie')
x_ray = scattering.scatterer(xband, temp, 'water', diameters=d)
x_ray.set_scattering_model('rayleigh')

s_mie = scattering.scatterer(sband, temp, 'water', diameters=d)
s_mie.set_scattering_model('mie')
s_ray = scattering.scatterer(sband, temp, 'water', diameters=d)
s_ray.set_scattering_model('rayleigh')

plot_csecs([x_mie, x_ray, s_mie, s_ray])
plt.legend(loc = 'lower right')
plt.show()
Exemple #6
0
import scattering
import scipy.constants as consts

d = np.linspace(0, 100, 500) * consts.milli
T = 0.0
wavelengths = np.array([10.0, 5.5, 3.21]) * consts.centi
lines = ['r--','b:','g-']

m_water = np.array([np.sqrt(80.255+24.313j), np.sqrt(65.476+37.026j),
    np.sqrt(44.593+41.449j)])
m_ice = np.array([np.sqrt(3.16835+0.02492j), np.sqrt(3.16835+0.01068j),
    np.sqrt(3.16835+0.0089j)])

plt.figure()
for mw, mi, lam, line in zip(m_water, m_ice, wavelengths, lines):
    scat = scattering.scatterer(lam, T, 'water', diameters=d, ref_index=mw)
    scat.set_scattering_model('tmatrix')
    plt.subplot(1,2,1)
    plt.semilogy(d / consts.milli, scat.sigma_b / (consts.centi)**2, line,
        label='%5.2fcm Tmat' % (lam / consts.centi))
    scat = scattering.scatterer(lam, T, 'ice', diameters=d, ref_index=mi)
    scat.set_scattering_model('tmatrix')
    plt.subplot(1,2,2)
    plt.semilogy(d / consts.milli, scat.sigma_b / (consts.centi)**2, line,
        label='%5.2fcm Tmat' % (lam / consts.centi))

plt.subplot(1,2,1)
plt.xlabel('Diameter (mm)')
plt.ylabel(r'Backscatter Cross-Section (cm$^{2}$)')
plt.xlim(0,100.0)
plt.ylim(1.0e-2,1e3)
Exemple #7
0
import matplotlib.pyplot as plt
import numpy as np
import scattering
import scipy.constants as consts

nd = np.logspace(-2, 1, 200)
T = 0.0
wavelengths = np.array([0.86, 3.21, 5.5, 10.0]) * consts.centi
colors = ['r','b','g','c']

plt.figure()
for lam,color in zip(wavelengths,colors):
    d = nd * lam / np.pi
    scat = scattering.scatterer(lam, T, 'water', diameters=d)
    scat.set_scattering_model('tmatrix')
    plt.loglog(nd, scat.sigma_e * 4/(np.pi * d**2), color+'-',
        label='%5.2fcm Tmat' % (lam / consts.centi))
#    scat.set_scattering_model('mie')
#    plt.loglog(nd, scat.sigma_e * 4/(np.pi * d**2), color+'x',
#        label='%5.2fcm Mie'%(lam / consts.centi))

plt.legend(loc='lower right')
plt.xlabel('Normalized Drop Diameter')
plt.ylabel('Normalized Extinction Cross-Section')
plt.xlim(0.01,10.0)
plt.ylim(1.0e-3,10)
plt.show()
Exemple #8
0
        plot_csec(s, l, s.get_copolar_cross_correlation(mp), 'rho(1)')
        plt.subplot(1,2,2)
        plot_csec(s, l, np.rad2deg(np.unwrap(
            s.get_backscatter_differential_phase(mp))), 'delta')

d = np.linspace(0.01, 2.0, 200).reshape(200, 1) * consts.centi
l = np.linspace(0.01, 25.0, 100).reshape(1,100) / consts.kilo
mp = dsd.mp_from_lwc(d, l)
sband = 0.1
cband = 0.05
xband = 0.0321

temp = 10.0
angleWidth = 10

x_fixed = scattering.scatterer(xband, temp, 'water', diameters=d, shape='oblate')
x_fixed.set_scattering_model('tmatrix')

x_spread = scattering.scatterer(xband, temp, 'water', diameters=d, shape='oblate')
x_spread.angle_width = angleWidth
x_spread.set_scattering_model('tmatrix')

c_fixed = scattering.scatterer(cband, temp, 'water', diameters=d, shape='oblate')
c_fixed.set_scattering_model('tmatrix')

c_spread = scattering.scatterer(cband, temp, 'water', diameters=d, shape='oblate')
c_spread.angle_width = angleWidth
c_spread.set_scattering_model('tmatrix')

s_fixed = scattering.scatterer(sband, temp, 'water', diameters=d, shape='oblate')
s_fixed.set_scattering_model('tmatrix')
def test_ones():
    scat = scatterer(0.1, 0.0, "water", diameters=np.array([0.04, 0.05]))
    scat.set_scattering_model("rayleigh")

    assert_array_almost_equal(scat.sigma_b, np.array([0.01170936, 0.04466766], np.float32))
    csec_units = 'mm**2'

    fig, ax = plt.subplots(2, 3, sharex=True, figsize=(10,8))
    fig.suptitle(title)
    fig.subplots_adjust(wspace=0.4)
    fig2, ax2 = plt.subplots(2, 3, sharex=True, figsize=(10,8))
    fig2.suptitle(title)
    fig2.subplots_adjust(wspace=0.4)
    fig3, ax3 = plt.subplots(1, 2, sharex=True, figsize=(10,8))
    fig3.suptitle(title)
    fig4, ax4 = plt.subplots(2, 3, sharex=True, figsize=(10,8))
    fig4.suptitle(title)
    fig4.subplots_adjust(wspace=0.4)

    for ind, t in enumerate(temps):
        scatt = scattering.scatterer(wavelength, t, 'water', diameters=d,
                shape='oblate')
        scatt.set_scattering_model('tmatrix')
        plot_label = u'%d\u00B0C' % t
        temp_color = temp_colors[int(t)]

        sig_b = scatt.sigma_bh.squeeze().rescale(csec_units)
        ax[0,0].plot(d_plot, sig_b, temp_color, label=plot_label)

        sig_e = scatt.sigma_eh.squeeze().rescale(csec_units)
        ax[0,1].plot(d_plot, sig_e, temp_color, label=plot_label)

        delta_d = -angle(-scatt.S_bkwd[0,0].conj() * scatt.S_bkwd[1,1],
                deg=True).squeeze()
        ax[0,2].plot(d_plot, delta_d, temp_color, label=plot_label)

        diff_sig_b = to_dB(scatt.sigma_bh / scatt.sigma_bv).squeeze()
    plt.xlabel("Diameter (%s)" % d.dimensionality)
    plt.ylabel(name)


def plot_csecs(d, scatterers):
    for s in scatterers:
        plt.subplot(1, 1, 1)
        plot_csec(s, d, np.rad2deg(np.unwrap(-np.angle(-s.S_bkwd[0, 0].conj() * s.S_bkwd[1, 1]).squeeze())), "delta")
        plt.gca().set_ylim(-4, 20)


d = np.linspace(0.01, 0.7, 200).reshape(200, 1) * pq.cm
sband = pq.c / (2.8 * pq.GHz)
cband = pq.c / (5.4 * pq.GHz)
xband = pq.c / (9.4 * pq.GHz)

temp = 10.0

x_fixed = scattering.scatterer(xband, temp, "water", diameters=d, shape="oblate")
x_fixed.set_scattering_model("tmatrix")

c_fixed = scattering.scatterer(cband, temp, "water", diameters=d, shape="oblate")
c_fixed.set_scattering_model("tmatrix")

s_fixed = scattering.scatterer(sband, temp, "water", diameters=d, shape="oblate")
s_fixed.set_scattering_model("tmatrix")

plot_csecs(d, [x_fixed, c_fixed, s_fixed])
plt.legend(loc="upper left")
plt.show()
import numpy as np
import scattering, dsd
import scipy.constants as consts

d = np.linspace(0.01, 2.0, 200).reshape(200,1) * consts.centi
l = np.linspace(0.01, 25.0, 100).reshape(1,100) / consts.kilo
mp = dsd.mp_from_lwc(d, l)
sband = .1 
xband = .0321

T = 10.0

db_factor = 10.0 * np.log10(np.e)
ref_adjust = 180

s_tmat = scattering.scatterer(sband, T, 'water', diameters=d)
s_tmat.set_scattering_model('tmatrix')
s_tmat_ref = 10.0 * np.log10(s_tmat.get_reflectivity_factor(mp)) + ref_adjust
s_tmat_atten = s_tmat.get_attenuation(mp) * consts.kilo * db_factor

x_tmat = scattering.scatterer(xband, T, 'water', diameters=d)
x_tmat.set_scattering_model('tmatrix')
x_tmat_ref = 10.0 * np.log10(x_tmat.get_reflectivity_factor(mp)) + ref_adjust
x_tmat_atten = x_tmat.get_attenuation(mp) * consts.kilo * db_factor

s_ray = scattering.scatterer(sband, T, 'water', diameters=d)
s_ray.set_scattering_model('rayleigh')
s_ray_ref = 10.0 * np.log10(s_ray.get_reflectivity_factor(mp)) + ref_adjust
s_ray_atten = s_ray.get_attenuation(mp) * consts.kilo * db_factor

s_mie = scattering.scatterer(sband, T, 'water', diameters=d)