(
self,
image_key: str,
stats_name: str = DataStatsKeys.IMAGE_HISTOGRAM,
hist_bins: list[int] | int | None = None,
hist_range: list | None = None,
)
| 896 | """ |
| 897 | |
| 898 | def __init__( |
| 899 | self, |
| 900 | image_key: str, |
| 901 | stats_name: str = DataStatsKeys.IMAGE_HISTOGRAM, |
| 902 | hist_bins: list[int] | int | None = None, |
| 903 | hist_range: list | None = None, |
| 904 | ): |
| 905 | self.image_key = image_key |
| 906 | |
| 907 | # set defaults |
| 908 | self.hist_bins: list[int] = ( |
| 909 | [100] if hist_bins is None else hist_bins if isinstance(hist_bins, list) else [hist_bins] |
| 910 | ) |
| 911 | self.hist_range: list = [-500, 500] if hist_range is None else hist_range |
| 912 | |
| 913 | report_format = {"counts": None, "bin_edges": None} |
| 914 | |
| 915 | super().__init__(stats_name, report_format) |
| 916 | self.update_ops(ImageStatsKeys.HISTOGRAM, SampleOperations()) |
| 917 | |
| 918 | # check histogram configurations for each channel in list |
| 919 | if not all(isinstance(hr, list) for hr in self.hist_range): |
| 920 | self.hist_range = [self.hist_range] |
| 921 | if len(self.hist_bins) != len(self.hist_range): |
| 922 | raise ValueError( |
| 923 | f"Number of histogram bins ({len(self.hist_bins)}) and " |
| 924 | f"histogram ranges ({len(self.hist_range)}) need to be the same!" |
| 925 | ) |
| 926 | for i, hist_params in enumerate(zip(self.hist_bins, self.hist_range)): |
| 927 | _hist_bins, _hist_range = hist_params |
| 928 | if not isinstance(_hist_bins, int) or _hist_bins < 0: |
| 929 | raise ValueError(f"Expected {i + 1}. hist_bins value to be positive integer but got {_hist_bins}") |
| 930 | if not isinstance(_hist_range, list) or len(_hist_range) != 2: |
| 931 | raise ValueError( |
| 932 | f"Expected {i + 1}. hist_range values to be list of length 2 but received {_hist_range}" |
| 933 | ) |
| 934 | |
| 935 | def __call__(self, data: dict) -> dict: |
| 936 | """ |
nothing calls this directly
no test coverage detected