-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix bug in _build_spectrum #66
Conversation
Codecov ReportBase: 84.88% // Head: 84.76% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #66 +/- ##
==========================================
- Coverage 84.88% 84.76% -0.13%
==========================================
Files 73 73
Lines 8892 8898 +6
Branches 1907 1955 +48
==========================================
- Hits 7548 7542 -6
- Misses 877 893 +16
+ Partials 467 463 -4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Would it make sense to test for the correct handling of the indexing? Note that the PS: Lint is unhappy with your new formatting ;-) |
I rebased to solve the merge conflict. There is an error in the test suite: ______________________ test_load_spectral_map_compressed _______________________
[gw1] linux -- Python 3.8.16 /opt/hostedtoolcache/Python/3.8.16/x64/bin/python
def test_load_spectral_map_compressed():
fname = os.path.join(
MY_PATH, "digitalsurf_data", "test_spectral_map_compressed.sur"
)
> s = hs.load(fname)
rsciio/tests/test_digitalsurface.py:235:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:[51](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:52)7: in load
objects = [load_single_file(filename, lazy=lazy, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:517: in <listcomp>
objects = [load_single_file(filename, lazy=lazy, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:[57](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:58)6: in load_single_file
return load_with_reader(filename=filename, reader=reader, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:[59](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:60)7: in load_with_reader
file_data_list = importlib.import_module(reader["api"]).file_reader(filename,
rsciio/digitalsurf/_api.py:1267: in file_reader
surdict = ds._build_sur_dict()
rsciio/digitalsurf/_api.py:512: in _build_sur_dict
self._build_hyperspectral_map()
rsciio/digitalsurf/_api.py:636: in _build_hyperspectral_map
self.signal_dict["original_metadata"] = self._build_original_metadata()
rsciio/digitalsurf/_api.py:928: in _build_original_metadata
parsedict = self._MS_parse(a["_[60](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:61)_Comment"], "$", "=")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
strMS = '@@SPECTRUMNAMES§@@\n\n$_WAFER\n$Lot Number = LOT_0000\n$ID = WAFER_0000\n$Type = ROUNDWITHFLAT\n$Center Position X = ...e Calibration Range_Y = 9.200000 V\n$Start_X = 0\n$Size_X = 1024\n$Start_Y = 0\n$Size_Y = 1024\n$Rotate = 0.000000 deg'
prefix = '$', delimiter = '='
@staticmethod
def _MS_parse(strMS, prefix, delimiter):
"""Parses a string containing metadata information. The string can be
read from the comment section of a .sur file, or, alternatively, a file
containing them with a similar formatting.
Parameters
----------
strMS: string containing metadata
prefix: string (or char) character assumed to start each line.
'$' if a .sur file.
delimiter: string that delimits the keyword from value. always '='
Returns
-------
dict_ms: dictionnary in the correct hyperspy metadata format
"""
# dict_ms is created as an empty dictionnary
dict_ms = {}
# Title lines start with an underscore
TITLESTART = "{:s}_".format(prefix)
for line in strMS.splitlines():
# Here we ignore any empty line or line starting with @@
ignore = False
if not line.strip() or line.startswith("@@"):
ignore = True
# If the line must not be ignored
if not ignore:
if line.startswith(TITLESTART):
# We strip keys from whitespace at the end and beginning
dict_ms = line[len(TITLESTART) :].strip()
> dict_ms[dict_ms] = {}
E TypeError: 'str' object does not support item assignment
rsciio/digitalsurf/_api.py:1031: TypeError
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
____________________________ test_load_spectral_map ____________________________
[gw1] linux -- Python 3.8.16 /opt/hostedtoolcache/Python/3.8.16/x64/bin/python
def test_load_spectral_map():
fname = os.path.join(MY_PATH, "digitalsurf_data", "test_spectral_map.sur")
> s = hs.load(fname)
rsciio/tests/test_digitalsurface.py:283:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:517: in load
objects = [load_single_file(filename, lazy=lazy, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:517: in <listcomp>
objects = [load_single_file(filename, lazy=lazy, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:576: in load_single_file
return load_with_reader(filename=filename, reader=reader, **kwds)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/hyperspy/io.py:597: in load_with_reader
file_data_list = importlib.import_module(reader["api"]).file_reader(filename,
rsciio/digitalsurf/_api.py:1267: in file_reader
surdict = ds._build_sur_dict()
rsciio/digitalsurf/_api.py:512: in _build_sur_dict
self._build_hyperspectral_map()
rsciio/digitalsurf/_api.py:[63](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:64)6: in _build_hyperspectral_map
self.signal_dict["original_metadata"] = self._build_original_metadata()
rsciio/digitalsurf/_api.py:928: in _build_original_metadata
parsedict = self._MS_parse(a["_60_Comment"], "$", "=")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
strMS = '@@SPECTRUMNAMES§@@\n\n$_WAFER\n$Lot Number = LOT_0000\n$ID = WAFER_0000\n$Type = ROUNDWITHFLAT\n$Center Position X = ...e Calibration Range_Y = 9.200000 V\n$Start_X = 0\n$Size_X = 1024\n$Start_Y = 0\n$Size_Y = 1024\n$Rotate = 0.000000 deg'
prefix = '$', delimiter = '='
@staticmethod
def _MS_parse(strMS, prefix, delimiter):
"""Parses a string containing metadata information. The string can be
read from the comment section of a .sur file, or, alternatively, a file
containing them with a similar formatting.
Parameters
----------
strMS: string containing metadata
prefix: string (or char) character assumed to start each line.
'$' if a .sur file.
delimiter: string that delimits the keyword from value. always '='
Returns
-------
dict_ms: dictionnary in the correct hyperspy metadata format
"""
# dict_ms is created as an empty dictionnary
dict_ms = {}
# Title lines start with an underscore
TITLESTART = "{:s}_".format(prefix)
for line in strMS.splitlines():
# Here we ignore any empty line or line starting with @@
ignore = False
if not line.strip() or line.startswith("@@"):
ignore = True
# If the line must not be ignored
if not ignore:
if line.startswith(TITLESTART):
# We strip keys from whitespace at the end and beginning
dict_ms = line[len(TITLESTART) :].strip()
> dict_ms[dict_ms] = {}
E TypeError: 'str' object does not support item assignment
rsciio/digitalsurf/_api.py:1031: TypeError
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:5[79](https://github.com/hyperspy/rosettasciio/actions/runs/4151444898/jobs/7181754420#step:10:80) If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
------------------------------ Captured log call -------------------------------
ERROR hyperspy.io:io.py:579 If this file format is supported, please report this error to the HyperSpy developers.
=============================== warnings summary =============================== |
Thanks for letting me know |
any progress on this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, just checked and the bug fixing change has slipped into #98. PR can be closed.
I suggest that I update the changelog of #98 to signal that this bug is fixed to deal with this easily.
Sorry for the mess, I was inbetween position and github accounts change so the VCS management went a bit messy on my side...
self.signal_dict["data"] = np.squeeze( | ||
hypdic["_62_points"].reshape( | ||
hypdic["_19_Number_of_Lines"], | ||
hypdic["_18_Number_of_Points"], | ||
) | ||
) | ||
data_shape = (hypdic["_19_Number_of_Lines"], hypdic["_18_Number_of_Points"]) | ||
data_array = np.squeeze(hypdic["_62_points"].reshape(data_shape, order="C")) | ||
|
||
self.signal_dict["data"] = data_array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only lines of code actually fixing code. They are already implemented in #98
Rest of the modifications (including one causing test suite error) are improvement on naming conventions that went wrong.
This PR can be closed
Description of the change
Fixes the same bug as hyperspy/hyperspy#3060
Progress of the PR
upcoming_changes
folder (seeupcoming_changes/README.rst
),readthedocs
doc build of this PR (link in github checks)Minimal example of the bug fix or the new feature
See hyperspy/hyperspy#3060