File: test_spatial_mp.py

package info (click to toggle)
pyresample 1.35.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,880 kB
  • sloc: python: 20,340; cpp: 463; makefile: 105
file content (66 lines) | stat: -rw-r--r-- 3,035 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pyresample, Resampling of remote sensing image data in python
#
# Copyright (C) 2014-2019 PyTroll developers
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Testing the _spatial_mp module."""

import unittest

import numpy as np

import pyresample._spatial_mp as sp


class SpatialMPTest(unittest.TestCase):
    """Test of spatial_mp."""

    def setUp(self):
        """Set up some variables."""
        self.exp_coords = np.array([[6370997., 0, 0],
                                    [6178887.9339746, 1089504.6535337, 1106312.0189715],
                                    [5233097.4664751, 2440233.4244888, 2692499.6776952]])
        self.lon = np.array([0, 10, 25])
        self.lat = np.array([0, 10, 25])
        self.lon32 = self.lon.astype(np.float32)
        self.lat32 = self.lon.astype(np.float32)
        self.lon64 = self.lon.astype(np.float64)
        self.lat64 = self.lon.astype(np.float64)

    def test_cartesian(self):
        """Test the transform_lonlats of class Cartesian."""
        my_cartesian = sp.Cartesian()
        coords_int = my_cartesian.transform_lonlats(self.lon, self.lat)
        coords_float = my_cartesian.transform_lonlats(self.lon64, self.lat64)
        coords_float32 = my_cartesian.transform_lonlats(self.lon32, self.lat32)
        np.testing.assert_almost_equal(coords_float, self.exp_coords, decimal=3)
        np.testing.assert_almost_equal(coords_int, coords_float, decimal=0)
        self.assertIs(type(coords_float32[0, 0]), np.float32)
        self.assertIs(type(coords_float[0, 0]), np.float64)
        self.assertTrue(np.issubdtype(coords_int.dtype, np.floating))

    def test_cartesian_without_ne(self):
        """Test the transform_lonlats of class Cartesian without numexpr."""
        sp.ne = False
        my_cartesian = sp.Cartesian()
        coords_int = my_cartesian.transform_lonlats(self.lon, self.lat)
        coords_float = my_cartesian.transform_lonlats(self.lon64, self.lat64)
        coords_float32 = my_cartesian.transform_lonlats(self.lon32, self.lat32)
        np.testing.assert_almost_equal(coords_float, self.exp_coords, decimal=3)
        np.testing.assert_almost_equal(coords_int, coords_float, decimal=0)
        self.assertIs(type(coords_float32[0, 0]), np.float32)
        self.assertIs(type(coords_float[0, 0]), np.float64)
        self.assertTrue(np.issubdtype(coords_int.dtype, np.floating))