Repository: paris-saclay-cds/specio

Issue:
Rename specio.Spectrum.spectrum into specio.Spectrum.amplitude

Discussion:

Patch:
diff --git a/doc/api.rst b/doc/api.rst
index 4b46ff1..57f9783 100644
--- a/doc/api.rst
+++ b/doc/api.rst
@@ -50,7 +50,7 @@ from the class :class:`specio.core.Spectrum`. This class is composed of three
 attributes:
 
 * a 1D ndarray of shape (n_wavelength,) or 2D ndarray of shape
-  (n_spectra, n_wavelength) ``spectrum`` containing the counts/amplitude for
+  (n_spectra, n_wavelength) ``amplitudes`` containing the counts/amplitude for
   the different wavelengths;
 * a 1D ndarray of shape (n_wavelength,) ``wavelength`` containing the
   wavelength for which the spectra have been acquired;
diff --git a/examples/plot_spectrum_usage.py b/examples/plot_spectrum_usage.py
index 747cc99..aaca836 100644
--- a/examples/plot_spectrum_usage.py
+++ b/examples/plot_spectrum_usage.py
@@ -26,7 +26,7 @@ print(__doc__)
 # information:
 #
 # * a 1D ndarray of shape (n_wavelength,) or 2D ndarray of shape
-#   (n_spectra, n_wavelength) ``spectrum``;
+#   (n_spectra, n_wavelength) ``amplitudes``;
 # * a 1D ndarray of shape (n_wavelength,) ``wavelength``;
 # * a dict ``meta``.
 #
diff --git a/examples/reader/plot_read_fsm.py b/examples/reader/plot_read_fsm.py
index d41aa2f..f50ccd6 100644
--- a/examples/reader/plot_read_fsm.py
+++ b/examples/reader/plot_read_fsm.py
@@ -28,5 +28,5 @@ spectra = specread(fsm_filename)
 
 # Plot the first spectra
 plt.plot(spectra.wavelength,
-         spectra.spectrum[0])
+         spectra.amplitudes[0])
 plt.show()
diff --git a/examples/reader/plot_read_multiple_files.py b/examples/reader/plot_read_multiple_files.py
index f144611..32bfadd 100644
--- a/examples/reader/plot_read_multiple_files.py
+++ b/examples/reader/plot_read_multiple_files.py
@@ -33,7 +33,7 @@ spectra = specread(spc_filenames)
 
 # Plot the first spectra
 plt.plot(spectra.wavelength,
-         spectra.spectrum.T)
+         spectra.amplitudes.T)
 
 # We get the axis information by using the meta data of the first file read.
 plt.xlabel(spectra.meta[0]['xlabel'])
diff --git a/examples/reader/plot_read_spc.py b/examples/reader/plot_read_spc.py
index ab2ec09..6ab1fd2 100644
--- a/examples/reader/plot_read_spc.py
+++ b/examples/reader/plot_read_spc.py
@@ -28,7 +28,7 @@ spectra = specread(spc_filename)
 
 # Plot the first spectra
 plt.plot(spectra.wavelength,
-         spectra.spectrum)
+         spectra.amplitudes)
 plt.xlabel(spectra.meta['xlabel'])
 plt.ylabel(spectra.meta['ylabel'])
 plt.show()
diff --git a/specio/core/format.py b/specio/core/format.py
index 6ff8db1..91f55fc 100644
--- a/specio/core/format.py
+++ b/specio/core/format.py
@@ -396,8 +396,8 @@ class Format(object):
 
             """
             if isinstance(self._data, Spectrum):
-                if index is not None and self._data.spectrum.ndim == 2:
-                    return Spectrum(self._data.spectrum[index],
+                if index is not None and self._data.amplitudes.ndim == 2:
+                    return Spectrum(self._data.amplitudes[index],
                                     self._data.wavelength,
                                     self._data.meta)
                 else:
diff --git a/specio/core/functions.py b/specio/core/functions.py
index a71f255..de6523b 100644
--- a/specio/core/functions.py
+++ b/specio/core/functions.py
@@ -159,7 +159,7 @@ def specread(uri, format=None, **kwargs):
         :class:`specio.core.Spectrum`.
         A :class:`specio.core.Spectrum` contains:
             * a 1D ndarray of shape (n_wavelength,) or 2D ndarray of shape
-              (n_spectra, n_wavelength) ``spectrum``;
+              (n_spectra, n_wavelength) ``amplitudes``;
             * a 1D ndarray of shape (n_wavelength,) ``wavelength``;
             * a dict ``meta``.
 
@@ -196,7 +196,7 @@ def specread(uri, format=None, **kwargs):
                     return spectrum
 
                 else:
-                    spectrum_2d, meta_2d = zip(*[(sp.spectrum, sp.meta)
+                    spectrum_2d, meta_2d = zip(*[(sp.amplitudes, sp.meta)
                                                  for sp in spectrum])
                     return Spectrum(np.vstack(spectrum_2d),
                                     wavelength,
diff --git a/specio/core/util.py b/specio/core/util.py
index ecaabb5..42a4ca3 100644
--- a/specio/core/util.py
+++ b/specio/core/util.py
@@ -61,8 +61,8 @@ class Spectrum(object):
 
     Parameters
     ----------
-    spectrum : ndarray, shape (n_wavelength) or (n_spectra, n_wavelength)
-        The spectrum read.
+    amplitudes : ndarray, shape (n_wavelength) or (n_spectra, n_wavelength)
+        The amplitudes or counts.
 
     wavelength : ndarray, shape (n_wavelength,)
         The corresponding wavelength.
@@ -77,41 +77,41 @@ class Spectrum(object):
     """
 
     @staticmethod
-    def _validate_spectrum_wavelength(spectrum, wavelength):
+    def _validate_amplitudes_wavelength(amplitudes, wavelength):
         msg = ("The number of frequencies in wavelength and spectra are"
-               " not equal. Wavelength: {} - Spectrum: {}.")
-        if wavelength.ndim == 1 and spectrum.ndim == 2:
-            if wavelength.shape[0] != spectrum.shape[1]:
+               " not equal. Wavelength: {} - Amplitudes: {}.")
+        if wavelength.ndim == 1 and amplitudes.ndim == 2:
+            if wavelength.shape[0] != amplitudes.shape[1]:
                 raise ValueError(msg.format(wavelength.shape[0],
-                                            spectrum.shape[1]))
-        elif wavelength.ndim == 1 and spectrum.ndim == 1:
-            if wavelength.size != spectrum.size:
+                                            amplitudes.shape[1]))
+        elif wavelength.ndim == 1 and amplitudes.ndim == 1:
+            if wavelength.size != amplitudes.size:
                 raise ValueError(msg.format(wavelength.size,
-                                            spectrum.size))
+                                            amplitudes.size))
         else:
-            raise ValueError("The dimension of wavelength and spectrum are"
+            raise ValueError("The dimension of wavelength and amplitudes are"
                              " incorrect. They need to be 1-D or 2-D."
-                             " Wavelength {} - Spectrum: {}".format(
-                                 wavelength.shape, spectrum.shape))
+                             " Wavelength {} - Amplitudes: {}".format(
+                                 wavelength.shape, amplitudes.shape))
 
-        return spectrum, wavelength
+        return amplitudes, wavelength
 
-    def __init__(self, spectrum, wavelength, meta=None):
-        self.spectrum, self.wavelength = self._validate_spectrum_wavelength(
-            spectrum, wavelength)
+    def __init__(self, amplitudes, wavelength, meta=None):
+        self.amplitudes, self.wavelength = \
+            self._validate_amplitudes_wavelength(amplitudes, wavelength)
         self.meta = meta if meta is not None else {}
 
     def __len__(self):
-        if self.spectrum.ndim == 1:
+        if self.amplitudes.ndim == 1:
             return 1
         else:
-            return self.spectrum.shape[0]
+            return self.amplitudes.shape[0]
 
     def __repr__(self):
         msg = ("Spectrum: \n"
                "wavelength:\n {} \n"
-               "spectra: \n {} \n"
+               "amplitudes: \n {} \n"
                "metadata: \n {} \n".format(self.wavelength,
-                                           self.spectrum,
+                                           self.amplitudes,
                                            self.meta))
         return msg
diff --git a/specio/plugins/fsm.py b/specio/plugins/fsm.py
index fd041ab..4e518e3 100644
--- a/specio/plugins/fsm.py
+++ b/specio/plugins/fsm.py
@@ -195,7 +195,7 @@ class FSM(Format):
     >>> spectra = specread(load_fsm_path())
     >>> spectra.wavelength
     array([ 4000.,  3998.,  3996., ...,   724.,   722.,   720.])
-    >>> spectra.spectrum # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
+    >>> spectra.amplitudes # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
     array([[  38.65655136,   38.6666069 ,   38.64698792, ...,   39.89584732,
               29.76511383,   28.13317108],
            [  44.61751175,   44.51957703,   44.59909439, ...,   27.84810638,
@@ -284,7 +284,7 @@ class FSM(Format):
         def _open(self):
             self._fp = self.request.get_file()
             self._data = self._read_fsm(self._fp)
-            self._length = self._data.spectrum.shape[0]
+            self._length = self._data.amplitudes.shape[0]
 
         def _close(self):
             # Close the reader.
diff --git a/specio/plugins/spc.py b/specio/plugins/spc.py
index ce535dd..2a33e3f 100644
--- a/specio/plugins/spc.py
+++ b/specio/plugins/spc.py
@@ -46,7 +46,7 @@ class SPC(Format):
     >>> spectra.wavelength
     array([  400.62109375,   402.94384766,   405.26721191, ...,  3797.08911133,
             3798.45288086,  3799.81542969])
-    >>> spectra.spectrum
+    >>> spectra.amplitudes
     array([ 1487.        ,  1385.        ,  1441.        , ...,   147.24124146,
              139.16082764,   134.08041382])
 


Test patch:
diff --git a/specio/core/tests/test_format.py b/specio/core/tests/test_format.py
index 005bad0..b7650c7 100644
--- a/specio/core/tests/test_format.py
+++ b/specio/core/tests/test_format.py
@@ -127,15 +127,15 @@ def test_reader():
     specs = [spec for spec in R]
     assert len(specs) == n
     for i in range(3):
-        assert specs[i].spectrum[0, 0] == i
+        assert specs[i].amplitudes[0, 0] == i
         assert specs[i].wavelength[0] == i
         assert specs[i].meta['index'] == i
     for i in range(3):
         assert R.get_meta_data(i)['index'] == i
     # Read next
-    assert R.get_data(0).spectrum[0, 0] == 0
-    assert R.get_next_data().spectrum[0, 0] == 1
-    assert R.get_next_data().spectrum[0, 0] == 2
+    assert R.get_data(0).amplitudes[0, 0] == 0
+    assert R.get_next_data().amplitudes[0, 0] == 1
+    assert R.get_next_data().amplitudes[0, 0] == 2
     # Fail
     R._failmode = 1
     with pytest.raises(ValueError, message="Meta data be a dict"):
diff --git a/specio/core/tests/test_functions.py b/specio/core/tests/test_functions.py
index 90884b3..0cfd489 100644
--- a/specio/core/tests/test_functions.py
+++ b/specio/core/tests/test_functions.py
@@ -47,9 +47,9 @@ def test_specread_single_file():
     filename = join(DATA_PATH, 'data', 'spectra.foobar')
     spec1 = specread(filename)
     spec2 = specread(filename, 'foobar')
-    assert spec1.spectrum.shape == (1, 801)
+    assert spec1.amplitudes.shape == (1, 801)
     assert spec1.wavelength.shape == (801,)
-    assert_allclose(spec1.spectrum, spec2.spectrum)
+    assert_allclose(spec1.amplitudes, spec2.amplitudes)
     assert_allclose(spec1.wavelength, spec2.wavelength)
 
 
@@ -106,7 +106,7 @@ def test_specread_consitent_wavelength(side_effect, spectra_type,
     spectra = specread('')
     assert isinstance(spectra, spectra_type)
     if isinstance(spectra, Spectrum):
-        assert spectra.spectrum.shape == spectra_shape
+        assert spectra.amplitudes.shape == spectra_shape
         assert spectra.wavelength.shape == (spectra_shape[1],)
         assert spectra.meta == tuple({} for _ in range(spectra_shape[0]))
     elif isinstance(spectra, list):
diff --git a/specio/core/tests/test_util.py b/specio/core/tests/test_util.py
index 287cfdf..eb34b86 100644
--- a/specio/core/tests/test_util.py
+++ b/specio/core/tests/test_util.py
@@ -29,7 +29,7 @@ def test_spectrum_error(spectrum, wavelength, msg):
      (np.ones((10,)), np.ones((10,)), {'kind': 'random'})])
 def test_spectrum(spectrum, wavelength, metadata):
     spec = Spectrum(spectrum, wavelength, metadata)
-    assert_allclose(spec.spectrum, spectrum)
+    assert_allclose(spec.amplitudes, spectrum)
     assert_allclose(spec.wavelength, wavelength)
     assert spec.meta == {'kind': 'random'}
 
diff --git a/specio/plugins/tests/test_common.py b/specio/plugins/tests/test_common.py
index bab8387..1882966 100644
--- a/specio/plugins/tests/test_common.py
+++ b/specio/plugins/tests/test_common.py
@@ -21,6 +21,6 @@ from specio.datasets import load_spc_path
 def test_toy_data(filename, spectrum_shape, wavelength_shape):
     spec = specread(filename)
     assert isinstance(spec, Spectrum)
-    assert spec.spectrum.shape == spectrum_shape
+    assert spec.amplitudes.shape == spectrum_shape
     assert spec.wavelength.shape == wavelength_shape
     assert spec.meta['filename'] == basename(filename)
diff --git a/specio/plugins/tests/test_example.py b/specio/plugins/tests/test_example.py
index 6e5cb29..801c54f 100644
--- a/specio/plugins/tests/test_example.py
+++ b/specio/plugins/tests/test_example.py
@@ -22,5 +22,5 @@ def test_dummy_format():
     assert reader.get_length() == 1
     assert reader.get_meta_data() == {}
     spec = reader.get_data(0)
-    assert spec.spectrum.shape == (1, 801)
+    assert spec.amplitudes.shape == (1, 801)
     assert spec.wavelength.shape == (801,)
diff --git a/specio/plugins/tests/test_fsm.py b/specio/plugins/tests/test_fsm.py
index b5fa2d2..13b8898 100644
--- a/specio/plugins/tests/test_fsm.py
+++ b/specio/plugins/tests/test_fsm.py
@@ -22,9 +22,9 @@ def test_fsm_format():
     assert reader.get_length() == 7998
     assert reader.get_meta_data()['signature'] == b'PEPE'
     spec = reader.get_data()
-    assert spec.spectrum.shape == (7998, 1641)
+    assert spec.amplitudes.shape == (7998, 1641)
     assert spec.wavelength.shape == (1641,)
     spec = reader.get_data(0)
-    assert spec.spectrum.shape == (1641,)
+    assert spec.amplitudes.shape == (1641,)
     assert spec.wavelength.shape == (1641,)
-    assert spec.spectrum[0] == pytest.approx(38.656551)
+    assert spec.amplitudes[0] == pytest.approx(38.656551)
diff --git a/specio/plugins/tests/test_spc.py b/specio/plugins/tests/test_spc.py
index ff96bf0..f872ebc 100644
--- a/specio/plugins/tests/test_spc.py
+++ b/specio/plugins/tests/test_spc.py
@@ -27,10 +27,10 @@ def test_spc_format():
     assert reader.get_length() == 1
     assert reader.get_meta_data()['dat_fmt'] == 'x-y'
     spec = reader.get_data()
-    assert spec.spectrum.shape == (1911,)
+    assert spec.amplitudes.shape == (1911,)
     assert spec.wavelength.shape == (1911,)
     spec = reader.get_data(0)
-    assert spec.spectrum.shape == (1911,)
+    assert spec.amplitudes.shape == (1911,)
     assert spec.wavelength.shape == (1911,)
 
 
@@ -48,8 +48,8 @@ def test_spc_file(filename, spectrum_shape, wavelength_shape):
         # in '-xy.spc', there is two different wavelength size: we are checking
         # each of them
         for wi in range(1):
-            assert spec[wi].spectrum.shape == spectrum_shape[wi]
+            assert spec[wi].amplitudes.shape == spectrum_shape[wi]
             assert spec[wi].wavelength.shape == wavelength_shape[wi]
     else:
-        assert spec.spectrum.shape == spectrum_shape
+        assert spec.amplitudes.shape == spectrum_shape
         assert spec.wavelength.shape == wavelength_shape