Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PointingCalculator #2623

Draft
wants to merge 228 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 112 commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
58d868c
added stats extractor parent component
Apr 29, 2024
edfccc6
added stats extractor based on sigma clipping
Apr 29, 2024
d19168c
added cut of outliers
Apr 30, 2024
49f0f8a
update docs
May 2, 2024
9035fb4
formatted with black
May 2, 2024
8a0e89f
added pass for __call__ function
May 2, 2024
82b29e9
added unit tests
May 3, 2024
1805cb2
added changelog
May 3, 2024
a4cea6a
fix lint
May 3, 2024
16e5920
Small commit for prototyping
May 7, 2024
63d1774
Removed unneeded functions
May 10, 2024
5768ed7
Merge branch 'stats_extractor' of https://github.com/cta-observatory/…
May 23, 2024
e6ba177
I altered the class variables to th evariance statistics extractor
May 23, 2024
ddf342b
added a container for mean variance images and fixed docustring
May 24, 2024
0beb975
I changed the container type for the StarVarianceExtractor
May 27, 2024
b4df919
fix pylint
May 31, 2024
3483fd4
change __call__() to _extract()
May 31, 2024
5bbedda
minor renaming
May 31, 2024
14a0910
use pytest.fixture for Extractors
May 31, 2024
f126748
reduce duplicated code of the call function
May 31, 2024
0ec81b9
edit description of StatisticsContainer
TjarkMiener Jun 12, 2024
3910c22
added feature to shift the extraction sequence
TjarkMiener Jun 12, 2024
5c6595b
fix boundary case for the last chunk
TjarkMiener Jun 12, 2024
bc65984
I made prototypes for the CalibrationCalculators
Jun 12, 2024
d7a65a3
I made PSFModel a generic class
Jun 12, 2024
ba00bf3
fix tests
TjarkMiener Jun 12, 2024
d3aae32
fix ruff
TjarkMiener Jun 12, 2024
825b25b
I fixed some variable names
Jun 12, 2024
a5b878d
Added a method for calibrating variance images
Jun 13, 2024
e8ebdd8
Merge branch 'stats_extractor' into CalibrationCalculators
Jun 13, 2024
78481cc
Commit before push for tjark
Jun 14, 2024
41a4246
added StatisticsCalculator
TjarkMiener Jun 28, 2024
010aea6
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
26ff8a4
added stats extractor parent component
Apr 29, 2024
d142995
added stats extractor based on sigma clipping
Apr 29, 2024
0737b7f
added cut of outliers
Apr 30, 2024
225346b
update docs
May 2, 2024
74c72bb
formatted with black
May 2, 2024
faad542
added pass for __call__ function
May 2, 2024
9867431
Small commit for prototyping
May 7, 2024
3a85ffa
Removed unneeded functions
May 10, 2024
69ebd1c
added unit tests
May 3, 2024
96b2dbb
added changelog
May 3, 2024
a007773
fix lint
May 3, 2024
96fe563
I altered the class variables to th evariance statistics extractor
May 23, 2024
67d34c4
added a container for mean variance images and fixed docustring
May 24, 2024
f1429da
I changed the container type for the StarVarianceExtractor
May 27, 2024
c9ec02b
fix pylint
May 31, 2024
444e370
change __call__() to _extract()
May 31, 2024
1c4cadb
minor renaming
May 31, 2024
0ebb464
use pytest.fixture for Extractors
May 31, 2024
bbbd891
reduce duplicated code of the call function
May 31, 2024
5deef74
I made prototypes for the CalibrationCalculators
Jun 12, 2024
f09bbe1
I made PSFModel a generic class
Jun 12, 2024
b8f0a4f
I fixed some variable names
Jun 12, 2024
39fca21
Added a method for calibrating variance images
Jun 13, 2024
b114638
edit description of StatisticsContainer
TjarkMiener Jun 12, 2024
5d18f61
added feature to shift the extraction sequence
TjarkMiener Jun 12, 2024
4df8c94
fix boundary case for the last chunk
TjarkMiener Jun 12, 2024
86eb15c
fix tests
TjarkMiener Jun 12, 2024
6200653
fix ruff
TjarkMiener Jun 12, 2024
4f604c5
Commit before push for tjark
Jun 14, 2024
6dfce15
added StatisticsCalculator
TjarkMiener Jun 28, 2024
8e873d3
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
bf36b90
Merge branch 'CalibrationCalculators' of https://github.com/cta-obser…
Aug 7, 2024
f7d3223
solved merge conflicts
TjarkMiener Aug 7, 2024
91812da
I made prototypes for the CalibrationCalculators
Jun 12, 2024
326c202
I made PSFModel a generic class
Jun 12, 2024
fa029f7
I fixed some variable names
Jun 12, 2024
7c90e0f
Added a method for calibrating variance images
Jun 13, 2024
8c44a42
Commit before push for tjark
Jun 14, 2024
bff611a
added StatisticsCalculator
TjarkMiener Jun 28, 2024
d85dd50
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
c522434
adding interpolator and Merge branch 'CalibrationCalculators' of http…
Aug 8, 2024
9192790
Removed Pointing Calculator
Aug 20, 2024
b729f82
Copying over code for interpolators and pointing calculators
Aug 20, 2024
aecc5dc
Removing PointingCalculator, PSF model and interpolators
Aug 20, 2024
92f0fb8
Fixed some issues with the ChunkFunction
Aug 22, 2024
2566a4d
Adding the StatisticsExtractors
Aug 22, 2024
e3113ab
implement the StatisticsCalculator
TjarkMiener Aug 23, 2024
b9dc929
removed the helper function to get the start and end slices
TjarkMiener Aug 24, 2024
ef920da
polish docstrings
TjarkMiener Aug 25, 2024
9bfc16a
further polishing of docstrings
TjarkMiener Aug 25, 2024
aee5c10
fix typo
TjarkMiener Aug 25, 2024
1484eca
move check of config settings before loading of data
TjarkMiener Aug 25, 2024
601cbb4
moved Interpolator outside
TjarkMiener Aug 25, 2024
0347153
removed Interpolator artifacts
TjarkMiener Aug 25, 2024
b2208d5
removed reading part with TableLoader
TjarkMiener Aug 25, 2024
61936e5
removed writing part
TjarkMiener Aug 25, 2024
52ecd8a
add unit tests for calculators
TjarkMiener Aug 26, 2024
4ffd39e
add unit tests for calculators
TjarkMiener Aug 26, 2024
c404a4a
split __call__ function into two function for the first and second pass
TjarkMiener Aug 26, 2024
a59664e
fix docs and add changelog
TjarkMiener Aug 26, 2024
0ed515d
removed check for any faulty chunk
TjarkMiener Aug 27, 2024
48c686b
removed base class CalibrationCalculator and only have one Statistics…
TjarkMiener Aug 27, 2024
3bae046
fix fstring in logging
TjarkMiener Aug 28, 2024
aa5666a
bug fix
TjarkMiener Aug 28, 2024
ef53ebb
removed print
TjarkMiener Aug 28, 2024
3ca7252
removed me from CODEOWNERS
TjarkMiener Sep 3, 2024
c5f385f
I added a basic star fitter
Sep 3, 2024
2756a38
Added the fitting
Sep 12, 2024
4af4e74
Merge branch 'main' into CalibrationCalculators
TjarkMiener Sep 23, 2024
e4bc632
Copying over code for interpolators and pointing calculators
Aug 20, 2024
3b147c3
Fixed some issues with the ChunkFunction
Aug 22, 2024
4bd5cb3
Adding the StatisticsExtractors
Aug 22, 2024
509e512
I added a basic star fitter
Sep 3, 2024
69eb08e
Added the fitting
Sep 12, 2024
da561d2
Finihed V1 of the startracker code
Sep 20, 2024
32894fd
I separated the star tracking out to the StarTracer class
Sep 30, 2024
4b97544
Adding a placeholder test script
Sep 30, 2024
aa40741
Merge branch 'PointingCalculator' of https://github.com/cta-observato…
Sep 30, 2024
40c3968
fixed astroquery import
Sep 30, 2024
cea1f21
removing merge marks
Oct 1, 2024
c6d7245
I moved the interpolator classes for flatfield events to to their pro…
Oct 1, 2024
12ae9fc
added stats extractor parent component
Apr 29, 2024
cfe8328
added stats extractor based on sigma clipping
Apr 29, 2024
4d02301
added cut of outliers
Apr 30, 2024
c16b044
update docs
May 2, 2024
3a82cec
formatted with black
May 2, 2024
5646b2b
added pass for __call__ function
May 2, 2024
487da6a
Small commit for prototyping
May 7, 2024
8b5b55e
Removed unneeded functions
May 10, 2024
6e918df
added unit tests
May 3, 2024
169ca37
added changelog
May 3, 2024
c78d1dc
fix lint
May 3, 2024
ff6ab1d
I altered the class variables to th evariance statistics extractor
May 23, 2024
f44f4d2
added a container for mean variance images and fixed docustring
May 24, 2024
2200aec
I changed the container type for the StarVarianceExtractor
May 27, 2024
c4d6809
fix pylint
May 31, 2024
388aae6
change __call__() to _extract()
May 31, 2024
07f4bef
minor renaming
May 31, 2024
a3782ae
use pytest.fixture for Extractors
May 31, 2024
ad47560
reduce duplicated code of the call function
May 31, 2024
8f49802
I made prototypes for the CalibrationCalculators
Jun 12, 2024
9d86e9a
I made PSFModel a generic class
Jun 12, 2024
cd122a8
I fixed some variable names
Jun 12, 2024
12cc766
Added a method for calibrating variance images
Jun 13, 2024
20de205
edit description of StatisticsContainer
TjarkMiener Jun 12, 2024
c4936d7
added feature to shift the extraction sequence
TjarkMiener Jun 12, 2024
f7fefd1
fix boundary case for the last chunk
TjarkMiener Jun 12, 2024
56118b8
fix tests
TjarkMiener Jun 12, 2024
e68c5dd
fix ruff
TjarkMiener Jun 12, 2024
057baf6
Commit before push for tjark
Jun 14, 2024
d5eda78
added StatisticsCalculator
TjarkMiener Jun 28, 2024
53d8e98
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
f982b36
added stats extractor parent component
Apr 29, 2024
9c46f55
added stats extractor based on sigma clipping
Apr 29, 2024
57879b1
added cut of outliers
Apr 30, 2024
fd79479
update docs
May 2, 2024
b886875
formatted with black
May 2, 2024
10723a3
added pass for __call__ function
May 2, 2024
9c46748
Small commit for prototyping
May 7, 2024
a08b38c
Removed unneeded functions
May 10, 2024
4f06344
added unit tests
May 3, 2024
d0f17ee
fix lint
May 3, 2024
0778648
I altered the class variables to th evariance statistics extractor
May 23, 2024
b04e6ee
added a container for mean variance images and fixed docustring
May 24, 2024
e7ec4b8
I changed the container type for the StarVarianceExtractor
May 27, 2024
0921641
fix pylint
May 31, 2024
fa65404
change __call__() to _extract()
May 31, 2024
08d43dd
minor renaming
May 31, 2024
734d03f
use pytest.fixture for Extractors
May 31, 2024
ce9e784
reduce duplicated code of the call function
May 31, 2024
233ffb7
I made prototypes for the CalibrationCalculators
Jun 12, 2024
74807c6
I made PSFModel a generic class
Jun 12, 2024
36da842
I fixed some variable names
Jun 12, 2024
511ebdf
Added a method for calibrating variance images
Jun 13, 2024
ed13253
edit description of StatisticsContainer
TjarkMiener Jun 12, 2024
732c5f9
added feature to shift the extraction sequence
TjarkMiener Jun 12, 2024
65ded40
fix boundary case for the last chunk
TjarkMiener Jun 12, 2024
a505ae6
fix tests
TjarkMiener Jun 12, 2024
fa6c65a
fix ruff
TjarkMiener Jun 12, 2024
e1d5d6d
Commit before push for tjark
Jun 14, 2024
f9f0d03
added StatisticsCalculator
TjarkMiener Jun 28, 2024
1616d4d
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
4cb9403
solved merge conflicts
TjarkMiener Aug 7, 2024
03b2637
I made prototypes for the CalibrationCalculators
Jun 12, 2024
0e85e82
I made PSFModel a generic class
Jun 12, 2024
d3b5d0b
I fixed some variable names
Jun 12, 2024
a5b3a02
Added a method for calibrating variance images
Jun 13, 2024
4478aed
Commit before push for tjark
Jun 14, 2024
4d41ad8
added StatisticsCalculator
TjarkMiener Jun 28, 2024
2b9dccd
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener Jul 5, 2024
de337cb
Removed Pointing Calculator
Aug 20, 2024
b1f591d
Removing PointingCalculator, PSF model and interpolators
Aug 20, 2024
9e19cb7
implement the StatisticsCalculator
TjarkMiener Aug 23, 2024
9540f21
removed the helper function to get the start and end slices
TjarkMiener Aug 24, 2024
7a2c77e
polish docstrings
TjarkMiener Aug 25, 2024
9afa277
further polishing of docstrings
TjarkMiener Aug 25, 2024
fc3c869
fix typo
TjarkMiener Aug 25, 2024
2f7466a
move check of config settings before loading of data
TjarkMiener Aug 25, 2024
534cbe8
moved Interpolator outside
TjarkMiener Aug 25, 2024
53c379b
removed Interpolator artifacts
TjarkMiener Aug 25, 2024
dfb179e
removed reading part with TableLoader
TjarkMiener Aug 25, 2024
955ff89
removed writing part
TjarkMiener Aug 25, 2024
47fc85d
add unit tests for calculators
TjarkMiener Aug 26, 2024
28101d1
add unit tests for calculators
TjarkMiener Aug 26, 2024
8b3d528
split __call__ function into two function for the first and second pass
TjarkMiener Aug 26, 2024
88e2126
fix docs and add changelog
TjarkMiener Aug 26, 2024
5b8a0b3
removed check for any faulty chunk
TjarkMiener Aug 27, 2024
d6681fc
removed base class CalibrationCalculator and only have one Statistics…
TjarkMiener Aug 27, 2024
54ab5e9
fix fstring in logging
TjarkMiener Aug 28, 2024
0edff64
bug fix
TjarkMiener Aug 28, 2024
c41b0b7
removed print
TjarkMiener Aug 28, 2024
4d8d896
removed me from CODEOWNERS
TjarkMiener Sep 3, 2024
fe1dfb9
Copying over code for interpolators and pointing calculators
Aug 20, 2024
1afef1e
Fixed some issues with the ChunkFunction
Aug 22, 2024
ccaffe2
Adding the StatisticsExtractors
Aug 22, 2024
18fb810
I added a basic star fitter
Sep 3, 2024
89a30ef
Added the fitting
Sep 12, 2024
f22de63
Finihed V1 of the startracker code
Sep 20, 2024
23e9b25
I separated the star tracking out to the StarTracer class
Sep 30, 2024
8c826eb
Adding a placeholder test script
Sep 30, 2024
5a4342e
Copying over code for interpolators and pointing calculators
Aug 20, 2024
675bc9b
Fixed some issues with the ChunkFunction
Aug 22, 2024
05aada6
Adding the StatisticsExtractors
Aug 22, 2024
5c51ed9
I added a basic star fitter
Sep 3, 2024
d1d146c
Added the fitting
Sep 12, 2024
7ff48c9
fixed astroquery import
Sep 30, 2024
2d913a9
removing merge marks
Oct 1, 2024
fd5bfc8
I moved the interpolator classes for flatfield events to to their pro…
Oct 1, 2024
de71d9d
I fixed an issue with the PointingCalculator traits
Oct 1, 2024
a59e8a4
Adding some parts to the unit tests
Oct 2, 2024
eee0394
Merge branch 'PointingCalculator' of https://github.com/cta-observato…
Oct 2, 2024
583b408
Some cleaning up after rebasing
Oct 2, 2024
aa4819f
Some more cleaning up
Oct 2, 2024
666e1d1
last cleanup
Oct 2, 2024
885bfcf
Switching to only test fitting, not cleaning
Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api-reference/monitoring/calculator.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. _calibration_calculator:

**********************
Calibration Calculator
**********************


Reference/API
=============

.. automodapi:: ctapipe.monitoring.calculator
3 changes: 2 additions & 1 deletion docs/api-reference/monitoring/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Monitoring data are time-series used to monitor the status or quality of hardwar

This module provides some code to help to generate monitoring data from processed event data, particularly for the purposes of calibration and data quality assessment.

Currently, only code related to :ref:`stats_aggregator` and :ref:`outlier_detector` is implemented here.
Code related to :ref:`stats_aggregator`, :ref:`calibration_calculator`, and :ref:`outlier_detector` is implemented here.


Submodules
Expand All @@ -20,6 +20,7 @@ Submodules
:maxdepth: 1

aggregator
calculator
interpolation
outlier

Expand Down
1 change: 1 addition & 0 deletions docs/changes/2609.features.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add calibration calculators which aggregates statistics, detects outliers, handles faulty data chunks.
7 changes: 5 additions & 2 deletions src/ctapipe/calib/camera/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Definition of the `CameraCalibrator` class, providing all steps needed to apply
calibration and image extraction, as well as supporting algorithms.
"""
<<<<<<< HEAD

=======
>>>>>>> c5f385f0 (I added a basic star fitter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge conflict markers

from functools import cache

import astropy.units as u
Expand All @@ -19,8 +23,8 @@
from ctapipe.image.invalid_pixels import InvalidPixelHandler
from ctapipe.image.reducer import DataVolumeReducer

__all__ = ["CameraCalibrator"]

__all__ = ["CameraCalibrator"]

@cache
def _get_pixel_index(n_pixels):
Expand All @@ -46,7 +50,6 @@ def _get_invalid_pixels(n_channels, n_pixels, pixel_status, selected_gain_channe

return broken_pixels


class CameraCalibrator(TelescopeComponent):
"""
Calibrator to handle the full camera calibration chain, in order to fill
Expand Down
233 changes: 233 additions & 0 deletions src/ctapipe/calib/camera/extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
"""
Extraction algorithms to compute the statistics from a sequence of images
"""

__all__ = [
"StatisticsExtractor",
"PlainExtractor",
"SigmaClippingExtractor",
]

from abc import abstractmethod

import numpy as np
from astropy.stats import sigma_clipped_stats

from ctapipe.containers import StatisticsContainer
from ctapipe.core import TelescopeComponent
from ctapipe.core.traits import (
Int,
List,
)


class StatisticsExtractor(TelescopeComponent):
sample_size = Int(2500, help="sample size").tag(config=True)
image_median_cut_outliers = List(
[-0.3, 0.3],
help="Interval of accepted image values (fraction with respect to camera median value)",
).tag(config=True)
image_std_cut_outliers = List(
[-3, 3],
help="Interval (number of std) of accepted image standard deviation around camera median value",
).tag(config=True)

def __init__(self, subarray, config=None, parent=None, **kwargs):
"""
Base component to handle the extraction of the statistics
from a sequence of charges and pulse times (images).

Parameters
----------
kwargs
"""
super().__init__(subarray=subarray, config=config, parent=parent, **kwargs)

@abstractmethod
def __call__(
self, dl1_table, masked_pixels_of_sample=None, col_name="image"
) -> list:
"""
Call the relevant functions to extract the statistics
for the particular extractor.

Parameters
----------
dl1_table : ndarray
dl1 table with images and times stored in a numpy array of shape
(n_images, n_channels, n_pix).
col_name : string
column name in the dl1 table

Returns
-------
List StatisticsContainer:
List of extracted statistics and validity ranges
"""


class PlainExtractor(StatisticsExtractor):
"""
Extractor the statistics from a sequence of images
using numpy and scipy functions
"""

def __call__(
self, dl1_table, masked_pixels_of_sample=None, col_name="image"
) -> list:
# in python 3.12 itertools.batched can be used
image_chunks = (
dl1_table[col_name].data[i : i + self.sample_size]
for i in range(0, len(dl1_table[col_name].data), self.sample_size)
)
time_chunks = (
dl1_table["time"][i : i + self.sample_size]
for i in range(0, len(dl1_table["time"]), self.sample_size)
)

# Calculate the statistics from a sequence of images
stats_list = []
for images, times in zip(image_chunks, time_chunks):
stats_list.append(
self._plain_extraction(images, times, masked_pixels_of_sample)
)
return stats_list

def _plain_extraction(
self, images, times, masked_pixels_of_sample
) -> StatisticsContainer:
# ensure numpy array
masked_images = np.ma.array(images, mask=masked_pixels_of_sample)

# median over the sample per pixel
pixel_median = np.ma.median(masked_images, axis=0)

# mean over the sample per pixel
pixel_mean = np.ma.mean(masked_images, axis=0)

# std over the sample per pixel
pixel_std = np.ma.std(masked_images, axis=0)

# median of the median over the camera
# median_of_pixel_median = np.ma.median(pixel_median, axis=1)

# outliers from median
image_median_outliers = np.logical_or(
pixel_median < self.image_median_cut_outliers[0],
pixel_median > self.image_median_cut_outliers[1],
)

return StatisticsContainer(
validity_start=times[0],
validity_stop=times[-1],
mean=pixel_mean.filled(np.nan),
median=pixel_median.filled(np.nan),
median_outliers=image_median_outliers.filled(True),
std=pixel_std.filled(np.nan),
)


class SigmaClippingExtractor(StatisticsExtractor):
"""
Extractor the statistics from a sequence of images
using astropy's sigma clipping functions
"""

sigma_clipping_max_sigma = Int(
default_value=4,
help="Maximal value for the sigma clipping outlier removal",
).tag(config=True)
sigma_clipping_iterations = Int(
default_value=5,
help="Number of iterations for the sigma clipping outlier removal",
).tag(config=True)

def __call__(
self, dl1_table, masked_pixels_of_sample=None, col_name="image"
) -> list:
# in python 3.12 itertools.batched can be used
image_chunks = (
dl1_table[col_name].data[i : i + self.sample_size]
for i in range(0, len(dl1_table[col_name].data), self.sample_size)
)
time_chunks = (
dl1_table["time"][i : i + self.sample_size]
for i in range(0, len(dl1_table["time"]), self.sample_size)
)

# Calculate the statistics from a sequence of images
stats_list = []
for images, times in zip(image_chunks, time_chunks):
stats_list.append(
self._sigmaclipping_extraction(images, times, masked_pixels_of_sample)
)
return stats_list

def _sigmaclipping_extraction(
self, images, times, masked_pixels_of_sample
) -> StatisticsContainer:
# ensure numpy array
masked_images = np.ma.array(images, mask=masked_pixels_of_sample)

# median of the event images
# image_median = np.ma.median(masked_images, axis=-1)

# mean, median, and std over the sample per pixel
max_sigma = self.sigma_clipping_max_sigma
pixel_mean, pixel_median, pixel_std = sigma_clipped_stats(
masked_images,
sigma=max_sigma,
maxiters=self.sigma_clipping_iterations,
cenfunc="mean",
axis=0,
)

# mask pixels without defined statistical values
pixel_mean = np.ma.array(pixel_mean, mask=np.isnan(pixel_mean))
pixel_median = np.ma.array(pixel_median, mask=np.isnan(pixel_median))
pixel_std = np.ma.array(pixel_std, mask=np.isnan(pixel_std))

unused_values = np.abs(masked_images - pixel_mean) > (max_sigma * pixel_std)

# only warn for values discard in the sigma clipping, not those from before
# outliers = unused_values & (~masked_images.mask)

# add outliers identified by sigma clipping for following operations
masked_images.mask |= unused_values

# median of the median over the camera
median_of_pixel_median = np.ma.median(pixel_median, axis=1)

# median of the std over the camera
median_of_pixel_std = np.ma.median(pixel_std, axis=1)

# std of the std over camera
std_of_pixel_std = np.ma.std(pixel_std, axis=1)

# outliers from median
image_deviation = pixel_median - median_of_pixel_median[:, np.newaxis]
image_median_outliers = np.logical_or(
image_deviation
< self.image_median_cut_outliers[0] * median_of_pixel_median[:, np.newaxis],
image_deviation
> self.image_median_cut_outliers[1] * median_of_pixel_median[:, np.newaxis],
)

# outliers from standard deviation
deviation = pixel_std - median_of_pixel_std[:, np.newaxis]
image_std_outliers = np.logical_or(
deviation
< self.image_std_cut_outliers[0] * std_of_pixel_std[:, np.newaxis],
deviation
> self.image_std_cut_outliers[1] * std_of_pixel_std[:, np.newaxis],
)

return StatisticsContainer(
validity_start=times[0],
validity_stop=times[-1],
mean=pixel_mean.filled(np.nan),
median=pixel_median.filled(np.nan),
median_outliers=image_median_outliers.filled(True),
std=pixel_std.filled(np.nan),
std_outliers=image_std_outliers.filled(True),
)
Loading
Loading