-
Notifications
You must be signed in to change notification settings - Fork 268
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
ctoennis
wants to merge
228
commits into
main
Choose a base branch
from
PointingCalculator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
add PointingCalculator #2623
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
edfccc6
added stats extractor based on sigma clipping
d19168c
added cut of outliers
49f0f8a
update docs
9035fb4
formatted with black
8a0e89f
added pass for __call__ function
82b29e9
added unit tests
1805cb2
added changelog
a4cea6a
fix lint
16e5920
Small commit for prototyping
63d1774
Removed unneeded functions
5768ed7
Merge branch 'stats_extractor' of https://github.com/cta-observatory/…
e6ba177
I altered the class variables to th evariance statistics extractor
ddf342b
added a container for mean variance images and fixed docustring
0beb975
I changed the container type for the StarVarianceExtractor
b4df919
fix pylint
3483fd4
change __call__() to _extract()
5bbedda
minor renaming
14a0910
use pytest.fixture for Extractors
f126748
reduce duplicated code of the call function
0ec81b9
edit description of StatisticsContainer
TjarkMiener 3910c22
added feature to shift the extraction sequence
TjarkMiener 5c6595b
fix boundary case for the last chunk
TjarkMiener bc65984
I made prototypes for the CalibrationCalculators
d7a65a3
I made PSFModel a generic class
ba00bf3
fix tests
TjarkMiener d3aae32
fix ruff
TjarkMiener 825b25b
I fixed some variable names
a5b878d
Added a method for calibrating variance images
e8ebdd8
Merge branch 'stats_extractor' into CalibrationCalculators
78481cc
Commit before push for tjark
41a4246
added StatisticsCalculator
TjarkMiener 010aea6
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener 26ff8a4
added stats extractor parent component
d142995
added stats extractor based on sigma clipping
0737b7f
added cut of outliers
225346b
update docs
74c72bb
formatted with black
faad542
added pass for __call__ function
9867431
Small commit for prototyping
3a85ffa
Removed unneeded functions
69ebd1c
added unit tests
96b2dbb
added changelog
a007773
fix lint
96fe563
I altered the class variables to th evariance statistics extractor
67d34c4
added a container for mean variance images and fixed docustring
f1429da
I changed the container type for the StarVarianceExtractor
c9ec02b
fix pylint
444e370
change __call__() to _extract()
1c4cadb
minor renaming
0ebb464
use pytest.fixture for Extractors
bbbd891
reduce duplicated code of the call function
5deef74
I made prototypes for the CalibrationCalculators
f09bbe1
I made PSFModel a generic class
b8f0a4f
I fixed some variable names
39fca21
Added a method for calibrating variance images
b114638
edit description of StatisticsContainer
TjarkMiener 5d18f61
added feature to shift the extraction sequence
TjarkMiener 4df8c94
fix boundary case for the last chunk
TjarkMiener 86eb15c
fix tests
TjarkMiener 6200653
fix ruff
TjarkMiener 4f604c5
Commit before push for tjark
6dfce15
added StatisticsCalculator
TjarkMiener 8e873d3
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener bf36b90
Merge branch 'CalibrationCalculators' of https://github.com/cta-obser…
f7d3223
solved merge conflicts
TjarkMiener 91812da
I made prototypes for the CalibrationCalculators
326c202
I made PSFModel a generic class
fa029f7
I fixed some variable names
7c90e0f
Added a method for calibrating variance images
8c44a42
Commit before push for tjark
bff611a
added StatisticsCalculator
TjarkMiener d85dd50
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener c522434
adding interpolator and Merge branch 'CalibrationCalculators' of http…
9192790
Removed Pointing Calculator
b729f82
Copying over code for interpolators and pointing calculators
aecc5dc
Removing PointingCalculator, PSF model and interpolators
92f0fb8
Fixed some issues with the ChunkFunction
2566a4d
Adding the StatisticsExtractors
e3113ab
implement the StatisticsCalculator
TjarkMiener b9dc929
removed the helper function to get the start and end slices
TjarkMiener ef920da
polish docstrings
TjarkMiener 9bfc16a
further polishing of docstrings
TjarkMiener aee5c10
fix typo
TjarkMiener 1484eca
move check of config settings before loading of data
TjarkMiener 601cbb4
moved Interpolator outside
TjarkMiener 0347153
removed Interpolator artifacts
TjarkMiener b2208d5
removed reading part with TableLoader
TjarkMiener 61936e5
removed writing part
TjarkMiener 52ecd8a
add unit tests for calculators
TjarkMiener 4ffd39e
add unit tests for calculators
TjarkMiener c404a4a
split __call__ function into two function for the first and second pass
TjarkMiener a59664e
fix docs and add changelog
TjarkMiener 0ed515d
removed check for any faulty chunk
TjarkMiener 48c686b
removed base class CalibrationCalculator and only have one Statistics…
TjarkMiener 3bae046
fix fstring in logging
TjarkMiener aa5666a
bug fix
TjarkMiener ef53ebb
removed print
TjarkMiener 3ca7252
removed me from CODEOWNERS
TjarkMiener c5f385f
I added a basic star fitter
2756a38
Added the fitting
4af4e74
Merge branch 'main' into CalibrationCalculators
TjarkMiener e4bc632
Copying over code for interpolators and pointing calculators
3b147c3
Fixed some issues with the ChunkFunction
4bd5cb3
Adding the StatisticsExtractors
509e512
I added a basic star fitter
69eb08e
Added the fitting
da561d2
Finihed V1 of the startracker code
32894fd
I separated the star tracking out to the StarTracer class
4b97544
Adding a placeholder test script
aa40741
Merge branch 'PointingCalculator' of https://github.com/cta-observato…
40c3968
fixed astroquery import
cea1f21
removing merge marks
c6d7245
I moved the interpolator classes for flatfield events to to their pro…
12ae9fc
added stats extractor parent component
cfe8328
added stats extractor based on sigma clipping
4d02301
added cut of outliers
c16b044
update docs
3a82cec
formatted with black
5646b2b
added pass for __call__ function
487da6a
Small commit for prototyping
8b5b55e
Removed unneeded functions
6e918df
added unit tests
169ca37
added changelog
c78d1dc
fix lint
ff6ab1d
I altered the class variables to th evariance statistics extractor
f44f4d2
added a container for mean variance images and fixed docustring
2200aec
I changed the container type for the StarVarianceExtractor
c4d6809
fix pylint
388aae6
change __call__() to _extract()
07f4bef
minor renaming
a3782ae
use pytest.fixture for Extractors
ad47560
reduce duplicated code of the call function
8f49802
I made prototypes for the CalibrationCalculators
9d86e9a
I made PSFModel a generic class
cd122a8
I fixed some variable names
12cc766
Added a method for calibrating variance images
20de205
edit description of StatisticsContainer
TjarkMiener c4936d7
added feature to shift the extraction sequence
TjarkMiener f7fefd1
fix boundary case for the last chunk
TjarkMiener 56118b8
fix tests
TjarkMiener e68c5dd
fix ruff
TjarkMiener 057baf6
Commit before push for tjark
d5eda78
added StatisticsCalculator
TjarkMiener 53d8e98
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener f982b36
added stats extractor parent component
9c46f55
added stats extractor based on sigma clipping
57879b1
added cut of outliers
fd79479
update docs
b886875
formatted with black
10723a3
added pass for __call__ function
9c46748
Small commit for prototyping
a08b38c
Removed unneeded functions
4f06344
added unit tests
d0f17ee
fix lint
0778648
I altered the class variables to th evariance statistics extractor
b04e6ee
added a container for mean variance images and fixed docustring
e7ec4b8
I changed the container type for the StarVarianceExtractor
0921641
fix pylint
fa65404
change __call__() to _extract()
08d43dd
minor renaming
734d03f
use pytest.fixture for Extractors
ce9e784
reduce duplicated code of the call function
233ffb7
I made prototypes for the CalibrationCalculators
74807c6
I made PSFModel a generic class
36da842
I fixed some variable names
511ebdf
Added a method for calibrating variance images
ed13253
edit description of StatisticsContainer
TjarkMiener 732c5f9
added feature to shift the extraction sequence
TjarkMiener 65ded40
fix boundary case for the last chunk
TjarkMiener a505ae6
fix tests
TjarkMiener fa6c65a
fix ruff
TjarkMiener e1d5d6d
Commit before push for tjark
f9f0d03
added StatisticsCalculator
TjarkMiener 1616d4d
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener 4cb9403
solved merge conflicts
TjarkMiener 03b2637
I made prototypes for the CalibrationCalculators
0e85e82
I made PSFModel a generic class
d3b5d0b
I fixed some variable names
a5b3a02
Added a method for calibrating variance images
4478aed
Commit before push for tjark
4d41ad8
added StatisticsCalculator
TjarkMiener 2b9dccd
make faulty_pixels_threshold and chunk_shift as traits
TjarkMiener de337cb
Removed Pointing Calculator
b1f591d
Removing PointingCalculator, PSF model and interpolators
9e19cb7
implement the StatisticsCalculator
TjarkMiener 9540f21
removed the helper function to get the start and end slices
TjarkMiener 7a2c77e
polish docstrings
TjarkMiener 9afa277
further polishing of docstrings
TjarkMiener fc3c869
fix typo
TjarkMiener 2f7466a
move check of config settings before loading of data
TjarkMiener 534cbe8
moved Interpolator outside
TjarkMiener 53c379b
removed Interpolator artifacts
TjarkMiener dfb179e
removed reading part with TableLoader
TjarkMiener 955ff89
removed writing part
TjarkMiener 47fc85d
add unit tests for calculators
TjarkMiener 28101d1
add unit tests for calculators
TjarkMiener 8b3d528
split __call__ function into two function for the first and second pass
TjarkMiener 88e2126
fix docs and add changelog
TjarkMiener 5b8a0b3
removed check for any faulty chunk
TjarkMiener d6681fc
removed base class CalibrationCalculator and only have one Statistics…
TjarkMiener 54ab5e9
fix fstring in logging
TjarkMiener 0edff64
bug fix
TjarkMiener c41b0b7
removed print
TjarkMiener 4d8d896
removed me from CODEOWNERS
TjarkMiener fe1dfb9
Copying over code for interpolators and pointing calculators
1afef1e
Fixed some issues with the ChunkFunction
ccaffe2
Adding the StatisticsExtractors
18fb810
I added a basic star fitter
89a30ef
Added the fitting
f22de63
Finihed V1 of the startracker code
23e9b25
I separated the star tracking out to the StarTracer class
8c826eb
Adding a placeholder test script
5a4342e
Copying over code for interpolators and pointing calculators
675bc9b
Fixed some issues with the ChunkFunction
05aada6
Adding the StatisticsExtractors
5c51ed9
I added a basic star fitter
d1d146c
Added the fitting
7ff48c9
fixed astroquery import
2d913a9
removing merge marks
fd5bfc8
I moved the interpolator classes for flatfield events to to their pro…
de71d9d
I fixed an issue with the PointingCalculator traits
a59e8a4
Adding some parts to the unit tests
eee0394
Merge branch 'PointingCalculator' of https://github.com/cta-observato…
583b408
Some cleaning up after rebasing
aa4819f
Some more cleaning up
666e1d1
last cleanup
885bfcf
Switching to only test fitting, not cleaning
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. _calibration_calculator: | ||
|
||
********************** | ||
Calibration Calculator | ||
********************** | ||
|
||
|
||
Reference/API | ||
============= | ||
|
||
.. automodapi:: ctapipe.monitoring.calculator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge conflict markers