# Path: lmatools/coordinateSystems.py
# class GeostationaryFixedGridSystem(CoordinateSystem):
# 
#     def __init__(self, subsat_lon=0.0, subsat_lat=0.0, sweep_axis='y',
#                  sat_ecef_height=35785831.0,
#                  ellipse='WGS84', datum='WGS84'):
#         """
#         Satellite height is with respect to the ellipsoid. Fixed grid
#         coordinates are in radians.
#         """
#         # self.ECEFxyz = proj4.Proj(proj='cart', ellps=ellipse)#, datum=datum)
#         self.ECEFxyz = proj4.Proj(proj='geocent', ellps=ellipse)#, datum=datum)
#         self.fixedgrid = proj4.Proj(proj='geos', lon_0=subsat_lon,
#             lat_0=subsat_lat, h=sat_ecef_height, x_0=0.0, y_0=0.0,
#             units='m', sweep=sweep_axis, ellps=ellipse)
#         self.h=sat_ecef_height
# 
#     def toECEF(self, x, y, z):
#         X, Y, Z = x*self.h, y*self.h, z*self.h
#         return proj4.transform(self.fixedgrid, self.ECEFxyz, X, Y, Z)
# 
#     def fromECEF(self, x, y, z):
#         X, Y, Z = proj4.transform(self.ECEFxyz, self.fixedgrid, x, y, z)
#         return X/self.h, Y/self.h, Z/self.h
# 
# class GeographicSystem(CoordinateSystem):
#     """
#     Coordinate system defined on the surface of the earth using latitude,
#     longitude, and altitude, referenced by default to the WGS84 ellipse.
# 
#     Alternately, specify the ellipse shape using an ellipse known
#     to pyproj, or [NOT IMPLEMENTED] specify r_equator and r_pole directly.
#     """
#     def __init__(self, ellipse='WGS84', datum='WGS84',
#                  r_equator=None, r_pole=None):
#         if (r_equator is not None) | (r_pole is not None):
#             if r_pole is None:
#                 r_pole=r_equator
#             self.ERSlla = proj4.Proj(proj='latlong', a=r_equator, b=r_pole)
#         else:
#             # lat lon alt in some earth reference system
#             self.ERSlla = proj4.Proj(proj='latlong', ellps=ellipse, datum=datum)
#         self.ERSxyz = proj4.Proj(proj='geocent', ellps=ellipse, datum=datum)
#     def toECEF(self, lon, lat, alt):
#         lat = atleast_1d(lat) # proj doesn't like scalars
#         lon = atleast_1d(lon)
#         alt = atleast_1d(alt)
#         if (lat.shape[0] == 0): return lon, lat, alt # proj doesn't like empties
#         projectedData = array(proj4.transform(self.ERSlla, self.ERSxyz, lon, lat, alt ))
#         if len(projectedData.shape) == 1:
#             return projectedData[0], projectedData[1], projectedData[2]
#         else:
#             return projectedData[0,:], projectedData[1,:], projectedData[2,:]
# 
#     def fromECEF(self, x, y, z):
#         x = atleast_1d(x) # proj doesn't like scalars
#         y = atleast_1d(y)
#         z = atleast_1d(z)
#         if (x.shape[0] == 0): return x, y, z # proj doesn't like empties
#         projectedData = array(proj4.transform(self.ERSxyz, self.ERSlla, x, y, z ))
#         if len(projectedData.shape) == 1:
#             return projectedData[0], projectedData[1], projectedData[2]
#         else:
#             return projectedData[0,:], projectedData[1,:], projectedData[2,:]


from lmatools.coordinateSystems import GeostationaryFixedGridSystem, GeographicSystem
from numpy.testing import assert_allclose


def test_fixed_grid_GOESR():
    """ Tests from the GOES-R PUG Volume 3, L1b data """
    sat_lon_nadir = -75.0
    goes_sweep = 'x' # Meteosat is 'y'
    ellipse = 'GRS80'
    datum = 'WGS84'
    sat_ecef_height=35786023.0
        

# Path: lmatools/coordinateSystems.py
# class GeostationaryFixedGridSystem(CoordinateSystem):
# 
#     def __init__(self, subsat_lon=0.0, subsat_lat=0.0, sweep_axis='y',
#                  sat_ecef_height=35785831.0,
#                  ellipse='WGS84', datum='WGS84'):
#         """
#         Satellite height is with respect to the ellipsoid. Fixed grid
#         coordinates are in radians.
#         """
#         # self.ECEFxyz = proj4.Proj(proj='cart', ellps=ellipse)#, datum=datum)
#         self.ECEFxyz = proj4.Proj(proj='geocent', ellps=ellipse)#, datum=datum)
#         self.fixedgrid = proj4.Proj(proj='geos', lon_0=subsat_lon,
#             lat_0=subsat_lat, h=sat_ecef_height, x_0=0.0, y_0=0.0,
#             units='m', sweep=sweep_axis, ellps=ellipse)
#         self.h=sat_ecef_height
# 
#     def toECEF(self, x, y, z):
#         X, Y, Z = x*self.h, y*self.h, z*self.h
#         return proj4.transform(self.fixedgrid, self.ECEFxyz, X, Y, Z)
# 
#     def fromECEF(self, x, y, z):
#         X, Y, Z = proj4.transform(self.ECEFxyz, self.fixedgrid, x, y, z)
#         return X/self.h, Y/self.h, Z/self.h
# 
# class GeographicSystem(CoordinateSystem):
#     """
#     Coordinate system defined on the surface of the earth using latitude,
#     longitude, and altitude, referenced by default to the WGS84 ellipse.
# 
#     Alternately, specify the ellipse shape using an ellipse known
#     to pyproj, or [NOT IMPLEMENTED] specify r_equator and r_pole directly.
#     """
#     def __init__(self, ellipse='WGS84', datum='WGS84',
#                  r_equator=None, r_pole=None):
#         if (r_equator is not None) | (r_pole is not None):
#             if r_pole is None:
#                 r_pole=r_equator
#             self.ERSlla = proj4.Proj(proj='latlong', a=r_equator, b=r_pole)
#         else:
#             # lat lon alt in some earth reference system
#             self.ERSlla = proj4.Proj(proj='latlong', ellps=ellipse, datum=datum)
#         self.ERSxyz = proj4.Proj(proj='geocent', ellps=ellipse, datum=datum)
#     def toECEF(self, lon, lat, alt):
#         lat = atleast_1d(lat) # proj doesn't like scalars
#         lon = atleast_1d(lon)
#         alt = atleast_1d(alt)
#         if (lat.shape[0] == 0): return lon, lat, alt # proj doesn't like empties
#         projectedData = array(proj4.transform(self.ERSlla, self.ERSxyz, lon, lat, alt ))
#         if len(projectedData.shape) == 1:
#             return projectedData[0], projectedData[1], projectedData[2]
#         else:
#             return projectedData[0,:], projectedData[1,:], projectedData[2,:]
# 
#     def fromECEF(self, x, y, z):
#         x = atleast_1d(x) # proj doesn't like scalars
#         y = atleast_1d(y)
#         z = atleast_1d(z)
#         if (x.shape[0] == 0): return x, y, z # proj doesn't like empties
#         projectedData = array(proj4.transform(self.ERSxyz, self.ERSlla, x, y, z ))
#         if len(projectedData.shape) == 1:
#             return projectedData[0], projectedData[1], projectedData[2]
#         else:
#             return projectedData[0,:], projectedData[1,:], projectedData[2,:]


# Path: lmatools/test/test_coords.py
from lmatools.coordinateSystems import GeostationaryFixedGridSystem, GeographicSystem
from numpy.testing import assert_allclose



def test_fixed_grid_GOESR():
    """ Tests from the GOES-R PUG Volume 3, L1b data """
    sat_lon_nadir = -75.0
    goes_sweep = 'x' # Meteosat is 'y'
    ellipse = 'GRS80'
    datum = 'WGS84'
    sat_ecef_height=35786023.0
        

    geofixcs = GeostationaryFixedGridSystem(subsat_lon=sat_lon_nadir,