DavidT3 / XGA

X-ray: Generate and Analyse is a module designed to make the analysis of XMM observations simple and efficient. It provides an interface with SAS for the creation of XMM data products, as well as a way to easily perform fits (scalable for multiple observations) and retrieve information about an object, all within a Python package.
BSD 3-Clause "New" or "Revised" License
29 stars 3 forks source link

Let XGA users be more flexible with entropy profiles #1167

Closed DavidT3 closed 2 months ago

DavidT3 commented 2 months ago

Currently the entropy profile class works in much the same way as the hydrostatic mass class - the user passes 3D temperature and density profiles, and models that they want to be fit to them, and then those models are used to generate the entropy profile.

This needs to change to give the user a bit more flexibility and better represent some of the different ways entropy profiles are calculated in literature. This will involve altering the SpecificEntropy class to allow for the following (in addition to the current method of passing 3D profiles and fitting models):

DavidT3 commented 2 months ago

For when the user selects data interpolation, I'm going to use linear/piecewise interpolation for now, though I may change it to 2nd or 3rd order polynomial interpolation (which I think should be sufficient for density/temperature profiles).

DavidT3 commented 2 months ago

Was considering using the numpy interp function, but unfortunately it doesn't support being passed a 2D array of 'realisations' of the data (basically drawing different realisations of the data points using their uncertainty) and just interpolating along a specified axis. The scipy interp1d function does support this, but it is a legacy function and thus may well be removed in the relatively near future - I'm looking at the different 1D interpolation options scipy supports (https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html#tutorial-interpolate-1dsection).

DavidT3 commented 2 months ago

I think I really have to use linear interpolation at the moment, even though the scipy1d function is deprecated - if you look at the figures in issue #1168, the cubic splines really go a mad bit towards the outskirts with a projected temperature profile (helped by the larger uncertainties there I'm sure).

I acknowledge that its a quick fix using it here rather than figuring out something better, but I need to get this done.

DavidT3 commented 2 months ago

At this point, interpolated data is now supported - here is a demonstration using 3D gas density and projected temperature:

image

The only thing left to add now is the data-point driven entropy measurement where the profile with fewer radial bins (generally going to be the temperature profile but I won't assume that) has data points matched to the points in the radial profile with more data points.

DavidT3 commented 2 months ago

Data point matching now working if density profile has more bins than temperature profile (and now will be trivial to make work in the other circumstance):

image

DavidT3 commented 2 months ago

I've thought of a failure case for the data-point version (without interpolation) - if the profile with more radial bins goes to a further-out radius then the we won't be able to find an appropriate value from the other profile. I think the simplest thing might be to do a check in the init for this circumstance, cut the radii off if necessary, and warn the user.

DavidT3 commented 2 months ago

Think I've achieved everything I wanted to here, so the issue is closing. Next entropy-related adventure is adding models (see issue #1169 )