prose icon indicating copy to clipboard operation
prose copied to clipboard

SelectiveStack: header and metadata

Open schackey opened this issue 2 years ago • 1 comments

Feature Request

It could be nice to write metadata and header information to the resulting stack from the 'SelectiveStack' Block.

Motivation

I tried doing the plate solving for automatic target detection on the stack (instead of the reference) to have the clearest contrast of star/background, when it started giving me issues like that it's missing 'pixel_scale' in the header (and so on). Currently, the stack image as produced by the 'SelectiveStack' Block does not get any header information. If this is on purpose and the user is encouraged to write the header for the stack themselves, then nevermind! Just thought this could help beginner users like myself!

Alternatives

Currently, I implemented a few lines in the 'SelectiveStack' Block that would just write the metadata and header of the last image that went into the block to the resulting stack image. I know that this is a bit crude and a careful selection of just few of the metadata/header properties would be more fitting. I am happy to think about what such a selection could be, if you are interested to include a header and metadata in the stack.

class SelectiveStack(Block): def init(self, n=5, name=None): """Build a median stack image from the n best-FWHM images

    |read| :code:`Image.fwhm`

    Parameters
    ----------
    n : int, optional
        number of images to use, by default 5
    name : str, optional
        name of the blocks, by default None
    """
    super().__init__(name=name)
    self.n = n
    self._images = []
    self._sigmas = []

def run(self, image: Image):
    sigma = image.fwhm
    self.metadata = image.metadata ######################## EDIT
    self.header = image.header ############################ EDIT
    if len(self._images) < self.n:
        self._images.append(image)
        self._sigmas.append(sigma)
    else:
        i = np.argmax(self._sigmas)
        if self._sigmas[i] > sigma:
            self._sigmas[i] = sigma
            self._images[i] = image

def terminate(self):
    self.stack = Image(easy_median([im.data for im in self._images]))
    self.stack.metadata = self.metadata ######################## EDIT
    self.stack.header = self.header ############################ EDIT

schackey avatar May 16 '23 10:05 schackey

That's a great addition indeed @schackey. Could you pull from the branch 3.0.0 (to fix #83), update your code and open a pull request?

lgrcia avatar May 16 '23 16:05 lgrcia