def set_theta(self, theta_deg): """Configures geometry and initiates spline calculation for :math:`\\rho(X)`. If the option 'use_atm_cache' is enabled in the config, the function will check, if a corresponding spline is available in the cache and use it. Otherwise it will call :func:`calculate_density_spline`, make the function :func:`r_X2rho` available to the core code and store the spline in the cache. Args: theta_deg (float): zenith angle :math:`\\theta` at detector """ def calculate_and_store(key, cache): self.thrad = geom._theta_rad(theta_deg) self.theta_deg = theta_deg self.calculate_density_spline() cache[key][theta_deg] = (self.X_surf, self.s_X2rho) _dump_cache(cache) if self.theta_deg == theta_deg: print self.__class__.__name__ + '::set_theta(): Using previous' + \ 'density spline.' return elif config['use_atm_cache']: from MCEq.misc import _get_closest cache = _load_cache() key = (self.__class__.__name__, self.location, self.season) if cache and key in cache.keys(): try: closest = _get_closest(theta_deg, cache[key].keys())[1] if abs(closest - theta_deg) < 1.: self.thrad = geom._theta_rad(closest) self.theta_deg = closest self.X_surf, self.s_X2rho = cache[key][closest] else: calculate_and_store(key, cache) except: cache[key] = {} calculate_and_store(key, cache) else: cache[key] = {} calculate_and_store(key, cache) else: self.thrad = geom._theta_rad(theta_deg) self.theta_deg = theta_deg self.calculate_density_spline()
def calculate_and_store(key, cache): self.thrad = geom._theta_rad(theta_deg) self.theta_deg = theta_deg self.calculate_density_spline() cache[key][theta_deg] = (self.X_surf, self.s_X2rho) _dump_cache(cache)