def water_self_diffusion_coefficient(T=None, units=None, warn=True, err_mult=None): """ Temperature-dependent self-diffusion coefficient of water. Parameters ---------- T : float Temperature (default: in Kelvin) units : object (optional) object with attributes: Kelvin, meter, kilogram warn : bool (default: True) Emit UserWarning when outside temperature range. err_mult : length 2 array_like (default: None) Perturb paramaters D0 and TS with err_mult[0]*dD0 and err_mult[1]*dTS respectively, where dD0 and dTS are the reported uncertainties in the fitted paramters. Useful for estimating error in diffusion coefficient. References ---------- Temperature-dependent self-diffusion coefficients of water and six selected molecular liquids for calibration in accurate 1H NMR PFG measurements Manfred Holz, Stefan R. Heila, Antonio Saccob; Phys. Chem. Chem. Phys., 2000,2, 4740-4742 http://pubs.rsc.org/en/Content/ArticleLanding/2000/CP/b005319h DOI: 10.1039/B005319H """ if units is None: K = 1 m = 1 s = 1 else: K = units.Kelvin m = units.meter s = units.second if T is None: T = 298.15 * K _D0 = D0 * m**2 * s**-1 _TS = TS * K if err_mult is not None: _dD0 = dD0 * m**2 * s**-1 _dTS = dTS * K _D0 += err_mult[0] * _dD0 _TS += err_mult[1] * _dTS if warn and (_any(T < low_t_bound * K) or _any(T > high_t_bound * K)): warnings.warn("Temperature is outside range (0-100 degC)") return _D0 * ((T / _TS) - 1)**gamma
def water_self_diffusion_coefficient(T=None, units=None, warn=True, err_mult=None): """ Temperature-dependent self-diffusion coefficient of water. Parameters ---------- T: float Temperature (default: in Kelvin) units: object (optional) object with attributes: Kelvin, meter, kilogram warn: bool (default: True) Emit UserWarning when outside temperature range. err_mult: length 2 array_like (default: None) Perturb paramaters D0 and TS with err_mult[0]*dD0 and err_mult[1]*dTS respectively, where dD0 and dTS are the reported uncertainties in the fitted paramters. Useful for estimating error in diffusion coefficient. References ---------- Temperature-dependent self-diffusion coefficients of water and six selected molecular liquids for calibration in accurate 1H NMR PFG measurements Manfred Holz, Stefan R. Heila, Antonio Saccob; Phys. Chem. Chem. Phys., 2000,2, 4740-4742 http://pubs.rsc.org/en/Content/ArticleLanding/2000/CP/b005319h DOI: 10.1039/B005319H """ if units is None: K = 1 m = 1 s = 1 else: K = units.Kelvin m = units.meter s = units.second if T is None: T = 298.15*K _D0 = D0 * m**2 * s**-1 _TS = TS * K if err_mult is not None: _dD0 = dD0 * m**2 * s**-1 _dTS = dTS * K _D0 += err_mult[0]*_dD0 _TS += err_mult[1]*_dTS if warn and (_any(T < low_t_bound*K) or _any(T > high_t_bound*K)): warnings.warn("Temperature is outside range (0-100 degC)") return _D0*((T/_TS) - 1)**gamma
def water_density(T=None, T0=None, units=None, a=None, just_return_a=False, warn=True): """ Density of water (kg/m3) as function of temperature (K) according to VSMOW model between 0 and 40 degree Celsius. Fitted using Thiesen's equation. Parameters ---------- T : float Temperature (in Kelvin) (default: 298.15). T0 : float Value of T for 0 degree Celsius (default: 273.15). units : object (optional) Object with attributes: Kelvin, meter, kilogram. a : array_like (optional) 5 parameters to the equation. just_return_a : bool (optional, default: False) Do not compute rho, just return the parameters ``a``. warn : bool (default: True) Emit UserWarning when outside temperature range. Returns ------- Density of water (float of kg/m3 if T is float and units is None) Examples -------- >>> print('%.2f' % water_density(277.13)) 999.97 References ---------- TANAKA M., GIRARD G., DAVIS R., PEUTO A. and BIGNELL N., "Recommanded table for the density of water between 0 °C and 40 °C based on recent experimental reports", Metrologia, 2001, 38, 301-309. http://iopscience.iop.org/article/10.1088/0026-1394/38/4/3 doi:10.1088/0026-1394/38/4/3 """ if units is None: K = 1 m = 1 kg = 1 else: K = units.Kelvin m = units.meter kg = units.kilogram if T is None: T = 298.15 * K m3 = m**3 if a is None: a = ( -3.983035 * K, # C 301.797 * K, # C 522528.9 * K * K, # C**2 69.34881 * K, # C 999.974950 * kg / m3) if just_return_a: return a if T0 is None: T0 = 273.15 * K t = T - T0 if warn and (_any(t < 0 * K) or _any(t > 40 * K)): warnings.warn("Temperature is outside range (0-40 degC)") return a[4] * (1 - ((t + a[0])**2 * (t + a[1])) / (a[2] * (t + a[3])))
def SIC_for_IIR(FO=11, BO=3, AR_amp=0.1, ts_size=5000, sigma_input_noise=0., sigma_output_noise=0., order=10, report_CI=False, ic_type=None, ic_max_order=None, welch_window_size=1000): """A function to assess the performance of SIC under additive noise on input, output, both and under denoising in all the previous scenarios""" print sigma_input_noise, sigma_output_noise # a coefficient to reduce the influence of autoregressive coefficients to increase the chance of stability AR_amp_x = AR_amp_z = AR_amp # setting the filter coefficients that generates X_t A_z = append(1., random.randn(FO)) B_z = append(1., random.randn(BO) * AR_amp_z) #checking whether the first filter has coefficients give rise to a stable IIR filter while any(abs(roots(A_z)) >= 0.95) or _any(abs(roots(B_z)) >= 0.95): A_z = append(1., random.randn(FO)) B_z = append(1., random.randn(BO) * AR_amp_z) # setting the filter coefficients that generates Y_t A_x = append(1., random.randn(FO)) B_x = append(1., random.randn(BO) * AR_amp_x) #checking whether the second filter has coefficients give rise to a stable IIR filter while any(abs(roots(A_x)) >= 0.95) or any(abs(roots(B_x)) >= 0.95): A_x = append(1., random.randn(FO)) B_x = append(1., random.randn(BO) * AR_amp_x) #input Z as random noise to a mechanism that generates the cause: X_t Z = random.randn(ts_size) X = lfilter(A_z, B_z, Z) # adding additive noise to the cause noisy_X = X + random.randn(X.shape[0]) * sigma_input_noise Y = lfilter(A_x, B_x, X) # adding additive noise to the effect noisy_Y = Y + random.randn(Y.shape[0]) * sigma_output_noise return_SDR_dict = dict() return_SDR_dict['stochastic_in_out'] = asarray([ stochastic_SDR_estimator(noisy_X, noisy_Y, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type), stochastic_SDR_estimator(noisy_Y, noisy_X, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type) ]) if sigma_input_noise > 0: return_SDR_dict['stochastic_in'] = asarray([ stochastic_SDR_estimator(noisy_X, Y, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type), stochastic_SDR_estimator(Y, noisy_X, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type) ]) else: return_SDR_dict['stochastic_in'] = return_SDR_dict['stochastic_in_out'] if sigma_output_noise > 0: return_SDR_dict['stochastic_out'] = asarray([ stochastic_SDR_estimator(X, noisy_Y, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type), stochastic_SDR_estimator(noisy_Y, X, report_CI=report_CI, ic_max_order=ic_max_order, ic_type=ic_type) ]) else: return_SDR_dict['stochastic_out'] = return_SDR_dict[ 'stochastic_in_out'] return_SDR_dict['deterministic_in_out'] = asarray([ deterministic_SDR_estimator(noisy_X, noisy_Y, welch_window_size=welch_window_size), deterministic_SDR_estimator(noisy_Y, noisy_X, welch_window_size=welch_window_size) ]) return_SDR_dict['deterministic_in'] = asarray([ deterministic_SDR_estimator(noisy_X, Y, welch_window_size=welch_window_size), deterministic_SDR_estimator(Y, noisy_X, welch_window_size=welch_window_size) ]) return_SDR_dict['deterministic_out'] = asarray([ deterministic_SDR_estimator(X, noisy_Y, welch_window_size=welch_window_size), deterministic_SDR_estimator(noisy_Y, X, welch_window_size=welch_window_size) ]) return var(X), var(Y), return_SDR_dict
def water_density(T=None, T0=None, units=None, a=None, just_return_a=False, warn=True): """ Density of water (kg/m3) as function of temperature (K) according to VSMOW model between 0 and 40 degree Celsius. Fitted using Thiesen's equation. Parameters ---------- T : float Temperature (in Kelvin) (default: 298.15). T0 : float Value of T for 0 degree Celsius (default: 273.15). units : object (optional) Object with attributes: Kelvin, meter, kilogram. a : array_like (optional) 5 parameters to the equation. just_return_a : bool (optional, default: False) Do not compute rho, just return the parameters ``a``. warn : bool (default: True) Emit UserWarning when outside temperature range. Returns ------- Density of water (float of kg/m3 if T is float and units is None) Examples -------- >>> print('%.2f' % water_density(277.13)) 999.97 References ---------- TANAKA M., GIRARD G., DAVIS R., PEUTO A. and BIGNELL N., "Recommanded table for the density of water between 0 °C and 40 °C based on recent experimental reports", Metrologia, 2001, 38, 301-309. http://iopscience.iop.org/article/10.1088/0026-1394/38/4/3 doi:10.1088/0026-1394/38/4/3 """ if units is None: K = 1 m = 1 kg = 1 else: K = units.Kelvin m = units.meter kg = units.kilogram if T is None: T = 298.15*K m3 = m**3 if a is None: a = (-3.983035*K, # C 301.797*K, # C 522528.9*K*K, # C**2 69.34881*K, # C 999.974950*kg/m3) if just_return_a: return a if T0 is None: T0 = 273.15*K t = T - T0 if warn and (_any(t < 0*K) or _any(t > 40*K)): warnings.warn("Temperature is outside range (0-40 degC)") return a[4]*(1-((t + a[0])**2*(t + a[1]))/(a[2]*(t + a[3])))