Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change filt variable from global to local #389

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions rdtools/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def irradiance_rescale(irrad, irrad_sim, max_iterations=100,
'''

if method == 'iterative':
def _rmse(fact):
def _rmse(fact, filt):
"""
Calculates RMSE with a given rescale fact(or) according to global
filt(er)
Expand All @@ -392,10 +392,9 @@ def _rmse(fact):

def _single_rescale(irrad, irrad_sim, guess):
"Optimizes rescale factor once"
global filt
csi = irrad / (guess * irrad_sim) # clear sky index
filt = (csi >= 0.8) & (csi <= 1.2) & (irrad > 200)
min_result = minimize(_rmse, guess, method='Nelder-Mead')
min_result = minimize(_rmse, guess, (filt), method='Nelder-Mead')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may need to use a lambda function like lambda x : _rmse(x, filt) here as the first argument to minimize

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdeceglie - I'm not seeing why we might need a lambda function. I created a jupyter notebook that re-creates the analysis and I obtain the same result between my suggested changes and the initial implementation. I opened a new PR #399 from the master branch to have running tests and to check whether my changes cause any troubles. So far, all pytests seem to be passing.


factor = min_result['x'][0]
return factor
Expand Down Expand Up @@ -429,7 +428,7 @@ def _rmse(fact):

guess = np.percentile(irrad.dropna(), 90) / \
np.percentile(irrad_sim.dropna(), 90)
min_result = minimize(_rmse, guess, method='Nelder-Mead')
min_result = minimize(_rmse, guess, (filt), method='Nelder-Mead')
factor = min_result['x'][0]

out_irrad = factor * irrad_sim
Expand Down
Loading