question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spectral library resampling question

See original GitHub issue

Hello, 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:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tboggscommented, Dec 3, 2020

Python is a copy-by-reference language so saying a = b just points variable a to whatever b 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:

new_speclib = SpectralLibrary(np.array(old_speclib.spectra), header=old_speclib.metadata)
1reaction
pythonic2020commented, Dec 2, 2020

This seems to have done the trick:

envi.spectra[18]
>>array([-1.2300000e+34, -1.2300000e+34,  1.7548670e-01,  1.9984178e-01,
        2.1063155e-01,  2.1460478e-01,  2.1685915e-01,  2.1990111e-01,
        2.2058058e-01,  2.2873949e-01,  2.3561078e-01,  2.4390015e-01,
        2.5014159e-01, -1.2300000e+34, -1.2300000e+34, -1.2300000e+34,
       -1.2300000e+34,  2.9385823e-01,  3.0357128e-01,  3.1490511e-01,...

envi.spectra[envi.spectra == -1.2300000e+34] = np.nan

envi.spectra[18]
>>array([       nan,        nan, 0.1754867 , 0.19984178, 0.21063155,
       0.21460478, 0.21685915, 0.21990111, 0.22058058, 0.22873949,
       0.23561078, 0.24390015, 0.2501416 ,        nan,        nan,
              nan,        nan, 0.29385823, 0.30357128, 0.3149051 ,
       0.32507223, 0.33639374, 0.34811777, 0.35825697, 0.3682927 ,
       0.37476093, 0.38296247, 0.38948968, 0.3960724 , 0.4032488 ,...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Spectral Resampling - L3HarrisGeospatial.com
Use Spectral Resampling to resample spectral data files to match one of the following: The response of a known instrument (for example, AVIRIS) ......
Read more >
75 questions with answers in RESAMPLING | Science topic
Hi, interesting question. You need to create a library of the spectral signatures. But before doing that, you need to re-sample the spectral...
Read more >
Re: Spectral Library Resampling Help!
I > want to resample the usgs spectral libraries to AVIRIS. Has anyone > ever done this? > Can someone help me on...
Read more >
field spectra comparison, spectral re-sampling, VIgnesh kumar ...
In this video, I explain how to compare field Spectra and Spectral Library such as USGS, JPL and JHU, Importance of spectral resampling...
Read more >
Solved Spectral resampling of a library may be necessary if
Question : Spectral resampling of a library may be necessary if it is to be compared with another library. What negative impacts can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found