Spectral library resampling question
See original GitHub issueHello, I am trying to resample an ENVI spectral library to the wavelengths and bandpass of a sensor.
Input speclib (“envi”): 480 bands covering 0.2 - 2.9 um, micron units Output speclib (“swiris”): 100 bands covering 0.96 - 2.44 um, nm units
There are bad values in the input library, so I tried setting the data ignore value thus,
envi.metadata['data ignore value'] = -1.2300000e+34
but that didn’t appear to have any effect. I don’t know how to set those values to NaN in a SpectralLibrary object.
I converted the BandInfo units of the output to microns:
# Convert swiris BandInfo to micron units to match envi speclib
swiris_bandinfo.centers = [x / 1000. for x in swiris_bandinfo.centers]
swiris_bandinfo.bandwidths = [x / 1000. for x in swiris_bandinfo.bandwidths]
I then tried to create BandResmpler object:
envi_swir2020_resampler = spy.BandResampler(envi.bands, swiris_bandinfo)
I then tried to apply the resampler, but I couldn’t find documentation on how to do so. I tried this:
envi_swiris = envi_swir2020_resampler(envi.spectra)
Error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-88-17a4918efcc2> in <module>
----> 1 envi_swiris = envi_swir2020_resampler(envi.spectra)
~\miniconda3\envs\py38\lib\site-packages\spectral\algorithms\resampling.py in __call__(self, spectrum)
236 Any target bands that do not have at lease one overlapping source band
237 will contain `float('nan')` as the resampled band value.'''
--> 238 return np.dot(self.matrix, spectrum)
<__array_function__ internals> in dot(*args, **kwargs)
ValueError: shapes (100,480) and (439,480) not aligned: 480 (dim 1) != 439 (dim 0)
Could you make any suggestions as to what I am doing wrong here? Thank you in advance…
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
Python is a copy-by-reference language so saying
a = b
just points variablea
to whateverb
is.There isn’t currently a
copy
method for spectral libraries. A relatively safe (but inefficient) way to do it is to save the library and load it into a new variable. A faster (but potentially not future-proof) way is to do this:This seems to have done the trick: