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 attribute == pytest.approx(0.027, rel=self.limit, abs=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 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 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.')