Skip to content

implementing #709 requests#726

Closed
apivarunas wants to merge 4 commits into
PmagPy:masterfrom
apivarunas:issue-709-midpoint
Closed

implementing #709 requests#726
apivarunas wants to merge 4 commits into
PmagPy:masterfrom
apivarunas:issue-709-midpoint

Conversation

@apivarunas

@apivarunas apivarunas commented Feb 15, 2025

Copy link
Copy Markdown
Collaborator

So, I made a few changes as related to #709.

  1. I implemented the derivative calculation using np.gradient() docs. This uses second-order accurate central differences for interior points. It also runs over the entire array which removes some of the messy T-1, T-2 parametesr throughout. Running the test case: ipmag.curie(file_name='curie_example.dat', window_length=10) shows identical behavior to the previous implementation with a slight difference in the maximum probably related to the T-array shift.

  2. I switched order of two docstring parameters to mirror the function and put 10 as the default window length.

  3. I commented out the sys.quit() line (so it's now just a warning, and doesn't quit the function) and moved that warning farther down the chain of loops to allow the earlier data interpolations to work.

  4. Two minor changes to account for numpy updates (np.float64 in ipmag.curie() and np.ones in ipmag.smooth().

I've also tested this with an irregularly spaced example file curie_irregular.txt, and it works as well. Kicks out one warning for the last pair of values, but behaves otherwise.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

@Swanson-Hysell If this looks okay, would you like this implemented in rockmagpy or are you pretty happy with that implementation?

@Swanson-Hysell

Swanson-Hysell commented Feb 20, 2025

Copy link
Copy Markdown
Member

Can you help me understand the warning saying that delta T should be integer, be careful! given that the delta T is irregular throughout the data set?

Screenshot 2025-02-20 at 3 46 34 PM

@Swanson-Hysell

Swanson-Hysell commented Feb 21, 2025

Copy link
Copy Markdown
Member

There is another method to implement which is the linearity of inverse susceptibility when dealing with high-temperature susceptibility data:
Screenshot 2025-02-21 at 2 14 17 PM

https://doi.org/10.1029/2006JB004507

@apivarunas

Copy link
Copy Markdown
Collaborator Author

Can you help me understand the warning saying that delta T should be integer, be careful! given that the delta T is irregular throughout the data set?

Yeah. Well, sort of. I believe the input arrays are being regularized (delta = 1) up until the last pair of values.

I don't think that this has much affect on the behavior of the function result, so we could remove the warning, I suppose. Better yet would be to figure out how to continue the regularization through the whole array...which I'm working on.

There is a broader discussion here about implementing varied approaches in the context of this function:

  • peak of first derivative
  • two tangent method
  • second derivative zero crossing
    Can you think about adding these different approaches and having there be parameters that can do one method or another?

Yes. I think that's a good idea. Including your most recent comment as far as approaches goes. I can work on this over the weekend.

The goal is to avoid duplicative functions between rockmagpy and other pmagpy libraries is the ipmag implementation is what we can be using in rockmagpy.

Right. I think eventually the function should have some comprehensive approaches and only needs to live in one module.

@apivarunas

apivarunas commented Feb 22, 2025

Copy link
Copy Markdown
Collaborator Author

There appears to be a fundamental issue in this ipmag.curie() function given that it is searching for the peak of the 2nd derivative. One could search for the peak of the first derivative, but this isn't appropriate for the second derivative which instead should be the zero crossing (as in this Verwey temperature example: https://pmagpy.github.io/RockmagPy-notebooks/MPMS_verwey_fit.html). In this example (and the other example file) the data are too noisy for this approach (two tangent is likely better).

Right. That's been the implementation in the software for a while. Can see it in the 1998 textbook version. I think, looking at Fabian et al., 2013 Figure 8 that it probably does okay. But I think adjusting it is in our best interest going forward.

So, a summary on the methods to implement:

  1. I think we'd want the minimum of the first derivative (Fabian et al., 2013)
image
  1. I was pretty convinced by (Petrovsky and A. Kapicka, 2006) that the two tangent method is not the correct way to go.

  2. Zero crossing is fine, but problematic when the data is noisy. Honestly, it seems as if the smoothing function ipmag.smooth() isn't doing too much until a pretty impressive large window size is reached.

It would be pretty easy to modify the function to address 1 and 3 together, really just a matter of reporting the minimum of the first derivative instead of the maximum of the second derivative. I have to see what exactly is up with the smoothing function.

There is another method to implement which is the linearity of inverse susceptibility when dealing with high-temperature susceptibility data: Screenshot 2025-02-21 at 2 14 17 PM

https://doi.org/10.1029/2006JB004507

Yes, this can be added as well, I think. I'll play around with these additions.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

@Swanson-Hysell

Okay, whew. I've rewritten the function so that it gives the Curie point estimate based on first derivative min and second derivative zero crossing.

Also, the interpolation for irregular input is better, that error is gone.

The plotting is now done by matplotlib, since the plot_xy() function in pmagplotlib is, according to the docstring, deprecated.

I don't think the two tangent method is necessary, since it isn't particularly good for susceptibility data. The current iteration is probably a viable point to provide an update to the ipmag.curie() function. I haven't implemented the inverse susceptibility operability yet. Trying to figure out if it makes sense to let a user pick a linear section or to linefind through the 1/kT curve for them. Options, options.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

@Swanson-Hysell I have now added the option to use inverse susceptibility. It is called by setting inverse_sus = True in the function (default is False).

There is an additional import added to ipmag.py:

from scipy.stats import linregress

And a small additional utility function called ez_line which uses matplotlib to plot a line from slope and intercept on the graph.

The basic flow of the addition is:

  1. Plot inverse susceptibility.
  2. Ask user to provide the high temperature window they want to examine (since its hard to view the whole curve).
  3. Plot that window.
  4. Ask user to provide the high and low temperature values that define the linear segment.
  5. Regress a line through that segment, calculate its parameters. Return the x-intercept and R-squared value, and plot the window, values used in the regression, and line (image of final output shown below).
image

@Swanson-Hysell

Copy link
Copy Markdown
Member

I will dig into this tomorrow. What are your thoughts on having this as an option within a single function (which I know is what I originally suggested) vs having it be its own function. Given how many specific parameters for the inverse susceptibility analysis the user needs to provide, it seems like it might work better was its own function.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

The overall function does end up pretty busy. However, there isn't much the user needs to do, necessarily. The inverse_sus flag is probably the most involved piece by a fair degree.

So...yeah. I think its reasonable break it out into its own function. Let me know if you want that to happen and it should be easy enough to implement.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

Okay, the inverse method is now broken out into its own function as suggested.

@apivarunas

Copy link
Copy Markdown
Collaborator Author

Any improvements wished, @Swanson-Hysell?

@apivarunas

Copy link
Copy Markdown
Collaborator Author

This PR request is out of date due to the incorporation of the rockmag module. As discussed in #802, curie should probably move out of ipmag. #776 incorporates the useful part of this PR.

@apivarunas apivarunas closed this Nov 6, 2025
@apivarunas apivarunas deleted the issue-709-midpoint branch November 10, 2025 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants