def example(): # possible values from get_ssa import get_ssa from Model import IrradianceModel zenith = 53.1836240528 AMass = 1.66450160404 rel_h = 0.665 pressure = 950 AM = 5 ssa = get_ssa(rel_h, AM) iteration = 20 alphas = np.zeros(len(range(1, iteration)) + 1) x = np.linspace(200, 800, 100) irr = IrradianceModel_python(AMass, rel_h, ssa, zenith, pressure) irr_symbol = IrradianceModel(x, zenith, AMass, pressure, ssa) func = irr_symbol._irradiance_ratio() y = irr.irradiance_ratio(x, 2.5, 0.06, 0.0, 1.0, 1.0) for i in range(0, iteration): ssa = get_ssa(rel_h, AM) print(ssa) irr = IrradianceModel_python(AMass, rel_h, ssa, zenith, pressure) yerror = np.random.normal(0, 0.009, len(x)) y = irr.irradiance_ratio(x, 1.5, 0.06, 0.0, 0.6, 0.9) + yerror weights = 1 / yerror gmod = Model(irr.irradiance_ratio, independent_vars=["x"], param_names=["alpha", "beta", "g_dsa", "g_dsr"]) gmod.set_param_hint("alpha", value=1.0, min=-0.2, max=2.5) gmod.set_param_hint("beta", value=0.01, min=0.0, max=2.0) gmod.set_param_hint("g_dsa", value=0.6, min=0.0, max=1.0) gmod.set_param_hint("g_dsr", value=0.9, min=0.0, max=1.0) print(gmod.param_hints) print(gmod.param_names) print(gmod.independent_vars) result = gmod.fit(y, x=x) print(result.fit_report()) alphas[i] = result.params["alpha"].value # plt.plot(x, y, label='%s' % AM) # plt.plot(x, result.best_fit, 'r-', label='fit') y = irr.irradiance_ratio(x, 1.5, 0.06, 0.0, 0.6, 0.9) y2 = irr.irradiance_ratio(x, 1.5, 0.08, 0.0, 0.6, 0.9) plt.legend() plt.show()
def example(): # possible values from get_ssa import get_ssa spectra = dict() zenith = 53.1836240528 AMass = 1.66450160404 rel_h = 0.665 pressure = 1020 AM_type = 6 ssa = get_ssa(rel_h, AM_type) irr = irradiance_models(AMass, rel_h, ssa, zenith, pressure) spectra['wave_nm'] = np.linspace(200, 800, 100) spectra['spectra'] = irr.irradiance_ratio(spectra['wave_nm'], 1.2, 0.06) + np.random.normal(0, 0.005, len(spectra['wave_nm'])) spectra['std'] = np.random.normal(0, 0.1, len(spectra['wave_nm'])) weights = 1 / spectra['std'] config_fitting = {'params': np.array(['alpha', 'beta', 'g_dsa', 'g_dsr']), \ 'initial_values': np.array([ 1. , 0.6, 1. , 1. ]), 'range_': np.array([360, 650])} aero = Aerosol_Retrievel(irr, config_fitting, spectra) aero.fit() print(aero.result.fit_report()) getattr(aero, 'params') plt.plot(spectra['wave_nm'], spectra['spectra']) plt.plot(aero.param_dict['wave_range'], aero.result.init_fit, 'k--') plt.plot(aero.param_dict['wave_range'], aero.result.best_fit, 'r-') plt.legend() plt.show()
def get_model_param(): setup = dict() setup['zenith'] = 76.33134 setup['AMass'] = get_atmospheric_path_length(setup['zenith']) setup['rel_h'] = 0.9 setup['pressure'] = 950 setup['AM'] = 5 setup['ssa'] = get_ssa(setup['rel_h'], setup['AM']) return setup
def get_model_param(): setup = dict() setup['zenith'] = 53.18 setup['AMass'] = 1.664 setup['rel_h'] = 0.665 setup['pressure'] = 950 setup['AM'] = 5 setup['ssa'] = get_ssa(setup['rel_h'], setup['AM']) setup['x'] = np.linspace(350, 700, 100) return setup
def test_main(): from get_ssa import get_ssa zenith = 53.1836240528 AMass = 1.66450160404 rel_h = 0.665 pressure = 950 AM = 5 ssa = get_ssa(rel_h, AM) x = np.linspace(200, 800, 100) # config variables = ['alpha', 'beta', 'g_dsa', 'g_dsr'] # config expected_values = [2.5, 0.06, 0.6, 0.5] print('Expected: %s' % expected_values) guess = [1.0, 0.01, 0.5, 0.8] # config bounds = [(-0.2, 4), (0., 3), (0., 2.), (0., 2.)] # config # Theano irr_symbol = IrradianceModel_sym(x, zenith, AMass, pressure, ssa, variables) getIrrRatio = irr_symbol.getcompiledModel('ratio') y_theano = getIrrRatio(*expected_values) res = Residuum(irr_symbol, 'ratio') residuum = FitWrapper(res.getResiduum()) residuals = FitWrapper(res.getResiduals()) derivative = FitWrapper(res.getDerivative()) Fit = FitModel() result = Fit._minimize(residuum, guess, y_theano, bounds, jacobian=derivative) print("Got %s" % result.x) resultls = Fit._least_squares(residuals, guess, y_theano, bounds) print("Got %s" % resultls.x) # Python IrradianceObject = IrradianceModel_python(AMass, rel_h, ssa, zenith, pressure) y_python = IrradianceObject.irradiance_ratio(x, 2.5, 0.06,0.0, 0.6, 0.5) gmod = Model(IrradianceObject.irradiance_ratio, independent_vars=['x'], param_names=variables) gmod.set_param_hint('alpha', value=guess[0], min=bounds[0][0], max=bounds[0][1]) gmod.set_param_hint('beta', value=guess[1], min=bounds[1][0], max=bounds[1][1]) gmod.set_param_hint('g_dsa', value=guess[2], min=bounds[2][0], max=bounds[2][1]) gmod.set_param_hint('g_dsr', value=guess[3], min=bounds[3][0], max=bounds[3][1]) result_lmfit = gmod.fit(y_python, x=x) print(result_lmfit.fit_report()) plt.plot(x, y_theano) x_new = np.linspace(300, 900,150) irr_symbol.set_wavelengthAOI(x_new) getIrrRatio = irr_symbol.getcompiledModel('ratio') y_new = getIrrRatio(*expected_values) plt.plot(x_new, y_new, '+', label='different wavelengths') plt.legend() plt.show()
def __init__(self, logger, config, wavelength): self.sun_zenith = get_sun_zenith(config["Processing"]["utc_time"], *config["Processing"]["gps_coords"]) self.atmos_path = get_atmospheric_path_length(self.sun_zenith) weather_dict = retrieve_weather_parameters( config["Processing"]["params"], config["Processing"]["gps_coords"], config["Processing"]["utc_time"] ) humidity = weather_dict["hum"] self.pressure = international_barometric_formula( config["Processing"]["gps_coords"][-1] ) # height (magic number) self.ssa = get_ssa(humidity) logger.info(" \n \t Zenith angle %s" % self.sun_zenith) logger.info(" \n \t Atmospheric path length %s" % self.atmos_path) logger.info(" \n \t Relative humidity %s" % humidity) logger.info(" \n \t Pressure %s" % self.pressure) logger.info(" \n \t Single scattering albedo %s" % self.ssa) logger.info(" \n \t Using %s model <<<< FIT" % config["Fitting"]["package"])