Skip to content

Commit

Permalink
Add test_convert_proj4_to_grid_mapping()
Browse files Browse the repository at this point in the history
Function added to tests/test_exporters.py
  • Loading branch information
FelixE91 committed Jul 18, 2024
1 parent 8f06737 commit 0ee2080
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pysteps/tests/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 0ee2080

Please sign in to comment.