[BUGFIX] Prevent unnecessary warning being raised in yaw optimization procedures #1045
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FLORIS v4.2.1 included a fix/enhancement #1031 for the yaw optimization routine. As part of that fix, I changed
self.fmodel_subset = self.fmodel.copy()
to aself.fmodel_subset = copy.deepcopy(self.fmodel)
at this line of yaw_optimization_base.py. I did this to ensure that control setpoints were carried over to thefmodel_subset
attribute. While this worked, it also copied over thewind_data
stored atself.fmodel._wind_data
.In itself, that is not really a problem. However, in the yaw optimization routine, the
wind_directions
,wind_speeds
, andturbulence_intensities
areset()
onself.fmodel_subset
, see here. This overrides the stored_wind_data
, which again is not an issue, except that it raises a warning because of these lines on theFlorisModel
class. The repeated printout of this warning each timeYawOptimization._calculate_farm_power()
is called is tedious and disconcerting. This is pointed out by @ @MiguelMarante in #1016To see this, one may run example 001_opt_yaw_single_ws.py in examples/examples_control_optimization/, and see the following printout
where previously, on v4.2 before #1031 was enacted, the printout was
(Note that the warning raised is once after the yaw optimization procedure is complete, but this is due to this line in the example and is the kind of situation the warning was intended for.)
To resolve this, I see a range of possible fixes:
(currently implemented on this branch): Simply set
self.fmodel_subset._wind_data = None
after theself.fmodel_subset = copy.deepcopy(self.fmodel)
statement onYawOptimization
. This works well, because it sets the unused._wind_data
toNone
and the warning is then not raised. However, it accesses a private attribute, and is therefore pretty clearly a "hacky" solution.Create a method on
FlorisModel
, perhaps calledreset_wind_data()
, that sets the private attribute toNone
, and then call this method after theself.fmodel_subset = copy.deepcopy(self.fmodel)
statement onYawOptimization
. However, it should be noted that although this seems similar toreset_operation()
, all it would do is override the_wind_data
attribute withNone
. This is arguably a bit dangerous, because thewind_speeds
,wind_directions
, andturbulence_intensities
that were set by the originally-passedWindData
object would not be dropped (as intended), so the name and purpose of the method isn't very clear.Simply remove the warning raised in
FlorisModel
. I'm not sure how useful this warning is in any circumstance; however, there may be some unintended consequences in situations for which the warning was originally intended.A more thorough fix would be to allow
wind_data
, along with other arguments toFlorisModel.set()
, to be explicitly removed. This is discussed in Allow "unsetting" non-critical keyword arguments toFlorisModel.set()
#974.@rafmudaf , @paulf81 , I'd like to hear your input on this. We actually originally did not store the
wind_data
on theFlorisModel
at all, which would also have avoided this issue, but it was added in #849 (along with the warning) to make post-processing methods more straightforward. Looking back at #849, perhaps option (3.) above is not so bad; perhaps I was a little too liberal with my raising of warnings.