spectralpython / spectral

Python module for hyperspectral image processing
MIT License
571 stars 139 forks source link

Use frombuffer instead of fromstring (deprecated) #101

Closed Dimchord closed 4 years ago

Dimchord commented 4 years ago

The function numpy.fromstring has been deprecated, so use frombuffer instead.

tboggs commented 4 years ago

Hi Rob,

I'm not aware that np.fromstring has been deprecated. Can you point me to where you got that info or with what numpy version you got the deprecation warning?

Thanks, Thomas

kormang commented 4 years ago

Latest documentation from May 24, 2020, does not say anything about deprecation. However, it might make sense in Python3 since we're not reading from string actually. Too bad author haven't responded for months. @tboggs Do you have a plan to merge or reject this? (Excuse me if I ping you too often lately, I just want to help a bit. This library is low entry point for hyperspectral imagery for many, and it does not have real alternative. I thought it could use some help to make it live and fresh.)

kormang commented 4 years ago

Documentation for the sep parameter actually says this:

Deprecated since version 1.14: Passing sep='', the default, is deprecated since it will trigger the deprecated binary mode of this function. This mode interprets string as binary bytes, rather than ASCII text with decimal numbers, an operation which is better spelt frombuffer(string, dtype, count).

Seems this should be merged.

tboggs commented 4 years ago

The change makes sense but as it stands, it is only a partial fix because np.fromstring is used in nearly 20 places:

grep -r "np.fromstring" --include="*.py"
spectral/io/bipfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bipfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bipfile.py:        pixel = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bipfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bipfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bipfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bsqfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bsqfile.py:            band = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bsqfile.py:        pixel = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bsqfile.py:            subArray = np.fromstring(tobytes(vals),
spectral/io/bsqfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bsqfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/spyfile.py:        npArray = np.fromstring(tobytes(data), dtype=self.dtype)
spectral/io/bilfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bilfile.py:            frame = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bilfile.py:        pixel = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bilfile.py:            subArray = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bilfile.py:        subArray = np.fromstring(tobytes(vals), dtype=self.dtype)
spectral/io/bilfile.py:        arr = np.fromstring(tobytes(vals), dtype=self.dtype)

It also appears that there is now a merge conflict with the original PR, presumably due to another change made since it was submitted.

kormang commented 4 years ago

I've made PR: https://github.com/spectralpython/spectral/pull/110