Skip to content

Commit b274686

Browse files
committed
Rename signature to spectrum
1 parent ea3812a commit b274686

10 files changed

+237
-263
lines changed

autoclustering.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
def find_related_clusters2(image, min_correlation, **kwargs):
1010
"""
1111
Primitive algorithm that scans image left to right, top to buttom,
12-
and assigns pixels/signatures to clusters. When, during scaning it finds
12+
and assigns pixels/spectra to clusters. When, during scaning it finds
1313
pixel that is less than min_correlation correlated with all already found centers,
1414
algorithm assigns that pixel to new cluster, and that pixel is also new center.
1515
if kwarg start_centers is not present, then starting center is first pixel.
1616
Which means, centers are not really centers, but starting pixels of each
1717
cluster. However, these centers are good potetial starting centers
1818
to apply K-Means.
1919
Returns pair of (map of cluster indices, centers).
20-
Centers have shape (num_centers, signature_length).
20+
Centers have shape (num_centers, spectrum_length).
2121
"""
2222
from spectral.algorithms.spymath import has_nan, NaNValueError
2323

@@ -78,7 +78,7 @@ def find_mincorr_centers(values, centers):
7878
that is, value that has smallest sum of cosines between itself
7979
and each of the centers.
8080
Values and centers should be normalized.
81-
Values are of shape (N, signature_length), and centers (sig_len, N).
81+
Values are of shape (N, spectrum_length), and centers (spec_len, N).
8282
Returns pair of value and its index.
8383
"""
8484
minci = np.argmin(np.sum(np.matmul(values, centers), axis=1))
@@ -149,16 +149,16 @@ def find_mincorr_from_center(values, centers):
149149

150150
def find_maxdist_clusters(image, min_correlation):
151151
"""
152-
First finds signature that is least correlated with the average.
152+
First finds spectrum that is least correlated with the average.
153153
It becomes first cluster center.
154154
Then finds next cluster center, the one that is least correlated
155155
with average (center) of existing cluster centers.
156-
Then the steps are repeated, until there is no more unclassified signatures.
157-
After each iteration all signatures that have correlation with new center
156+
Then the steps are repeated, until there is no more unclassified spectra.
157+
After each iteration all spectra that have correlation with new center
158158
equal or greater than min_correlation are clussified to belong to this new cluster,
159159
and excluded from further classification.
160160
Returns pair of map of indices of clusters,
161-
and cluster centers of shape (N, signature_length).
161+
and cluster centers of shape (N, spectrum_length).
162162
"""
163163
from spectral.algorithms.spymath import has_nan, NaNValueError
164164

continuummodule.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -80,54 +80,54 @@ continuum_generic_impl(PyObject *self, PyObject *args,
8080
if (PyArray_NDIM(ain) == 1) {
8181
double* datain = (double*)PyArray_DATA(ain);
8282
double* dataout = (double*)PyArray_DATA(aout);
83-
Py_ssize_t signature_length = PyArray_SHAPE(ain)[0];
84-
if (signature_length != PyArray_SHAPE(awl)[0]) {
83+
Py_ssize_t spectrum_length = PyArray_SHAPE(ain)[0];
84+
if (spectrum_length != PyArray_SHAPE(awl)[0]) {
8585
PyErr_SetString(PyExc_ValueError,
8686
"In continuum_generic_impl: wavelengths array has incorrect length.");
8787
return Py_None;
8888
}
89-
continuum_processing_f(datain, dataout, dataawl, signature_length);
89+
continuum_processing_f(datain, dataout, dataawl, spectrum_length);
9090
} else {
91-
Py_ssize_t num_signatures = PyArray_SHAPE(ain)[0];
92-
Py_ssize_t signature_length = PyArray_SHAPE(ain)[1];
93-
if (signature_length != PyArray_SHAPE(awl)[0]) {
91+
Py_ssize_t num_spectra = PyArray_SHAPE(ain)[0];
92+
Py_ssize_t spectrum_length = PyArray_SHAPE(ain)[1];
93+
if (spectrum_length != PyArray_SHAPE(awl)[0]) {
9494
PyErr_SetString(PyExc_ValueError,
9595
"In continuum_generic_impl: wavelengths array has incorrect length.");
9696
return Py_None;
9797
}
9898

9999
#pragma omp parallel for
100-
for (Py_ssize_t i = 0; i < num_signatures; ++i) {
100+
for (Py_ssize_t i = 0; i < num_spectra; ++i) {
101101
double* datain = (double*)(PyArray_DATA(ain)
102102
+ i * PyArray_STRIDES(ain)[0]);
103103
double* dataout = (double*)(PyArray_DATA(aout)
104104
+ i * PyArray_STRIDES(aout)[0]);
105-
continuum_processing_f(datain, dataout, dataawl, signature_length);
105+
continuum_processing_f(datain, dataout, dataawl, spectrum_length);
106106
}
107107
}
108108

109109
return Py_None;
110110
}
111111

112-
/* Function accepting 1d array and returning continuum signature. */
112+
/* Function accepting 1d array and returning continuum spectrum. */
113113

114114
PyDoc_STRVAR(continuum_continuum_doc,
115-
"continuum(signature)\n\
115+
"continuum(spectrum)\n\
116116
\n\
117-
Return continuum of the signature.");
117+
Return continuum of the spectrum.");
118118

119119
static PyObject *
120120
continuum_continuum(PyObject *self, PyObject *args)
121121
{
122122
return continuum_generic_impl(self, args, &continuum);
123123
}
124124

125-
/* Function accepting 1d array and returning continuum removed signature. */
125+
/* Function accepting 1d array and returning continuum removed spectrum. */
126126

127127
PyDoc_STRVAR(continuum_continuum_removed_doc,
128-
"continuum_removed(signature)\n\
128+
"continuum_removed(spectrum)\n\
129129
\n\
130-
Return continuum removed signature.");
130+
Return continuum removed spectrum.");
131131

132132
static PyObject *
133133
continuum_continuum_removed(PyObject *self, PyObject *args)

custo_math_funcs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def bspline2_from_points(points, xs):
7070
x_stitching_points.append(bspline2x_t(1.0, p0, p1, p2))
7171

7272
# Fill results with pairs (i, y(i)),
73-
# where i is x coordinate and also index in signature array,
73+
# where i is x coordinate and also index in spectrum array,
7474
# and y(i) is respective y coordinate of bspline2.
7575
results = np.empty(len(xs))
7676
filled_i = 0
@@ -227,7 +227,7 @@ def bspline3_from_points(points, xs):
227227
x_stitching_points.append(bspline3x_t(1.0, p0, p1, p2, p3))
228228

229229
# Fill results with pairs (i, y(i)),
230-
# where i is x coordinate and also index in signature array,
230+
# where i is x coordinate and also index in spectrum array,
231231
# and y(i) is respective y coordinate of bspline3.
232232
results = np.empty(len(xs))
233233
filled_i = 0

explore.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def show_centers(centers, title, labels):
4747
#for i in range(data.shape[2]):
4848
# save_rgb('./aerodrom_channels/' + str(i+1) + '.png', data[:, :, i])
4949

50-
signatures = np.empty((5, data.shape[2]))
50+
spectra = np.empty((5, data.shape[2]))
5151
labels = [u"вода", u"загрязнённая вода", u"бетон", u"болото", u"почва"]
5252
positions = [(863, 369), (999, 519), (1199, 422), (1056, 352), (357, 585)]
5353
for i in range(len(positions)):
54-
signatures[i] = data[positions[i][0], positions[i][1]]
54+
spectra[i] = data[positions[i][0], positions[i][1]]
5555

56-
show_centers(signatures, u'Сигнатуры некоторых точек изображения', labels)
56+
show_centers(spectra, u'Сигнатуры некоторых точек изображения', labels)
5757

gsus_splib_utils/__init__.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from spectral import *
77

88
class SpectralData:
9-
def __init__(self, signature = None, libname = None,
9+
def __init__(self, spectrum = None, libname = None,
1010
record = None, description = None, spectrometer = None,
1111
purity = None, measurement_type = None, spectrometer_data = None):
12-
self.signature = signature
12+
self.spectrum = spectrum
1313
self.libname = libname
1414
self.record = record
1515
self.description = description
@@ -25,11 +25,11 @@ def header(self):
2525
self.purity, self.measurement_type)
2626

2727
def __repr__(self):
28-
sig_lines = ['{:.5E}'.format(s) for s in self.signature]
29-
return self.header() + '\n' + ('\n'.join(sig_lines))
28+
spectra_lines = ['{:.5E}'.format(s) for s in self.spectrum]
29+
return self.header() + '\n' + ('\n'.join(spectra_lines))
3030

3131
def __str__(self):
32-
return self.header() + ' \t {} channels'.format(len(self.signature))
32+
return self.header() + ' \t {} channels'.format(len(self.spectrum))
3333

3434
@staticmethod
3535
def parse_header(header_line):
@@ -61,41 +61,41 @@ def read_from_file(filename):
6161
libname, record, description, spectrometer, purity, measurment_type = \
6262
SpectralData.parse_header(header_line.strip())
6363

64-
signature = []
64+
spectrum = []
6565
for line in f:
6666
try:
67-
signature.append(float(line.strip()))
67+
spectrum.append(float(line.strip()))
6868
except:
6969
pass
7070

7171
spectrometer_data = SpectrometerData.get_by_name(spectrometer)
7272

73-
return SpectralData(np.array(signature),
73+
return SpectralData(np.array(spectrum),
7474
libname, record, description,
7575
spectrometer, purity, measurment_type,
7676
spectrometer_data)
7777

7878
def replace_invalid(self, value):
79-
self.signature[self.signature < 0.0] = value
79+
self.spectrum[self.spectrum < 0.0] = value
8080
return self
8181

8282
def interpolate_invalid(self, kind='slinear'):
83-
full_xs = list(range(len(self.signature)))
84-
xs = [x for x, y in zip(full_xs, self.signature) if y > 0.0]
85-
ys = [y for y in self.signature if y > 0.0]
83+
full_xs = list(range(len(self.spectrum)))
84+
xs = [x for x, y in zip(full_xs, self.spectrum) if y > 0.0]
85+
ys = [y for y in self.spectrum if y > 0.0]
8686
if xs[0] > full_xs[0]:
8787
xs.insert(0, full_xs[0])
8888
ys.insert(0, ys[0])
8989
if xs[-1] < full_xs[-1]:
9090
xs.append(full_xs[-1])
9191
ys.append(ys[-1])
9292
f = scipy.interpolate.interp1d(xs, ys, kind=kind, assume_sorted=True)
93-
self.signature = f(full_xs)
93+
self.spectrum = f(full_xs)
9494
return self
9595

9696
def resample_as(self, spectrometer_name, with_fixed_dest = False):
9797
"""
98-
Returns signature resampled to different spectrometer.
98+
Returns spectrum resampled to different spectrometer.
9999
"""
100100
dest = SpectrometerData.get_by_name(spectrometer_name)
101101
dest_wl = dest.wavelengths
@@ -108,16 +108,16 @@ def resample_as(self, spectrometer_name, with_fixed_dest = False):
108108

109109
def resample_at(self, dest_wl, dest_bw = None):
110110
"""
111-
Returns signature resampled to different spectrometer.
111+
Returns spectrum resampled to different spectrometer.
112112
"""
113113
resampler = BandResampler(self.spectrometer_data.wavelengths, dest_wl,
114114
self.spectrometer_data.bandwidths, dest_bw)
115-
return resampler(self.signature)
115+
return resampler(self.spectrum)
116116

117117

118118
def interpolate_as(self, spectrometer_name, with_fixed_dest = True, kind='quadratic'):
119119
"""
120-
Returns signature interpoleted at wavelengths of different spectrometer,
120+
Returns spectrum interpoleted at wavelengths of different spectrometer,
121121
based on wavelengths and reflectances of original.
122122
"""
123123
dest = SpectrometerData.get_by_name(spectrometer_name)
@@ -129,37 +129,37 @@ def interpolate_as(self, spectrometer_name, with_fixed_dest = True, kind='quadra
129129

130130
def interpolate_at(self, dest_wl, kind='quadratic'):
131131
"""
132-
Returns signature interpoleted at specified wavelengths,
132+
Returns spectrum interpoleted at specified wavelengths,
133133
based on wavelengths and reflectances of original.
134134
"""
135135
xs = self.wavelengths()
136-
ys = self.signature
136+
ys = self.spectrum
137137
f = scipy.interpolate.interp1d(xs, ys, kind=kind, assume_sorted=True, fill_value='extrapolate')
138138
return f(dest_wl)
139139

140140
def in_range(self, min_wl, max_wl):
141141
"""
142-
Return wavelengths and signature part between min wavelength and max wavelength.
142+
Return wavelengths and spectrum part between min wavelength and max wavelength.
143143
"""
144144
src_wavelengths = self.spectrometer_data.wavelengths
145145
min_wl = max(src_wavelengths[0], min_wl)
146146
max_wl = min(src_wavelengths[-1], max_wl)
147147
min_index = np.argmax(src_wavelengths >= min_wl)
148148
max_index = np.argmax(src_wavelengths > max_wl)
149149
range_wl = src_wavelengths[min_index:max_index]
150-
range_sig = self.signature[min_index:max_index]
151-
return range_wl, range_sig
150+
range_spec = self.spectrum[min_index:max_index]
151+
return range_wl, range_spec
152152

153153
def in_range_of(self, spectrometer_name):
154154
"""
155-
Return wavelengths and signature part that overlaps with other spectrometer.
155+
Return wavelengths and spectrum part that overlaps with other spectrometer.
156156
"""
157157
dest_wavelengths = SpectrometerData.get_by_name(spectrometer_name).wavelengths
158158
return self.in_range(dest_wavelengths[0], dest_wavelengths[-1])
159159

160160
def fix(self):
161161
self.interpolate_invalid()
162-
self.signature = self.resample_as(self.spectrometer, True)
162+
self.spectrum = self.resample_as(self.spectrometer, True)
163163
self.fixed = True
164164
self._wavelengths = np.sort(self.spectrometer_data.wavelengths)
165165
return self
@@ -182,7 +182,7 @@ def header(self):
182182
self.spectrometer_name, self.description)
183183

184184
def __repr__(self):
185-
sig_lines = ['{:.5E}'.format(s) for s in self.signature]
185+
spectra_lines = ['{:.5E}'.format(s) for s in self.spectrum]
186186
return self.header() + '\n' + ('\n'.join(wavelengths))
187187

188188
def __str__(self):

0 commit comments

Comments
 (0)