diff --git a/.travis.yml b/.travis.yml index f51f3a1b..99b89424 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: - '3.7' - - '2.7' - '3.8' - '3.6' - '3.5' diff --git a/docs/source/conf.py b/docs/source/conf.py index 99e9d8a8..cc4bfd97 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -46,7 +46,7 @@ project = 'sidpy' copyright = '2020, Suhas Somnath, Gerd Duscher, and contributors' -author = 'Suhas Somnath, Gerd Duscher, and contributors' +author = 'Pycroscopy contributors' # The short X.Y version version = sidpy_version @@ -301,7 +301,7 @@ # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'sidpy.tex', 'sidpy Documentation', - 'Suhas Somnath, Gerd Duscher, and contributors', 'manual'), + 'Pycroscopy contributors', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/setup.py b/setup.py index 94beefdd..74df4ede 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,6 @@ 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Cython', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', @@ -53,7 +52,7 @@ packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), url='https://pycroscopy.github.io/sidpy/about.html', license='MIT', - author='Suhas Somnath and contributors', + author='Pycroscopy contributors', author_email='pycroscopy@gmail.com', install_requires=requirements, setup_requires=['pytest-runner'], diff --git a/sidpy/__version__.py b/sidpy/__version__.py index 2fde2869..0ea2ecc7 100644 --- a/sidpy/__version__.py +++ b/sidpy/__version__.py @@ -1,2 +1,2 @@ version = '0.0.3' -time = '2020-09-18 10:00:25' +time = '2020-10-09 16:00:25' diff --git a/sidpy/sid/dataset.py b/sidpy/sid/dataset.py index f6d35ff1..0d77a485 100644 --- a/sidpy/sid/dataset.py +++ b/sidpy/sid/dataset.py @@ -290,9 +290,9 @@ def copy(self): dset_copy.modality = self.modality dset_copy.source = self.source - dset_copy.axes = {} - for dim in range(dset_copy.ndim): - dset_copy.set_dimension(dim, self.metadata[dim].copy()) + dset_copy._axes = {} + for dim in self._axes: + dset_copy.set_dimension(dim, self._axes[dim]) dset_copy.metadata = dict(self.metadata).copy() return dset_copy diff --git a/tests/sid/test_dataset.py b/tests/sid/test_dataset.py index b9d31ae3..a93ad307 100644 --- a/tests/sid/test_dataset.py +++ b/tests/sid/test_dataset.py @@ -24,39 +24,56 @@ def validate_dataset_properties(self, dataset, values, name='generic', - title='generic', units='generic', - modality='generic', dimension_dict=None, - # add anything I missed here + title='generic', quantity='generic', units='generic', + modality='generic', source='generic', dimension_dict=None, + data_type=DataTypes.UNKNOWN, + metadata={}, original_metadata={} ): + self.assertIsInstance(self, unittest.TestCase) self.assertIsInstance(dataset, Dataset) - # TODO: Validate that EVERY property is set correctly + # DONE: Validate that EVERY property is set correctly + values = np.array(values) + self.assertTrue(np.all([hasattr(dataset, att) for att in generic_attributes])) -class TestDatasetFromArray(unittest.TestCase): + expected = values.flatten() + actual = np.array(dataset).flatten() + self.assertTrue(np.all([x == y for x, y in zip(expected, actual)])) - def test_std_inputs(self): - # verify generic properties, dimensions, etc. - values = np.random.random([4, 5, 6]) - descriptor = Dataset.from_array(values) + this_attributes = [title, quantity, units, modality, source] + dataset_attributes = [getattr(dataset, att) for att in generic_attributes] - for expected, actual in zip(values, descriptor): - self.assertTrue(np.all([x == y for x, y in zip(expected, actual)])) + for expected, actual in zip(dataset_attributes, this_attributes): + self.assertTrue(np.all([x == y for x, y in zip(expected, actual)])) - self.assertTrue(np.all([hasattr(descriptor, att) for att in generic_attributes])) + self.assertEqual(dataset.data_type, data_type) - self.assertTrue(np.all([getattr(descriptor, att) == 'generic' for att in generic_attributes])) + self.assertEqual(dataset.metadata, metadata) + self.assertEqual(dataset.original_metadata, original_metadata) - self.assertEqual(descriptor.data_type, DataTypes.UNKNOWN) + if dimension_dict is None: + for dim in range(len(values.shape)): + self.assertEqual(getattr(dataset, string.ascii_lowercase[dim]), + getattr(dataset, 'dim_{}'.format(dim))) + else: + for dim in range(len(values.shape)): + self.assertEqual(getattr(dataset, dimension_dict[dim].name), + getattr(dataset, 'dim_{}'.format(dim))) + self.assertEqual(dataset._axes[dim], dimension_dict[dim]) - self.assertEqual(descriptor.metadata, {}) - self.assertEqual(descriptor.original_metadata, {}) + # Make sure we do not have too many dimensions + self.assertFalse(hasattr(dataset, 'dim_{}'.format(len(values.shape)))) + self.assertFalse(hasattr(dataset, string.ascii_lowercase[len(values.shape)])) - for dim in range(len(values.shape)): - self.assertEqual(getattr(descriptor, string.ascii_lowercase[dim]), - getattr(descriptor, 'dim_{}'.format(dim))) - self.assertFalse(hasattr(descriptor, 'dim_{}'.format(len(values.shape)))) - self.assertFalse(hasattr(descriptor, string.ascii_lowercase[len(values.shape)])) +class TestDatasetFromArray(unittest.TestCase): + + def test_std_inputs(self): + # verify generic properties, dimensions, etc. + values = np.random.random([4, 5, 6]) + descriptor = Dataset.from_array(values) + + validate_dataset_properties(self, descriptor, values) class TestDatasetConstructor(unittest.TestCase): @@ -67,28 +84,28 @@ def test_minimal_inputs(self): with self.assertRaises(TypeError): Dataset.from_array() descriptor = Dataset.from_array(np.arange(3)) - self.assertIsInstance(descriptor, Dataset) - # TODO: call validate_dataset_properties instead + validate_dataset_properties(self, descriptor, np.arange(3)) def test_all_inputs(self): - descriptor = Dataset.from_array(np.arange(3), name='test') - self.assertEqual(descriptor.title, 'test') - # TODO: call validate_dataset_properties instead + validate_dataset_properties(self, descriptor, np.arange(3), title='test') def test_user_defined_parms(self): descriptor = Dataset.from_array(np.arange(3), name='test') for att in generic_attributes: setattr(descriptor, att, 'test') - self.assertTrue(np.all([getattr(descriptor, att) == 'test' for att in generic_attributes])) test_dict = {0: 'test'} descriptor.metadata = test_dict.copy() descriptor.original_metadata = test_dict.copy() - self.assertEqual(descriptor.metadata, test_dict) - self.assertEqual(descriptor.original_metadata, test_dict) - # TODO: call validate_dataset_properties instead + + validate_dataset_properties(self, descriptor, np.arange(3), name='test', + title='test', quantity='test', units='test', + modality='test', source='test', dimension_dict=None, + data_type=DataTypes.UNKNOWN, + metadata=test_dict, original_metadata=test_dict + ) def test_invalid_main_types(self): """ @@ -271,15 +288,15 @@ def test_user_defined_parameters(self): class TestLikeData(unittest.TestCase): def test_minimal_inputs(self): - values = np.ones([4,5]) + values = np.ones([4, 5]) source_dset = Dataset.from_array(values) values = np.zeros([4, 5]) descriptor = source_dset.like_data(values) - self.assertTrue(descriptor.shape ==values.shape) + self.assertTrue(descriptor.shape == values.shape) self.assertIsInstance(descriptor, Dataset) def test_all_customized_properties(self): - values = np.ones([4,5]) + values = np.ones([4, 5]) source_dset = Dataset.from_array(values) for att in generic_attributes: setattr(source_dset, att, 'test') @@ -309,14 +326,41 @@ def test_changing_size(self): class TestCopy(unittest.TestCase): def test_minimal_inputs(self): - values = np.zeros([4, 5]) - descriptor = Dataset.from_array(values) + values = np.random.random([4, 5]) + dataset = Dataset.from_array(values) - # Just the main dataset - pass + descriptor = dataset.copy() + + self.assertIsInstance(descriptor, Dataset) + for expected, actual in zip(dataset, descriptor): + self.assertTrue(np.all([x == y for x, y in zip(expected, actual)])) + + self.assertTrue(np.all([hasattr(descriptor, att) for att in generic_attributes])) + + self.assertTrue(np.all([getattr(descriptor, att) == 'generic' for att in generic_attributes])) + + self.assertEqual(descriptor.data_type, DataTypes.UNKNOWN) + + self.assertEqual(descriptor.metadata, {}) + self.assertEqual(descriptor.original_metadata, {}) + + for dim in range(len(values.shape)): + self.assertEqual(getattr(descriptor, string.ascii_lowercase[dim]), + getattr(descriptor, 'dim_{}'.format(dim))) + + self.assertFalse(hasattr(descriptor, 'dim_{}'.format(len(dataset.shape)))) + self.assertFalse(hasattr(descriptor, string.ascii_lowercase[len(dataset.shape)])) def test_all_customized_properties(self): - pass + values = np.random.random([4, 5]) + dataset = Dataset.from_array(values) + dataset.rename_dimension(0, 'x') + dataset.quantity = 'test' + descriptor = dataset.copy() + + self.assertIsInstance(descriptor, Dataset) + self.assertEqual(descriptor.quantity, dataset.quantity) + self.assertTrue(hasattr(descriptor, 'a')) class TestRenameDimension(unittest.TestCase): @@ -363,7 +407,7 @@ class TestSetDimension(unittest.TestCase): def test_valid_index_and_dim_obj(self): values = np.zeros([4, 5]) descriptor = Dataset.from_array(values) - descriptor.set_dimension(0,Dimension(np.arange(4),'x', quantity='test', units='test' )) + descriptor.set_dimension(0, Dimension(np.arange(4), 'x', quantity='test', units='test')) self.assertIsInstance(descriptor.x, Dimension) def test_invalid_dim_object(self): @@ -390,15 +434,13 @@ def test_default_empty_metadata(self): def test_entered_metadata(self): values = np.zeros([4, 5]) descriptor = Dataset.from_array(values) - descriptor.metadata= {0: 'test'} + descriptor.metadata = {0: 'test'} # print('{}'.format(descriptor.view_metadata())) # self.assertEqual(descriptor.view_metadata(), '0 : test') - - class TestViewOriginalMetadata(unittest.TestCase): def test_default_empty_metadata(self): @@ -408,11 +450,5 @@ def test_entered_metadata(self): pass -class TestViewOriginalMetadata(unittest.TestCase): - - def test_valid(self): - pass - - if __name__ == '__main__': unittest.main()