From 0ee2080156de3d776dd257a2ce115fad33e1bdbe Mon Sep 17 00:00:00 2001 From: Felix Erdmann Date: Thu, 18 Jul 2024 10:11:47 +0200 Subject: [PATCH] Add test_convert_proj4_to_grid_mapping() Function added to tests/test_exporters.py --- pysteps/tests/test_exporters.py | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/pysteps/tests/test_exporters.py b/pysteps/tests/test_exporters.py index f72c248bb..2cdb1bbf8 100644 --- a/pysteps/tests/test_exporters.py +++ b/pysteps/tests/test_exporters.py @@ -13,6 +13,7 @@ from pysteps.io.exporters import close_forecast_files from pysteps.io.exporters import export_forecast_dataset from pysteps.io.exporters import initialize_forecast_exporter_netcdf +from pysteps.io.exporters import _convert_proj4_to_grid_mapping from pysteps.tests.helpers import get_precipitation_fields, get_invalid_mask # Test arguments @@ -135,3 +136,61 @@ def test_io_export_netcdf_one_member_one_time_step( precip_new, _ = import_netcdf_pysteps(output_file_path, fillna=-1000) new_invalid_mask = precip_new == -1000 assert (new_invalid_mask == invalid_mask).all() + + +@pytest.mark.paramterize( + ["proj4str", "expected_value"], + [ + ( + "+proj=lcc +lat_1=49.83333333333334 +lat_2=51.16666666666666 +lat_0=50.797815 +lon_0=4.359215833333333 +x_0=649328 +y_0=665262 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ", + ( + "lcc", + "lambert_conformal_conic", + { + "false_easting": 649328.0, + "false_northing": 665262.0, + "longitude_of_central_meridian": 4.359215833333333, + "latitude_of_projection_origin": 50.797815, + "standard_parallel": (49.83333333333334, 51.16666666666666), + "reference_ellipsoid_name": "GRS80", + "towgs84": "0,0,0,0,0,0,0", + }, + ), + ), + ( + "+proj=aea +lat_0=-37.852 +lon_0=144.752 +lat_1=-18.0 +lat_2=-36.0 +a=6378.137 +b=6356.752 +x_0=0 +y_0=0", + ( + "proj", + "albers_conical_equal_area", + { + "false_easting": 0.0, + "false_northing": 0.0, + "longitude_of_central_meridian": 144.752, + "latitude_of_projection_origin": -37.852, + "standard_parallel": (-18.0, -36.0), + }, + ), + ), + ( + "+proj=stere +lat_0=90 +lon_0=0.0 +lat_ts=60.0 +a=6378.137 +b=6356.752 +x_0=0 +y_0=0", + ( + "polar_stereographic", + "polar_stereographic", + { + "straight_vertical_longitude_from_pole": 0.0, + "latitude_of_projection_origin": 90.0, + "standard_parallel": 60.0, + "false_easting": 0.0, + "false_northing": 0.0, + }, + ), + ), + ], +) +def test_convert_proj4_to_grid_mapping(proj4str, expected_value): + """ + test the grid mapping in function _convert_proj4_to_grid_mapping() + """ + output = _convert_proj4_to_grid_mapping(proj4str) + + assert output == expected_value