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_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 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_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 set_extra_attr(fits_file: str, nimages: int, config_port: ConfigPort, image_out_port: OutputPort, first_index: int) -> int: """ Function which adds extra attributes to the central database. Parameters ---------- fits_file : str Absolute path and filename of the FITS file. nimages : int Number of images. config_port : pynpoint.core.dataio.ConfigPort Configuration port. image_out_port : pynpoint.core.dataio.OutputPort Output port of the images to which the attributes are stored. first_index : int First image index of the current subset. Returns ------- int First image index for the next subset. """ pixscale = config_port.get_attribute('PIXSCALE') image_index = np.arange(first_index, first_index + nimages, 1) for item in image_index: image_out_port.append_attribute_data('INDEX', item) image_out_port.append_attribute_data('FILES', fits_file) image_out_port.add_attribute('PIXSCALE', pixscale, static=True) return first_index + nimages
def set_nonstatic_attr(header: fits.header.Header, config_port: ConfigPort, image_out_port: OutputPort, check: bool = True) -> None: """ Function which adds the non-static attributes to the central database. Parameters ---------- header : astropy.io.fits.header.Header Header information from the FITS file that is read. config_port : pynpoint.core.dataio.ConfigPort Configuration port. image_out_port : pynpoint.core.dataio.OutputPort Output port of the images to which the non-static attributes are stored. Returns ------- NoneType None """ attributes = get_attributes() nonstatic = [] for key, value in six.iteritems(attributes): if value['attribute'] == 'non-static': nonstatic.append(key) for attr in nonstatic: if attributes[attr]['config'] == 'header': fitskey = config_port.get_attribute(attr) # if type(fitskey) == np.bytes_: # fitskey = str(fitskey.decode('utf-8')) if fitskey != 'None': if fitskey in header: image_out_port.append_attribute_data(attr, header[fitskey]) elif header['NAXIS'] == 2 and attr == 'NFRAMES': image_out_port.append_attribute_data(attr, 1) elif check: warnings.warn( 'Non-static attribute %s (=%s) not found in the ' 'FITS header.' % (attr, fitskey)) image_out_port.append_attribute_data(attr, -1)
def __init__(self, name_in): """ Abstract constructor of a PypelineModule which needs a name as identifier. :param name_in: The name of the PypelineModule. :type name_in: str :return: None """ assert (isinstance(name_in, str)), "Name of the PypelineModule needs to be a string." self._m_name = name_in self._m_data_base = None self._m_config_port = ConfigPort("config")
def __init__(self, name_in: str) -> None: """ Abstract constructor of a :class:`~pynpoint.core.processing.PypelineModule`. Parameters ---------- name_in : str The name of the :class:`~pynpoint.core.processing.PypelineModule`. Returns ------- NoneType None """ self._m_name = name_in self._m_data_base = None self._m_config_port = ConfigPort('config')
def __init__(self, name_in): """ Abstract constructor of a PypelineModule. Needs a name as identifier. Parameters ---------- name_in : str The name of the PypelineModule. Returns ------- NoneType None """ assert isinstance(name_in, str), 'Name of the PypelineModule needs to be a string.' self._m_name = name_in self._m_data_base = None self._m_config_port = ConfigPort('config')
def set_static_attr(fits_file: str, header: fits.header.Header, config_port: ConfigPort, image_out_port: OutputPort, check: bool = True) -> None: """ Function which adds the static attributes to the central database. Parameters ---------- fits_file : str Name of the FITS file. header : astropy.io.fits.header.Header Header information from the FITS file that is read. config_port : pynpoint.core.dataio.ConfigPort Configuration port. image_out_port : pynpoint.core.dataio.OutputPort Output port of the images to which the static attributes are stored. check : bool Print a warning if certain attributes from the configuration file are not present in the FITS header. If set to `False`, attributes are still written to the dataset but there will be no warning if a keyword is not found in the FITS header. Returns ------- NoneType None """ attributes = get_attributes() static = [] for key, value in six.iteritems(attributes): if value['config'] == 'header' and value['attribute'] == 'static': static.append(key) for attr in static: fitskey = config_port.get_attribute(attr) if isinstance(fitskey, np.bytes_): fitskey = str(fitskey.decode('utf-8')) if fitskey != 'None': if fitskey in header: status = image_out_port.check_static_attribute( attr, header[fitskey]) if status == 1: image_out_port.add_attribute(attr, header[fitskey], static=True) elif status == 0: pass elif status == -1: warnings.warn( f'Static attribute {fitskey} has changed. Possibly the ' f'current file {fits_file} does not belong to the data set ' f'\'{image_out_port.tag}\'. Attribute value is updated.' ) elif check: warnings.warn( f'Static attribute {attr} (={fitskey}) not found in the FITS ' 'header.')