Skip to content

Commit

Permalink
Use Python code for downloading test file
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Nov 13, 2023
1 parent d866216 commit 26287ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
27 changes: 21 additions & 6 deletions tests/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import os
os.system("""
ls /tmp/test_dem.tif > /dev/null
if [ $? -eq 0 ]; then exit; fi
wget https://coast.noaa.gov/htdata/raster2/elevation/NCEI_ninth_Topobathy_2014_8483/northeast_sandy/ncei19_n40x75_w073x75_2015v1.tif -O /tmp/fullsize_dem.tif
gdalwarp -tr 0.0005 0.0005 -r average -overwrite /tmp/fullsize_dem.tif /tmp/test_dem.tif
""")
import tempfile
import urllib.request
from pathlib import Path

from rasterio.enums import Resampling

from ocsmesh.raster import Raster


# Find a better way!
tif_url = (
'https://coast.noaa.gov/htdata/raster2/elevation/NCEI_ninth_Topobathy_2014_8483/northeast_sandy/ncei19_n40x75_w073x75_2015v1.tif'
)
TEST_FILE = os.path.join(tempfile.gettempdir(), 'test_dem.tif')
if not Path(TEST_FILE).exists():
with tempfile.NamedTemporaryFile() as tfp:
urllib.request.urlretrieve(tif_url, filename=tfp.name)
r = Raster(tfp.name)
r.resampling_method = Resampling.average
r.resample(scaling_factor=0.01)
r.save(TEST_FILE)
11 changes: 6 additions & 5 deletions tests/api/hfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import ocsmesh

from tests.api import TEST_FILE
from tests.api.common import (
topo_2rast_1mesh,
)
Expand Down Expand Up @@ -492,7 +493,7 @@ def test_hfun_fast_extent(self):
class SizeFromMesh(unittest.TestCase):

def setUp(self):
rast = ocsmesh.raster.Raster('/tmp/test_dem.tif')
rast = ocsmesh.raster.Raster(TEST_FILE)

hfun_orig = ocsmesh.hfun.hfun.Hfun(rast, hmin=100, hmax=1500)
hfun_orig.add_contour(level=0, expansion_rate=0.001, target_size=100)
Expand Down Expand Up @@ -530,7 +531,7 @@ def test_hfun_raster_cfl_constraint_support(self):
courant_hi = 0.8
courant_lo = 0.2

rast = ocsmesh.raster.Raster('/tmp/test_dem.tif')
rast = ocsmesh.raster.Raster(TEST_FILE)

hfun_raster = ocsmesh.hfun.hfun.Hfun(rast, hmin=100, hmax=5000)
hfun_raster.add_courant_num_constraint(
Expand Down Expand Up @@ -586,7 +587,7 @@ def test_hfun_raster_cfl_constraint_support(self):
)

def test_hfun_raster_cfl_constraint_io(self):
rast = ocsmesh.raster.Raster('/tmp/test_dem.tif')
rast = ocsmesh.raster.Raster(TEST_FILE)
hfun_raster = ocsmesh.hfun.hfun.Hfun(rast, hmin=100, hmax=5000)
self.assertRaises(
ValueError,
Expand Down Expand Up @@ -614,8 +615,8 @@ def test_hfun_coll_cfl_constraint(self):
# TODO: Add subTest

# Creating adjacent rasters from the test raster
rast1 = ocsmesh.raster.Raster('/tmp/test_dem.tif')
rast2 = ocsmesh.raster.Raster('/tmp/test_dem.tif')
rast1 = ocsmesh.raster.Raster(TEST_FILE)
rast2 = ocsmesh.raster.Raster(TEST_FILE)
bounds = rast1.bbox.bounds
bbox1 = geometry.box(
bounds[0], bounds[1], (bounds[0] + bounds[2]) / 2, bounds[3]
Expand Down

0 comments on commit 26287ef

Please sign in to comment.