Skip to content

Commit e8967cb

Browse files
committed
Fix code style issues with Black
1 parent 7b24b80 commit e8967cb

File tree

2 files changed

+109
-62
lines changed

2 files changed

+109
-62
lines changed

rocketpy/Environment.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ def allInfoReturned(self):
33293329

33303330
def exportEnvironment(self, filename="environment"):
33313331
"""Export important attributes of Environment class so it can be used
3332-
again in further siulations by using the customAtmosphere atmospheric
3332+
again in further siulations by using the customAtmosphere atmospheric
33333333
model.
33343334
Parameters
33353335
----------
@@ -3339,10 +3339,10 @@ def exportEnvironment(self, filename="environment"):
33393339
------
33403340
None
33413341
"""
3342-
3342+
33433343
# TODO: in the future, allow the user to select which format will be used (json, csv, etc.). Default must be JSON.
33443344
# TODO: add self.exportEnvDictionary to the documentation
3345-
# TODO: find a way to documennt the workaround I've used on ma.getdata(self...
3345+
# TODO: find a way to documennt the workaround I've used on ma.getdata(self...
33463346
self.exportEnvDictionary = {
33473347
"railLength": self.rL,
33483348
"gravity": self.g,
@@ -3356,26 +3356,33 @@ def exportEnvironment(self, filename="environment"):
33563356
"atmosphericModelType": self.atmosphericModelType,
33573357
"atmosphericModelFile": self.atmosphericModelFile,
33583358
"atmosphericModelDict": self.atmosphericModelDict,
3359-
"atmosphericModelPressureProfile": ma.getdata(self.pressure.getSource()).tolist(),
3360-
"atmosphericModelTemperatureProfile": ma.getdata(self.temperature.getSource()).tolist(),
3361-
"atmosphericModelWindVelocityXProfile": ma.getdata(self.windVelocityX.getSource()).tolist(),
3362-
"atmosphericModelWindVelocityYProfile": ma.getdata(self.windVelocityY.getSource()).tolist()
3359+
"atmosphericModelPressureProfile": ma.getdata(
3360+
self.pressure.getSource()
3361+
).tolist(),
3362+
"atmosphericModelTemperatureProfile": ma.getdata(
3363+
self.temperature.getSource()
3364+
).tolist(),
3365+
"atmosphericModelWindVelocityXProfile": ma.getdata(
3366+
self.windVelocityX.getSource()
3367+
).tolist(),
3368+
"atmosphericModelWindVelocityYProfile": ma.getdata(
3369+
self.windVelocityY.getSource()
3370+
).tolist(),
33633371
}
33643372

3365-
f = open(filename+".json","w")
3373+
f = open(filename + ".json", "w")
33663374

33673375
# write json object to file
3368-
f.write(json.dumps(
3369-
self.exportEnvDictionary,
3370-
sort_keys=False,
3371-
indent=4,
3372-
default=str)
3373-
)
3374-
3376+
f.write(
3377+
json.dumps(self.exportEnvDictionary, sort_keys=False, indent=4, default=str)
3378+
)
3379+
33753380
# close file
33763381
f.close()
33773382
print("Your Environment file was saved, check it out: " + filename + ".json")
3378-
print("You can use it in the future by using the customAtmosphere atmospheric model.")
3383+
print(
3384+
"You can use it in the future by using the customAtmosphere atmospheric model."
3385+
)
33793386

33803387
return None
33813388

rocketpy/EnvironmentAnalysis.py

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ def __init__(
105105
load_previous_data : str, optional
106106
If True, the class will try to load the data from a previous ran Environment Analysis.
107107
Use .json file resulted from ... as input.
108-
Default is None.
108+
Default is None.
109109
Returns
110110
-------
111111
None
112112
"""
113-
warnings.warn("Please notice this class is still under development, and some features may not work as expected as they were not exhaustively tested yet.")
113+
warnings.warn(
114+
"Please notice this class is still under development, and some features may not work as expected as they were not exhaustively tested yet."
115+
)
114116

115117
# Save inputs
116118
self.start_date = start_date
@@ -141,18 +143,34 @@ def __init__(
141143
with open(self.load_previous_data) as json_file:
142144
self.loaded_data = json.load(json_file)
143145
except:
144-
raise RuntimeError("Unable to read json file from previous ran Environment Analysis. Please try again.")
145-
146+
raise RuntimeError(
147+
"Unable to read json file from previous ran Environment Analysis. Please try again."
148+
)
149+
146150
self.surfaceDataDict = self.loaded_data["surfaceDataDict"]
147151
self.pressureLevelDataDict = self.loaded_data["pressureLevelDataDict"]
148-
print("Information of the data loaded from previous Environment Analysis.\n")
149-
print("Available dates: ", self.loaded_data["start_date"], " to ", self.loaded_data["end_date"])
150-
print("Available hours: ", self.loaded_data["start_hour"], " to ", self.loaded_data["end_hour"])
152+
print(
153+
"Information of the data loaded from previous Environment Analysis.\n"
154+
)
155+
print(
156+
"Available dates: ",
157+
self.loaded_data["start_date"],
158+
" to ",
159+
self.loaded_data["end_date"],
160+
)
161+
print(
162+
"Available hours: ",
163+
self.loaded_data["start_hour"],
164+
" to ",
165+
self.loaded_data["end_hour"],
166+
)
151167
print("Latitude", self.loaded_data["latitude"])
152168
print("Longitude", self.loaded_data["longitude"])
153169
print("Elevation:", self.loaded_data["elevation"])
154170
print("Surface data file: ", self.loaded_data["surfaceDataFile"])
155-
print("Pressure level data file: ", self.loaded_data["pressureLevelDataFile"])
171+
print(
172+
"Pressure level data file: ", self.loaded_data["pressureLevelDataFile"]
173+
)
156174
print("User timezone: ", self.loaded_data["preferred_timezone"])
157175
print("User unit system: ", self.loaded_data["unit_system"])
158176

@@ -2345,7 +2363,9 @@ def process_temperature_profile_over_average_day(self):
23452363
max_temperature = np.max(mean_temperature_values_for_this_hour)
23462364
if max_temperature >= self.max_average_temperature_at_altitude:
23472365
self.max_average_temperature_at_altitude = max_temperature
2348-
self.average_temperature_profile_at_given_hour = average_temperature_profile_at_given_hour
2366+
self.average_temperature_profile_at_given_hour = (
2367+
average_temperature_profile_at_given_hour
2368+
)
23492369

23502370
def process_pressure_profile_over_average_day(self):
23512371
"""Compute the average pressure profile for each available hour of a day, over all
@@ -2376,7 +2396,9 @@ def process_pressure_profile_over_average_day(self):
23762396
max_pressure = np.max(mean_pressure_values_for_this_hour)
23772397
if max_pressure >= self.max_average_pressure_at_altitude:
23782398
self.max_average_pressure_at_altitude = max_pressure
2379-
self.average_pressure_profile_at_given_hour = average_pressure_profile_at_given_hour
2399+
self.average_pressure_profile_at_given_hour = (
2400+
average_pressure_profile_at_given_hour
2401+
)
23802402

23812403
def process_wind_speed_profile_over_average_day(self):
23822404
"""Compute the average wind profile for each available hour of a day, over all
@@ -2438,9 +2460,11 @@ def process_wind_velocity_x_profile_over_average_day(self):
24382460
max_windVelocityX = np.max(mean_windVelocityX_values_for_this_hour)
24392461
if max_windVelocityX >= self.max_average_windVelocityX_at_altitude:
24402462
self.max_average_windVelocityX_at_altitude = max_windVelocityX
2441-
self.average_windVelocityX_profile_at_given_hour = average_windVelocityX_profile_at_given_hour
2463+
self.average_windVelocityX_profile_at_given_hour = (
2464+
average_windVelocityX_profile_at_given_hour
2465+
)
24422466

2443-
def process_wind_velocity_y_profile_over_average_day(self):
2467+
def process_wind_velocity_y_profile_over_average_day(self):
24442468
"""Compute the average windVelocityY profile for each available hour of a day, over all
24452469
days in the dataset."""
24462470
altitude_list = np.linspace(*self.altitude_AGL_range, 100)
@@ -2469,7 +2493,9 @@ def process_wind_velocity_y_profile_over_average_day(self):
24692493
max_windVelocityY = np.max(mean_windVelocityY_values_for_this_hour)
24702494
if max_windVelocityY >= self.max_average_windVelocityY_at_altitude:
24712495
self.max_average_windVelocityY_at_altitude = max_windVelocityY
2472-
self.average_windVelocityY_profile_at_given_hour = average_windVelocityY_profile_at_given_hour
2496+
self.average_windVelocityY_profile_at_given_hour = (
2497+
average_windVelocityY_profile_at_given_hour
2498+
)
24732499

24742500
def plot_wind_profile_over_average_day(self, SAcup_altitude_constraints=False):
24752501
"""Creates a grid of plots with the wind profile over the average day."""
@@ -2718,21 +2744,29 @@ def exportMeanProfiles(self, filename="export_env_analysis"):
27182744

27192745
for hour in self.average_temperature_profile_at_given_hour.keys():
27202746
organized_temperature_dict[hour] = np.column_stack(
2721-
(self.average_temperature_profile_at_given_hour[hour][1],
2722-
self.average_temperature_profile_at_given_hour[hour][0])
2723-
).tolist()
2747+
(
2748+
self.average_temperature_profile_at_given_hour[hour][1],
2749+
self.average_temperature_profile_at_given_hour[hour][0],
2750+
)
2751+
).tolist()
27242752
organized_pressure_dict[hour] = np.column_stack(
2725-
(self.average_pressure_profile_at_given_hour[hour][1],
2726-
self.average_pressure_profile_at_given_hour[hour][0])
2727-
).tolist()
2753+
(
2754+
self.average_pressure_profile_at_given_hour[hour][1],
2755+
self.average_pressure_profile_at_given_hour[hour][0],
2756+
)
2757+
).tolist()
27282758
organized_windX_dict[hour] = np.column_stack(
2729-
(self.average_windVelocityX_profile_at_given_hour[hour][1],
2730-
self.average_windVelocityX_profile_at_given_hour[hour][0])
2731-
).tolist()
2759+
(
2760+
self.average_windVelocityX_profile_at_given_hour[hour][1],
2761+
self.average_windVelocityX_profile_at_given_hour[hour][0],
2762+
)
2763+
).tolist()
27322764
organized_windY_dict[hour] = np.column_stack(
2733-
(self.average_windVelocityY_profile_at_given_hour[hour][1],
2734-
self.average_windVelocityY_profile_at_given_hour[hour][0])
2735-
).tolist()
2765+
(
2766+
self.average_windVelocityY_profile_at_given_hour[hour][1],
2767+
self.average_windVelocityY_profile_at_given_hour[hour][0],
2768+
)
2769+
).tolist()
27362770

27372771
self.exportEnvAnalDict = {
27382772
"start_date": self.start_date,
@@ -2752,24 +2786,27 @@ def exportMeanProfiles(self, filename="export_env_analysis"):
27522786
"atmosphericModelPressureProfile": organized_pressure_dict,
27532787
"atmosphericModelTemperatureProfile": organized_temperature_dict,
27542788
"atmosphericModelWindVelocityXProfile": organized_windX_dict,
2755-
"atmosphericModelWindVelocityYProfile": organized_windY_dict
2789+
"atmosphericModelWindVelocityYProfile": organized_windY_dict,
27562790
}
27572791

27582792
# Convert to json
2759-
f = open(filename+".json","w")
2793+
f = open(filename + ".json", "w")
27602794

27612795
# write json object to file
2762-
f.write(json.dumps(
2763-
self.exportEnvAnalDict,
2764-
sort_keys=False,
2765-
indent=4,
2766-
default=str)
2767-
)
2768-
2796+
f.write(
2797+
json.dumps(self.exportEnvAnalDict, sort_keys=False, indent=4, default=str)
2798+
)
2799+
27692800
# close file
27702801
f.close()
2771-
print("Your Environment Analysis file was saved, check it out: " + filename + ".json")
2772-
print("You can use it in the future by using the customAtmosphere atmospheric model.")
2802+
print(
2803+
"Your Environment Analysis file was saved, check it out: "
2804+
+ filename
2805+
+ ".json"
2806+
)
2807+
print(
2808+
"You can use it in the future by using the customAtmosphere atmospheric model."
2809+
)
27732810

27742811
return None
27752812

@@ -2798,19 +2835,22 @@ def saveEnvAnalysisDict(self, filename="EnvAnalysisDict"):
27982835
}
27992836

28002837
# Convert to json
2801-
f = open(filename+".json","w")
2838+
f = open(filename + ".json", "w")
28022839

28032840
# write json object to file
2804-
f.write(json.dumps(
2805-
self.EnvAnalysisDict,
2806-
sort_keys=False,
2807-
indent=4,
2808-
default=str)
2809-
)
2810-
2841+
f.write(
2842+
json.dumps(self.EnvAnalysisDict, sort_keys=False, indent=4, default=str)
2843+
)
2844+
28112845
# close file
28122846
f.close()
2813-
print("Your Environment Analysis file was saved, check it out: " + filename + ".json")
2814-
print("You can use it in the future by using the customAtmosphere atmospheric model.")
2847+
print(
2848+
"Your Environment Analysis file was saved, check it out: "
2849+
+ filename
2850+
+ ".json"
2851+
)
2852+
print(
2853+
"You can use it in the future by using the customAtmosphere atmospheric model."
2854+
)
28152855

28162856
return None

0 commit comments

Comments
 (0)