Skip to content

Commit

Permalink
Replaced deprecated numpy data types. Bumped version.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Scheffler <[email protected]>
  • Loading branch information
danschef committed Dec 16, 2021
1 parent de045fd commit a088630
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
History
=======

0.10.2 (2021-12-16)
-------------------

* Replaced deprecated numpy data types.


0.10.1 (2021-12-15)
-------------------

Expand Down
6 changes: 3 additions & 3 deletions spechomo/classifier_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def generate_reference_cubes(self, fmt_out='ENVI', try_read_dumped_clf=True, sam
self.logger.info('Performing spectral resampling to match %s %s specifications...' % (tgt_sat, tgt_sen))
unif_random_spectra_rsp = self.resample_spectra(
unif_random_spectra,
src_cwl=np.array(src_im.meta.band_meta['wavelength'], dtype=np.float).flatten(),
src_cwl=np.array(src_im.meta.band_meta['wavelength'], dtype=float).flatten(),
tgt_rsr=self._get_tgt_RSR_object(tgt_sat, tgt_sen),
nodataVal=src_im.nodata,
alg_nodata=alg_nodata)
Expand Down Expand Up @@ -392,7 +392,7 @@ def resample_image_spectrally(self, src_im, tgt_rsr, src_nodata=None, alg_nodata

# read input image
self.logger.info('Reading the input image %s...' % im_name)
im_gA.cwl = np.array(im_gA.meta.band_meta['wavelength'], dtype=np.float).flatten()
im_gA.cwl = np.array(im_gA.meta.band_meta['wavelength'], dtype=float).flatten()

# perform spectral resampling of input image to match spectral properties of target sensor
self.logger.info('Performing spectral resampling to match spectral properties of %s %s...'
Expand Down Expand Up @@ -495,7 +495,7 @@ def mean_absolute_percentage_error(y_true, y_pred):

# avoid division by 0
if 0 in y_true:
y_true = y_true.astype(np.float)
y_true = y_true.astype(float)
y_true[y_true == 0] = np.nan

return np.nanmean(np.abs((y_true - y_pred) / y_true), axis=0) * 100
Expand Down
10 changes: 5 additions & 5 deletions spechomo/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def goodSpecMask(self):

self._goodSpecMask = goodSpecMask
else:
self._goodSpecMask = np.ones((self.im.rows * self.im.cols), dtype=np.bool)
self._goodSpecMask = np.ones((self.im.rows * self.im.cols), dtype=bool)

return self._goodSpecMask

Expand Down Expand Up @@ -256,7 +256,7 @@ def compute_euclidian_distance_2D(spectra, endmembers):

# loop over all endmember spectra and compute spectral angle for each input spectrum
for n_sample in range(n_samples):
train_spectrum = endmembers[n_sample, :].astype(np.float)
train_spectrum = endmembers[n_sample, :].astype(float)
diff = spectra - train_spectrum
dists[:, n_sample] = np.sqrt((diff ** 2).sum(axis=1))

Expand All @@ -272,7 +272,7 @@ def compute_euclidian_distance_for_labelled_spectra(spectra, labels, endmembers)

# loop over all endmember spectra and compute spectral angle for each input spectrum
for lbl in np.unique(labels):
train_spectrum = endmembers[lbl, :].astype(np.float)
train_spectrum = endmembers[lbl, :].astype(float)
mask_curlbl = labels == lbl
spectra_curlbl = spectra[mask_curlbl, :]
diff_curlbl = spectra_curlbl - train_spectrum
Expand Down Expand Up @@ -321,7 +321,7 @@ def spectral_distances_with_nodata(self):
if self.n_spectra == (self.im.rows * self.im.cols):
self._spectral_distances_with_nodata = self.spectral_distances
else:
dists = np.full_like(self.goodSpecMask, np.nan, dtype=np.float)
dists = np.full_like(self.goodSpecMask, np.nan, dtype=float)
dists[self.goodSpecMask] = self.spectral_distances
self._spectral_distances_with_nodata = dists

Expand All @@ -341,7 +341,7 @@ def spectral_angles_with_nodata(self):
if self.n_spectra == (self.im.rows * self.im.cols):
self._spectral_angles_with_nodata = self.spectral_angles
else:
angles = np.full_like(self.goodSpecMask, np.nan, dtype=np.float)
angles = np.full_like(self.goodSpecMask, np.nan, dtype=float)
angles[self.goodSpecMask] = self.spectral_angles
self._spectral_angles_with_nodata = angles

Expand Down
6 changes: 3 additions & 3 deletions spechomo/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, wvl_src, rsr_tgt, logger=None):
self._wvl_1nm = None
self._rsr_1nm = {}

wvl_src = np.array(wvl_src, dtype=np.float).flatten()
wvl_src = np.array(wvl_src, dtype=float).flatten()
if rsr_tgt.wvl_unit != 'nanometers':
rsr_tgt.convert_wvl_unit()

Expand Down Expand Up @@ -106,7 +106,7 @@ def resample_signature(self, spectrum, scale_factor=10000, nodataVal=None, alg_n
if not spectrum.ndim == 1:
raise ValueError("The array of the given spectral signature must be 1-dimensional. "
"Received a %s-dimensional array." % spectrum.ndim)
spectrum = np.array(spectrum, dtype=np.float).flatten()
spectrum = np.array(spectrum, dtype=float).flatten()
assert spectrum.size == self.wvl_src_nm.size

# convert spectrum to one multispectral image pixel and resample it
Expand Down Expand Up @@ -253,7 +253,7 @@ def _resample_tile_mp(tilebounds, nodataVal=None, alg_nodata='radical'):
else:
raise NotImplementedError(nodataVal)

tiledata = tiledata.astype(np.float)
tiledata = tiledata.astype(float)
tiledata[_mask_bool3d] = np.nan

# fill pixels with all bands nodata
Expand Down
4 changes: 2 additions & 2 deletions spechomo/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.10.1'
__versionalias__ = '20211215.01'
__version__ = '0.10.2'
__versionalias__ = '20211216.01'
2 changes: 1 addition & 1 deletion tests/test_classifier_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_resample_spectra(self):
# tgt_rsr = RSR(satellite='Terra', sensor='MODIS', sort_by_cwl=True)
unif_random_spectra_rsp = \
self.SHC.resample_spectra(unif_random_spectra,
src_cwl=np.array(src_im.meta.band_meta['wavelength'], dtype=np.float).flatten(),
src_cwl=np.array(src_im.meta.band_meta['wavelength'], dtype=float).flatten(),
tgt_rsr=tgt_rsr,
nodataVal=src_im.nodata)
self.assertIsInstance(unif_random_spectra_rsp, np.ndarray)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def setUpClass(cls):

def test_resample_signature(self):
# Get a hyperspectral spectrum.
spectrum_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=np.float).flatten()
spectrum_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=float).flatten()
spectrum = self.geoArr[0, 0, :].flatten()

sr = SR(spectrum_wvl, self.rsr_l8)
Expand All @@ -74,7 +74,7 @@ def test_resample_signature(self):

def test_resample_signature_with_nodata(self):
# Get a hyperspectral spectrum.
spectrum_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=np.float).flatten()
spectrum_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=float).flatten()
spectrum = self.geoArr[0, 0, :].flatten()
spectrum[130: 140] = -9999

Expand All @@ -84,7 +84,7 @@ def test_resample_signature_with_nodata(self):

def test_resample_image(self):
# Get a hyperspectral image.
image_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=np.float).flatten()
image_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=float).flatten()
image = self.geoArr[:]

sr = SR(image_wvl, self.rsr_l8)
Expand All @@ -94,7 +94,7 @@ def test_resample_image(self):
@unittest.SkipTest
def test__resample_tile_with_nodata(self):
# Get a hyperspectral image tile.
image_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=np.float).flatten()
image_wvl = np.array(self.geoArr.meta.band_meta['wavelength'], dtype=float).flatten()
tile = self.geoArr[:10, :5, :]
tile[0, 0, 1] = -9999 # pixel with one band nodata
tile[0, 1, 2] = -9999 # pixel with one band nodata
Expand Down

0 comments on commit a088630

Please sign in to comment.