11import pytest
22import numpy as np
3+ from packaging .version import Version
4+ import imas
5+
6+ _IMAS_GE_2_3 = Version (imas .__version__ ) >= Version ("2.3.0" )
37
48
59def test_status_codes (entry_path ):
@@ -123,7 +127,8 @@ def test_plot_data_smoothing_with_wrong_target_node(entry_path):
123127 assert response .status_code == 466
124128
125129
126- def test_plot_data_2d (entry_path ):
130+ @pytest .mark .parametrize ("expected_unit" , ["m" ] if _IMAS_GE_2_3 else ["mixed" ])
131+ def test_plot_data_2d (entry_path , expected_unit ):
127132 parameters = {
128133 "uri" : f"imas:hdf5?path={ entry_path } #core_profiles/profiles_2d[:]/ion[:]/temperature" ,
129134 }
@@ -147,13 +152,15 @@ def test_plot_data_2d(entry_path):
147152 assert time_coordinate ["description" ] == "Generic time"
148153
149154 dim1_coordinate = response_body ["data" ]["coordinates" ][0 ]
150- assert dim1_coordinate ["name" ] == "dim1"
155+ assert dim1_coordinate ["name" ] == "R" # alias for dim1
156+ assert dim1_coordinate ["unit" ] == expected_unit
151157 assert dim1_coordinate ["target" ] == "#core_profiles/profiles_2d[:]/ion[:]/temperature"
152158 assert dim1_coordinate ["shape" ] == [5 , 3 ]
153159 assert dim1_coordinate ["path" ] == "#core_profiles/profiles_2d[:]/grid/dim1"
154160
155161 dim2_coordinate = response_body ["data" ]["coordinates" ][1 ]
156- assert dim2_coordinate ["name" ] == "dim2"
162+ assert dim2_coordinate ["name" ] == "Z" # alias for dim2
163+ assert dim2_coordinate ["unit" ] == expected_unit
157164 assert dim2_coordinate ["target" ] == "#core_profiles/profiles_2d[:]/ion[:]/temperature"
158165 assert dim2_coordinate ["shape" ] == [5 , 3 ]
159166 assert dim2_coordinate ["path" ] == "#core_profiles/profiles_2d[:]/grid/dim2"
@@ -205,3 +212,35 @@ def test_plot_data_requires_savgol_window_length_and_polyorder(entry_path):
205212 )
206213 assert response .status_code == 422
207214 assert "savgol_smoothing_polyorder is required" in response .text
215+
216+
217+ @pytest .mark .parametrize ("expected_unit" , [("m" , "rad" )] if _IMAS_GE_2_3 else [("mixed" , "mixed" )])
218+ def test_plot_data_coordinate_aliases (entry_path , expected_unit ):
219+
220+ parameters = {
221+ "uri" : f"imas:hdf5?path={ entry_path } #core_profiles/profiles_2d[0]/grid/volume_element" ,
222+ }
223+ response = pytest .test_client .get ("/data/plot_data" , params = parameters )
224+ response_body = response .json ()
225+
226+ assert response .status_code == 200
227+
228+ dim1_coordinate = response_body ["data" ]["coordinates" ][0 ]
229+ assert dim1_coordinate ["name" ].lower () == "r"
230+ assert dim1_coordinate ["unit" ].lower () == expected_unit [0 ]
231+
232+ parameters = {
233+ "uri" : f"imas:hdf5?path={ entry_path } #core_profiles/profiles_2d[1]/grid/volume_element" ,
234+ }
235+ response = pytest .test_client .get ("/data/plot_data" , params = parameters )
236+ response_body = response .json ()
237+
238+ assert response .status_code == 200
239+
240+ dim1_coordinate = response_body ["data" ]["coordinates" ][0 ]
241+ dim2_coordinate = response_body ["data" ]["coordinates" ][1 ]
242+ assert dim1_coordinate ["name" ].lower () == "rho"
243+ assert dim1_coordinate ["unit" ].lower () == expected_unit [0 ]
244+
245+ assert dim2_coordinate ["name" ].lower () == "theta"
246+ assert dim2_coordinate ["unit" ].lower () == expected_unit [1 ]
0 commit comments