Ejemplo n.º 1
0
Archivo: point.py Proyecto: angri/nhlib
    def from_vector(cls, vector):
        """
        Create a point object from a 3d vector in Cartesian space.

        :param vector:
            Tuple, list or numpy array of three float numbers representing
            point coordinates in Cartesian 3d space.
        :returns:
            A :class:`Point` object created from those coordinates.
        """
        return cls(*geo_utils.cartesian_to_spherical(vector))
Ejemplo n.º 2
0
    def from_vector(cls, vector):
        """
        Create a point object from a 3d vector in Cartesian space.

        :param vector:
            Tuple, list or numpy array of three float numbers representing
            point coordinates in Cartesian 3d space.
        :returns:
            A :class:`Point` object created from those coordinates.
        """
        return cls(*geo_utils.cartesian_to_spherical(vector))
Ejemplo n.º 3
0
    def test1(self):
        lons, lats, depths = geo_utils.cartesian_to_spherical(
            numpy.array([[60, -10, -10], [60, -10, 10], [60, 10, 10], [60, 10, -10]], float)
        )
        surface = PlanarSurface(10, 20, 30, *Mesh(lons, lats, depths))
        aaae = numpy.testing.assert_array_almost_equal

        plons, plats, pdepths = geo_utils.cartesian_to_spherical(
            numpy.array([[60, -10, -10], [59, 0, 0], [70, -11, -10]], float)
        )

        dists, xx, yy = surface._project(plons, plats, pdepths)
        aaae(xx, [0, 10, 0])
        aaae(yy, [0, 10, -1])
        aaae(dists, [0, 1, -10])

        lons, lats, depths = surface._project_back(dists, xx, yy)
        aaae(lons, plons)
        aaae(lats, plats)
        aaae(depths, pdepths)
Ejemplo n.º 4
0
    def test1(self):
        lons, lats, depths = geo_utils.cartesian_to_spherical(
            numpy.array([[60, -10, -10], [60, -10, 10],
                         [60, 10, 10], [60, 10, -10]], float)
        )
        surface = PlanarSurface(10, 20, 30, *Mesh(lons, lats, depths))
        aaae = numpy.testing.assert_array_almost_equal

        plons, plats, pdepths = geo_utils.cartesian_to_spherical(
            numpy.array([[60, -10, -10], [59, 0, 0], [70, -11, -10]], float)
        )

        dists, xx, yy =  surface._project(plons, plats, pdepths)
        aaae(xx, [0, 10, 0])
        aaae(yy, [0, 10, -1])
        aaae(dists, [0, 1, -10])

        lons, lats, depths = surface._project_back(dists, xx, yy)
        aaae(lons, plons)
        aaae(lats, plats)
        aaae(depths, pdepths)
Ejemplo n.º 5
0
class SphericalToCartesianAndBackTestCase(unittest.TestCase):
    def _test(self, (lons, lats, depths), vectors):
        res_cart = utils.spherical_to_cartesian(lons, lats, depths)
        self.assertIsInstance(res_cart, numpy.ndarray)
        self.assertTrue(numpy.allclose(vectors, res_cart), str(res_cart))
        res_sphe = utils.cartesian_to_spherical(res_cart)
        self.assertIsInstance(res_sphe, tuple)
        self.assertEqual(len(res_sphe), 3)
        if depths is None:
            depths = numpy.zeros_like(lons)
        self.assertEqual(
            numpy.array(res_sphe).shape,
            numpy.array([lons, lats, depths]).shape)
        self.assertTrue(numpy.allclose([lons, lats, depths], res_sphe),
                        str(res_sphe))
Ejemplo n.º 6
0
    def _project_back(self, dists, xx, yy):
        """
        Convert coordinates in plane's Cartesian space back to spherical
        coordinates.

        Parameters are numpy arrays, as returned from :meth:`_project`, which
        this method does the opposite to.

        :return:
            Tuple of longitudes, latitudes and depths numpy arrays.
        """
        vectors = self.zero_zero \
                  + self.uv1 * xx.reshape(xx.shape + (1, )) \
                  + self.uv2 * yy.reshape(yy.shape + (1, )) \
                  + self.normal * dists.reshape(dists.shape + (1, ))
        return geo_utils.cartesian_to_spherical(vectors)
Ejemplo n.º 7
0
    def _project_back(self, dists, xx, yy):
        """
        Convert coordinates in plane's Cartesian space back to spherical
        coordinates.

        Parameters are numpy arrays, as returned from :meth:`_project`, which
        this method does the opposite to.

        :return:
            Tuple of longitudes, latitudes and depths numpy arrays.
        """
        vectors = self.zero_zero \
                  + self.uv1 * xx.reshape(xx.shape + (1, )) \
                  + self.uv2 * yy.reshape(yy.shape + (1, )) \
                  + self.normal * dists.reshape(dists.shape + (1, ))
        return geo_utils.cartesian_to_spherical(vectors)
Ejemplo n.º 8
0
 def v2p(*vectors):  # "vectors to points"
     return [Point(*coords)
             for coords in zip(*geo_utils.cartesian_to_spherical(
                 numpy.array(vectors, dtype=float)
             ))]
Ejemplo n.º 9
0
 def v2p(*vectors):  # "vectors to points"
     return [Point(*coords)
             for coords in zip(*geo_utils.cartesian_to_spherical(
                 numpy.array(vectors, dtype=float)
             ))]