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

Interpolator #2600

Merged
merged 23 commits into from
Sep 3, 2024
Merged

Interpolator #2600

merged 23 commits into from
Sep 3, 2024

Conversation

ctoennis
Copy link

This PR is for extending the pointing interpolator to also handle pedestal and gain. This request is related to issue #2565.

A new interpolator is added based on the searchsorted function in numpy and set up to accept the same options as interp1d class from numpy that is already in use for the pointing interpolation. This interpolator is creating a step function that applies a pedestal or gain calibration after a corresponding timestamp until the next pedestal or gain value is available.

The new interpolator is able to interpolate array-like objects to handle

It is currently set up to automatically recognise what data is interpolated and picks an appropriate interpolator based on that determination. This can be changed to require a choice when the data that is to be interpolated is added.

The pointing interpolator has a location for the pointing data hardcoded into it that is used by default for now to avoid having to change code elsewhere. This scheme can be extended to have the place of pointing corrections, pedestals or gain at hand as well.

Tests have been included that check that the step interpolation works as expected.

This comment has been minimized.

1 similar comment

This comment has been minimized.

@Tobychev
Copy link
Contributor

Why do you put everything into one big constructor instead of having a base class and with several more specialised children? Is there some specific technical reason for why you want to entirely eliminate the PointingInterpolator instead of adding more classes for the case you want to cover?

@ctoennis
Copy link
Author

@Tobychev Yes, i should split it up like that. I wanted to have something working first, but i'll restructure it.

This comment has been minimized.

@maxnoe
Copy link
Member

maxnoe commented Jul 23, 2024

@ctoennis I think we need separate classes here, per thing that can be interpolated, putting common code into free function or a common base class.

This has to do with our configuration system: it configures things by class name. So to be able to have two interpolators with different configurations (e.g. for input file from which it reads the monitoring table), we need different class names.

@ctoennis
Copy link
Author

@maxnoe im doing that right now

@ctoennis
Copy link
Author

I split it up into a parent and 2 child classes. I am now updating the docustrings.

This comment has been minimized.

return self.values[i - 1]


class Interpolator(Component):
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be an abstract base class

Copy link
Member

@maxnoe maxnoe Jul 24, 2024

Choose a reason for hiding this comment

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

which means adding metaclass=ABCMeta as second argument here.


def add_table(self, tel_id, input_table):
# sort first, so it's not done twice for each interpolator
input_table.sort("time")
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't do anything here. Remove all code from this method and make it an @abstractmethod

mjd, alt, **self.interp_options
)

def _read_parameter_table(self, tel_id):
Copy link
Member

@maxnoe maxnoe Jul 24, 2024

Choose a reason for hiding this comment

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

This could probably be put into the base class, if we add a class attribute table_path like this:

class PointingInterpolator(Interpolator):
    table_path = "/dl0/monitoring/telescope/pointing"

class PedestalInterpolator(Interpolator):
    table_path = "/dl0/monitoring/telescope/pedestal"

interpolated calibration quantity
"""

if tel_id not in self._interpolators:
Copy link
Member

Choose a reason for hiding this comment

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

This is probably the same for all subclasses, so it could be put in the base class.

This comment has been minimized.

@ctoennis
Copy link
Author

So, i split the Calibration Interpolator into a pedestal and gain interpolator. This way the variable par_name is not needed anymore.

src/ctapipe/io/interpolation.py Outdated Show resolved Hide resolved
src/ctapipe/io/interpolation.py Outdated Show resolved Hide resolved
@ctoennis
Copy link
Author

ctoennis commented Aug 6, 2024

sorry for th oversight with the class variable. I moved it to the definition and made it so the other calibration data is required to have a dimensionless unit.

Copy link
Contributor

@kosack kosack left a comment

Choose a reason for hiding this comment

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

one more minor change (sorry), but otherwise, looks ready!

src/ctapipe/io/interpolation.py Show resolved Hide resolved
kosack
kosack previously approved these changes Aug 6, 2024
@kosack
Copy link
Contributor

kosack commented Aug 7, 2024

Looks like all comments from @maxnoe are addressed, but he is on vacation, so maybe @mexanick you can do a final review and we can merge?

@@ -11,6 +11,8 @@

from .astropy_helpers import read_table

dimensionless_unit = u.Unit()
Copy link
Member

Choose a reason for hiding this comment

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

There e is no need to define this.

There is u.one as short alias or u.dimensionless_unscaled if you want to be explicit.

Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

It seems that the Flat field interpolator is not clear / final. It has some TBD comments, but most importantly, it doesn't match the definition of the dl1 calibration container.

I think this should match, right? The interpolator fills the values to be used for the calibration.

@ctoennis
Copy link
Author

ctoennis commented Aug 7, 2024

It seems that the Flat field interpolator is not clear / final. It has some TBD comments, but most importantly, it doesn't match the definition of the dl1 calibration container.

I think this should match, right? The interpolator fills the values to be used for the calibration.

So, the pedestal and flatfield calibration data will in the end have different time values and the interpolator will have to load each type of data from a different table. To me it makes sense to therefore have a different interpolator for those fields in the DL1CameraCalibrationContainer.

The TBD comments relate to the location where the input groups for the different types of the calibration data will be stored. This would be settled when we add the CalibrationCalculators. Some of these, like the PointingCalculator will need to have the interpolator there to interpolate gain or pedestal data for their calculations. I think it would make sense to leave these fields with the TBD comments and fix this when we implement the CalibrationCalculators.

@maxnoe
Copy link
Member

maxnoe commented Aug 7, 2024

I think it would make more sense then to only introduce the base class in this PR here and change the pointing interpolator.

The other interpolators can be added once the TBDs are clear. It doesn't make much sense to have interpolators in main for which no input data exists.

@ctoennis
Copy link
Author

ctoennis commented Aug 8, 2024

i will move the other interpolators into the branch me and tjark have for the CalibrationCalculators then and remove them here. Does that make sense?

kosack
kosack previously approved these changes Aug 8, 2024
@ctoennis
Copy link
Author

@maxnoe can you have look again? i think it should be good to merge now.

@maxnoe maxnoe merged commit 6485283 into main Sep 3, 2024
12 checks passed
@maxnoe maxnoe deleted the Interpolator branch September 3, 2024 08:57
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.

5 participants