# Path: retina/screen/map/mapimpl.py
# class AlbersProjectionMap(PointMap):
#     """ https://en.wikipedia.org/wiki/Albers_projection
#         Compared to the entry of 8/21/2015
#         (numbers were chosen to have simpler formulas)
#         phi1 = 90, phi2 = 0, phi0 = 90, lambda0 = 90
#         lambda <- 2n (lambda - lambda0) (doubles the area)
#         =>
#         n = 0.5
#         rho0 = 0, C = 1, rho = 2sqrt(1-sin(phi))
#     """
# 
#     def __init__(self, r, eulerangles=None):
#         """ r: radious of the sphere from which the projection is made
#         """
#         self._r = r
#         self.rotationmap = EulerAnglesMap(eulerangles)
#         self.x_rotationmap = EulerAnglesMap(eulerangles=[0, np.pi/2, 0])
# 
#     def map(self, elev, azim):
#         """ Returns (nan, nan) if point cannot be mapped else (x, y)
#             arguments can be numpy arrays or scalars
#         """
#         elev, azim = self.rotationmap.invmap(elev, azim)
#         elev, azim = self.x_rotationmap.invmap(elev, azim)
# 
#         rxy = self._r*np.sqrt(1-np.sin(elev))
#         x = -rxy*np.cos(azim)
#         y = -rxy*np.sin(azim)
#         return (x, y)
# 
#     def invmap(self, x, y):
#         """ Returns (nan, nan) if point cannot be mapped else
#             (elevation, azimuth)
#             arguments can be numpy arrays or scalars
#         """
#         r = self._r
#         rxy = np.sqrt(x*x + y*y)
# 
#         elev = np.arcsin(1-(rxy/r)**2)
#         azim = np.arctan2(-y, -x)
# 
#         # this angle is nan if rxy = 0 but can be anything
#         try:
#             azim[np.isnan(azim)] = 0
#         except TypeError:  # Thrown if azim is scalar
#             if np.isnan(azim):
#                 azim = 0
# 
#         try:
#             azim[np.isnan(elev)] = np.nan
#         except TypeError:  # Thrown if azim is scalar
#             if np.isnan(elev):
#                 azim = np.nan
# 
#         elev, azim = self.x_rotationmap.map(elev, azim)
#         return self.rotationmap.map(elev, azim)


import argparse
import atexit
import os
import numpy as np
import pycuda.driver as cuda
import neurokernel.LPU.utils.simpleio as sio
import retina.retina as ret
import retina.geometry.hexagon as hx
import retina.classmapper as cls_map
from retina.screen.map.mapimpl import AlbersProjectionMap

    suffix = config['General']['file_suffix']

    eye_num = config['General']['eye_num']

    eulerangles = config['Retina']['eulerangles']
    radius = config['Retina']['radius']

    rings = config['Retina']['rings']
    steps = config['General']['steps']

    screen_write_step = config['Retina']['screen_write_step']
    config['Retina']['screen_write_step'] = 1
    screen_type = config['Retina']['screentype']
    screen_cls = cls_map.get_screen_cls(screen_type)

    for i in range(eye_num):
        screen = screen_cls(config)
        screen_file = 'intensities_tmp{}.h5'.format(i)
        screen.setup_file(screen_file)
    
        retina_elev_file = 'retina_elev{}.h5'.format(i)
        retina_azim_file = 'retina_azim{}.h5'.format(i)

        screen_dima_file = 'grid_dima{}.h5'.format(i)
        screen_dimb_file = 'grid_dimb{}.h5'.format(i)

        retina_dima_file = 'retina_dima{}.h5'.format(i)
        retina_dimb_file = 'retina_dimb{}.h5'.format(i)


# Path: retina/screen/map/mapimpl.py
# class AlbersProjectionMap(PointMap):
#     """ https://en.wikipedia.org/wiki/Albers_projection
#         Compared to the entry of 8/21/2015
#         (numbers were chosen to have simpler formulas)
#         phi1 = 90, phi2 = 0, phi0 = 90, lambda0 = 90
#         lambda <- 2n (lambda - lambda0) (doubles the area)
#         =>
#         n = 0.5
#         rho0 = 0, C = 1, rho = 2sqrt(1-sin(phi))
#     """
# 
#     def __init__(self, r, eulerangles=None):
#         """ r: radious of the sphere from which the projection is made
#         """
#         self._r = r
#         self.rotationmap = EulerAnglesMap(eulerangles)
#         self.x_rotationmap = EulerAnglesMap(eulerangles=[0, np.pi/2, 0])
# 
#     def map(self, elev, azim):
#         """ Returns (nan, nan) if point cannot be mapped else (x, y)
#             arguments can be numpy arrays or scalars
#         """
#         elev, azim = self.rotationmap.invmap(elev, azim)
#         elev, azim = self.x_rotationmap.invmap(elev, azim)
# 
#         rxy = self._r*np.sqrt(1-np.sin(elev))
#         x = -rxy*np.cos(azim)
#         y = -rxy*np.sin(azim)
#         return (x, y)
# 
#     def invmap(self, x, y):
#         """ Returns (nan, nan) if point cannot be mapped else
#             (elevation, azimuth)
#             arguments can be numpy arrays or scalars
#         """
#         r = self._r
#         rxy = np.sqrt(x*x + y*y)
# 
#         elev = np.arcsin(1-(rxy/r)**2)
#         azim = np.arctan2(-y, -x)
# 
#         # this angle is nan if rxy = 0 but can be anything
#         try:
#             azim[np.isnan(azim)] = 0
#         except TypeError:  # Thrown if azim is scalar
#             if np.isnan(azim):
#                 azim = 0
# 
#         try:
#             azim[np.isnan(elev)] = np.nan
#         except TypeError:  # Thrown if azim is scalar
#             if np.isnan(elev):
#                 azim = np.nan
# 
#         elev, azim = self.x_rotationmap.map(elev, azim)
#         return self.rotationmap.map(elev, azim)


# Path: examples/retina_demo/gen_input.py
import argparse
import atexit
import os
import numpy as np
import pycuda.driver as cuda
import neurokernel.LPU.utils.simpleio as sio
import retina.retina as ret
import retina.geometry.hexagon as hx
import retina.classmapper as cls_map
from retina.screen.map.mapimpl import AlbersProjectionMap


    suffix = config['General']['file_suffix']

    eye_num = config['General']['eye_num']

    eulerangles = config['Retina']['eulerangles']
    radius = config['Retina']['radius']

    rings = config['Retina']['rings']
    steps = config['General']['steps']

    screen_write_step = config['Retina']['screen_write_step']
    config['Retina']['screen_write_step'] = 1
    screen_type = config['Retina']['screentype']
    screen_cls = cls_map.get_screen_cls(screen_type)

    for i in range(eye_num):
        screen = screen_cls(config)
        screen_file = 'intensities_tmp{}.h5'.format(i)
        screen.setup_file(screen_file)
    
        retina_elev_file = 'retina_elev{}.h5'.format(i)
        retina_azim_file = 'retina_azim{}.h5'.format(i)

        screen_dima_file = 'grid_dima{}.h5'.format(i)
        screen_dimb_file = 'grid_dimb{}.h5'.format(i)

        retina_dima_file = 'retina_dima{}.h5'.format(i)
        retina_dimb_file = 'retina_dimb{}.h5'.format(i)


        input_file = 'retina_input{}.h5'.format(i)