Run the test


In [1]:
import atmPy
from atmPy.unit_testing import run_nose_tests
from atmPy.unit_testing import nose_tests
plt.style.use('hagen_default')

In [2]:
reload(run_nose_tests)
reload(nose_tests)


Out[2]:
<module 'atmPy.unit_testing.nose_tests' from '/Users/htelg/prog/atm-py/atmPy/unit_testing/nose_tests.py'>

all


In [2]:
run_nose_tests.run()


/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xarray/core/formatting.py:16: FutureWarning: The pandas.tslib module is deprecated and will be removed in a future version.
  from pandas.tslib import OutOfBoundsDatetime
./Users/htelg/prog/atm-py/atmPy/aerosols/instruments/AMS/AMS.py:63: UserWarning: Sulfate rich is not implemented yet. Mostly because I don't get it!
         There are not supposed to be any Nitrates or Chlorides present when we are in the sulfate rich regime ... but there are.
         I guess it has to do with the organics? Talk to chuck
  _warnings.warn(txt)
/Users/htelg/prog/atm-py/atmPy/file_io.py:96: RuntimeWarning: invalid value encountered in greater
  ts_data = _pd.DataFrame(var_data[:], index=index)
/Users/htelg/prog/atm-py/atmPy/file_io.py:100: RuntimeWarning: invalid value encountered in greater
  ts_data = _pd.DataFrame(var_data[:], index=index,
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/fromnumeric.py:2957: RuntimeWarning: Mean of empty slice.
  out=out, **kwargs)
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/_methods.py:80: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
/Users/htelg/prog/atm-py/atmPy/aerosols/physics/optical_properties.py:112: RuntimeWarning: invalid value encountered in true_divide
  y_phase_func = y_1p * 4 * _np.pi / scattering_cross_eff.sum()
........
----------------------------------------------------------------------
Ran 9 tests in 358.089s

OK

In [ ]:

onebyone


In [5]:
reload(nose_tests)


Out[5]:
<module 'atmPy.unit_testing.nose_tests' from '/Users/htelg/prog/atm-py/atmPy/unit_testing/nose_tests.py'>

In [1]:
from atmPy.unit_testing import run_nose_tests
from atmPy.unit_testing import nose_tests

In [3]:
test = nose_tests.SizeDistTest()
test.test_mixing_ratios()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-e02ce5f455b0> in <module>()
      1 test = nose_tests.SizeDistTest()
----> 2 test.test_mixing_ratios()

/Users/htelg/prog/atm-py/atmPy/unit_testing/nose_tests.py in test_mixing_ratios(self)
     74                                                                                      startDate='2015-10-23 16:00:00',
     75                                                                                      endDate='2015-10-23 17:00:00',
---> 76                                                                                      frequency=60)
     77 
     78         sd.data = sd.data.iloc[[0], :]

/Users/htelg/prog/atm-py/atmPy/aerosols/size_distribution/sizedistribution.py in simulate_sizedistribution_timeseries(diameter, numberOfDiameters, centerOfAerosolMode, widthOfAerosolMode, numberOfParticsInMode, startDate, endDate, frequency)
   2747 
   2748     oszi = _np.linspace(0, noOfOsz * 2 * _np.pi, periods)
-> 2749     sdArray = _np.zeros((periods, numberOfDiameters - 1))
   2750     for e, i in enumerate(rng):
   2751         sdtmp = simulate_sizedistribution(diameter=diameter,

TypeError: 'float' object cannot be interpreted as an integer

data_archives

ARM


In [1]:
from atmPy.data_archives import arm

In [2]:
arm.arm_products.keys()


Out[2]:
dict_keys(['tdmasize', 'aipfitrh1ogrenC1', 'noaaaos', 'aosacsm', '1twr10xC1', 'tdmahyg', 'tdmaapssize'])

In [15]:
fname = './test_data/'

1twr10xC1


In [2]:
# %%debug -b /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_1twr10xC1.py:44
# %%debug -b /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_read_data.py:193

# %%debug -b /Users/htelg/prog/atm-py/atmPy/general/timeseries.py:327
# # create the test file
fname = './test_data/'
out = atmPy.data_archives.arm.read_netCDF(fname, data_product='1twr10xC1')
out = out['1twr10xC1']
# out.relative_humidity.data.to_csv(fname+'1twr10xC1_rh.csv')
# out.temperature.data.to_csv(fname+'1twr10xC1_temp.csv')
# out.vapor_pressure.data.to_csv(fname + '1twr10xC1_p_vapor.csv')

In [4]:
from copy import deepcopy

In [2]:
%%debug -b /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_read_data.py:178
fname = './test_data/sgp1twr10xC1.b1.20120201.000000.cdf'
out = atmPy.data_archives.arm.read_netCDF(fname, data_product='1twr10xC1')


Breakpoint 1 at /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_read_data.py:178
NOTE: Enter 'c' at the ipdb>  prompt to continue execution.
> /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_read_data.py(118)read_cdf()
    116 
    117     # list or single file
--> 118     if type(fname) == str:
    119         if fname[-1] == '/':
    120             f = _os.listdir(fname)

ipdb> c
> /Users/htelg/prog/atm-py/atmPy/data_archives/arm/_read_data.py(178)read_cdf()
    176         # pdb.set_trace()
    177 
1-> 178         no_valid += 1
    179         if arm_file_object._parsing_error:
    180             continue

ipdb> dir(arm_file_object)
['_ArmDataset__time_stamps', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_close', '_concat', '_data_period', '_data_quality_control', '_error_bad_file', '_get_variable_info', '_parse_netCDF', '_parsing_error', '_read_variable', '_read_variable2timeseries', '_time_offset', 'data_quality', 'data_quality_flag_max', 'netCDF', 'plot_all', 'relative_humidity', 'temperature', 'time_stamps', 'vapor_pressure']
ipdb> delattr(arm_file_object, 'netCDF')
ipdb> c

In [ ]:


In [30]:
bla = deepcopy(out.relative_humidity.data)

In [36]:
bla = atmPy.general.timeseries.TimeSeries(out.relative_humidity.data)

In [40]:
out.relative_humidity._data_period


Out[40]:
60.0

In [42]:
delattr(out, 'netCDF')

In [5]:
deepcopy(out.relative_humidity)


Out[5]:
Relative Humidity (%)     rh_25m     rh_60m
Time                                       
2012-01-31 23:59:00    32.917000  31.136999
2012-02-01 00:00:00    33.081001  31.191000
2012-02-01 00:01:00    33.257999  31.441000
2012-02-01 00:02:00    33.442001  31.041000
2012-02-01 00:03:00    33.630001  30.471001
2012-02-01 00:04:00    33.682999  30.465000
2012-02-01 00:05:00    33.852001  30.382999
2012-02-01 00:06:00    33.974998  30.028000
2012-02-01 00:07:00    33.938999  30.389000
2012-02-01 00:08:00    34.129002  30.398001
2012-02-01 00:09:00    34.148998  30.436001
2012-02-01 00:10:00    34.270000  29.899000
2012-02-01 00:11:00    34.377998  29.811001
2012-02-01 00:12:00    34.401001  29.850000
2012-02-01 00:13:00    34.223000  30.138000
2012-02-01 00:14:00    34.096001  30.354000
2012-02-01 00:15:00    34.103001  30.493999
2012-02-01 00:16:00    34.098000  30.521999
2012-02-01 00:17:00    33.966000  30.483000
2012-02-01 00:18:00    34.074001  30.455999
2012-02-01 00:19:00    34.247002  30.451000
2012-02-01 00:20:00    34.401001  30.455000
2012-02-01 00:21:00    34.539001  30.375000
2012-02-01 00:22:00    34.687000  30.351999
2012-02-01 00:23:00    34.919998  30.422001
2012-02-01 00:24:00    35.192001  30.452999
2012-02-01 00:25:00    35.132000  30.445999
2012-02-01 00:26:00    35.168999  30.427000
2012-02-01 00:27:00    35.327000  30.469999
2012-02-01 00:28:00    35.400002  30.480000
...                          ...        ...
2012-02-01 23:29:00    32.146000  32.268002
2012-02-01 23:30:00    32.279999  32.382999
2012-02-01 23:31:00    32.319000  32.282001
2012-02-01 23:32:00    32.317001  32.306999
2012-02-01 23:33:00    32.396000  32.431000
2012-02-01 23:34:00    32.507000  32.347000
2012-02-01 23:35:00    32.536999  32.298000
2012-02-01 23:36:00    32.493000  32.249001
2012-02-01 23:37:00    32.641998  32.320999
2012-02-01 23:38:00    32.622002  32.412998
2012-02-01 23:39:00    32.581001  32.387001
2012-02-01 23:40:00    32.365002  32.273998
2012-02-01 23:41:00    32.157001  32.081001
2012-02-01 23:42:00    31.979000  32.094002
2012-02-01 23:43:00    32.111000  32.014999
2012-02-01 23:44:00    32.050999  32.042999
2012-02-01 23:45:00    32.143002  32.389000
2012-02-01 23:46:00    32.423000  32.622002
2012-02-01 23:47:00    32.768002  32.898998
2012-02-01 23:48:00    32.990002  33.001999
2012-02-01 23:49:00    33.252998  32.872002
2012-02-01 23:50:00    33.612000  32.901001
2012-02-01 23:51:00    34.245998  32.875999
2012-02-01 23:52:00    34.353001  32.832001
2012-02-01 23:53:00    33.876999  32.984001
2012-02-01 23:54:00    33.452000  33.057999
2012-02-01 23:55:00    33.453999  33.250999
2012-02-01 23:56:00    33.341000  33.234001
2012-02-01 23:57:00    33.368000  33.227001
2012-02-01 23:58:00    33.469002  33.230999

[1440 rows x 2 columns]

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [27]:
out.relative_humidity.copy()


---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-27-87b00a2f1138> in <module>()
----> 1 out.relative_humidity.copy()

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    180                             raise Error(
    181                                 "un(deep)copyable object of type %s" % cls)
--> 182                 y = _reconstruct(x, rv, 1, memo)
    183 
    184     # If is its own copy, don't memoize.

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
    295     if state is not None:
    296         if deep:
--> 297             state = deepcopy(state, memo)
    298         if hasattr(y, '__setstate__'):
    299             y.__setstate__(state)

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    153     copier = _deepcopy_dispatch.get(cls)
    154     if copier:
--> 155         y = copier(x, memo)
    156     else:
    157         try:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
    241     memo[id(x)] = y
    242     for key, value in x.items():
--> 243         y[deepcopy(key, memo)] = deepcopy(value, memo)
    244     return y
    245 d[dict] = _deepcopy_dict

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    180                             raise Error(
    181                                 "un(deep)copyable object of type %s" % cls)
--> 182                 y = _reconstruct(x, rv, 1, memo)
    183 
    184     # If is its own copy, don't memoize.

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
    295     if state is not None:
    296         if deep:
--> 297             state = deepcopy(state, memo)
    298         if hasattr(y, '__setstate__'):
    299             y.__setstate__(state)

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    153     copier = _deepcopy_dispatch.get(cls)
    154     if copier:
--> 155         y = copier(x, memo)
    156     else:
    157         try:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
    241     memo[id(x)] = y
    242     for key, value in x.items():
--> 243         y[deepcopy(key, memo)] = deepcopy(value, memo)
    244     return y
    245 d[dict] = _deepcopy_dict

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    180                             raise Error(
    181                                 "un(deep)copyable object of type %s" % cls)
--> 182                 y = _reconstruct(x, rv, 1, memo)
    183 
    184     # If is its own copy, don't memoize.

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
    295     if state is not None:
    296         if deep:
--> 297             state = deepcopy(state, memo)
    298         if hasattr(y, '__setstate__'):
    299             y.__setstate__(state)

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    153     copier = _deepcopy_dispatch.get(cls)
    154     if copier:
--> 155         y = copier(x, memo)
    156     else:
    157         try:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
    241     memo[id(x)] = y
    242     for key, value in x.items():
--> 243         y[deepcopy(key, memo)] = deepcopy(value, memo)
    244     return y
    245 d[dict] = _deepcopy_dict

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    172                     reductor = getattr(x, "__reduce_ex__", None)
    173                     if reductor:
--> 174                         rv = reductor(4)
    175                     else:
    176                         reductor = getattr(x, "__reduce__", None)

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__reduce__()

NotImplementedError: Dataset is not picklable

In [73]:
reload(nose_tests)


Out[73]:
<module 'nose_tests' from '/Users/htelg/prog/atm-py/unit_testing/nose_tests.py'>

In [63]:
nose_tests.test_1twr10xC1()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-63-3884ff5b1795> in <module>()
----> 1 nose_tests.test_1twr10xC1()

AttributeError: module 'atmPy.unit_testing.nose_tests' has no attribute 'test_1twr10xC1'

In [9]:
test_data_folder = './test_data/'

In [10]:
from atmPy.data_archives import arm

In [11]:
out = arm.read_netCDF(test_data_folder, data_product='1twr10xC1')
out = out['1twr10xC1']

In [13]:
# rh
soll = pd.read_csv(test_data_folder + '1twr10xC1_rh.csv', index_col=0,
                   dtype={'rh_25m': np.float32, 'rh_60m': np.float32}
                   )
# self.assertTrue(np.all(out.relative_humidity.data == soll))
# np.all(out.relative_humidity.data.index == soll.index)

In [19]:
out.relative_humidity.data.index == pd.to_datetime(soll.index)


Out[19]:
array([ True,  True,  True, ...,  True,  True,  True], dtype=bool)

In [16]:
out.relative_humidity.data.index


Out[16]:
DatetimeIndex(['2012-01-31 23:59:00', '2012-02-01 00:00:00',
               '2012-02-01 00:01:00', '2012-02-01 00:02:00',
               '2012-02-01 00:03:00', '2012-02-01 00:04:00',
               '2012-02-01 00:05:00', '2012-02-01 00:06:00',
               '2012-02-01 00:07:00', '2012-02-01 00:08:00',
               ...
               '2012-02-03 23:49:00', '2012-02-03 23:50:00',
               '2012-02-03 23:51:00', '2012-02-03 23:52:00',
               '2012-02-03 23:53:00', '2012-02-03 23:54:00',
               '2012-02-03 23:55:00', '2012-02-03 23:56:00',
               '2012-02-03 23:57:00', '2012-02-03 23:58:00'],
              dtype='datetime64[ns]', name='Time', length=4320, freq=None)

In [72]:
soll.columns.name = out.relative_humidity.data.columns.name

In [ ]:
# temp
soll = pd.read_csv(test_data_folder + '1twr10xC1_temp.csv', index_col=0,
                   dtype={'temp_25m': np.float32, 'temp_60m': np.float32}
                   )
self.assertTrue(np.all(out.temperature.data == soll))

# vapor pressure
soll = pd.read_csv(test_data_folder + '1twr10xC1_p_vapor.csv', index_col=0,
                   dtype={'vap_pres_25m': np.float32, 'vap_pres_60m': np.float32}
                   )

self.assertTrue(np.all(out.vapor_pressure.data == soll))

Aerosols

sizedistribution

concentrations


In [28]:
from atmPy.aerosols import size_distribution
%matplotlib inline

In [87]:
sd = size_distribution.sizedistribution.simulate_sizedistribution(diameter=[15, 3000], 
                                                             numberOfDiameters=50, 
                                                             centerOfAerosolMode=222, 
                                                             widthOfAerosolMode=0.18, 
                                                             numberOfParticsInMode=888)

sd.particle_number_concentration == 888.0

float(sd.particle_surface_concentration.values) == 194.42186363605904

float(sd.particle_volume_concentration.values) == 11.068545094055812

sd.properties.particle_density =2.2

float(sd.particle_mass_concentration) == 24.350799206922783

including mixing rations


In [1]:
from atmPy.aerosols import size_distribution
%matplotlib inline

In [5]:
sd = size_distribution.sizedistribution.simulate_sizedistribution_timeseries(diameter=[15, 3000], 
                                                                             numberOfDiameters=50, 
                                                                             centerOfAerosolMode=222, 
                                                                             widthOfAerosolMode=0.18, 
                                                                             numberOfParticsInMode=888, 
                                                                             startDate='2015-10-23 16:00:00', 
                                                                             endDate='2015-10-23 17:00:00', 
                                                                             frequency=60)

sd.data = sd.data.iloc[[0],:]
sd.housekeeping = atmPy.general.timeseries.TimeSeries(pd.DataFrame(np.array([[250.], [750.]]).transpose(), index = sd.data.index, columns=['temperature_K', 'pressure_Pa']))
sd.parameters4reductions.particle_density =2.8
float(sd.particle_mass_mixing_ratio.data.values) * 1e6 == 2.96533739732464


> /Users/htelg/prog/atm-py/atmPy/aerosols/size_distribution/sizedistribution.py(2751)simulate_sizedistribution_timeseries()
-> sdArray = _np.zeros((periods, numberOfDiameters - 1))
(Pdb) c
Out[5]:
True

muell


In [1]:
from atmPy.aerosols import size_distribution
%matplotlib inline

In [2]:
sd = size_distribution.sizedistribution.simulate_sizedistribution_timeseries(diameter=[15, 3000], 
                                                                             numberOfDiameters=50, 
                                                                             centerOfAerosolMode=222, 
                                                                             widthOfAerosolMode=0.18, 
                                                                             numberOfParticsInMode=888, 
                                                                             startDate='2015-10-23 16:00:00', 
                                                                             endDate='2015-10-23 17:00:00', 
                                                                             frequency=60)

In [3]:
sd.hygroscopicity.parameters._check_growth_parameters_exist()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-dfa498556169> in <module>()
----> 1 sd.hygroscopicity.parameters._check_growth_parameters_exist()

/Users/htelg/prog/atm-py/atmPy/aerosols/size_distribution/sizedistribution.py in _check_growth_parameters_exist(self, raise_error)
    421 
    422     def _check_growth_parameters_exist(self, raise_error = True):
--> 423         return self._check_parameter_exists(parameters= [['kappa','growth_distribution']], raise_error = raise_error)
    424 
    425     def _check_mixing_ratio_param_exist(self, raise_error = True):

/Users/htelg/prog/atm-py/atmPy/aerosols/size_distribution/sizedistribution.py in _check_parameter_exists(self, parameters, raise_error)
    394                     else:
    395                         txt = 'Parameter {} is not set ... do so!'.format(param[0])
--> 396                     raise ValueError(txt)
    397                 else:
    398                     passed = False

ValueError: One of the Parameters kappa or growth_distribution needs to be set ... do so!

In [4]:
sd.hygroscopicity.parameters.kappa = 1.5
sd.hygroscopicity.parameters._check_growth_parameters_exist()


Out[4]:
True

In [6]:
sd.hygroscopicity.parameters.growth_distribution = 5
sd.hygroscopicity.parameters


Out[6]:
RH                  :  None
growth_distribution :  5
kappa               :  None
particle_density    :  1.8
refractive_index    :  None

In [4]:
sd.optical_properties.parameters.wavelength = 550
sd.optical_properties.parameters.refractive_index = 1.5
sd.optical_properties.parameters._check_opt_prop_param_exist()


Out[4]:
True

In [9]:
np.any([False,False])


Out[9]:
False

In [ ]:


In [ ]:

moment conversion


In [28]:
from atmPy.aerosols import size_distribution
%matplotlib inline

In [76]:
sd = size_distribution.sizedistribution.simulate_sizedistribution(diameter=[15, 3000], 
                                                             numberOfDiameters=50, 
                                                             centerOfAerosolMode=222, 
                                                             widthOfAerosolMode=0.18, 
                                                             numberOfParticsInMode=888)

sd_dNdDp = sd.convert2dNdDp()
sd_dNdlogDp = sd.convert2dNdlogDp()
sd_dSdDp = sd.convert2dSdDp()
sd_dSdlogDp = sd.convert2dSdlogDp()
sd_dVdDp = sd.convert2dVdDp()
sd_dVdlogDp = sd.convert2dVdlogDp()

folder = './test_data/'

# sd.save_csv(folder + 'aerosols_size_dist_moments_sd.nc')
# sd_dNdDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dNdDp.nc')
# sd_dNdlogDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dNdlogDp.nc')
# sd_dSdDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dSdDp.nc')
# sd_dSdlogDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dSdlogDp.nc')
# sd_dVdDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dVdDp.nc')
# sd_dVdlogDp.save_csv(folder + 'aerosols_size_dist_moments_sd_dVdlogDp.nc')

sd_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd.nc')
sd_dNdDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dNdDp.nc')
sd_dNdlogDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dNdlogDp.nc')
sd_dSdDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dSdDp.nc')
sd_dSdlogDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dSdlogDp.nc')
sd_dVdDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dVdDp.nc')
sd_dVdlogDp_soll = size_distribution.sizedistribution.read_csv(folder + 'aerosols_size_dist_moments_sd_dVdlogDp.nc')

threshold = 1e-10
assert(abs((sd.data.values - sd_soll.data)).values.sum() < (sd.data.values.max() * threshold))
assert((sd_dNdDp.data - sd_dNdDp_soll.data).values.sum() < (sd_dNdDp.data.values.max() * threshold))
assert((sd_dSdDp.data - sd_dSdDp_soll.data).values.sum() < (sd_dSdDp.data.values.max() * threshold))
assert((sd_dVdDp.data - sd_dVdDp_soll.data).values.sum() < (sd_dVdDp.data.values.max() * threshold))
assert((sd_dNdlogDp.data - sd_dNdlogDp_soll.data).values.sum() < (sd_dNdlogDp.data.values.max() * threshold))
assert((sd_dSdlogDp.data - sd_dSdlogDp_soll.data).values.sum() < (sd_dSdlogDp.data.values.max() * threshold))
assert((sd_dVdlogDp.data - sd_dVdlogDp_soll.data).values.sum() < (sd_dVdlogDp.data.values.max() * threshold))


/Users/htelg/prog/atm-py/atmPy/aerosols/size_distribution/sizedistribution.py:844: UserWarning: This function is deprecated use close_gaps instead ... unless you like thisone better
  _warnings.warn('This function is deprecated use close_gaps instead ... unless you like thisone better')
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/_methods.py:70: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)

In [86]:
(sd.data.values - sd_soll.data.values).sum()


Out[86]:
-8.7785748722638802e-16

In [81]:
(abs((sd.data - sd_soll.data).dropna()).values.sum() < (sd.data.values.max() * threshold))


Out[81]:
True

optical properties


In [1]:
from atmPy.aerosols import size_distribution
import atmPy
from atmPy.unit_testing import nose_tests
%matplotlib inline

In [3]:
test = nose_tests.SizeDistTest()
test.test_opt_prop_LS()


calc opt_prop

In [6]:
sd = size_distribution.sizedistribution.simulate_sizedistribution_layerseries(diameter=[10, 2500], 
                                                                              numberOfDiameters=100, 
                                                                              heightlimits=[0, 6000], 
                                                                              noOflayers=100, 
                                                                              layerHeight=[500.0, 4000.0], 
                                                                              layerThickness=[100.0, 300.0], 
                                                                              layerDensity=[1000.0, 50.0], 
                                                                              layerModecenter=[200.0, 800.0], 
                                                                              widthOfAerosolMode=0.2)

sd.optical_properties.parameters.refractive_index = 1.56
sd.optical_properties.parameters.wavelength = 515

fname = './test_data/aerosols_size_dist_LS_optprop.nc'
sdl = atmPy.read_file.netCDF(fname)

np.all(sd.optical_properties.aod_cumulative.data['aod'] == sdl.data['AOD per Layer'])


calc opt_prop
Out[6]:
False

In [8]:
(sd.optical_properties.aod_cumulative.data['aod'] - sdl.data['AOD per Layer']).sum()


Out[8]:
1.5445301543875677e-19

In [ ]:


In [ ]:


In [ ]:
if aod:
            layerThickness = sdls.layerbounderies[i][1] - sdls.layerbounderies[i][0]
            AOD_perBin = extinction_coefficient * layerThickness
            AOD_layer[i] = AOD_perBin.values.sum()

In [ ]:
out['AOD'] = AOD_layer[~ _np.isnan(AOD_layer)].sum()
        out['AOD_layer'] = _pd.DataFrame(AOD_layer, index=sdls.layercenters, columns=['AOD per Layer'])
        out['AOD_cum'] = out['AOD_layer'].iloc[::-1].cumsum().iloc[::-1]

In [ ]:
layerThickness = sd.layerbounderies[i][1] - sd.layerbounderies[i][0]
AOD_perBin = extinction_coefficient * layerThickness
AOD_layer[i] = AOD_perBin.values.sum()

In [49]:
layerthickness = sd.layerbounderies[:,1] - sd.layerbounderies[:,0]
aod_per_bin_per_layer = sd.optical_properties.extinction_coeff_per_bin.multiply(layerthickness, axis=0)
aod_per_layer = pd.DataFrame(aod_per_bin_per_layer.sum(axis=1), columns= ['aod_per_layer'])
aod = aod_per_layer.values.sum()
aod_cumulative = aod_per_layer.iloc[::-1].cumsum()
aod_cumulative.rename(columns={'aod_per_layer': 'aod'})


Out[49]:
aod
5970.0 2.552018e-12
5910.0 1.185391e-11
5850.0 4.442911e-11
5790.0 1.540343e-10
5730.0 5.083605e-10
5670.0 1.608895e-09
5610.0 4.893115e-09
5550.0 1.430961e-08
5490.0 4.024986e-08
5430.0 1.089073e-07
5370.0 2.835012e-07
5310.0 7.100795e-07
5250.0 1.711454e-06
5190.0 3.969969e-06
5130.0 8.864120e-06
5070.0 1.905379e-05
5010.0 3.943691e-05
4950.0 7.861199e-05
4890.0 1.509518e-04
4830.0 2.792949e-04
4770.0 4.980692e-04
4710.0 8.563704e-04
4650.0 1.420175e-03
4590.0 2.272562e-03
4530.0 3.510712e-03
4470.0 5.238691e-03
4410.0 7.555719e-03
4350.0 1.054078e-02
4290.0 1.423567e-02
4230.0 1.862987e-02
... ...
1770.0 7.388802e-02
1710.0 7.388802e-02
1650.0 7.388802e-02
1590.0 7.388802e-02
1530.0 7.388802e-02
1470.0 7.388802e-02
1410.0 7.388802e-02
1350.0 7.388802e-02
1290.0 7.388802e-02
1230.0 7.388802e-02
1170.0 7.388802e-02
1110.0 7.388802e-02
1050.0 7.388803e-02
990.0 7.388806e-02
930.0 7.388861e-02
870.0 7.389469e-02
810.0 7.394146e-02
750.0 7.419239e-02
690.0 7.513174e-02
630.0 7.758501e-02
570.0 8.205518e-02
510.0 8.773787e-02
450.0 9.277797e-02
390.0 9.589670e-02
330.0 9.724309e-02
270.0 9.764861e-02
210.0 9.773383e-02
150.0 9.774632e-02
90.0 9.774760e-02
30.0 9.774769e-02

100 rows × 1 columns


In [ ]:


In [6]:
sd.optical_properties._optical_porperties.keys()


Out[6]:
dict_keys(['parent_type', 'index_of_refraction', 'absCoeff_perrow_perbin', 'scattCoeff_perrow_perbin', 'angular_scatt_func', 'wavelength', 'bins', 'bin_centers', 'extCoeff_perrow_perbin', 'asymmetry_param', 'binwidth', 'distType'])

In [35]:
fname = './test_data/aerosols_size_dist_LS_optprop.nc'
sd.optical_properties.aerosol_optical_depth_cumulative_VP.save_netCDF(fname)

hygroscopic growth


In [5]:
sdto = nose_tests.SizeDistTest()
sdto.test_opt_prop_LS()
sdto.test_growth_opt_propLS()


> /Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py(696)apply_growth2sizedist()
-> return sd_grown
(Pdb) sd.distributionType
'numberConcentration'
(Pdb) sd_grown.distributionType
'numberConcentration'
(Pdb) sd.data == sd_grown.data
bincenters_(nm) 10.286785   10.876803   11.500663   12.160306   12.857784    \
30.0                  False       False       False       False       False   
90.0                  False       False       False       False       False   
150.0                 False       False       False       False       False   
210.0                 False       False       False       False       False   
270.0                 False       False       False       False       False   
330.0                 False       False       False       False       False   
390.0                 False       False       False       False       False   
450.0                 False       False       False       False       False   
510.0                 False       False       False       False       False   
570.0                 False       False       False       False       False   
630.0                 False       False       False       False       False   
690.0                 False       False       False       False       False   
750.0                 False       False       False       False       False   
810.0                 False       False       False       False       False   
870.0                 False       False       False       False       False   
930.0                 False       False       False       False       False   
990.0                 False       False       False       False       False   
1050.0                False       False       False       False       False   
1110.0                False       False       False       False       False   
1170.0                False       False       False       False       False   
1230.0                False       False       False       False       False   
1290.0                False       False       False       False       False   
1350.0                False       False       False       False       False   
1410.0                False       False       False       False       False   
1470.0                False       False       False       False       False   
1530.0                False       False       False       False       False   
1590.0                False       False       False       False       False   
1650.0                False       False       False       False       False   
1710.0                False       False       False       False       False   
1770.0                False       False       False       False       False   
...                     ...         ...         ...         ...         ...   
4230.0                False       False       False       False       False   
4290.0                False       False       False       False       False   
4350.0                False       False       False       False       False   
4410.0                False       False       False       False       False   
4470.0                False       False       False       False       False   
4530.0                False       False       False       False       False   
4590.0                False       False       False       False       False   
4650.0                False       False       False       False       False   
4710.0                False       False       False       False       False   
4770.0                False       False       False       False       False   
4830.0                False       False       False       False       False   
4890.0                False       False       False       False       False   
4950.0                False       False       False       False       False   
5010.0                False       False       False       False       False   
5070.0                False       False       False       False       False   
5130.0                False       False       False       False       False   
5190.0                False       False       False       False       False   
5250.0                False       False       False       False       False   
5310.0                False       False       False       False       False   
5370.0                False       False       False       False       False   
5430.0                False       False       False       False       False   
5490.0                False       False       False       False       False   
5550.0                False       False       False       False       False   
5610.0                False       False       False       False       False   
5670.0                False       False       False       False       False   
5730.0                False       False       False       False       False   
5790.0                False       False       False       False       False   
5850.0                False       False       False       False       False   
5910.0                False       False       False       False       False   
5970.0                False       False       False       False       False   

bincenters_(nm) 13.595267   14.375049   15.199558   16.071358   16.993162    \
30.0                  False       False       False       False       False   
90.0                  False       False       False       False       False   
150.0                 False       False       False       False       False   
210.0                 False       False       False       False       False   
270.0                 False       False       False       False       False   
330.0                 False       False       False       False       False   
390.0                 False       False       False       False       False   
450.0                 False       False       False       False       False   
510.0                 False       False       False       False       False   
570.0                 False       False       False       False       False   
630.0                 False       False       False       False       False   
690.0                 False       False       False       False       False   
750.0                 False       False       False       False       False   
810.0                 False       False       False       False       False   
870.0                 False       False       False       False       False   
930.0                 False       False       False       False       False   
990.0                 False       False       False       False       False   
1050.0                False       False       False       False       False   
1110.0                False       False       False       False       False   
1170.0                False       False       False       False       False   
1230.0                False       False       False       False       False   
1290.0                False       False       False       False       False   
1350.0                False       False       False       False       False   
1410.0                False       False       False       False       False   
1470.0                False       False       False       False       False   
1530.0                False       False       False       False       False   
1590.0                False       False       False       False       False   
1650.0                False       False       False       False       False   
1710.0                False       False       False       False       False   
1770.0                False       False       False       False       False   
...                     ...         ...         ...         ...         ...   
4230.0                False       False       False       False       False   
4290.0                False       False       False       False       False   
4350.0                False       False       False       False       False   
4410.0                False       False       False       False       False   
4470.0                False       False       False       False       False   
4530.0                False       False       False       False       False   
4590.0                False       False       False       False       False   
4650.0                False       False       False       False       False   
4710.0                False       False       False       False       False   
4770.0                False       False       False       False       False   
4830.0                False       False       False       False       False   
4890.0                False       False       False       False       False   
4950.0                False       False       False       False       False   
5010.0                False       False       False       False       False   
5070.0                False       False       False       False       False   
5130.0                False       False       False       False       False   
5190.0                False       False       False       False       False   
5250.0                False       False       False       False       False   
5310.0                False       False       False       False       False   
5370.0                False       False       False       False       False   
5430.0                False       False       False       False       False   
5490.0                False       False       False       False       False   
5550.0                False       False       False       False       False   
5610.0                False       False       False       False       False   
5670.0                False       False       False       False       False   
5730.0                False       False       False       False       False   
5790.0                False       False       False       False       False   
5850.0                False       False       False       False       False   
5910.0                False       False       False       False       False   
5970.0                False       False       False       False       False   

bincenters_(nm)     ...     3799.889527 4017.839526 4248.290469 4491.959370  \
30.0                ...            True        True        True        True   
90.0                ...            True        True        True        True   
150.0               ...            True        True        True        True   
210.0               ...            True        True        True        True   
270.0               ...            True        True        True        True   
330.0               ...            True        True        True        True   
390.0               ...            True        True        True        True   
450.0               ...            True        True        True        True   
510.0               ...            True        True        True        True   
570.0               ...            True        True        True        True   
630.0               ...            True        True        True        True   
690.0               ...            True        True        True        True   
750.0               ...            True        True        True        True   
810.0               ...            True        True        True        True   
870.0               ...            True        True        True        True   
930.0               ...            True        True        True        True   
990.0               ...            True        True        True        True   
1050.0              ...            True        True        True        True   
1110.0              ...            True        True        True        True   
1170.0              ...            True        True        True        True   
1230.0              ...            True        True        True        True   
1290.0              ...            True        True        True        True   
1350.0              ...            True        True        True        True   
1410.0              ...            True        True        True        True   
1470.0              ...            True        True        True        True   
1530.0              ...            True        True        True        True   
1590.0              ...            True        True        True        True   
1650.0              ...            True        True        True        True   
1710.0              ...            True        True        True        True   
1770.0              ...            True        True        True        True   
...                 ...             ...         ...         ...         ...   
4230.0              ...            True        True        True        True   
4290.0              ...            True        True        True        True   
4350.0              ...            True        True        True        True   
4410.0              ...            True        True        True        True   
4470.0              ...            True        True        True        True   
4530.0              ...            True        True        True        True   
4590.0              ...            True        True        True        True   
4650.0              ...            True        True        True        True   
4710.0              ...            True        True        True        True   
4770.0              ...            True        True        True        True   
4830.0              ...            True        True        True        True   
4890.0              ...            True        True        True        True   
4950.0              ...            True        True        True        True   
5010.0              ...            True        True        True        True   
5070.0              ...            True        True        True        True   
5130.0              ...            True        True        True        True   
5190.0              ...            True        True        True        True   
5250.0              ...            True        True        True        True   
5310.0              ...            True        True        True        True   
5370.0              ...            True        True        True        True   
5430.0              ...            True        True        True        True   
5490.0              ...            True        True        True        True   
5550.0              ...            True        True        True        True   
5610.0              ...            True        True        True        True   
5670.0              ...            True        True        True        True   
5730.0              ...            True        True        True        True   
5790.0              ...            True        True        True        True   
5850.0              ...            True        True        True        True   
5910.0              ...            True        True        True        True   
5970.0              ...            True        True        True        True   

bincenters_(nm) 4749.604372 5022.027100 5310.075159 5614.644771 5936.683561  \
30.0                  False       False       False       False       False   
90.0                  False       False       False       False       False   
150.0                 False       False       False       False       False   
210.0                 False       False       False       False       False   
270.0                 False       False       False       False       False   
330.0                 False       False       False       False       False   
390.0                 False       False       False       False       False   
450.0                 False       False       False       False       False   
510.0                 False       False       False       False       False   
570.0                 False       False       False       False       False   
630.0                 False       False       False       False       False   
690.0                 False       False       False       False       False   
750.0                 False       False       False       False       False   
810.0                 False       False       False       False       False   
870.0                 False       False       False       False       False   
930.0                 False       False       False       False       False   
990.0                 False       False       False       False       False   
1050.0                False       False       False       False       False   
1110.0                False       False       False       False       False   
1170.0                False       False       False       False       False   
1230.0                False       False       False       False       False   
1290.0                False       False       False       False       False   
1350.0                False       False       False       False       False   
1410.0                False       False       False       False       False   
1470.0                False       False       False       False       False   
1530.0                False       False       False       False       False   
1590.0                False       False       False       False       False   
1650.0                False       False       False       False       False   
1710.0                False       False       False       False       False   
1770.0                False       False       False       False       False   
...                     ...         ...         ...         ...         ...   
4230.0                False       False       False       False       False   
4290.0                False       False       False       False       False   
4350.0                False       False       False       False       False   
4410.0                False       False       False       False       False   
4470.0                False       False       False       False       False   
4530.0                False       False       False       False       False   
4590.0                False       False       False       False       False   
4650.0                False       False       False       False       False   
4710.0                False       False       False       False       False   
4770.0                False       False       False       False       False   
4830.0                False       False       False       False       False   
4890.0                False       False       False       False       False   
4950.0                False       False       False       False       False   
5010.0                False       False       False       False       False   
5070.0                False       False       False       False       False   
5130.0                False       False       False       False       False   
5190.0                False       False       False       False       False   
5250.0                False       False       False       False       False   
5310.0                False       False       False       False       False   
5370.0                False       False       False       False       False   
5430.0                False       False       False       False       False   
5490.0                False       False       False       False       False   
5550.0                False       False       False       False       False   
5610.0                False       False       False       False       False   
5670.0                False       False       False       False       False   
5730.0                False       False       False       False       False   
5790.0                False       False       False       False       False   
5850.0                False       False       False       False       False   
5910.0                False       False       False       False       False   
5970.0                False       False       False       False       False   

bincenters_(nm) 6277.193508  
30.0                  False  
90.0                  False  
150.0                 False  
210.0                 False  
270.0                 False  
330.0                 False  
390.0                 False  
450.0                 False  
510.0                 False  
570.0                 False  
630.0                 False  
690.0                 False  
750.0                 False  
810.0                 False  
870.0                 False  
930.0                 False  
990.0                 False  
1050.0                False  
1110.0                False  
1170.0                False  
1230.0                False  
1290.0                False  
1350.0                False  
1410.0                False  
1470.0                False  
1530.0                False  
1590.0                False  
1650.0                False  
1710.0                False  
1770.0                False  
...                     ...  
4230.0                False  
4290.0                False  
4350.0                False  
4410.0                False  
4470.0                False  
4530.0                False  
4590.0                False  
4650.0                False  
4710.0                False  
4770.0                False  
4830.0                False  
4890.0                False  
4950.0                False  
5010.0                False  
5070.0                False  
5130.0                False  
5190.0                False  
5250.0                False  
5310.0                False  
5370.0                False  
5430.0                False  
5490.0                False  
5550.0                False  
5610.0                False  
5670.0                False  
5730.0                False  
5790.0                False  
5850.0                False  
5910.0                False  
5970.0                False  

[100 rows x 116 columns]
(Pdb) sd.data.values == sd_grown.data.values
array([[False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       ..., 
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False]], dtype=bool)
(Pdb) sd.data.values[0,0]
nan
(Pdb) sd.data.values[0,0], sd_grown.data.values[0,0]
(nan, nan)
(Pdb) sd.data.values[10,10]
nan
(Pdb) sd.data.values[100,0]
*** IndexError: index 100 is out of bounds for axis 0 with size 100
(Pdb) sd.data.values[0,100]
1.0288326149418536e-07
(Pdb) sd.data.values[0,100], sd_grown.data.values[0,100]
(1.0288326149418536e-07, 1.0288326149418536e-07)
(Pdb) (sd.data.values == sd_grown.data.values).sum()
9800
(Pdb) sd.data.colums == sd_grown.data.colums
*** AttributeError: 'DataFrame' object has no attribute 'colums'
(Pdb) sd.data.columns == sd_grown.data.columns
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True], dtype=bool)
(Pdb) sd.parameters4reduction
*** AttributeError: 'SizeDist_LS' object has no attribute 'parameters4reduction'
(Pdb) sd.parameters4reductions
RH                  :  <atmPy.general.vertical_profile.VerticalProfile object at 0x110ba2358>
growth_distribution :  None
kappa               :  0.7
particle_density    :  1.8
refractive_index    :  1.56
wavelength          :  515
(Pdb) sd_grown.parameters4reductions
RH                  :  None
growth_distribution :  None
kappa               :  None
particle_density    :  1.8
refractive_index    :  None
wavelength          :  515
(Pdb) exit
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-5-0665276fdbd1> in <module>()
      1 sdto = nose_tests.SizeDistTest()
      2 sdto.test_opt_prop_LS()
----> 3 sdto.test_growth_opt_propLS()

/Users/htelg/prog/atm-py/atmPy/unit_testing/nose_tests.py in test_growth_opt_propLS(self)
    165         # let it grow
    166         sdto.sizedistributionLS.hygroscopicity.parameters.kappa = 0.7
--> 167         distg = sdto.sizedistributionLS.hygroscopicity.grown_size_distribution
    168         distg.optical_properties.parameters.wavelength = sdto.sizedistributionLS.optical_properties.parameters.wavelength.value
    169 

/Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py in grown_size_distribution(self)
    878             if self.parameters.kappa:
    879                 # self._grown_size_distribution = self._parent_sizedist.apply_hygro_growth(self.parameters.kappa.value, self.parameters.RH.value)
--> 880                 self._grown_size_distribution = apply_hygro_growth2sizedist(self._parent_sizedist)
    881             else:
    882                 self._grown_size_distribution = SizeDistGrownByGrowthDistribution(self) #apply_growth_distribution_on_sizedist(self._parent_sizedist, self.parameters.growth_distribution.value, self.parameters.RH.value)

/Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py in apply_hygro_growth2sizedist(sizedist, how, adjust_refractive_index)
    738             raise TypeError(txt)
    739 
--> 740     dist_g = apply_growth2sizedist(dist_g, gf)
    741     dist_g.gf = gf
    742     if how == 'shift_bins':

/Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py in apply_growth2sizedist(sd, gf)
    694 
    695     import pdb; pdb.set_trace()
--> 696     return sd_grown
    697 
    698 

/Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py in apply_growth2sizedist(sd, gf)
    694 
    695     import pdb; pdb.set_trace()
--> 696     return sd_grown
    697 
    698 

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/bdb.py in trace_dispatch(self, frame, event, arg)
     46             return # None
     47         if event == 'line':
---> 48             return self.dispatch_line(frame)
     49         if event == 'call':
     50             return self.dispatch_call(frame, arg)

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/bdb.py in dispatch_line(self, frame)
     65         if self.stop_here(frame) or self.break_here(frame):
     66             self.user_line(frame)
---> 67             if self.quitting: raise BdbQuit
     68         return self.trace_dispatch
     69 

BdbQuit: 

In [4]:
sdto.sizedistributionLS.distributionType


Out[4]:
'dNdDp'

In [1]:
from atmPy.unit_testing import nose_tests
from atmPy.general import vertical_profile
import atmPy
%matplotlib inline
# nose_tests.size_distribution.sizedistribution.settings

In [2]:
# use the same dist_LS as in test_opt_prop_LS
sdto = nose_tests.SizeDistTest()
sdto.test_opt_prop_LS()

# generate some RH which we can put into the housekeeping
hk = pd.DataFrame(index = sdto.sizedistributionLS.data.index, columns=['Relative_humidity'])
hk['Relative_humidity'] = 90
hk = vertical_profile.VerticalProfile(hk)
sdto.sizedistributionLS.housekeeping = hk

sdto.sizedistributionLS.hygroscopicity.parameters.RH = hk

# let it grow
sdto.sizedistributionLS.hygroscopicity.parameters.kappa = 0.7

distg = sdto.sizedistributionLS.hygroscopicity.grown_size_distribution

distg.optical_properties.parameters.wavelength = sdto.sizedistributionLS.optical_properties.parameters.wavelength.value

# load the test data
fname = './test_data/aerosols_size_dist_LS_hyg_growth_optprop.nc'
aodcs = atmPy.read_file.netCDF(fname)

threshold = distg.optical_properties.aod_cumulative.data.values.sum() * 1e-5

res = np.abs(distg.optical_properties.aod_cumulative.data.values
 - aodcs.data.values).sum() < threshold
print(np.abs(distg.optical_properties.aod_cumulative.data.values
 - aodcs.data.values).sum() , threshold), res


calculating opt prop

In [13]:
distg.plot()


Out[13]:
(<matplotlib.figure.Figure at 0x107df4be0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x109dbc6a0>,
 <matplotlib.collections.QuadMesh at 0x109dbcc50>,
 <matplotlib.colorbar.Colorbar at 0x1099f0198>)

In [25]:
a = aodcs.plot()
distg.optical_properties.aod_cumulative.plot(ax = a)


Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x10c0614a8>

In [33]:
(aodcs.data.iloc[:,0] / distg.optical_properties.aod_cumulative.data.iloc[:,0]).plot()


Out[33]:
<matplotlib.axes._subplots.AxesSubplot at 0x10803a6a0>

In [15]:
distg.optical_properties.aod_cumulative.plot()


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x109cea048>

In [ ]:


In [ ]:


In [16]:
fname = './test_data/aerosols_size_dist_LS_hyg_growth_optprop.nc'
distg.optical_properties.aod_cumulative.save_netCDF(fname)

physics

hygroscopicity

growth_factor_distribution


In [3]:
from atmPy.aerosols.physics import hygroscopicity as hyg
from atmPy.data_archives import arm
from atmPy.unit_testing import nose_tests

In [4]:
sdto = nose_tests.PhysicsHygroscopicityTest()

In [5]:
sdto.test_hygroscopic_growth_factor_distributions()

In [14]:
fname = './test_data/sgptdmahygC1.b1.20120601.004227.cdf'
out = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
hgfd = hyg.HygroscopicGrowthFactorDistributions(out.hyg_distributions.data.loc[:,200.0,:].transpose())
hgfd.plot()

fname = './test_data/aerosols_physics_hygroscopicity_growth_mode.csv'
growth_mode_soll = pd.read_csv(fname, index_col=0)

threshold = growth_mode_soll.ratio.sum() * 1e-5
res = np.abs(hgfd.growth_modes_gf.ratio - growth_mode_soll.ratio).sum() < threshold
print(np.abs(hgfd.growth_modes_gf.ratio - growth_mode_soll.ratio).sum(), threshold, res)

threshold = growth_mode_soll.gf.sum() * 1e-7
res = np.abs(hgfd.growth_modes_gf.gf - growth_mode_soll.gf).sum()< threshold
print(np.abs(hgfd.growth_modes_gf.gf - growth_mode_soll.gf).sum(), threshold, res)

#######
fname = './test_data/aerosols_physics_hygroscopicity_mixing_state.csv'
mixing_state_soll = pd.read_csv(fname, index_col=0)

threshold = mixing_state_soll.mixing_state.sum() * 1e-6
res = np.abs(hgfd.mixing_state.mixing_state - mixing_state_soll.mixing_state).sum() < threshold
print(np.abs(hgfd.mixing_state.mixing_state - mixing_state_soll.mixing_state).sum(), threshold, res)


0.00013942675005562856 0.00028999998226984477 True
1.0720131907726582e-06 1.0701970171113901e-05 True
1.46980131315e-05 2.3521201654915003e-05 True
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/colors.py:581: RuntimeWarning: invalid value encountered in less
  cbook._putmask(xa, xa < 0.0, -1)

In [183]:
fname = './test_data/aerosols_physics_hygroscopicity_growth_mode.csv'
hgfd.growth_modes.to_csv(fname)

In [184]:
fname = './test_data/aerosols_physics_hygroscopicity_mixing_state.csv'
hgfd.mixing_state.to_csv(fname)

f of RH

kappa


In [4]:
from atmPy.data_archives import arm
%matplotlib inline
plt.style.use('hagen_default')

In [5]:
fname = 'test_data/sgptdmaapssizeC1.c1.20120601.004227.cdf'
tdmaaps = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
sd = tdmaaps.size_distribution

fname = 'test_data/sgpaosacsmC1.b1.20120601.002649.cdf'
acsm = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)

sd.parameters4reductions.refractive_index = acsm.refractive_index

sd.hygroscopicity.parameters.kappa = 0.6
sd.optical_properties.parameters.wavelength = 550
sd.optical_properties.parameters.refractive_index = 1.5

fname = './test_data/aerosols_physics_hygroscopicity_fRH_kappa.csv'
fRHk_soll = atmPy.read_file.netCDF(fname)

threshold = sd.hygroscopicity.f_RH_85_40.data.sum().values[0] * 1e-10
np.abs(sd.hygroscopicity.f_RH_85_40.data - fRHk_soll.data).sum().values[0] < threshold


/Users/htelg/prog/atm-py/atmPy/aerosols/instruments/AMS/AMS.py:63: UserWarning: Sulfate rich is not implemented yet. Mostly because I don't get it!
         There are not supposed to be any Nitrates or Chlorides present when we are in the sulfate rich regime ... but there are.
         I guess it has to do with the organics? Talk to chuck
  _warnings.warn(txt)
/Users/htelg/prog/atm-py/atmPy/aerosols/physics/optical_properties.py:112: RuntimeWarning: invalid value encountered in true_divide
  y_phase_func = y_1p * 4 * _np.pi / scattering_cross_eff.sum()
Out[5]:
False

In [8]:
a = sd.hygroscopicity.f_RH_85_40.plot()
fRHk_soll.plot(ax = a)


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x110ac1048>

In [ ]:


In [9]:
fname = './test_data/aerosols_physics_hygroscopicity_fRH_kappa.csv'
sd.hygroscopicity.f_RH_85_40.save_netCDF(fname)

growth distribution


In [2]:
from atmPy.data_archives import arm
import atmPy
%matplotlib inline
plt.style.use('hagen_default')

In [3]:
fname = 'test_data/sgptdmaapssizeC1.c1.20120601.004227.cdf'
tdmaaps = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
sd = tdmaaps.size_distribution

fname = 'test_data/sgpaosacsmC1.b1.20120601.002649.cdf'
acsm = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)

sd.parameters4reductions.refractive_index = acsm.refractive_index

fname = 'test_data/sgptdmahygC1.b1.20120601.004227.cdf'
out = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
hgfd = out.hyg_distributions_d200nm
sd.hygroscopicity.parameters.growth_distribution = hgfd
sd.optical_properties.parameters.wavelength = 550

# sd.hygroscopicity.parameters.RH = 85

fname = './test_data/aerosol_fRH_from_size_dist_and_growthdistribution.cdf'
fRH_gd_soll  = atmPy.read_file.netCDF(fname)

threshold = sd.hygroscopicity.f_RH_85_40.data.sum().values[0] * 1e-5
np.abs(sd.hygroscopicity.f_RH_85_40.data - fRH_gd_soll.data).sum().values[0] < threshold


/Users/htelg/prog/atm-py/atmPy/aerosols/instruments/AMS/AMS.py:63: UserWarning: Sulfate rich is not implemented yet. Mostly because I don't get it!
         There are not supposed to be any Nitrates or Chlorides present when we are in the sulfate rich regime ... but there are.
         I guess it has to do with the organics? Talk to chuck
  _warnings.warn(txt)
/Users/htelg/prog/atm-py/atmPy/aerosols/physics/optical_properties.py:112: RuntimeWarning: invalid value encountered in true_divide
  y_phase_func = y_1p * 4 * _np.pi / scattering_cross_eff.sum()
Out[3]:
True

In [4]:
a = sd.hygroscopicity.f_RH_85_40.plot()
fRH_gd_soll.plot(ax = a)


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x1127dce80>

In [10]:
fname = './test_data/aerosol_fRH_from_size_dist_and_growthdistribution.cdf'
sd.hygroscopicity.f_RH_85_40.save_netCDF(fname)

In [ ]:


In [ ]:


In [ ]: