Skip to content

bug fix for Relab library: Sometimes data files don't have description#182

Open
kvngvikram wants to merge 1 commit intospectralpython:developfrom
kvngvikram:develop
Open

bug fix for Relab library: Sometimes data files don't have description#182
kvngvikram wants to merge 1 commit intospectralpython:developfrom
kvngvikram:develop

Conversation

@kvngvikram
Copy link

Hi,

The Relab spectral database sometimes doesn't have description in their data files (.asc files). This can be any number of lines before the last lines of Source info and Date lines.
And I guess it is arbitary. Some have and some don't.

In the current state for files with no description, creating database results in an error because there is no s.sample['description'] which is necessary.

So this pull request adds a test spectra that doesn't have the description along with the existing one.
And the code was edited so that anything lines that do not have 'Source' or 'Date' are appended as description. And even if there is no description, the s.measurement['name'] will be used (as intended previously).

Note:
Here is the error message for the newer test files but older code:

$ python -m spectral.tests.database
------------------------------------------------------------------------
Running database tests.
------------------------------------------------------------------------
Testing create_database..................................... OK
Testing create_envi_lib..................................... OK
Testing read_signatures..................................... OK
Traceback (most recent call last):
  File "/home/happy/Desktop/spectral/spectral/database/relab.py", line 317, in _import_files
    sampleNum, s['owner'], s['origin'], phase, s['description'])
                                               ~^^^^^^^^^^^^^^^
KeyError: 'description'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/happy/Desktop/spectral/spectral/tests/database.py", line 210, in <module>
    run()
    ~~~^^
  File "/home/happy/Desktop/spectral/spectral/tests/database.py", line 201, in run
    T().run()
    ~~~~~~~^^
  File "/home/happy/Desktop/spectral/spectral/tests/spytest.py", line 57, in run
    method()
    ~~~~~~^^
  File "/home/happy/Desktop/spectral/spectral/tests/database.py", line 90, in test_create_database
    db = spy.RelabDatabase.create(RELAB_DB, RELAB_DATA_DIR)
  File "/home/happy/Desktop/spectral/spectral/database/relab.py", line 246, in create
    db._import_files(relab_data_dir)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/happy/Desktop/spectral/spectral/database/relab.py", line 319, in _import_files
    raise Exception ('Error creating IDD')
Exception: Error creating IDD
Testing create_database.....................................

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