Skip to content

Commit 7348053

Browse files
BUG: fix the wind velocity factors usage and better visualization of uniform distributions in Stochastic Classes (#783)
* wind factor bug corrected the wind factor wasn't applied to the env.wind_velocity properties * BUG: StochasticModel visualize attributes of a uniform distribution It showed the nominal and the standard deviation values and it doesn't make sense in a uniform distribution. In a np.random.uniform the 'nominal value' is the lower bound of the distribution, and the 'standard deviation' value is the upper bound. Now, a new condition has been added for the uniform distributions where the mean and semi range are calculated and showed. This way the visualize_attribute function will show the whole range where the random values are uniformly taken in * variable names corrections * Corrections requested by the pylint test * ENH: more intuitive uniform distribution display in StochasticModel Co-authored-by: MateusStano <[email protected]> --------- Co-authored-by: MateusStano <[email protected]>
1 parent d2f89ba commit 7348053

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

rocketpy/stochastic/stochastic_environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@ def create_object(self):
184184
# get original attribute value and multiply by factor
185185
attribute_name = f"_{key.replace('_factor', '')}"
186186
value = getattr(self, attribute_name) * value
187+
key = f"{key.replace('_factor', '')}"
187188
setattr(self.obj, key, value)
188189
return self.obj

rocketpy/stochastic/stochastic_model.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,19 @@ def format_attribute(attr, value):
514514
)
515515
elif isinstance(value, tuple):
516516
nominal_value, std_dev, dist_func = value
517-
return (
518-
f"\t{attr.ljust(max_str_length)} "
519-
f"{nominal_value:.5f} ± "
520-
f"{std_dev:.5f} ({dist_func.__name__})"
521-
)
517+
if callable(dist_func) and dist_func.__name__ == "uniform":
518+
lower_bound = nominal_value
519+
upper_bound = std_dev
520+
return (
521+
f"\t{attr.ljust(max_str_length)} "
522+
f"{lower_bound:.5f}, {upper_bound:.5f} ({dist_func.__name__})"
523+
)
524+
else:
525+
return (
526+
f"\t{attr.ljust(max_str_length)} "
527+
f"{nominal_value:.5f} ± "
528+
f"{std_dev:.5f} ({dist_func.__name__})"
529+
)
522530
return None
523531

524532
attributes = {k: v for k, v in self.__dict__.items() if not k.startswith("_")}

0 commit comments

Comments
 (0)