@@ -98,3 +98,110 @@ def test_get_nasa_power_duplicate_parameter_name(data_index):
9898 start = data_index [0 ],
9999 end = data_index [- 1 ],
100100 parameters = 2 * ['ALLSKY_SFC_SW_DWN' ])
101+
102+
103+ @pytest .mark .remote_data
104+ @pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
105+ def test_get_nasa_power_all_variable_map_parameters_valid ():
106+ """
107+ Every NASA POWER parameter name in VARIABLE_MAP must be accepted by the
108+ live API. A typo or stale name (e.g. CLRSKY_DIFF vs CLRSKY_SFC_SW_DIFF)
109+ causes the API to return an HTTPError, which would fail this test.
110+
111+ NASA POWER allows max 15 parameters per request; VARIABLE_MAP is split
112+ into two batches to stay within that limit.
113+ """
114+ from pvlib .iotools .nasa_power import VARIABLE_MAP
115+ nasa_params = list (VARIABLE_MAP .keys ())
116+ # Split into two batches; API limit is 15.
117+ half = (len (nasa_params ) + 1 ) // 2
118+ batch1 = nasa_params [:half ]
119+ batch2 = nasa_params [half :]
120+
121+ for batch in [batch1 , batch2 ]:
122+ data , meta = pvlib .iotools .get_nasa_power (
123+ latitude = 44.76 ,
124+ longitude = 7.64 ,
125+ start = '2025-02-02' ,
126+ end = '2025-02-02' ,
127+ parameters = batch ,
128+ map_variables = False ,
129+ )
130+ missing = set (batch ) - set (data .columns )
131+ assert not missing , f"NASA POWER did not return: { sorted (missing )} "
132+
133+
134+ @pytest .mark .remote_data
135+ @pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
136+ def test_get_nasa_power_all_variable_map_renamed ():
137+ """
138+ With map_variables=True every NASA name must be renamed to its pvlib
139+ equivalent. Catches duplicate-target collisions (e.g. two entries both
140+ mapping to 'temp_dew', which silently drops a column under pandas rename).
141+ """
142+ from pvlib .iotools .nasa_power import VARIABLE_MAP
143+ nasa_params = list (VARIABLE_MAP .keys ())
144+ pvlib_names = set (VARIABLE_MAP .values ())
145+
146+ data , _ = pvlib .iotools .get_nasa_power (
147+ latitude = 44.76 ,
148+ longitude = 7.64 ,
149+ start = '2025-02-02' ,
150+ end = '2025-02-02' ,
151+ parameters = nasa_params ,
152+ map_variables = True ,
153+ )
154+
155+ missing = pvlib_names - set (data .columns )
156+ assert not missing , (
157+ f"map_variables=True dropped pvlib columns: { sorted (missing )} . "
158+ "Likely cause: duplicate target names in VARIABLE_MAP."
159+ )
160+
161+
162+ @pytest .mark .remote_data
163+ @pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
164+ def test_get_nasa_power_pressure_unit_conversion ():
165+ """
166+ NASA POWER returns PS in kPa; pvlib convention is Pa.
167+ Sea-level surface pressure should be ~101 kPa = ~101325 Pa, not ~101.
168+ """
169+ data , _ = pvlib .iotools .get_nasa_power (
170+ latitude = 0.0 , # sea-level equatorial point
171+ longitude = - 30.0 ,
172+ start = '2025-02-02' ,
173+ end = '2025-02-02' ,
174+ parameters = ['PS' ],
175+ map_variables = True ,
176+ )
177+ mean_pressure = data ['pressure' ].mean ()
178+ # Anywhere on earth, surface pressure in Pa is between ~50k and ~110k.
179+ # If the conversion is missing, value will be ~100 (kPa) and fail this.
180+ assert 50_000 < mean_pressure < 110_000 , (
181+ f"PS not converted from kPa to Pa. Got mean={ mean_pressure } "
182+ )
183+
184+
185+ @pytest .mark .remote_data
186+ @pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
187+ def test_get_nasa_power_precipitable_water_unit_conversion ():
188+ """
189+ NASA POWER returns TQV in kg/m^2 (= mm of water column);
190+ pvlib convention is cm. Typical atmospheric column is 1-5 cm,
191+ never above ~7 cm. If the /10 conversion is missing, values will
192+ be 10-50 and fail this bound.
193+ """
194+ data , _ = pvlib .iotools .get_nasa_power (
195+ latitude = 0.0 , # tropics: high water vapor, worst case for bounds
196+ longitude = - 60.0 ,
197+ start = '2025-02-02' ,
198+ end = '2025-02-02' ,
199+ parameters = ['TQV' ],
200+ map_variables = True ,
201+ )
202+ mean_pw = data ['precipitable_water' ].mean ()
203+ # pvlib precipitable_water is in cm. Tropical column is <~7 cm.
204+ # Missing /10 conversion would give 10-70 (kg/m^2 = mm).
205+ assert 0 < mean_pw < 10 , (
206+ f"TQV not converted from kg/m^2 to cm. Got mean={ mean_pw } "
207+ )
0 commit comments