Skip to content

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