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

Eqw 2 #94

Merged
merged 13 commits into from Apr 30, 2020
Merged

Eqw 2 #94

merged 13 commits into from Apr 30, 2020

Conversation

Rlamboll
Copy link
Collaborator

Pull request

Please confirm that this pull request has done the following:

  • Tests added
  • Documentation added (where applicable)
  • Example added (either to an existing notebook or as a new notebook, where applicable)
  • Description in CHANGELOG.rst added

Adding to CHANGELOG.rst

Please add a single line in the changelog notes similar to one of the following:

- (`#XX <https://github.com/znicholls/silicone/pull/XX>`_) Added feature which does something
- (`#XX <https://github.com/znicholls/silicone/pull/XX>`_) Fixed bug identified in (`#YY <https://github.com/znicholls/silicone/issues/YY>`_)

@Rlamboll Rlamboll mentioned this pull request Apr 30, 2020
4 tasks
@Rlamboll Rlamboll requested a review from znicholls April 30, 2020 09:25
Copy link
Collaborator

@znicholls znicholls left a comment

Choose a reason for hiding this comment

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

lgtm, I'm not sure I fully understand the tests but the code change is sufficiently simple that I'll leave it up to you how thoroughly you want to test it.

Assuming notebooks etc. come next?

Database cruncher which uses the 'equal quantile walk' technique.

This cruncher assumes that the amount of effort going into reducing one emission set
is equal to that for another emission, therefore the lead and follow data should be
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
is equal to that for another emission, therefore the lead and follow data should be
is equal to that for another emission, therefore the lead and follow data should come from

This cruncher assumes that the amount of effort going into reducing one emission set
is equal to that for another emission, therefore the lead and follow data should be
the same quantile of all pathways in the infiller database.
It calculates what quantile the lead infillee data is in the lead infiller database,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
It calculates what quantile the lead infillee data is in the lead infiller database,
It calculates the quantile of the lead infillee data is in the lead infiller database,

lead_vals = lead_vals.sort_values()
quant_of_lead_vals = np.arange(len(lead_vals)) / (len(lead_vals) - 1)
if any(quant_of_lead_vals > 1) or any(quant_of_lead_vals < 0):
raise NotImplementedError("Impossible quantiles!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
raise NotImplementedError("Impossible quantiles!")
raise ValueError("Impossible quantiles!")

Also very amusing +1

input_quantiles = scipy.interpolate.interp1d(
lead_vals, quant_of_lead_vals, bounds_error=False, fill_value=(0, 1)
)(lead_input)
return np.nanquantile(follow_vals, input_quantiles)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return np.nanquantile(follow_vals, input_quantiles)
return np.nanquantile(follow_vals, input_quantiles, interpolation="linear")

It's already what happens but just makes clear?

return self._db.filter(variable=variable_follower)

def _find_same_quantile(self, follow_vals, lead_vals, lead_input):
if len(lead_vals) == 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if len(lead_vals) == 1:
if len(follow_vals) == 1:

Would this be clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's to avoid a singularity later, we could also short-circuit the calculation in the case of 1 follow but that's for computational reasons not essential ones. I guess it's better to take the mean afterwards in case the length of the two are different.


infilled = res(simple_df)
# We compare the results with the expected results: for T1, we are below the
# lower limit on the first, in the middle on the second. At later times we are
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# lower limit on the first, in the middle on the second. At later times we are
# lower limit on the first, in the middle on the second scenario. At later times we are

? Is there a way to make it slightly clearer in the test rather than having the hard-coded 50 and 100?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's derived better now


def test_with_one_value_in_infiller_db(self, test_db, caplog):
# The calculation is different with only one entry in the infiller db. We
# expect a warning and the only value to be returned in all cases.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# expect a warning and the only value to be returned in all cases.
#

No warning at the moment ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True. Probably not going to add one now, they are annoying

)

# Repeat with reducing the minimum value. This works differently because the
# minimum point is doubled. By default the cruncher selects the higher
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# minimum point is doubled. By default the cruncher selects the higher
# minimum point is doubled. This modification causes the cruncher to pick the lower value.

@Rlamboll Rlamboll merged commit 0562e27 into master Apr 30, 2020
@Rlamboll Rlamboll deleted the EQW_2 branch April 30, 2020 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants