how_this_code_will_be_used.py 1.8 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
5
import joblib
from astropy.io import fits
from csst.core.processor import CsstProcessor
from csst.msc.data_manager import CsstMscDataManager

BO ZHANG's avatar
BO ZHANG committed
6
from csst_proto.api import flip_image
BO ZHANG's avatar
BO ZHANG committed
7
8
9


class CsstProcFlipImage(CsstProcessor):
BO ZHANG's avatar
BO ZHANG committed
10
    """ This processor flips images """
BO ZHANG's avatar
BO ZHANG committed
11
12

    def __init__(self, dm: CsstMscDataManager, n_jobs: int = 1):
BO ZHANG's avatar
BO ZHANG committed
13
14
15
16
17
18
19
20
21
        """

        Parameters
        ----------
        dm:
            csst data manager, used to manage the input/output file paths
        n_jobs:
            number of jobs launched
        """
BO ZHANG's avatar
BO ZHANG committed
22
23
24
25
26
        super(CsstProcFlipImage, self).__init__()
        self.dm = dm
        self.n_jobs = n_jobs

    def run(self, debug: bool = False):
BO ZHANG's avatar
BO ZHANG committed
27
        """ flip images for all detectors
BO ZHANG's avatar
BO ZHANG committed
28
29
30
31
32
33
34
35

        Parameters
        ----------
        debug:
            if True, use debug mode

        Returns
        -------
BO ZHANG's avatar
BO ZHANG committed
36
        a list of flipped images
BO ZHANG's avatar
BO ZHANG committed
37
38
        """
        img_flipped_list = joblib.Parallel(n_jobs=self.n_jobs)(
BO ZHANG's avatar
BO ZHANG committed
39
            joblib.delayed(CsstProcFlipImage.run_one_detector)(this_ccd_id)
BO ZHANG's avatar
BO ZHANG committed
40
41
42
43
44
45
46
47
48
49
50
51
            for this_ccd_id in self.dm.target_ccd_ids)
        return img_flipped_list

    def prepare(self, **kwargs):
        """ prepare the environment """
        return

    def cleanup(self):
        """ clean up the environment """
        return

    @staticmethod
BO ZHANG's avatar
BO ZHANG committed
52
    def run_one_detector(dm: CsstMscDataManager, ccd_id: int = 6):
BO ZHANG's avatar
BO ZHANG committed
53
        """ run for one detector
BO ZHANG's avatar
BO ZHANG committed
54

BO ZHANG's avatar
BO ZHANG committed
55
56
57
58
59
60
61
62
63
64
        Parameters
        ----------
        dm:
            csst data manager, used to manage the input/output file paths
        ccd_id:
            detector id

        Returns
        -------
        the flipped image
BO ZHANG's avatar
BO ZHANG committed
65
66
67
68
69
70
71
        """
        # input file path
        fp_input = dm.l1_ccd(ccd_id, post="img.fits")
        img_input = fits.getdata(fp_input)
        # flip image
        img_flipped = flip_image(img_input)
        return img_flipped