Skip to content

Commit f3a282e

Browse files
committed
MNT: ruff and pylint
1 parent 4df187e commit f3a282e

4 files changed

Lines changed: 27 additions & 31 deletions

File tree

rocketpy/environment/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ def process_ensemble(self, file, dictionary): # pylint: disable=too-many-locals
20592059
lat_array = data.variables[dictionary["latitude"]]
20602060

20612061
# Some THREDDS datasets use projected x/y coordinates.
2062-
#TODO CHECK THIS I AM NOT SURE?????
2062+
# TODO CHECK THIS I AM NOT SURE?????
20632063
if dictionary.get("projection") is not None:
20642064
projection_variable = data.variables[dictionary["projection"]]
20652065
x_units = getattr(lon_array, "units", "m")

rocketpy/environment/fetchers.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ def fetch_gfs_file_return_dataset(max_attempts=10, base_delay=2):
114114
If unable to load the latest weather data for GFS.
115115
"""
116116
file_url = (
117-
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/"
118-
"Global_0p25deg/Best"
117+
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p25deg/Best"
119118
)
120119
attempt_count = 0
121120
while attempt_count < max_attempts:
@@ -149,10 +148,7 @@ def fetch_nam_file_return_dataset(max_attempts=10, base_delay=2):
149148
RuntimeError
150149
If unable to load the latest weather data for NAM.
151150
"""
152-
file_url = (
153-
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/NAM/"
154-
"CONUS_12km/Best"
155-
)
151+
file_url = "https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/NAM/CONUS_12km/Best"
156152
attempt_count = 0
157153
while attempt_count < max_attempts:
158154
try:
@@ -185,10 +181,7 @@ def fetch_rap_file_return_dataset(max_attempts=10, base_delay=2):
185181
RuntimeError
186182
If unable to load the latest weather data for RAP.
187183
"""
188-
file_url = (
189-
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/RAP/"
190-
"CONUS_13km/Best"
191-
)
184+
file_url = "https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/RAP/CONUS_13km/Best"
192185
attempt_count = 0
193186
while attempt_count < max_attempts:
194187
try:
@@ -221,10 +214,7 @@ def fetch_hrrr_file_return_dataset(max_attempts=10, base_delay=2):
221214
RuntimeError
222215
If unable to load the latest weather data for HRRR.
223216
"""
224-
file_url = (
225-
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/HRRR/"
226-
"CONUS_2p5km/Best"
227-
)
217+
file_url = "https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/HRRR/CONUS_2p5km/Best"
228218
attempt_count = 0
229219
while attempt_count < max_attempts:
230220
try:
@@ -233,7 +223,9 @@ def fetch_hrrr_file_return_dataset(max_attempts=10, base_delay=2):
233223
attempt_count += 1
234224
time.sleep(base_delay**attempt_count)
235225

236-
raise RuntimeError("Unable to load latest weather data for HRRR through " + file_url)
226+
raise RuntimeError(
227+
"Unable to load latest weather data for HRRR through " + file_url
228+
)
237229

238230

239231
def fetch_aigfs_file_return_dataset(max_attempts=10, base_delay=2):
@@ -258,8 +250,7 @@ def fetch_aigfs_file_return_dataset(max_attempts=10, base_delay=2):
258250
If unable to load the latest weather data for AIGFS.
259251
"""
260252
file_url = (
261-
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/AIGFS/"
262-
"Global_0p25deg/Best"
253+
"https://thredds.ucar.edu/thredds/dodsC/grib/NCEP/AIGFS/Global_0p25deg/Best"
263254
)
264255
attempt_count = 0
265256
while attempt_count < max_attempts:
@@ -269,7 +260,10 @@ def fetch_aigfs_file_return_dataset(max_attempts=10, base_delay=2):
269260
attempt_count += 1
270261
time.sleep(base_delay**attempt_count)
271262

272-
raise RuntimeError("Unable to load latest weather data for AIGFS through " + file_url)
263+
raise RuntimeError(
264+
"Unable to load latest weather data for AIGFS through " + file_url
265+
)
266+
273267

274268
def fetch_hiresw_file_return_dataset(max_attempts=10, base_delay=2):
275269
"""Fetches the latest HiResW (High-Resolution Window) dataset from the NOAA's

rocketpy/environment/tools.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def geodesic_to_lambert_conformal(lat, lon, projection_variable, x_units="m"):
133133
lon_radians = math.radians(lon % 360)
134134

135135
lat_origin = math.radians(float(projection_variable.latitude_of_projection_origin))
136-
lon_origin = math.radians(
137-
float(projection_variable.longitude_of_central_meridian)
138-
)
136+
lon_origin = math.radians(float(projection_variable.longitude_of_central_meridian))
139137

140138
standard_parallel = projection_variable.standard_parallel
141139
if np.ndim(standard_parallel) == 0:
@@ -157,9 +155,7 @@ def geodesic_to_lambert_conformal(lat, lon, projection_variable, x_units="m"):
157155
f_const = (math.cos(phi_1) * math.tan(math.pi / 4 + phi_1 / 2) ** n) / n
158156

159157
rho = earth_radius * f_const / (math.tan(math.pi / 4 + lat_radians / 2) ** n)
160-
rho_origin = (
161-
earth_radius * f_const / (math.tan(math.pi / 4 + lat_origin / 2) ** n)
162-
)
158+
rho_origin = earth_radius * f_const / (math.tan(math.pi / 4 + lat_origin / 2) ** n)
163159
theta = n * (lon_radians - lon_origin)
164160

165161
x_meters = rho * math.sin(theta)
@@ -229,7 +225,7 @@ def mask_and_clean_dataset(*args):
229225
return data_array
230226

231227

232-
def find_longitude_index(longitude, lon_list):
228+
def find_longitude_index(longitude, lon_list): # pylint: disable=too-many-statements
233229
"""Finds the index of the given longitude in a list of longitudes.
234230
235231
Parameters
@@ -249,6 +245,7 @@ def find_longitude_index(longitude, lon_list):
249245
ValueError
250246
If the longitude is not within the range covered by the list.
251247
"""
248+
252249
def _coord_value(source, index):
253250
return float(source[index])
254251

@@ -286,7 +283,7 @@ def _coord_value(source, index):
286283
if lon_index == lon_len and _coord_value(lon_list, lon_index - 1) == lon:
287284
lon_index -= 1
288285
# Check if longitude value is inside the grid
289-
if lon_index == 0 or lon_index == lon_len:
286+
if lon_index in (0, lon_len):
290287
raise ValueError(
291288
f"Longitude {lon} not inside region covered by file, which is "
292289
f"from {lon_start} to {lon_end}."
@@ -315,6 +312,7 @@ def find_latitude_index(latitude, lat_list):
315312
ValueError
316313
If the latitude is not within the range covered by the list.
317314
"""
315+
318316
def _coord_value(source, index):
319317
return float(source[index])
320318

@@ -338,15 +336,15 @@ def _coord_value(source, index):
338336
if lat_index == lat_len and _coord_value(lat_list, lat_index - 1) == latitude:
339337
lat_index -= 1
340338
# Check if latitude value is inside the grid
341-
if lat_index == 0 or lat_index == lat_len:
339+
if lat_index in (0, lat_len):
342340
raise ValueError(
343341
f"Latitude {latitude} not inside region covered by file, "
344342
f"which is from {lat_start} to {lat_end}."
345343
)
346344
return latitude, lat_index
347345

348346

349-
def find_time_index(datetime_date, time_array):
347+
def find_time_index(datetime_date, time_array): # pylint: disable=too-many-statements
350348
"""Finds the index of the given datetime in a netCDF4 time array.
351349
352350
Parameters
@@ -382,7 +380,11 @@ def find_time_index(datetime_date, time_array):
382380
while low < high:
383381
mid = (low + high) // 2
384382
mid_time_num = float(time_array[mid])
385-
if (mid_time_num < input_time_num) if is_ascending else (mid_time_num > input_time_num):
383+
if (
384+
(mid_time_num < input_time_num)
385+
if is_ascending
386+
else (mid_time_num > input_time_num)
387+
):
386388
low = mid + 1
387389
else:
388390
high = mid

tests/unit/environment/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import pytz
77

88
from rocketpy import Environment
9-
from rocketpy.environment.weather_model_mapping import WeatherModelMapping
109
from rocketpy.environment.tools import geodesic_to_utm, utm_to_geodesic
10+
from rocketpy.environment.weather_model_mapping import WeatherModelMapping
1111

1212

1313
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)