Introduction

The sizedistribution module contains various classes associated with sizedistributions:

  • SizeDist - a one dimentional size distribution
  • SizeDist_TS - size distribution time series
  • SizeDist_LS - size distribution layer series
  • OpticalProperties - optical properties derived from one of the sizedistribution classes above

All sizedistribution classes are relatives of each other with SizeDist beeing the parent. In other words SizeDist_TS and SizeDist_LS can do exactly the same things like SizeDist and a bit more.

In addition to the classes sizedistribution also contains a few usefull functions:

  • simulate_sizedistribution, simulate_sizedistribution_timeseries, and simulate_sizedistribution_layerseries - the name speaks for themself.

Imports


In [48]:
from atmPy import sizedistribution as sd
# from atmPy.instruments.POPS import housekeeping
from atmPy.instruments.piccolo import piccolo
from atmPy.tools import plt_tools
%matplotlib inline
plt_tools.setRcParams(plt)

SizeDist

Due to the similarity to SizeDist_TS and SizeDist_LS I will skip this class. It will show up every now and then below.

SizeDist_TS

Load a size distribution

Usually a SizeDistribution is generated by reading experimental data using a module designed for the particular instrument (pick one from in atmPy.instruments). The following is a size distribution recorded using a POPS instrument.


In [49]:
dist_TS = sd.read_csv('./data/POPS_dist_TS.csv')

In [112]:
dist_TS.


Out[112]:
150-154 154-158 158-163 163-168 168-172 172-177 177-183 183-188 188-193 193-199 ... 1881-1935 1935-1991 1991-2049 2049-2108 2108-2168 2168-2231 2231-2295 2295-2361 2361-2429 2429-2499
2015-04-21 08:20:54.541016 327.317097 409.146372 600.081345 600.081345 545.528496 381.869947 545.528496 681.910620 436.422797 818.292744 ... 0 27.276425 0.000000 0 0 0 0 0 0 0
2015-04-21 08:20:55.541016 297.110776 324.120846 567.211481 459.171199 459.171199 459.171199 540.201410 972.362538 486.181269 648.241692 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:20:56.544922 403.574695 349.764735 322.859756 403.574695 672.624491 538.099593 726.434451 726.434451 645.719512 726.434451 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:20:57.541016 325.391826 406.739783 379.623798 433.855769 433.855769 460.971754 406.739783 623.667667 460.971754 650.783653 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:20:58.541016 324.120846 297.110776 648.241692 567.211481 486.181269 486.181269 459.171199 648.241692 567.211481 351.130917 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:20:59.544922 403.574695 430.479674 376.669715 591.909552 538.099593 565.004573 699.529471 295.954776 645.719512 591.909552 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:00.541016 569.435696 460.971754 406.739783 352.507812 732.131610 515.203725 894.827523 732.131610 759.247595 840.595552 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:01.544922 349.764735 538.099593 376.669715 269.049796 565.004573 591.909552 457.384654 457.384654 914.769308 780.244410 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:02.544922 405.151058 324.120846 324.120846 486.181269 702.261833 432.161128 702.261833 648.241692 513.191340 702.261833 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:03.544922 324.120846 459.171199 513.191340 540.201410 486.181269 567.211481 567.211481 675.251763 513.191340 513.191340 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:04.544922 189.070494 486.181269 243.090635 432.161128 432.161128 270.100705 756.281974 837.312186 567.211481 783.292045 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:05.546875 242.616804 458.276185 458.276185 646.978144 539.148453 485.233608 646.978144 377.403917 700.892989 620.020721 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:06.546875 297.110776 432.161128 621.231622 432.161128 621.231622 567.211481 567.211481 621.231622 459.171199 864.322256 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:07.541016 407.538827 353.200317 380.369572 407.538827 815.077655 597.723614 434.708083 407.538827 679.231379 624.892869 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:08.546875 295.380143 456.496585 510.202066 537.054806 349.085624 429.643845 510.202066 644.465767 483.349325 456.496585 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:09.544922 270.629244 351.818017 378.880941 405.943866 460.069715 460.069715 649.510185 730.698959 622.447261 676.573110 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:10.544922 432.161128 432.161128 459.171199 351.130917 243.090635 378.140987 621.231622 432.161128 432.161128 945.352468 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:11.542969 433.006790 324.755093 351.818017 514.195563 514.195563 433.006790 514.195563 866.013581 405.943866 595.384337 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:12.539062 325.392153 433.856204 379.624179 488.088230 515.204242 271.160128 569.436268 650.784306 460.972217 542.320255 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:13.544922 483.348845 456.496131 402.790704 483.348845 805.581408 563.906986 429.643418 483.348845 671.317840 805.581408 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:14.544922 270.100705 405.151058 432.161128 594.221551 540.201410 648.241692 540.201410 513.191340 567.211481 621.231622 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:15.544922 351.130917 432.161128 702.261833 378.140987 567.211481 513.191340 675.251763 567.211481 621.231622 864.322256 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:16.541016 325.391826 433.855769 433.855769 433.855769 298.275841 379.623798 352.507812 786.363581 650.783653 298.275841 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:17.546875 456.496585 349.085624 671.318507 510.202066 563.907546 563.907546 725.023988 510.202066 429.643845 483.349325 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:18.542969 216.927884 406.739783 352.507812 488.087740 460.971754 596.551682 406.739783 732.131610 515.203725 542.319711 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:19.544922 431.318762 458.276185 458.276185 377.403917 458.276185 566.105876 485.233608 431.318762 593.063298 566.105876 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:20.544922 459.171199 351.130917 540.201410 459.171199 675.251763 648.241692 216.080564 891.332327 837.312186 783.292045 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:21.541016 325.391826 488.087740 325.391826 569.435696 705.015624 460.971754 542.319711 542.319711 623.667667 623.667667 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:22.548828 294.807737 455.611958 455.611958 428.811254 589.615475 428.811254 509.213365 509.213365 482.412661 830.821806 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 08:21:23.541016 245.004611 462.786487 653.345628 353.895549 408.341018 462.786487 653.345628 626.122894 680.568363 517.231956 ... 0 0.000000 54.445469 0 0 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2015-04-21 09:57:51.531250 216.080564 432.161128 189.070494 243.090635 108.040282 351.130917 54.020141 243.090635 162.060423 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:52.531250 189.070494 297.110776 432.161128 81.030212 216.080564 351.130917 216.080564 270.100705 162.060423 243.090635 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:53.531250 216.080564 351.130917 54.020141 351.130917 216.080564 162.060423 108.040282 243.090635 135.050353 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:54.531250 216.080564 270.100705 270.100705 351.130917 216.080564 189.070494 162.060423 81.030212 135.050353 189.070494 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:55.531250 405.151058 405.151058 216.080564 324.120846 162.060423 270.100705 135.050353 216.080564 81.030212 54.020141 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:56.531250 432.161128 378.140987 243.090635 324.120846 216.080564 189.070494 54.020141 189.070494 135.050353 135.050353 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:57.531250 432.161128 243.090635 216.080564 270.100705 216.080564 243.090635 108.040282 162.060423 189.070494 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:58.531250 297.110776 270.100705 54.020141 297.110776 108.040282 243.090635 189.070494 216.080564 108.040282 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:57:59.531250 459.171199 459.171199 189.070494 189.070494 324.120846 162.060423 189.070494 162.060423 108.040282 216.080564 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:00.531250 216.080564 351.130917 270.100705 297.110776 216.080564 108.040282 162.060423 270.100705 189.070494 108.040282 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:01.531250 216.080564 405.151058 351.130917 270.100705 162.060423 162.060423 243.090635 135.050353 216.080564 243.090635 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:02.531250 270.100705 270.100705 243.090635 216.080564 189.070494 162.060423 162.060423 54.020141 81.030212 81.030212 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:03.531250 270.100705 216.080564 270.100705 162.060423 243.090635 108.040282 189.070494 243.090635 189.070494 81.030212 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:04.531250 297.110776 189.070494 243.090635 270.100705 108.040282 189.070494 189.070494 216.080564 324.120846 189.070494 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:05.531250 162.060423 162.060423 162.060423 243.090635 243.090635 189.070494 162.060423 216.080564 81.030212 108.040282 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:06.531250 351.130917 216.080564 297.110776 216.080564 270.100705 189.070494 216.080564 162.060423 27.010071 135.050353 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:07.531250 324.120846 216.080564 297.110776 162.060423 135.050353 243.090635 108.040282 270.100705 135.050353 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:08.531250 243.090635 297.110776 297.110776 270.100705 216.080564 270.100705 270.100705 162.060423 162.060423 135.050353 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:09.531250 189.070494 270.100705 297.110776 270.100705 270.100705 108.040282 351.130917 189.070494 216.080564 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:10.531250 243.090635 405.151058 270.100705 270.100705 162.060423 189.070494 243.090635 81.030212 189.070494 135.050353 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:11.531250 270.100705 270.100705 243.090635 189.070494 405.151058 243.090635 135.050353 216.080564 216.080564 81.030212 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:12.531250 324.120846 351.130917 405.151058 216.080564 162.060423 216.080564 270.100705 162.060423 189.070494 27.010071 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:13.531250 270.100705 216.080564 243.090635 135.050353 270.100705 351.130917 135.050353 189.070494 162.060423 189.070494 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:14.531250 243.090635 216.080564 189.070494 351.130917 216.080564 162.060423 189.070494 216.080564 216.080564 216.080564 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:15.531250 297.110776 297.110776 162.060423 216.080564 216.080564 135.050353 189.070494 108.040282 162.060423 324.120846 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:16.531250 162.060423 270.100705 351.130917 189.070494 216.080564 351.130917 189.070494 162.060423 135.050353 297.110776 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:17.531250 270.100705 189.070494 351.130917 324.120846 189.070494 54.020141 135.050353 108.040282 108.040282 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:18.531250 162.060423 432.161128 189.070494 297.110776 324.120846 108.040282 270.100705 216.080564 189.070494 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:19.531250 216.080564 297.110776 324.120846 162.060423 135.050353 243.090635 243.090635 135.050353 189.070494 189.070494 ... 0 0.000000 0.000000 0 0 0 0 0 0 0
2015-04-21 09:58:20.531250 216.080564 270.100705 216.080564 270.100705 297.110776 162.060423 27.010071 135.050353 216.080564 162.060423 ... 0 0.000000 0.000000 0 0 0 0 0 0 0

5847 rows × 99 columns

Moment conversion

Current moment:


In [50]:
dist_TS.distributionType


Out[50]:
'dNdDp'

In [51]:
dist_TS = dist_TS.convert2dNdlogDp()

Now its different:


In [52]:
dist_TS.distributionType


Out[52]:
'dNdlogDp'

There are plenty more, just play with the auto-completion.

Fitting normal distribution to sizedistribution

This can take some time.


In [53]:
out = dist_TS.fit_normal()

See effect below in the plots

Plottin stuff

All plotting functions will return matplotlib figures and axes, so further manipulation is possible. The also have a lot of optional arguments that are worth exploring.


In [54]:
out = dist_TS.plot()



In [55]:
out = dist_TS.plot_particle_concentration()



In [56]:
out = dist_TS.plot_fitres()


Change time or diameter inteveral


In [57]:
dist_TS.get_timespan()


Out[57]:
(Timestamp('2015-04-21 07:52:58.542969'),
 Timestamp('2015-04-21 10:22:10.546875'))

In [58]:
dt = dist_TS.zoom_time(start = '2015-04-21 08:00:00.00', end = '2015-04-21 08:10:00.00')
dt = dt.zoom_diameter(start = 150, end = 600)
out = dt.plot(fit_pos=False)


Averaging over time


In [59]:
dt = dist_TS.average_overTime(window = '60S')
out = dt.plot(fit_pos=False)


The following will return a SizeDist instance since it is no longer a time series


In [60]:
avg = dist_TS.average_overAllTime()
out = avg.plot()


/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)

SizeDist_LS

generating a SizeDist_LS instance

Before we can generate a layerseries we need a time series that contains information about Altitude. Furthermore we want to truncate the data to the timeperiode during which a vertical profile was taken.


In [75]:
from atmPy.instruments.Manta_payload import manta_payload

In [80]:
hk = piccolo.read_csv('./data/piccolo.log')
hk_II = manta_payload.read_csv('./data/Manta_raw.dat')
hk = hk.merge(hk_II)
spiral_up_start = '2015-04-21 08:20:54'
spiral_up_end = '2015-04-21 09:58:21'
dist_TS = dist_TS.zoom_time(spiral_up_start,spiral_up_end)
hk = hk.zoom_time(spiral_up_start,spiral_up_end)

The following will generate the SizeDist_LS instance with a layer thickness of 30 meters. (force is necessary since the Altitude time series is not monotonic)


In [81]:
dist_LS = dist_TS.convert2layerseries(hk, layer_thickness= 30, force = True)


/Users/htelg/prog/atm-py/atmPy/sizedistribution.py:1042: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
  hk.data = hk.data.sort(columns='Altitude')
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)

Plotting stuff (LS)


In [82]:
out = dist_LS.fit_normal()
out = dist_LS.plot()


hygroscopic growth

Hygroscopic growth can either be applied with one RH value or by using the 'Relative_humidity' column in the associated housekeeping file. We made sure that this column exist by merging the file from the manta aircraft earlier. Since the index of refraction is adjusted during the growth it is nesecarry to define that value before proceeding.


In [88]:
dist_LS.index_of_refraction = 1.455 # refractive index of the calibration material DOS
dist_LS_grown = dist_LS.apply_hygro_growth(0.5)
out = dist_LS_grown.plot(fit_pos=False)


Optical properties

generating OpticalProperties instance

To calculate optical properties it is again necessary to specify the refractive index, which we already did earlier.


In [99]:
wavelength = 550
opt_prop = dist_LS.calculate_optical_properties(wavelength)

In [100]:
out = opt_prop.plot_extCoeffPerLayer()


Out[100]:
(<matplotlib.figure.Figure at 0x110a482e8>,
 <matplotlib.axes._subplots.AxesSubplot at 0x10f4f4eb8>,
 <matplotlib.collections.QuadMesh at 0x1107df828>,
 <matplotlib.colorbar.Colorbar at 0x111054b38>)

In [110]:
ext = opt_prop.get_extinction_coeff_verticle_profile()
ax = ext.plot()
ax.set_title('Extinction coefficient')


Out[110]:
<matplotlib.text.Text at 0x1100f9710>

In [111]:
ax = opt_prop.plot_AOD_cum()
ax.set_title('Cumulative AOD')


Out[111]:
<matplotlib.text.Text at 0x1106a34a8>

In [109]:
ax = opt_prop.asymmetry_parameter_LS.plot()
ax.set_xlabel('Altitude (m)')
ax.set_ylabel('Asymmetry parameter')
ax.set_title('Asymmetry parameter')


Out[109]:
<matplotlib.text.Text at 0x10e6c6438>

In [ ]: