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

Implement method for Mc by b-value stability (based on Cao & Gao 2002). #165

Merged
merged 17 commits into from
Nov 5, 2024

Conversation

RitzVanille
Copy link
Collaborator

The stability test is done on half a magnitude unit and not 5*magnitude binning.
Also new: introduced pytest fixture for future use of the swiss 2023 catalogue in tests for Mc methods (GOF I'm coming for you...)

Args:
sample : np.array Vector of magnitudes
delta_m : float. Discretization of the magnitudes.
stability_factor : float. Magnitude bin to consider for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to use a stability_range- and the binning would be used as is given by the delta_m.

The stability_range would be default at 0.5, but could be any value, (e.g., 0.2), and stability_range/delta_m points will be evaluated for stability. E.g., for stability_range = 0.6 and delta_m = 0.1, six points will be evaluated, but if delta_m= 0.2, only 3 points.

This would make the parameter stability_range more meaningful. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would also be very easy to implement I think :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I agree it would be more elegant and more in line with what we decided last time (i.e. not sticking to the original Cao & Gao 2002 definition).
I'll modify it accordingly.

for each step in Mc
bs : np.ndarray. Estimated b-value for each step in Mc
"""
sample = bin_to_precision(sample, delta_x=delta_m)
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 it would be better to test if it is binned correctly and then give a warning. Maybe this is for the future though, because this would require a test_binning function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAIK this is inconsistent between methods. Some require the catalogue to be pre-binned-to-precision and some don't. I would keep this out for a different clean-up issue.

b = estimate_b(sample[sample >= mcp - delta_m / 2],
mcp, delta_m, b_parameter='b_value', method="tinti")
b_ex.append(b)
b_avg = np.sum(b_ex) / 5
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, it should be divided by len(b_ex)? It seems that it is possible that there are a different number of b-values than 5

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, in line with our new and updated definition that doesn't stick to the original definition.



@pytest.fixture
def swiss_2023_magnitudes():
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like that we are dependent that the server is always working for the testing. I We should instead have a static catalog (I guess a csv?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be discussed with Nicolas at our next meeting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Took care of it :)

@@ -207,3 +236,11 @@ def test_estimate_mc_maxc(setup_magnitudes):
mc = mc_max_curvature(setup_magnitudes, delta_m=0.1, correction_factor=0.2)

assert_equal(1.3, mc)


def test_estimate_mc_bvalue_stability(swiss_2023_magnitudes):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be tested also for different binning and stability range :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another missing test: one catalogue that fails to be stable enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

test for 0.1 binning added

@RitzVanille
Copy link
Collaborator Author

@aronsho should be good to go now (minus the test for failing catalogue but we can figure this one out later)

@aronsho aronsho merged commit 06d2fb8 into main Nov 5, 2024
1 check passed
@aronsho aronsho deleted the mc_bvalue_stability branch November 5, 2024 17:31
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.

2 participants