Quick usage examples for PyDSD

This notebook shows some (very) brief examples of current PyDSD functionality and how to interact with it.

NASA GV Field Campaign Parsivel Format

Let's start with a NASA Ground Validation Parsivel formatted file. We've downloaded this from the HyDRO search for the iFloodS field campaign.


In [1]:
%matplotlib inline

import pydsd
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import numpy as np
import pydsd.plot

In [2]:
filename = '/Users/hard505/Downloads/ifloods_apu01_20130502_N421419.54_W922749.33_rainDSD.txt' #Parsivel 05, March 2nd

Reading in files is quite easy. There are several readers in pydsd in either pydsd.io or pydsd.io.aux_readers depending on their level of support. In this case we will use the read_parsivel_nasa_gv function, and pass an argument telling it which campaign this is. This is to support some of the changing file formats during nasa's campaign.


In [3]:
dsd = pydsd.read_parsivel_nasa_gv(filename, campaign='ifloods')

So at this point we have the drop size distribution read in. NASA strips out rainfall information though and stores it in a separate file so we will want to handle that at some point. Let's calculate what some of the DSD parameters are. We will estimate parameters of a normalized gamma, an exponential, as well as a few supplemental parameters.


In [4]:
dsd.calculate_dsd_parameterization()

Each of these parameters is calculated and stored on the dsd object in a dictionary called fields. Each of the fields should have the data, units, and any other auxillary information about the parameter. Let's look at the current list of these.


In [5]:
dsd.fields.keys()


Out[5]:
dict_keys(['Nd', 'D0', 'Dmax', 'Dm', 'Nt', 'Nw', 'N0', 'W', 'mu', 'Lambda'])

And we can dig down further and see what is in one of these objects.


In [6]:
dsd.fields['D0']


Out[6]:
{'standard_name': 'median_drop_diameter',
 'units': 'mm',
 'long_name': 'Median Drop Diameter',
 'data': masked_array(data=[1.05044172, 1.00717798, 0.9271987 , 0.84906312,
                    0.76371447, 0.71844115, 0.65176375, 0.69932754,
                    0.61767797, 0.50243424, 0.53135984, 0.56358002,
                    1.05731982, 0.89245016, 0.90639239, 0.90106529,
                    0.77053378, 0.76441474, 0.75131511, 0.69598596,
                    0.66201703, 0.63045703, 0.62993463, 0.63209366,
                    0.56250375, 0.52237415, 0.5114849 , 0.51089024,
                    0.50978824, 0.53993716, 0.52529797, 0.46634357,
                    0.44258101, 0.43567515, 0.40266181, 0.38996854,
                    0.39366428, 0.40305257, 0.37962542, 0.94611453,
                    0.87649146, 0.87965814, 0.72063401, 0.77244156,
                    0.75407617, 0.69883763, 0.69045428, 0.66021129,
                    0.64339105, 0.63348575, 0.6518258 , 0.66446841,
                    2.32287038, 1.66878814, 1.39032643, 1.24606603,
                    1.08411004, 1.00181104, 0.97687945, 0.93448549,
                    0.96614004, 0.92090887, 0.87618963, 0.84389635,
                    0.78383755, 0.7481754 , 0.69726849, 0.70324963,
                    0.6798382 , 0.64356771, 0.63980532, 0.67353717,
                    0.82298626, 0.85354861, 0.81785908, 0.99223465,
                    0.65997231, 0.55713731, 0.50675474, 0.53849087,
                    0.48740579, 0.51989599, 0.41654232, 0.49127149,
                    0.4396763 , 1.07415817, 0.75597   , 1.39896945,
                    1.29822849, 1.14763089, 1.12766257, 1.03017591,
                    0.99585344, 0.98489189, 0.94941727, 1.26024443,
                    1.17957933, 1.01680232, 1.04110769, 0.97002394,
                    0.94952288, 0.81306069, 0.69552226, 0.79211863,
                    0.69849139, 0.67269851, 3.69583769, 2.90029468,
                    1.96698141, 1.46313322, 1.22227997, 1.24753621,
                    1.16750409, 1.040804  , 0.85617223, 0.72037176,
                    0.70020924, 0.61897744, 0.58302648, 0.63307861,
                    0.56278305, 0.59259994, 0.61592292, 1.06378674,
                    1.54456094, 1.63161689, 1.62988474, 1.36441917,
                    1.24204746, 1.16318243, 1.21080765, 1.24170763,
                    1.23395423, 1.18782813, 1.13436293, 1.06575304,
                    1.04412484, 1.03479619, 1.09752418, 1.04948108,
                    1.01425754, 0.89091852, 0.8678177 , 0.81173566,
                    0.77187398, 0.77986166, 0.92984595, 1.17382644,
                    1.21694224, 1.11142605, 1.02051878, 0.96176046,
                    0.89758399, 0.8261856 , 0.84166033, 0.79140058,
                    0.78217203, 0.74431469, 0.74091031, 0.69792868,
                    0.72351274, 0.75980088, 1.1411247 , 1.3745503 ,
                    1.25504842, 1.24032173, 1.15729937, 1.05053712,
                    1.11774237, 1.10588123, 1.12488518, 1.0467192 ,
                    0.97805175, 0.94462994, 0.9298944 , 0.89307106,
                    0.87536083, 0.89377951, 0.82209205, 0.76574703,
                    0.7473068 , 0.69884313, 0.69191176, 0.6510377 ,
                    0.75845493, 0.93963351, 0.94243227, 0.8741958 ,
                    0.82734049, 0.76797375, 0.75401814, 0.66987732,
                    0.64975761, 0.63541023, 0.60758209, 0.54625839,
                    0.53342061, 0.51613284, 0.50805181, 0.49480649,
                    0.47365615, 0.45159955, 0.4612965 , 0.41092744,
                    0.38113099, 0.39318087, 0.38595772, 0.38190054,
                    0.39307134, 0.39984345, 0.39830253, 0.3979665 ,
                    0.43413327, 0.42208434, 0.50155536, 0.59350304,
                    0.56635661, 0.57388954, 0.67891671, 0.85983351,
                    0.8044422 , 0.78580362, 0.68009607, 0.63306161,
                    0.68641677, 0.63282109, 0.63551489, 0.64953155,
                    0.70150802, 0.78492711, 0.7372706 , 0.69344196,
                    0.73202775, 0.73940504, 0.7221625 , 0.71027498,
                    0.69363691, 0.66774622, 0.64937166, 0.61787524,
                    0.58664664, 0.58077754, 0.53626145, 0.54217611,
                    0.50598308, 0.52843371, 0.53632013, 0.51174536,
                    0.49022029, 0.47331599, 0.49214435, 0.44401018,
                    0.42301677, 0.41906108, 0.37878025, 0.38460076,
                    0.40300132, 0.36457791, 0.38383898, 0.35858918,
                    0.34632951, 0.36426709, 0.34928799, 0.34341367,
                    0.3228993 , 0.3353703 , 0.39155532, 1.13916121,
                    1.12391936, 0.95628152, 0.84233593, 0.81061051,
                    0.81089103, 0.96607361, 0.98062824, 1.32813571,
                    1.60904655, 1.28454021, 1.23823522, 1.14197722,
                    1.13799568, 1.01971614, 1.29523412, 1.26628425,
                    1.31504821, 1.34854312, 1.28629647, 1.2569783 ,
                    1.2248008 , 1.16575155, 1.07585161, 1.10237209,
                    1.10049683, 1.19543134, 1.13998975, 1.12991909,
                    1.02365127, 0.91793123, 0.90869335, 0.93690371,
                    0.88506502, 0.83484547, 0.86741351, 0.76879995,
                    0.77304074, 0.71077043, 0.75372349, 0.77191498,
                    0.65766337, 0.84449256, 1.42560888, 1.66398074,
                    1.4213479 , 1.37976091, 1.22124399, 1.19641021,
                    1.10533041, 1.17776102, 1.09886664, 1.09076829,
                    1.00611323, 1.00240891, 0.98095857, 1.02620794,
                    1.14369676, 1.10314619, 1.23306228, 1.15198519,
                    1.06459189, 1.02165959, 0.94285401, 0.86806169,
                    0.83175771, 0.73936414, 0.75233783, 0.68791898,
                    0.62631861, 0.64095812, 0.65816319, 0.64193334,
                    0.58564939, 0.58579187, 0.55272663, 0.55667111,
                    0.61100298, 0.60461849, 0.65620845, 0.57389562,
                    0.61882254, 0.58029741, 0.56664481, 0.55015673,
                    0.50744054, 0.51348231, 0.48514554, 0.46866658,
                    0.47662334, 0.45557393, 0.39359653, 0.39743126,
                    0.381648  , 0.3812374 , 0.38838028, 0.38752747,
                    0.41293315, 0.39842607, 0.39070224, 0.3861754 ,
                    0.48668452, 0.38801639, 0.39134643, 0.38700625,
                    0.97910653, 0.84929993, 0.70922986, 0.63581046,
                    0.63296189, 0.60524085, 0.59500241, 0.92387897,
                    0.88577974, 0.83761633, 0.82039155, 0.79087112,
                    0.76175796, 1.08893283, 0.9959611 , 0.94246075,
                    0.79268324, 0.79779495, 0.78469039, 0.75270377,
                    0.65822373, 0.66831674, 0.58045574, 1.02966537,
                    1.09965335, 1.09005181, 1.00572564, 0.95763326,
                    0.90764624, 0.94960341, 0.99230031, 1.00485191,
                    0.98267559, 0.90462754, 0.87052377, 0.83324456,
                    0.82664992, 0.79715523, 0.75140673, 0.71396761,
                    0.72935106, 0.73296534, 0.70516013, 0.69831014,
                    0.71364418, 0.6949044 , 0.68546103, 0.66606177,
                    0.65978144, 0.61659018, 0.60723663, 0.60053935,
                    0.5900105 , 0.56330503, 0.55964299, 0.56177543,
                    0.56389518, 0.55584456, 0.5621954 , 0.55280741,
                    0.55726824, 0.55092088, 0.58084801, 0.54806463,
                    0.52066907, 0.61484053, 0.59206034, 0.59764936,
                    0.60393459, 0.64163737, 0.6319293 , 0.63328771,
                    0.60653538, 0.63972043, 0.64157188, 0.63917742,
                    0.70408746, 0.6604698 , 0.68603528, 0.71933394,
                    0.69058033, 0.70213459, 0.6074043 , 0.61434036,
                    0.58567904, 0.56054034, 0.55396899, 0.54213007,
                    0.53032512, 0.52994062, 0.50934287, 0.49220002,
                    0.54243207, 0.55368896, 0.60295167, 0.60334794,
                    0.61892865, 0.63846903, 0.69604635, 0.83923047,
                    0.80121671, 0.74557527, 0.75717294, 0.71789059,
                    0.67339284, 0.64502779, 0.64022234, 0.63803978,
                    0.6236321 , 0.57758433, 0.57214428, 0.5635252 ,
                    0.55369755, 0.5432076 , 0.53566601, 0.53391066,
                    0.67054446, 0.96214021, 0.93281655, 0.88179494,
                    0.84226257, 0.80393853, 0.78611379, 0.73976551,
                    0.73663649, 0.72034898, 0.66848756, 0.65267436,
                    0.62931766, 0.62122575, 0.61017983, 0.55965103,
                    0.59649755, 0.56117066, 0.57719306, 0.65859225,
                    0.96312278, 1.00366225, 0.97926728, 0.94533154,
                    0.93670658, 0.92679789, 0.85925885, 0.85098315,
                    0.78385695, 0.75680481, 0.7034326 , 0.66242149,
                    0.63033234, 0.6089381 , 0.60171918, 0.63844388,
                    0.63588097, 0.63805251, 0.64194903, 0.63838576,
                    0.64393667, 0.65445638, 0.6236718 , 0.74196544,
                    0.79060383, 0.85247729, 0.8445686 , 0.84827995,
                    0.83418431, 0.79715522, 0.80525176, 0.96973733,
                    0.939675  , 1.00415443, 1.03697383, 0.95185556,
                    0.89589014, 0.83785001, 0.9083975 , 0.88524474,
                    0.79017954, 0.75050795, 0.79510705, 0.92466862,
                    0.97791878, 1.01248909, 1.14799782, 0.99848793,
                    1.00566917, 0.92321712, 0.89927298, 0.89504178,
                    0.99225631, 1.03331678, 1.02631501, 1.18657904,
                    1.00594438, 0.93084266, 0.84570153, 0.90245427,
                    0.86575235, 0.84719467, 0.87693262, 0.84339246,
                    0.78000663, 0.78608437, 0.74207153, 0.72223646,
                    0.76531335, 0.71424429, 0.89084882, 0.94908379,
                    0.77933092, 0.77416019, 0.83822371, 1.41883428,
                    1.21323093, 0.87375537, 1.96801707, 3.39556554,
                    4.58049427, 2.18167886, 2.5630123 , 1.32346787,
                    1.39379648, 1.47096648, 1.99253678, 0.99647638,
                    5.06593062, 0.88301396, 1.80161367, 0.90818488,
                    1.09395689, 0.9133876 , 0.82182306, 6.84313368,
                    1.69845982, 9.18396579, 1.28210333, 1.52331936,
                    0.92363338, 8.99648223, 7.89978932, 7.90262446,
                    4.45017013, 0.77378838, 1.07416864, 0.99906056,
                    0.77143781, 0.82045994, 0.80556936, 0.92867575,
                    1.22436424, 1.35326969, 0.86015666, 0.78746364,
                    0.90311184, 1.15350095, 6.93277495, 0.74723583,
                    3.28555166, 0.85446791, 0.92737065, 0.82747333,
                    5.78481579, 2.08081046, 0.88062017, 1.21129738,
                    0.8861717 , 0.95363457, 0.91505216, 0.94017997,
                    0.863397  , 0.9296454 , 0.89650284, 0.87566229,
                    0.94213452, 0.85713248, 0.8122745 , 0.78370335,
                    3.8714997 , 0.6818757 , 0.74716446, 9.07365504,
                    0.67813012, 1.10885789, 3.45293421, 0.70076137,
                    0.70177101, 0.78783211, 8.96071175, 0.86942544,
                    5.39305802, 0.82536904, 1.57019253, 4.35368627,
                    0.9064627 , 1.95045473, 0.98714132, 0.75783608,
                    0.69512083, 1.11544099, 0.90257002, 2.80023051,
                    0.74238073, 2.06559018, 2.65956851, 1.82188637,
                    1.51211555, 2.11500003, 1.39976074, 1.61528954,
                    0.84829409, 0.93925043, 1.24491979, 1.40412114,
                    1.08259619, 0.95654293, 1.01849449, 0.87986146,
                    0.89556168, 0.88717703, 0.8477986 , 1.19077007,
                    0.82635453, 0.81868614, 0.86591447, 0.82455966,
                    0.80984443, 0.77678666, 0.80933204, 0.78392839,
                    0.81017106, 0.78405747, 0.77652609, 0.81518887,
                    0.87414313, 0.80567185, 0.77625648, 0.79932966,
                    0.81185713, 0.78286397, 0.77242243, 0.72448654,
                    0.72397163, 0.77273778, 0.72862881, 0.78197921,
                    0.81030107, 0.78169166, 0.68797288, 0.67490562,
                    0.73669864, 0.63380946, 0.74612888, 1.15949916,
                    0.73900188, 1.10864768, 0.77730492, 0.86043405,
                    0.82631106, 0.74094645, 0.86332949, 0.76929563,
                    0.79217542, 0.79677483, 0.84852634, 0.81393795,
                    0.75252927, 0.67165926, 0.85362385, 0.85720138,
                    0.77646189, 1.09558053, 0.85111179, 0.86533469,
                    0.83276827, 0.89650674, 0.85900964, 0.80925789,
                    0.81587486, 0.82984219, 0.82819792, 0.74191258,
                    0.91873534, 0.87687962, 0.77100687, 0.81189303,
                    0.78069866, 0.73026569, 0.84157558, 1.08055652,
                    0.67376698, 0.71746547, 0.73556729, 1.42797505,
                    5.86623862, 0.68293952, 0.70214224, 0.77406535,
                    1.2986458 , 0.67148923, 0.76647371, 0.91056209,
                    2.27997427, 1.29974582, 0.87881571, 1.13327458,
                    0.95886387, 0.93367291, 0.90694409, 0.88862389,
                    0.94834522, 0.97704249, 0.85443126, 1.17268017,
                    0.79779415, 0.95953721, 1.36151025, 1.10102179,
                    1.03489387, 0.93300278, 0.93692539, 0.82560884,
                    0.87533756, 0.8094319 , 0.82783787, 1.10773497,
                    0.91744697, 0.87732576, 0.84322999, 0.95372429,
                    0.86182945, 0.95757697, 0.93321569, 0.8356193 ,
                    0.82552964, 0.88781015, 1.30169515, 0.84683176,
                    0.84635221, 0.79719027, 0.84716937, 0.79831669,
                    0.94339982, 0.92957699, 1.15948008, 0.89615672,
                    0.8087551 , 0.86075603, 0.78240664, 0.81814611,
                    0.87644864, 0.80724565, 0.75561645, 0.77560659,
                    0.74514682, 0.70640029, 0.71662158, 0.67805873,
                    0.65601906, 0.65841126, 0.65500623, 0.67342609,
                    0.67493963, 0.6847325 , 0.72258507, 0.75166985,
                    0.71486266, 0.65512493, 0.65621374, 0.6835563 ,
                    0.61527934, 0.696936  , 0.68161446],
              mask=False,
        fill_value=1e+20)}

There are also several built in parameters for plotting in PyDSD that are listed in the documentation. These can be found in the pydsd.plot module. Let's use the plot_ts function to plot D0 and look at it.


In [7]:
pydsd.plot.plot_ts(dsd, 'D0', x_min_tick_format='hour')


Out[7]:
(<matplotlib.axes._subplots.AxesSubplot at 0x11d3eb7b8>,
 <matplotlib.axes._subplots.AxesSubplot at 0x11d3eb7b8>)

We can pass in our on figure our axis if we'd like.


In [8]:
fig = plt.figure(figsize=(8,8))
pydsd.plot.plot_ts(dsd, 'Nw', x_min_tick_format='hour')


Out[8]:
(<matplotlib.axes._subplots.AxesSubplot at 0x11d389cf8>,
 <matplotlib.axes._subplots.AxesSubplot at 0x11d389cf8>)

Similarly we can visualize the actual drop size distribution itself. It is stored in the Nd field. We also have a plotting function for this.


In [9]:
fig = plt.figure(figsize=(8,5))
pydsd.plot.plot_dsd(dsd, fig=fig)


Out[9]:
(<Figure size 576x360 with 2 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x11d364ac8>)

We can make side by side plots too.


In [10]:
fig = plt.figure(figsize=(12,6))
ax = plt.subplot(1,2,1)
pydsd.plot.plot_dsd(dsd, ax=ax)

ax = plt.subplot(1,2,2)
pydsd.plot.plot_NwD0(dsd,  ax=ax)
plt.tight_layout()


We can calculate radar parameters as well. Let's look at what these measurements would look like if we did T-Matrix scatttering at X-band, which is the default.


In [11]:
dsd.calculate_radar_parameters()

This assumes BC shape relationship, X band, 10C. You can pass in a new wavelength to change that. Let's plot some of the parameters, and then try to do something with the data.


In [ ]:


In [12]:
plt.figure(figsize=(12,12))

plt.subplot(2,2,1)
pydsd.plot.plot_ts(dsd, 'Zh', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('Reflectivity(dBZ)')
# plt.xlim(5,24)

plt.subplot(2,2,2)
pydsd.plot.plot_ts(dsd, 'Zdr', x_min_tick_format='hour')

plt.xlabel('Time(minutes)')
plt.ylabel('Differential Reflectivity(dB)')
# plt.xlim(5,24)

plt.subplot(2,2,3)
pydsd.plot.plot_ts(dsd, 'Kdp', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('Specific Differential Phase(deg/km)')
# plt.xlim(5,24)

plt.subplot(2,2,4)
pydsd.plot.plot_ts(dsd, 'Ai', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('Specific Attenuation')
# plt.xlim(5,24)

plt.tight_layout()

plt.show()


Next let's estimate some microphysical parameterizations.


In [13]:
dsd.calculate_dsd_parameterization()

In [14]:
plt.figure(figsize=(12,12))

plt.subplot(2,2,1)
pydsd.plot.plot_ts(dsd, 'D0', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('$D_0$')
# plt.xlim(5,24)

plt.subplot(2,2,2)
pydsd.plot.plot_ts(dsd, 'Nw', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('$log_{10}(N_w)$')
# plt.xlim(5,24)

plt.subplot(2,2,3)
pydsd.plot.plot_ts(dsd, 'Dmax', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('Maximum Drop Size')
# plt.xlim(5,24)

plt.subplot(2,2,4)
pydsd.plot.plot_ts(dsd, 'mu', x_min_tick_format='hour')

plt.xlabel('Time(hrs)')
plt.ylabel('$\mu$')

plt.tight_layout()

plt.show()