def test_create_config_port(self) -> None: storage = DataStorage(self.test_dir + 'PynPoint_database.hdf5') with pytest.raises(ValueError) as error: ConfigPort('images', storage) assert str(error.value) == 'The tag name of the central configuration should be ' \ '\'config\'.' port = ConfigPort('config', None) with pytest.warns(UserWarning) as warning: check_error = port._check_error_cases() assert len(warning) == 1 assert warning[0].message.args[0] == 'ConfigPort can not load data unless a database is ' \ 'connected.' assert not check_error port = ConfigPort('config', storage) assert isinstance(port, ConfigPort) with pytest.warns(UserWarning) as warning: port._check_error_cases() assert len(warning) == 1 assert warning[0].message.args[0] == 'No data under the tag which is linked by the ' \ 'ConfigPort.'
def test_get_config_attribute(self): create_config(self.test_dir + "PynPoint_config.ini") Pypeline(self.test_dir, self.test_dir, self.test_dir) storage = DataStorage(self.test_dir + "PynPoint_database.hdf5") port = ConfigPort("config", None) with pytest.warns(UserWarning) as warning: attribute = port.get_attribute("CPU") assert len(warning) == 1 assert warning[0].message.args[0] == "ConfigPort can not load data unless a database is " \ "connected." assert attribute is None port = ConfigPort("config", storage) attribute = port.get_attribute("CPU") assert attribute == 1 attribute = port.get_attribute("NFRAMES") assert attribute == "NAXIS3" attribute = port.get_attribute("PIXSCALE") assert np.allclose(attribute, 0.027, rtol=limit, atol=0.) with pytest.warns(UserWarning) as warning: attribute = port.get_attribute("test") assert len(warning) == 1 assert warning[0].message.args[ 0] == "No attribute found - requested: test." assert attribute is None
def test_create_config_port(self): storage = DataStorage(self.test_dir + "PynPoint_database.hdf5") with pytest.raises(ValueError) as error: ConfigPort("images", storage) assert str( error.value ) == "The tag name of the central configuration should be 'config'." port = ConfigPort("config", None) with pytest.warns(UserWarning) as warning: check_error = port._check_error_cases() assert len(warning) == 1 assert warning[0].message.args[0] == "ConfigPort can not load data unless a database is " \ "connected." assert not check_error port = ConfigPort("config", storage) assert isinstance(port, ConfigPort) with pytest.warns(UserWarning) as warning: port._check_error_cases() assert len(warning) == 1 assert warning[0].message.args[ 0] == "No data under the tag which is linked by the ConfigPort."
def test_get_config_attribute(self) -> None: create_config(self.test_dir + 'PynPoint_config.ini') Pypeline(self.test_dir, self.test_dir, self.test_dir) storage = DataStorage(self.test_dir + 'PynPoint_database.hdf5') port = ConfigPort('config', None) with pytest.warns(UserWarning) as warning: attribute = port.get_attribute('CPU') assert len(warning) == 1 assert warning[0].message.args[0] == 'ConfigPort can not load data unless a database is ' \ 'connected.' assert attribute is None port = ConfigPort('config', storage) attribute = port.get_attribute('CPU') assert attribute == 1 attribute = port.get_attribute('NFRAMES') assert attribute == 'NAXIS3' attribute = port.get_attribute('PIXSCALE') assert np.allclose(attribute, 0.027, rtol=limit, atol=0.) with pytest.warns(UserWarning) as warning: attribute = port.get_attribute('test') assert len(warning) == 1 assert warning[0].message.args[ 0] == 'The attribute \'test\' was not found.' assert attribute is None
def __init__(self, working_place_in: Optional[str] = None, input_place_in: Optional[str] = None, output_place_in: Optional[str] = None) -> None: """ Constructor of Pypeline. Parameters ---------- working_place_in : str Working location of the Pypeline which needs to be a folder on the hard drive. The given folder will be used to save the central PynPoint database (an HDF5 file) in which all the intermediate processing steps are saved. Note that the HDF5 file can become very large depending on the size and number of input images. input_place_in : str Default input directory of the Pypeline. All ReadingModules added to the Pypeline use this directory to look for input data. It is possible to specify a different location for the ReadingModules using their constructors. output_place_in : str Default result directory used to save the output of all WritingModules added to the Pypeline. It is possible to specify a different locations for the WritingModules by using their constructors. Returns ------- NoneType None """ pynpoint_version = 'PynPoint v' + pynpoint.__version__ print(len(pynpoint_version) * '=') print(pynpoint_version) print(len(pynpoint_version) * '=' + '\n') try: contents = urllib.request.urlopen( 'https://pypi.org/pypi/pynpoint/json').read() data = json.loads(contents) latest_version = data['info']['version'] except URLError: latest_version = None if latest_version is not None and pynpoint.__version__ != latest_version: print(f'A new version ({latest_version}) is available!\n') self._m_working_place = working_place_in self._m_input_place = input_place_in self._m_output_place = output_place_in self._m_modules = collections.OrderedDict() self.m_data_storage = DataStorage( os.path.join(working_place_in, 'PynPoint_database.hdf5')) print(f'Database: {self.m_data_storage._m_location}') self._config_init()
def test_create_storage_without_existing_database(self): storage = DataStorage(self.test_data) storage.open_connection() storage.m_data_bank["data"] = [0, 1, 2, 5, 7] assert storage.m_data_bank["data"][2] == 2 assert list(storage.m_data_bank.keys()) == ["data", ] storage.close_connection() os.remove(self.test_data)
def test_create_storage_with_existing_database(self) -> None: np.random.seed(1) images = np.random.normal(loc=0, scale=2e-4, size=(10, 100, 100)) with h5py.File(self.test_data, 'w') as hdf_file: hdf_file.create_dataset('images', data=images) storage = DataStorage(self.test_data) storage.open_connection() data = storage.m_data_bank['images'] assert data[0, 0, 0] == pytest.approx(0.00032486907273264834, rel=self.limit, abs=0.) assert np.mean(data) == pytest.approx(1.0506056979365338e-06, rel=self.limit, abs=0.) os.remove(self.test_data)
def test_create_storage_with_existing_database(self): np.random.seed(1) images = np.random.normal(loc=0, scale=2e-4, size=(10, 100, 100)) h5f = h5py.File(self.test_data, "w") h5f.create_dataset("images", data=images) h5f.close() storage = DataStorage(self.test_data) storage.open_connection() data = storage.m_data_bank["images"] assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 1.0506056979365338e-06, rtol=limit, atol=0.) os.remove(self.test_data)
def test_open_close_connection(self): storage = DataStorage(self.test_data) storage.open_connection() assert storage.m_open is True storage.open_connection() assert storage.m_open is True storage.close_connection() assert storage.m_open is False storage.close_connection() assert storage.m_open is False os.remove(self.test_data)
def __init__(self, working_place_in=None, input_place_in=None, output_place_in=None): """ Constructor of Pypeline. Parameters ---------- working_place_in : str Working location of the Pypeline which needs to be a folder on the hard drive. The given folder will be used to save the central PynPoint database (an HDF5 file) in which all the intermediate processing steps are saved. Note that the HDF5 file can become very large depending on the size and number of input images. input_place_in : str Default input directory of the Pypeline. All ReadingModules added to the Pypeline use this directory to look for input data. It is possible to specify a different location for the ReadingModules using their constructors. output_place_in : str Default result directory used to save the output of all WritingModules added to the Pypeline. It is possible to specify a different locations for the WritingModules by using their constructors. Returns ------- NoneType None """ pynpoint_version = 'PynPoint v' + pynpoint.__version__ print(len(pynpoint_version) * '=') print(pynpoint_version) print(len(pynpoint_version) * '=' + '\n') self._m_working_place = working_place_in self._m_input_place = input_place_in self._m_output_place = output_place_in self._m_modules = collections.OrderedDict() self.m_data_storage = DataStorage( os.path.join(working_place_in, 'PynPoint_database.hdf5')) print(f'Database: {self.m_data_storage._m_location}') self._config_init()
def __init__(self, working_place_in=None, input_place_in=None, output_place_in=None): """ Constructor of Pypeline. :param working_place_in: Working location of the Pypeline which needs to be a folder on the hard drive. The given folder will be used to save the central PynPoint database (an HDF5 file) in which all the intermediate processing steps are saved. Note that the HDF5 file can become very large depending on the size and number of input images. :type working_place_in: str :param input_place_in: Default input directory of the Pypeline. All ReadingModules added to the Pypeline use this directory to look for input data. It is possible to specify a different location for the ReadingModules using their constructors. :type input_place_in: str :param output_place_in: Default result directory used to save the output of all WritingModules added to the Pypeline. It is possible to specify a different locations for the WritingModules by using their constructors. :return: None """ sys.stdout.write("Initiating PynPoint v" + pynpoint.__version__ + "...") sys.stdout.flush() self._m_working_place = working_place_in self._m_input_place = input_place_in self._m_output_place = output_place_in self._m_modules = collections.OrderedDict() self.m_data_storage = DataStorage( os.path.join(working_place_in, 'PynPoint_database.hdf5')) self._config_init() sys.stdout.write(" [DONE]\n") sys.stdout.flush()
def setup(self) -> None: self.limit = 1e-10 self.storage = DataStorage( os.path.dirname(__file__) + '/PynPoint_database.hdf5')
def setup(self): file_in = os.path.dirname(__file__) + "/PynPoint_database.hdf5" self.storage = DataStorage(file_in)
def setup(self): self.storage = DataStorage( os.path.dirname(__file__) + '/PynPoint_database.hdf5')
def test_create_storage_with_wrong_location(self): file_in = "/test/test.hdf5" with pytest.raises(AssertionError): DataStorage(file_in)
def setup(self) -> None: file_in = os.path.dirname(__file__) + '/PynPoint_database.hdf5' self.storage = DataStorage(file_in)
def __init__(self, working_place_in: Optional[str] = None, input_place_in: Optional[str] = None, output_place_in: Optional[str] = None) -> None: """ Parameters ---------- working_place_in : str, None Working location where the central HDF5 database and the configuration file will be stored. Sufficient space is required in the working folder since each pipeline module stores a dataset in the HDF5 database. The current working folder of Python is used as working folder if the argument is set to None. input_place_in : str, None Default input folder where a :class:`~pynpoint.core.processing.ReadingModule` that is added to the :class:`~pynpoint.core.pypeline.Pypeline` will look for input data. The current working folder of Python is used as input folder if the argument is set to None. output_place_in : str, None Default output folder where a :class:`~pynpoint.core.processing.WritingModule` that is added to the :class:`~pynpoint.core.pypeline.Pypeline` will store output data. The current working folder of Python is used as output folder if the argument is set to None. Returns ------- NoneType None """ pynpoint_version = 'PynPoint v' + pynpoint.__version__ print(len(pynpoint_version) * '=') print(pynpoint_version) print(len(pynpoint_version) * '=' + '\n') try: contents = urllib.request.urlopen( 'https://pypi.org/pypi/pynpoint/json').read() data = json.loads(contents) latest_version = data['info']['version'] except URLError: latest_version = None if latest_version is not None and pynpoint.__version__ != latest_version: print(f'A new version ({latest_version}) is available!\n') print( 'Want to stay informed about updates, bug fixes, and new features?' ) print( 'Please consider using the \'Watch\' button on the Github page:' ) print('https://github.com/PynPoint/PynPoint\n') if working_place_in is None: self._m_working_place = os.getcwd() else: self._m_working_place = working_place_in if input_place_in is None: self._m_input_place = os.getcwd() else: self._m_input_place = input_place_in if output_place_in is None: self._m_output_place = os.getcwd() else: self._m_output_place = output_place_in print(f'Working place: {self._m_working_place}') print(f'Input place: {self._m_input_place}') print(f'Output place: {self._m_output_place}\n') self._m_modules = collections.OrderedDict() hdf5_path = os.path.join(self._m_working_place, 'PynPoint_database.hdf5') self.m_data_storage = DataStorage(hdf5_path) print(f'Database: {self.m_data_storage._m_location}') self._config_init()