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

Helper functions for arithmetic on MSDS #1081

Open
tjdcs opened this issue Dec 7, 2022 · 7 comments
Open

Helper functions for arithmetic on MSDS #1081

tjdcs opened this issue Dec 7, 2022 · 7 comments

Comments

@tjdcs
Copy link
Contributor

tjdcs commented Dec 7, 2022

In a previous discussion the need for getting the sum of an MSDS object came up. I've needed to do this twice recently. Once where I needed the sum of the spectrum because I was computing the total power of a spectroradiometer measurement between the requisite wavelengths. And another time when each of the underlying instances of SpectralDistribution represented independent control channels of a light source (RGB for a spectral display model, for example)

So summation would need to have respect to some "axis", either the sum of the values for each SD object or the sum at every wavelength across all SDs

You are right, there is no easy way to do that but it would not be too hard to implement dedicated methods for that. Under the hood, the colour.MultiSpectralDistributions is a bunch of colour.SpectralDistributions instances.

I'm thinking that the following would be useful for example:

  • colour.MultiSpectralDistributions.sum
  • colour.MultiSpectralDistributions.average
  • colour.MultiSpectralDistributions.median

What do you think @tjdcs?

Originally posted by @KelSolaar in #1078 (reply in thread)

@tjdcs
Copy link
Contributor Author

tjdcs commented Dec 7, 2022

@KelSolaar @frankkjensen

@tjdcs
Copy link
Contributor Author

tjdcs commented Dec 7, 2022

Other functions might be useful, such as mean, median, range (np.ptp), variance, etc... which all could benefit from the axis semantics mentioned above.

Some of these functions are numpy ufuncs, is there an easy way to just decorate and apply the numpy algorithms with the expected behavior? There could be other statistical methods that we are unaware of which could be useful to someone in the future.

I've added the label good first issue if someone want's to implement just sum, mean, median, and std.dev which seem like the most useful set of options in my mind.

@KelSolaar
Copy link
Member

It is worth noting that one of the reasons that those functions do not exist was to keep the classes lightweight thus one can trivially convert a colour.SpectralDistribution to a Pandas Series and conversely colour.MultiSpectralDistributions can be converted to a Pandas DataFrame.

@b21827541
Copy link

b21827541 commented Dec 31, 2023

Hello, 👋
I'm new here. I saw this as a good first issue. I was wondering if I could work on this.

Many thanks,
Berk

@KelSolaar
Copy link
Member

Hi Berk,

Sorry for the late reply! I was on holidays break and working on other things. Are you still interested into implementing this?

Cheers,

Thomas

@b21827541
Copy link

Thanks for getting back to me. I appreciate it. I'd be so happy to contribute.

Many thanks,
Berk

@KelSolaar
Copy link
Member

Hello,

I think that we should be able to add them to the colour.continuous.AbstractContinuousFunction class directly: https://github.com/colour-science/colour/blob/develop/colour/continuous/abstract.py

Idea would be to implement the various methods there and work using the self.range property value as an input. Because of the abstract nature of the class and the fact it enforces having a self.range property, if we were to implement it there, all the subclasses should be able to benefit from it.

Cheers,

Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants