• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

winter-telescope / winterdrp / 3769342838

pending completion
3769342838

push

github

Robert Stein
lintify cal hunter

1 of 1 new or added line in 1 file covered. (100.0%)

4635 of 6126 relevant lines covered (75.66%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.29
/winterdrp/processors/utils/header_annotate.py
1
"""
2
Module for adding metadata to Image headers
3
"""
4
import logging
1✔
5

6
from winterdrp.data import ImageBatch
1✔
7
from winterdrp.processors.base_processor import BaseImageProcessor
1✔
8

9
logger = logging.getLogger(__name__)
1✔
10

11

12
class HeaderAnnotator(BaseImageProcessor):
1✔
13
    """
14
    Processor for adding metadata to Image headers
15
    """
16

17
    base_key = "header_annotator"
1✔
18

19
    def __init__(
1✔
20
        self,
21
        input_keys: str | list[str],
22
        output_key: str,
23
    ):
24
        super().__init__()
×
25
        if not isinstance(input_keys, list):
×
26
            input_keys = [input_keys]
×
27

28
        self.input_keys = input_keys
×
29
        self.output_key = output_key
×
30

31
    def __str__(self) -> str:
1✔
32
        return (
×
33
            f"Updates image headers by adding values "
34
            f"for {' and '.join(self.output_key)}."
35
        )
36

37
    def _apply_to_images(
1✔
38
        self,
39
        batch: ImageBatch,
40
    ) -> ImageBatch:
41

42
        for i, image in enumerate(batch):
×
43

44
            new_val = ""
×
45
            for key in self.input_keys:
×
46
                new_val += str(image[key])
×
47

48
            image[self.output_key] = new_val
×
49
            batch[i] = image
×
50

51
        return batch
×
52

53

54
class HeaderEditor(BaseImageProcessor):
1✔
55
    """
56
    Processor for modifying metadata in Image headers
57
    """
58

59
    base_key = "header_editor"
1✔
60

61
    def __init__(
1✔
62
        self,
63
        edit_keys: str | list[str],
64
        values: str | float | int | list,
65
    ):
66
        super().__init__()
1✔
67
        if not isinstance(edit_keys, list):
1✔
68
            edit_keys = [edit_keys]
1✔
69

70
        if not isinstance(values, list):
1✔
71
            values = [values]
1✔
72

73
        assert len(edit_keys) == len(values)
1✔
74
        self.edit_keys = edit_keys
1✔
75
        self.values = values
1✔
76

77
    def __str__(self) -> str:
1✔
78
        return (
1✔
79
            f"Modifies image headers by "
80
            f"updating values for {' and '.join(self.edit_keys)}."
81
        )
82

83
    def _apply_to_images(
1✔
84
        self,
85
        batch: ImageBatch,
86
    ) -> ImageBatch:
87

88
        for i, image in enumerate(batch):
1✔
89

90
            for ind, key in enumerate(self.edit_keys):
1✔
91
                image[key] = self.values[ind]
1✔
92

93
            batch[i] = image
1✔
94

95
        return batch
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc