Ejemplo n.º 1
0
    def test_geodetic(self):
        ecef = ECEF(x=6378137, y=0, z=0)
        geod = Geodetic(ecef, reference="ELLIPSOID")
        ecef1 = geod.geodetic_to_ecef()
        geod1 = ecef.ecef_to_geodetic(reference="ELLIPSOID")
        horz = geod.geodetic_to_horizontal()
        grnd = geod.geodetic_to_grandcs()
        ltpf = LTP(location=self.location, orientation="NWU")
        ltp = geod.geodetic_to_ltp(ltpf)

        # Check the method transformation
        self.assertQuantity(geod, self.location, 6)
        self.assertQuantity(geod1, self.location, 6)
        self.assertQuantity(ecef, ecef1, 6)
        self.assertCartesian(ecef, ecef1, 6)

        # RK TODO: Add more test.
        self.assertEqual(geod.reference, "ELLIPSOID")
        self.assertQuantity(ltp.location, ecef)
        # check input value is either number or array of numbers.
        with self.assertRaises(TypeError) as context:
            Geodetic(azimuth="zero", elevation=0, norm=0)
        # check input argument is of knonw coordinate system.
        with self.assertRaises(TypeError) as context:
            Geodetic(numpy.ones(10))
Ejemplo n.º 2
0
    def test_topography_distance(self):
        # Fetch a test tile
        # geo = GeodeticRepresentation(latitude=39.5 * u.deg,
        #                             longitude=90.5 * u.deg)
        # geo = Geodetic(latitude=39.5, longitude=90.5, height=0.)
        geo = Geodetic(latitude=41.27, longitude=96.53, height=0)
        # c = ECEF(geo)
        topography.update_data(geo)

        # Test the distance getter
        z = topography.elevation(geo) + topography.geoid_undulation(geo)
        # z = topography.elevation(c) + topography.geoid_undulation(c)
        # c = ECEF(GeodeticRepresentation(latitude=geo.latitude,
        #                                longitude=geo.longitude,
        #                                height=z - 1 * u.m))

        v0 = GRANDCS(x=100, y=10, z=-0.1, location=geo)
        x0 = GRANDCS(x=-8000, y=12000, z=2200,
                     location=geo)  # Initial point along traj (in LTP frame)
        v = numpy.matmul(
            x0.basis.T, v0
        )  # GRANDCS --> ECEF. input direction must be in ECEF. ToDo: Fix this.

        # v = LTP(0 * u.deg, 45 * u.deg, representation_type='horizontal',
        #        location = c)

        # d = topography.distance(c, v, 10 * u.m)
        d = topography.distance(
            x0, v)  # (pos, dir, max_dist). max_dist is optional

        self.assertEqual(d.size, 1)
        # self.assertEqual(d.unit, u.m)
        self.assertFalse(numpy.isnan(d))
        self.assertTrue(d > 0)

        # d = topography.distance(c, v, 50 * u.cm)
        d = topography.distance(x0, v, 50)
        self.assertTrue(numpy.isnan(d))

        o = numpy.ones(10)
        # c = ECEF(GeodeticRepresentation(latitude=geo.latitude * o,
        #                                longitude=geo.longitude * o,
        #                                height=(z - 1 * u.m) * o))
        c = Geodetic(latitude=41.27 * o,
                     longitude=96.53 * o,
                     height=(z - 1) * o)
        # d = topography.distance(c, v, 10 * u.m)
        d = topography.distance(c, v * o)
        self.assertEqual(d.size, o.size)
        # self.assertEqual(d.unit, u.m)
        for i in range(o.size):
            self.assertTrue(d[i] < 0)
Ejemplo n.º 3
0
    def __init__(self, *args):
        super().__init__(*args)

        self.obstime = "2020-01-01"
        self.location = Geodetic(
            latitude=0.0, longitude=0.0, height=0.0, reference="ELLIPSOID"
        )
Ejemplo n.º 4
0
 def test_geoid(self):
     # Test the undulation getter
     # c = ECEF(GeodeticRepresentation(latitude=45.5 * u.deg,
     #                                longitude=3.5 * u.deg))
     c = ECEF(Geodetic(latitude=45.5, longitude=3.5, height=0))
     # z = tools.topography.geoid_undulation(c)
     z = topography.geoid_undulation(c)
     self.assertEqual(z.size, 1)
Ejemplo n.º 5
0
    def test_topography_elevation(self):
        # Fetch a test tile
        # geo = GeodeticRepresentation(latitude=39.5 * u.deg,
        #                             longitude=90.5 * u.deg)
        geo = Geodetic(latitude=39.5, longitude=90.5, height=0)
        c = ECEF(geo)
        topography.update_data(c)

        # Test the global topography getter
        # z0 = topography.elevation(c)
        z0 = topography.elevation(geo)
        self.assertEqual(z0.size, 1)
        #   self.assertEqual(z0.unit, u.m)
        self.assertFalse(numpy.isnan(z0))

        z1 = topography.elevation(geo, reference="ELLIPSOID")
        z1 -= topography.geoid_undulation(geo)
        self.assertEqual(z1.size, 1)
        # self.assertEqual(z1.unit, u.m)
        self.assertFalse(numpy.isnan(z1))

        self.assertQuantity(z0, z1)

        o = numpy.ones(10)
        # cv = ECEF(GeodeticRepresentation(latitude=geo.latitude * o,
        #                                 longitude=geo.longitude * o))
        cv = ECEF(
            Geodetic(
                latitude=geo.latitude * o,
                longitude=geo.longitude * o,
                height=geo.height * o,
            ))
        z2 = topography.elevation(cv)
        self.assertEqual(z2.size, o.size)
        # self.assertEqual(z2.unit, u.m)
        for i in range(o.size):
            self.assertQuantity(z2[i], z0)

        # Test the local topography getter
        # cl = LTP(0 << u.m, 0 << u.m, 0 << u.m, location=c)
        cl = LTP(x=0, y=0, z=0, location=c, orientation="NWU")
        z3 = topography.elevation(cl, "LOCAL")
        self.assertEqual(z3.size, 1)
        # self.assertEqual(z3.unit, u.m)
        self.assertQuantity(z3, z1, 7)
Ejemplo n.º 6
0
    def test_topography_cache(self):
        # Check the cache config
        self.assertEqual(topography.model(), "SRTMGL1")
        self.assertRegex(str(topography.cachedir()),
                         "^.*/grand/tools/data/topography")

        # Clear the cache
        topography.update_data(clear=True)
        self.assertFalse([p for p in topography.cachedir().glob("**/*")])

        # Fetch data
        # c = ECEF(GeodeticRepresentation(latitude=39.5 * u.deg,
        #                                longitude=90.5 * u.deg))
        c = ECEF(Geodetic(latitude=39.5, longitude=90.5, height=0))
        topography.update_data(c)
        self.assertTrue(
            (topography.cachedir() / "N39E090.SRTMGL1.hgt").exists())

        # c = ECEF(GeodeticRepresentation(
        #    latitude=u.Quantity((39.5, 40.5)) * u.deg,
        #    longitude=u.Quantity((90.5, 90.5)) * u.deg))
        c = ECEF(
            Geodetic(
                latitude=numpy.array([39.5, 40.5]),
                longitude=numpy.array([90.5, 90.5]),
                height=numpy.array([0, 0]),
            ))
        topography.update_data(c)
        self.assertTrue(
            (topography.cachedir() / "N40E090.SRTMGL1.hgt").exists())

        # c = ECEF(GeodeticRepresentation(latitude=40 * u.deg,
        #                                longitude=90.5 * u.deg))
        c = ECEF(Geodetic(latitude=40, longitude=90.5, height=0))
        # topography.update_data(c, radius=100 * u.km)
        topography.update_data(c, radius=100e3)  # RK radius in meters.
        self.assertTrue(
            (topography.cachedir() / "N39E089.SRTMGL1.hgt").exists())
        self.assertTrue(
            (topography.cachedir() / "N39E091.SRTMGL1.hgt").exists())
        self.assertTrue(
            (topography.cachedir() / "N40E089.SRTMGL1.hgt").exists())
        self.assertTrue(
            (topography.cachedir() / "N40E091.SRTMGL1.hgt").exists())
Ejemplo n.º 7
0
    def test_custom_topography(self):
        # Fetch a test tile
        # dirname, basename = Path('tests/topography'), 'N39E090.SRTMGL1.hgt'
        dirname, basename = Path("../topography"), "N39E090.SRTMGL1.hgt"
        path = dirname / basename
        if not path.exists():
            dirname.mkdir(exist_ok=True)
            with path.open("wb") as f:
                f.write(store.get(basename))

        # Test the topography getter
        topo = Topography(dirname)
        # c = ECEF(GeodeticRepresentation(latitude=39.5 * u.deg,
        #                                longitude=90.5 * u.deg))
        c = ECEF(Geodetic(latitude=39.5, longitude=90.5, height=0))
        z = topo.elevation(c)
        self.assertEqual(z.size, 1)
        # self.assertEqual(z.unit, u.m)
        self.assertFalse(numpy.isnan(z))
Ejemplo n.º 8
0
#! /usr/bin/env python
from grand import ECEF, Geodetic, LTP, topography
import matplotlib.pyplot as pl
import numpy as np


# Set the local frame origin
origin = Geodetic(
    latitude=42.923516,
    longitude=86.716069,
    height=0,
)

# Get the corresponding topography data. Note that does are dowloaded from the
# web and cached which might take some time. Reducing the area results in less
# data to be downloaded, i.e. speeding up this step
radius = 200000  # m
topography.update_data(origin, radius=radius)


# Generate a grid of local coordinates using numpy.meshgrid
x = np.linspace(-1 * radius, radius, 1001)
y = np.linspace(-1 * radius, radius, 1001)
X, Y = np.meshgrid(x, y)
coordinates = LTP(
    x=X.flatten(),
    y=Y.flatten(),
    z=np.zeros(X.size),
    location=origin,
    orientation="ENU",
    magnetic=False,
Ejemplo n.º 9
0
    def test_readwrite(self):
        r0 = CartesianRepresentation(x=1, y=2, z=3)
        u0 = SphericalRepresentation(theta=90, phi=-90, r=1)
        c = numpy.array((1, 2))
        r1 = CartesianRepresentation(x=c, y=c, z=c)
        c = 90
        u1 = SphericalRepresentation(theta=c, phi=c, r=1)
        loc = Geodetic(latitude=45, longitude=6, height=0)

        elements = {
            "primary":
            "pà",
            "bytes":
            b"0100011",
            "id":
            1,
            "energy0":
            1.0,
            "energy1":
            1,
            "data":
            numpy.array(((1, 2, 3), (4, 5, 6))),
            "position0":
            r0,
            "position1": [r0.x, r0.y, r0.z],
            "position2":
            r0,
            "position3":
            r1,
            "direction0":
            u0,
            "direction1":
            u1,
            "frame0":
            ECEF(x=0, y=0, z=0, obstime="2010-01-01"),
            "frame1":
            LTP(
                x=0,
                y=0,
                z=0,
                location=loc,
                obstime="2010-01-01",
                magnetic=True,
                orientation="NWU",
            )
            # rotation=Rotation.from_euler('z', 90 * u.deg)) #RK. TODO.
        }

        with io.open(self.path, "w") as root:
            for k, v in elements.items():
                root.write(k, v)

        with io.open(self.path) as root:
            for name, element in root.elements:
                a = elements[name]
                print(a, type(a))
                if hasattr(a, "shape"):
                    self.assertEqual(a.shape, element.shape)

                # RK: TODO: ECEF, LTP is not detected by isinstance, instead
                #           they are seen as CartesianRepresentation objects.
                if isinstance(a, CartesianRepresentation):
                    self.assertCartesian(a, element)
                elif isinstance(a, SphericalRepresentation):
                    self.assertSpherical(a, element)
                elif isinstance(a, numpy.ndarray):
                    self.assertEqual(a.shape, element.shape)
                    self.assertArray(a, element)
                elif isinstance(a, ECEF):
                    self.assertEqual(a.obstime, element.obstime)
                elif isinstance(a, LTP):
                    self.assertEqual(a.obstime, element.obstime)
                    self.assertCartesian(a.location, element.location, 8)
                    self.assertEqual(a.orientation, element.orientation)
                    self.assertEqual(a.magnetic, element.magnetic)
                    # self.assertArray(a.rotation.matrix, element.rotation.matrix)
                    self.assertArray(a.basis, element.basis)
                else:
                    self.assertEqual(a, element)