# Path: lmatools/stream/subset.py
# def coroutine(func):
#     def start(*args,**kwargs):
#         cr = func(*args,**kwargs)
#         next(cr)
#         return cr
#     return start
# 
# Path: lmatools/density_tools.py
# def unique_vectors(*args, **kwargs):
#     """ Given D, N-element arrays of vector components return the
#         unique vectors as a (D, N_reduced) array. If return_indices_only=True
#         is true (the default) then return the N_reduced indices of the original
#         arrays corresponding to the unique vectors.
#         
#         args: x0_i, x1_i, x2_i, ...
#             where each x0, x1, etc. are discretized (bin index) values of point
#             locations.
#         """
#     try:
#         return_indices_only=kwargs['return_indices_only']
#     except KeyError:
#         return_indices_only=True
#         
#     vector_len = len(args)
#     itemsize = max((x_i.itemsize for x_i in args))
#     inttype = 'i{0:d}'.format(itemsize)
#     
#     vec_cast = tuple((x_i.astype(inttype) for x_i in args))
#         
#     # Because we do casting below, ascontiguousarray is important
#     locs = np.ascontiguousarray(np.vstack(vec_cast).T)
# 
# 	# Find unique rows (unique grid cells occupied per flash) by casting to a set
# 	# of strings comprised of the bytes that make up the rows. Strings are not serialized, just ints cast to byte strings.
# 	# Based on the example at
# 	# http://www.mail-archive.com/numpy-discussion@scipy.org/msg04176.html
#     # which doesn't quite get it right: it returns unique elements.
#     vectorbytes = 'S{0:d}'.format(itemsize*vector_len)
#     unq, unq_index = np.unique(locs.view(vectorbytes), return_index=True)
# 
#     if return_indices_only==True:
#         return unq_index
#     else:
#         # this is unnecessary if we only need the row indices
#         unq_restored = unq.view(inttype).reshape(unq.shape[0],vector_len)
#         return unq_restored, unq_index


import glob
import gc
import numpy as np
import logging
from lmatools.stream.subset import coroutine
from lmatools.density_tools import unique_vectors


            
# class map_projector(object):
#     def __init__(self, ctr_lat, ctr_lon, proj_name='eqc'):
#         self.mapProj = MapProjection(projection=proj_name, ctrLat=ctr_lat, ctrLon=ctr_lon, lat_ts=ctr_lat, lon_0=ctr_lon)
#         self.geoProj = GeographicSystem()
# 
#     def __call__(self, lon, lat, alt):
#         x,y,z = self.mapProj.fromECEF( 
#                 *self.geoProj.toECEF(lon, lat, alt)
#                 )
#         return x, y, z
#         
# @coroutine
# def map_projector(ctr_lat, ctr_lon, target, proj_name='eqc'):
#     mapProj = MapProjection(projection=proj_name, ctrLat=ctr_lat, ctrLon=ctr_lon, lat_ts=ctr_lat, lon_0=ctr_lon)
#     geoProj = GeographicSystem()
#     while True:
#         lon, lat, alt = (yield)
#         x,y,z = self.mapProj.fromECEF( 
#                 *self.geoProj.toECEF(lon, lat, alt)
#                 )
#         target.send((x,y,z))

# -------------------------------------------------------------------------- 
# -------------------------------------------------------------------------- 
# -------------------------------------------------------------------------- 



# Path: lmatools/stream/subset.py
# def coroutine(func):
#     def start(*args,**kwargs):
#         cr = func(*args,**kwargs)
#         next(cr)
#         return cr
#     return start
# 
# Path: lmatools/density_tools.py
# def unique_vectors(*args, **kwargs):
#     """ Given D, N-element arrays of vector components return the
#         unique vectors as a (D, N_reduced) array. If return_indices_only=True
#         is true (the default) then return the N_reduced indices of the original
#         arrays corresponding to the unique vectors.
#         
#         args: x0_i, x1_i, x2_i, ...
#             where each x0, x1, etc. are discretized (bin index) values of point
#             locations.
#         """
#     try:
#         return_indices_only=kwargs['return_indices_only']
#     except KeyError:
#         return_indices_only=True
#         
#     vector_len = len(args)
#     itemsize = max((x_i.itemsize for x_i in args))
#     inttype = 'i{0:d}'.format(itemsize)
#     
#     vec_cast = tuple((x_i.astype(inttype) for x_i in args))
#         
#     # Because we do casting below, ascontiguousarray is important
#     locs = np.ascontiguousarray(np.vstack(vec_cast).T)
# 
# 	# Find unique rows (unique grid cells occupied per flash) by casting to a set
# 	# of strings comprised of the bytes that make up the rows. Strings are not serialized, just ints cast to byte strings.
# 	# Based on the example at
# 	# http://www.mail-archive.com/numpy-discussion@scipy.org/msg04176.html
#     # which doesn't quite get it right: it returns unique elements.
#     vectorbytes = 'S{0:d}'.format(itemsize*vector_len)
#     unq, unq_index = np.unique(locs.view(vectorbytes), return_index=True)
# 
#     if return_indices_only==True:
#         return unq_index
#     else:
#         # this is unnecessary if we only need the row indices
#         unq_restored = unq.view(inttype).reshape(unq.shape[0],vector_len)
#         return unq_restored, unq_index


# Path: lmatools/grid/density_to_files.py
import glob
import gc
import numpy as np
import logging
from lmatools.stream.subset import coroutine
from lmatools.density_tools import unique_vectors



            
# class map_projector(object):
#     def __init__(self, ctr_lat, ctr_lon, proj_name='eqc'):
#         self.mapProj = MapProjection(projection=proj_name, ctrLat=ctr_lat, ctrLon=ctr_lon, lat_ts=ctr_lat, lon_0=ctr_lon)
#         self.geoProj = GeographicSystem()
# 
#     def __call__(self, lon, lat, alt):
#         x,y,z = self.mapProj.fromECEF( 
#                 *self.geoProj.toECEF(lon, lat, alt)
#                 )
#         return x, y, z
#         
# @coroutine
# def map_projector(ctr_lat, ctr_lon, target, proj_name='eqc'):
#     mapProj = MapProjection(projection=proj_name, ctrLat=ctr_lat, ctrLon=ctr_lon, lat_ts=ctr_lat, lon_0=ctr_lon)
#     geoProj = GeographicSystem()
#     while True:
#         lon, lat, alt = (yield)
#         x,y,z = self.mapProj.fromECEF( 
#                 *self.geoProj.toECEF(lon, lat, alt)
#                 )
#         target.send((x,y,z))

# -------------------------------------------------------------------------- 
# -------------------------------------------------------------------------- 
# -------------------------------------------------------------------------- 



@coroutine