reffits.py 1.9 KB
Newer Older
Wei Shoulin's avatar
Wei Shoulin committed
1

Wei Shoulin's avatar
Wei Shoulin committed
2
3
from ..common.delegate import Delegate

Wei Shoulin's avatar
Wei Shoulin committed
4
class RefFitsApi(object):
Wei Shoulin's avatar
Wei Shoulin committed
5
6
7
8
9
10
11
12
13
14
15
16
    """
    Reference Fits Operation Class of IFS
    """
    REF_FITS_BIAS = "bias"
    REF_FITS_FLAT = "flat"
    REF_FITS_DARK = "dark"
    REF_FITS_SKY = "sky"
    REF_FITS_ARC = "arc"

    REF_FITS_TYPES = [REF_FITS_BIAS, REF_FITS_FLAT, REF_FITS_DARK, REF_FITS_SKY, REF_FITS_ARC]

    def __init__(self, sub_system="ifs"):
Wei Shoulin's avatar
Wei Shoulin committed
17
        self.sub_system = sub_system
Wei Shoulin's avatar
Wei Shoulin committed
18
19
20
21
22
23
24
25
26
27
        self.module = Delegate().load(sub_module = "ifs")
        self.stub = getattr(self.module, "RefFitsApi")()
        self.file_prefix = self.stub.root_dir

    def find(self, **kwargs):
        '''
        parameter kwargs:
            obs_time = [int],
            file_name = [str],
            exp_time = (start, end),
Wei Shoulin's avatar
add rss    
Wei Shoulin committed
28
            ccd_num = [int],
Wei Shoulin's avatar
Wei Shoulin committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            status = [int],
            ref_type = [str]

        return list of reference's files records
        '''
        return self.stub.find(**kwargs)

    def get(self, **kwargs):
        '''  query database, return a record as dict

        parameter kwargs:
            fits_id = [int] 

        return dict or None
        '''
        return self.stub.get(**kwargs)

    def read(self, **kwargs):
        ''' yield bytes of fits file

        parameter kwargs:
            fits_id = [int],
            file_path = [str], 
            chunk_size = [int] default 20480

        yield bytes of fits file
        '''
        return self.stub.read(**kwargs)

    def update_status(self, **kwargs):
        ''' update the status of reduction

        parameter kwargs:
            fits_id = [int],
            status = [int]
        '''
        return self.stub.update_status(**kwargs)

    def write(self, **kwargs):
        ''' copy a local file to file storage, then reduce the header of fits file and insert a record into database
 
        parameter kwargs:
            file_path = [str]
        '''        
Wei Shoulin's avatar
Wei Shoulin committed
73
        return self.stub.write(**kwargs)
Wei Shoulin's avatar
Wei Shoulin committed
74