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

Added operations for the spectrum class #20

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Conversation

fnemina
Copy link

@fnemina fnemina commented May 26, 2022

Added common arithmetic operations as well as numpy functions to be used
in the SPECTRUM class. To do this we defined the array_ufunc method
as recommended here

https://numpy.org/doc/stable/reference/arrays.classes.html

as well as changed the kind to numpy.lib.mixins.NDArrayOperatorsMixin to
allow for the normal operations to be handled by numpy.

An SPECTRUM class is returned with the same metadata, a new name and
a 'TRANS_TYPE' measure_type.

Also it was defined how the array method should be handled.

This should make it easier to operate with SPECTRUM data, for example

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from specdal import *

measurement1 = pd.Series([1, 2, 3, 4], index=pd.Index([1, 2, 3, 4], name='wavelength'),
                                name='pct_reflect')
measurement2 = pd.Series([2, 4, 6, 8], index=pd.Index([1, 2, 3, 4], name='wavelength'),
                                name='pct_reflect')
s1 = Spectrum(name='s1', measurement=measurement1)
s2 = Spectrum(name='s2', measurement=measurement2)

s = (s1+s2)/2

s1.plot(label="s1")
s2.plot(label="s2")
s.plot(label="average")
plt.legend()
plt.show()

returns in s an SPECTRUM class object with the average of both spectra. Also more
complicated functions as np.sin(s) can be calculated.

It was also incorporated the __array__ method, so that functions as np.mean(s)
returns the means over all wavelengths.

fnemina added 6 commits May 26, 2022 20:05
Added common arithmetic operations as well as numpy functions to be used
in the SPECTRUM class. To do this we defined the __array_ufunc__ method
as recommended here

https://numpy.org/doc/stable/reference/arrays.classes.html

as well as changed the kind to numpy.lib.mixins.NDArrayOperatorsMixin to
allow for the normal operations to be handled by numpy.

An SPECTRUM class is returned with the same metadata, a new name and
a 'TRANS_TYPE' measure_type.

Also it was defined how the __array__ method should be handled.
Added new method .get_Satellite() to compute the spectral convolution of
a spectral signature with RSR function of a satellite.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant