Skip to content

Commit

Permalink
Add test for interpolate band arg
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Oct 10, 2023
1 parent 199dc4e commit 87aa00f
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions tests/api/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import tempfile
import unittest
import warnings
import shutil
from pathlib import Path

import numpy as np
from jigsawpy import jigsaw_msh_t
from pyproj import CRS
from shapely import geometry

from ocsmesh import utils
from ocsmesh.mesh.mesh import Mesh
from ocsmesh.mesh.mesh import Mesh, Raster



Expand Down Expand Up @@ -319,11 +321,64 @@ def test_specify_boundary_on_mesh_with_no_boundary(self):

class RasterInterpolation(unittest.TestCase):

def setUp(self):
self.tdir = Path(tempfile.mkdtemp())

msht1 = utils.create_rectangle_mesh(
nx=13, ny=5, x_extent=(-73.9, -71.1), y_extent=(40.55, 40.85),
holes=[],
)
msht1.crs = CRS.from_user_input(4326)
msht2 = utils.create_rectangle_mesh(
nx=11, ny=7, x_extent=(-73.9, -71.1), y_extent=(40.55, 40.85),
holes=[],
)
msht2.crs = CRS.from_user_input(4326)
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', category=UserWarning,
message='Input mesh has no CRS information'
)
self.mesh1 = Mesh(msht1)
self.mesh2 = Mesh(msht2)

self.rast = self.tdir / 'rast.tif'

rast_xy = np.mgrid[-74:-71:0.1, 40.9:40.5:-0.01]
rast_z = np.ones((rast_xy.shape[1], rast_xy.shape[2], 2))
rast_z[:, :, 1] = 2
utils.raster_from_numpy(
self.rast, rast_z, rast_xy, 4326
)


def tearDown(self):
shutil.rmtree(self.tdir)


def test_interpolation_io(self):
self.assert(False)
rast = Raster(self.rast)

self.mesh1.interpolate(rast)
self.assertTrue(np.isclose(self.mesh1.value, 1).all())

# TODO: Improve the assertion!
with self.assertRaises(Exception):
self.mesh1.interpolate(self.mesh2)


def test_interpolation_band(self):
self.assert(False)
rast = Raster(self.rast)

self.mesh1.interpolate(rast)
self.assertTrue(np.isclose(self.mesh1.value, 1).all())

self.mesh1.interpolate(rast, band=2)
self.assertTrue(np.isclose(self.mesh1.value, 2).all())


# TODO Add more interpolation tests


if __name__ == '__main__':
unittest.main()

0 comments on commit 87aa00f

Please sign in to comment.