pyFAI icon indicating copy to clipboard operation
pyFAI copied to clipboard

Collate inheritence from Geometry/PoniFile classes

Open mattgebert opened this issue 4 months ago • 2 comments

PoniFile descriptions of an experiment are incredibly useful to store alongside experimental configurations for later processing.

With this in mind, it would be great to have seamless compatibility between classes from the PoniFile or Geometry object, so users can invoke any integrator, which literally are inherited from the Geometry.

I see there are recently set_config and get_config options created, including save and load for the Geometry object. I think instead of having set_config and calling a method like _init_from_poni you could instead use a static method as follows:

@classmethod
def from_poni(cls, ponifile: PoniFile) --> Self
    """Init the geometry/azimuthal from a poni object."""
    obj = cls(**ponifile.as)
    obj.reset()
    return obj

Similar for integrators:

@classmethod
def from_geom(cls, geom: Geometry) --> Self
    """Init the integrator from a Geometry object."""
    obj = cls(**geom.get_config())
    obj.reset()
    return obj

There are a couple of issues here:

  1. The PoniFile.as_dict method creates a dictionary that doesn't match the Geometry.__init__ signature (though it's a subset). We could add a method to PoniFile that intentionally matches the Geometry signature or add an option to the as_dict.

  2. The Geometry core class (geometry/core.py) itself has a couple of todo notes on the set/get config options

     # TODO: ponifile should not be used here
     #     if it was only used for IO, it would be better to remove
     #     this function
    

    I'm not exactly sure what this is referring to, and whether you're intending to keep this interface for working with the Integrator/Goemetry objects.

Not sure if related to #2556.

I'd be quite interested in drafting a PR for this, If this sounds like a good idea I'm happy to tackle it.

I'm also interested in helping contributing to this repository longer-term - perhaps I can shoot you an email about that Jerome. I've recently been implementing typed python libraries (i.e. #2572 especially as you migrate to later versions of python) and am pretty keen to get pyFAI up to the same API standard as well; this will let you add so much extra type-checking, documentation auto creation etc if you want it down the line. It seems like this might be a strong goal for you as well.

mattgebert avatar Aug 18 '25 12:08 mattgebert