Beispiel #1
0
    def set_theta(self, theta_deg, force_spline_calc=False):
        """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
          force_spline_calc (bool): forces (re-)calculation of the
                                    spline for each call
        """
        def calculate_and_store(key, cache):
            self.thrad = theta_rad(theta_deg)
            self.theta_deg = theta_deg
            self.calculate_density_spline()
            cache[key][theta_deg] = (self.max_X, self.s_h2X, self.s_X2rho,
                                     self.s_lX2h)
            _dump_cache(cache)

        if self.theta_deg == theta_deg and not force_spline_calc:
            if dbg:
                print(self.__class__.__name__ +
                      '::set_theta(): Using previous' + 'density spline.')
            return

        elif config['use_atm_cache'] and not force_spline_calc:
            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 = theta_rad(closest)
                        self.theta_deg = closest
                        self.max_X, self.s_h2X, self.s_X2rho, self.s_lX2h = 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 = theta_rad(theta_deg)
            self.theta_deg = theta_deg
            self.calculate_density_spline()
Beispiel #2
0
 def calculate_and_store(key, cache):
     self.thrad = theta_rad(theta_deg)
     self.theta_deg = theta_deg
     self.calculate_density_spline()
     cache[key][theta_deg] = (self.max_X, self.s_h2X, self.s_X2rho,
                              self.s_lX2h)
     _dump_cache(cache)
Beispiel #3
0
    def set_theta(self, theta_deg, force_spline_calc=False):
        """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
          force_spline_calc (bool): forces (re-)calculation of the
                                    spline for each call
        """
        if theta_deg < 0. or theta_deg > self.max_theta:
            raise Exception('Zenith angle not in allowed range.')

        self.thrad = theta_rad(theta_deg)
        self.theta_deg = theta_deg
        self.calculate_density_spline()
Beispiel #4
0
    p3 = 0.958633
    p4 = 0.0407253
    p5 = 0.817285
    x = costheta
    return np.sqrt(
        (x**2 + p1**2 + p2 * x**p3 + p4 * x**p5) / (1 + p1**2 + p2 + p4))


if __name__ == "__main__":
    import matplotlib.pyplot as plt

    earth = EarthGeometry()

    theta_list = np.linspace(0, 90, 500)
    h_vec = np.linspace(0, earth.h_atm, 500)
    th_list_rad = theta_rad(theta_list)
    fig = plt.figure(figsize=(5, 4))
    fig.set_tight_layout(dict(rect=[0.00, 0.00, 1, 1]))
    plt.plot(theta_list, earth.l(th_list_rad) / 1e5, lw=2)
    plt.xlabel(r'zenith $\theta$ at detector')
    plt.ylabel(r'path length $l(\theta)$ in km')
    ax = plt.gca()
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')

    fig = plt.figure(figsize=(5, 4))
    fig.set_tight_layout(dict(rect=[0.00, 0.00, 1, 1]))
    plt.plot(theta_list,
             np.arccos(earth.cos_th_star(th_list_rad)) / np.pi * 180.,