<jupyter_start><jupyter_text>HygroscopicGrowthFactorDistributions We need to generate a data set that can be used to initiate a HygroscopicGrowthFactorDistributions instance. Hiere we take Arm data generated by a HTDMA. The Arm data contains gf-distributions for different diameters, so we select one (200.0 nm).<jupyter_code>fname = '../atmPy/unit_testing/test_data/sgptdmahygC1.b1.20120601.004227.cdf'
out = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)<jupyter_output><empty_output><jupyter_text>in general Peaks in the gf-distribution are detected and fit by normal distributions (at log-base). Fit parameters are tightly constrained to avoid run-away parameters and unrealistic results, which in turn can result in unexpacted results ... hard coded fit parameters/boundaries might need adjustment.  Growth modes Position of detected growthmodes and ratio of particles in it as a function of time. Here plotted on top of the gf-distribution time series.<jupyter_code>out.hyg_distributions_d200nm.plot(growth_modes=True)
out.hyg_distributions_d200nm.growth_modes_kappa<jupyter_output><empty_output><jupyter_text>Mixing state I came up with the following definition, it should be adjusted if there is a better one in the literature Mixing state is given by the pythagoras of the particle ratios of all detected growth modes in a growth distribution. E.g. if there where three modes detected with ratios $r_1$, $r_2$, $r_3$ the mixing state is given by $\sqrt{r_1^2 + r_2^2 + r_3^2}$.<jupyter_code>out.hyg_distributions_d200nm.mixing_state.plot(marker = 'o', ls = '')<jupyter_output><empty_output><jupyter_text>Grown size distribution this is the sum. for optical properties the individual information is used so the change in the refractive index which is different for each growth mode is considered individually.<jupyter_code>fname = '../atmPy/unit_testing/test_data/sgptdmaapssizeC1.c1.20120601.004227.cdf'
tdmaaps = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
sd = tdmaaps.size_distribution
hgfd = out.hyg_distributions_d200nm
# gmk = out.hyg_distributions_d200nm.growth_modes_kappa
sd.convert2dVdlogDp().plot()
sd.hygroscopicity.parameters.growth_distribution = hgfd
sd.hygroscopicity.parameters.RH = 90
sd.hygroscopicity.grown_size_distribution.sum_of_all_sizeditributions.convert2dVdlogDp().plot()<jupyter_output><empty_output><jupyter_text>Optical properties  scattering<jupyter_code>sd.optical_properties.parameters.wavelength = 550
sd.optical_properties.parameters.refractive_index = 1.5
sd.hygroscopicity.grown_size_distribution.optical_properties.scattering_coeff.plot()<jupyter_output>/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()<jupyter_text>fRH<jupyter_code>a = sd.hygroscopicity.f_RH_85_40.plot()
sd.hygroscopicity.f_RH_85_0.plot(ax = a)<jupyter_output>/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()<jupyter_text>catch fit runaways<jupyter_code>from atmPy.tools import math_functions as _math_functions
def multi_gauss(x, *params, verbose=False):
    #     print(params)
    y = np.zeros_like(x)
    for i in range(0, len(params), 3):
        if verbose:
            print(len(params), i)
        amp = params[i]
        pos = params[i + 1]
        sig = params[i + 2]
        y = y + _math_functions.gauss(x, amp, pos, sig)
    return y
# %%debug --breakpoint /Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py:523
out.hyg_distributions_d200nm.plot(growth_modes=True)<jupyter_output><empty_output><jupyter_text>atmPy.aerosols.physics.hygroscopicityipdb> globals()['x'] = xipdb> globals()['y'] = yipdb> globals()['param'] = paramipdb> globals()['bound_l'] = bound_lipdb> globals()['bound_h'] = bound_hglobals()['x'] = x; globals()['y'] = y; globals()['param'] = param; globals()['bound_l'] = bound_l; globals()['bound_h'] = bound_h<jupyter_code>x = atmPy.aerosols.physics.hygroscopicity.x
y = atmPy.aerosols.physics.hygroscopicity.y
param = atmPy.aerosols.physics.hygroscopicity.param
bound_l = atmPy.aerosols.physics.hygroscopicity.bound_l
bound_h= atmPy.aerosols.physics.hygroscopicity.bound_h
plt.plot(x,y)
plt.plot(x, y_start)
plt.plot(x, new_y)
parry = np.array(param)
# parry[::3] *= 10
y_start = multi_gauss(x, *parry)
# fitres, _ = atmPy.aerosols.physics.hygroscopicity._curve_fit(multi_gauss, x, y, p0=param[:-3], bounds=(bound_l[:-3], bound_h[:-3]))
fitres, _ = atmPy.aerosols.physics.hygroscopicity._curve_fit(multi_gauss, x, y, p0=parry, bounds=(bound_l, bound_h), 
#                                                              max_nfev = 10000
                                                            )

new_y = multi_gauss(x, *fitres)<jupyter_output><empty_output><jupyter_text>Kappa In this section a kappa is defined instead of a growth distribution.<jupyter_code># fname = '../atmPy/unit_testing/test_data/sgptdmaapssizeC1.c1.20120601.004227.cdf
fname = '/Users/htelg/data/ARM/SGP/tdmaaps/sgptdmaapssizeC1.c1.20120201.002958.cdf'
tdmaaps = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
fname = '/Users/htelg/data/ARM/SGP/acsm/sgpaosacsmC1.b1.20120201.002022.cdf'
acsm = arm.read_netCDF(fname, data_quality= 'patchy', leave_cdf_open= False)
tdmaaps.size_distribution.parameters4reductions.wavelength = 550
# %%debug --breakpoint /Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py:606
tdmaaps.size_distribution.hygroscopicity.parameters.kappa = acsm.kappa
tdmaaps.size_distribution.hygroscopicity.parameters.refractive_index = acsm.refractive_index
fRH_nams_kams = tdmaaps.size_distribution.hygroscopicity.f_RH_85_0.copy()
# %%debug --breakpoint /Users/htelg/prog/atm-py/atmPy/aerosols/physics/hygroscopicity.py:742
tdmaaps.size_distribution.hygroscopicity.parameters.kappa = acsm.kappa
tdmaaps.size_distribution.hygroscopicity.parameters.refractive_index = 1.5#acsm.refractive_index
fRH_nfix_kams = tdmaaps.size_distribution.hygroscopicity.f_RH_85_0.copy()
tdmaaps.size_distribution.hygroscopicity.parameters.kappa = acsm.kappa.data.values.mean() #acsm.kappa
tdmaaps.size_distribution.hygroscopicity.parameters.refractive_index = 1.5#acsm.refractive_index
fRH_nfix_kfix = tdmaaps.size_distribution.hygroscopicity.f_RH_85_0.copy()
a = fRH_nfix_kfix.plot(label = 'nfix kfix')
fRH_nfix_kams.plot(ax = a, label = 'nfix_kams')
fRH_nams_kams.plot(ax = a, label = 'nams_kams')
a.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11034275405892964, 'fraction_numerical': 0.027059530968129887, 'mean_word_length': 5.619900497512438, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '163983', 'license': 'MIT', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2435, 'n_words': 434, 'path': 'examples/aerosols_pysics_hygroscopicity.ipynb', 'repo_name': 'wblumberg/atm-py', 'size': '6652'}