Exemplo n.º 1
0
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
Exemplo n.º 2
0
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.')
Exemplo n.º 3
0
def write_selected_attributes(indices: np.ndarray, port_input: InputPort,
                              port_selected: OutputPort,
                              port_removed: OutputPort) -> None:
    """
    Function to write the attributes of a selected number of images.

    Parameters
    ----------
    indices : numpy.ndarray
        Indices that are removed.
    port_input : pynpoint.core.dataio.InputPort
        Port to the input data.
    port_selected : pynpoint.core.dataio.OutputPort
        Port to store the attributes of the selected images.
    port_removed : pynpoint.core.dataio.OutputPort
        Port to store the attributes of the removed images. Not written if set to None.

    Returns
    -------
    NoneType
        None
    """

    non_static = port_input.get_all_non_static_attributes()

    for i, item in enumerate(non_static):
        values = port_input.get_attribute(item)

        if values.shape[0] == port_input.get_shape()[0]:

            if port_selected is not None:
                if np.size(indices) > 0:
                    if values.ndim == 1:
                        selected = np.delete(values, indices)

                    elif values.ndim == 2:
                        selected = np.delete(values, indices, axis=0)

                else:
                    selected = values

                port_selected.add_attribute(item, selected, static=False)

            if port_removed is not None and np.size(indices) > 0:
                removed = values[indices]

                port_removed.add_attribute(item, removed, static=False)

    if 'NFRAMES' in non_static:
        nframes = port_input.get_attribute('NFRAMES')

        nframes_sel = np.zeros(nframes.shape, dtype=np.int)
        nframes_del = np.zeros(nframes.shape, dtype=np.int)

        for i, frames in enumerate(nframes):
            total = np.sum(nframes[0:i])

            if np.size(indices) > 0:
                index_del = np.where(
                    np.logical_and(indices >= total,
                                   indices < total + frames))[0]

                nframes_sel[i] = frames - np.size(index_del)
                nframes_del[i] = np.size(index_del)

            else:
                nframes_sel[i] = frames
                nframes_del[i] = 0

        if port_selected is not None:
            port_selected.add_attribute('NFRAMES', nframes_sel, static=False)

        if port_removed is not None:
            port_removed.add_attribute('NFRAMES', nframes_del, static=False)