|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import pysteps |
| 6 | +from pysteps.tests.helpers import smart_assert |
| 7 | + |
| 8 | +pytest.importorskip("pyproj") |
| 9 | +pytest.importorskip("osgeo") |
| 10 | + |
| 11 | +root_path = pysteps.rcparams.data_sources["fmi_geotiff"]["root_path"] |
| 12 | +filename = os.path.join( |
| 13 | + root_path, |
| 14 | + "20160928", |
| 15 | + "201609281600_FINUTM.tif", |
| 16 | +) |
| 17 | +precip, _, metadata = pysteps.io.import_fmi_geotiff(filename) |
| 18 | + |
| 19 | + |
| 20 | +def test_io_import_fmi_geotiff_shape(): |
| 21 | + """Test the shape of the read file.""" |
| 22 | + assert precip.shape == (7316, 4963) |
| 23 | + |
| 24 | + |
| 25 | +expected_proj = ( |
| 26 | + "+proj=utm +zone=35 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" |
| 27 | +) |
| 28 | + |
| 29 | +# test_geodata: list of (variable,expected,tolerance) tuples |
| 30 | +test_geodata = [ |
| 31 | + ("projection", expected_proj, None), |
| 32 | + ("x1", -196593.0043142295908183, 1e-10), |
| 33 | + ("x2", 1044176.9413554778, 1e-10), |
| 34 | + ("y1", 6255329.6988206729292870, 1e-10), |
| 35 | + ("y2", 8084432.005259146, 1e-10), |
| 36 | + ("xpixelsize", 250.0040188736061566, 1e-6), |
| 37 | + ("ypixelsize", 250.0139839309011904, 1e-6), |
| 38 | + ("cartesian_unit", "m", None), |
| 39 | + ("yorigin", "upper", None), |
| 40 | +] |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.parametrize("variable, expected, tolerance", test_geodata) |
| 44 | +def test_io_import_fmi_pgm_geodata(variable, expected, tolerance): |
| 45 | + """Test the GeoTIFF and metadata reading.""" |
| 46 | + smart_assert(metadata[variable], expected, tolerance) |
0 commit comments