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

Hillas image test #34

Open
wants to merge 143 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
f3fc76a
removed test* from gitignore
ellijobst Jan 11, 2022
8317b3b
add test for hillas parameters
ellijobst Jan 11, 2022
6e5186a
Add execution right for user.
ellijobst Jan 11, 2022
8fa8bab
changed percentage of allowed events with errors higher than thresholds
ellijobst Jan 11, 2022
2112a5c
use correct path to config file
ellijobst Jan 11, 2022
4920118
Add .coverage file.
ellijobst Jan 11, 2022
68eb19e
Change output paths and remove comments.
ellijobst Jan 11, 2022
62684ca
Modified container argument
ellijobst Jan 18, 2022
92fdba3
Scripts for image comparison
ellijobst Jan 18, 2022
00b0748
Merge branch 'master' into hillas-params-tests
ellijobst Jan 18, 2022
929b026
Merge branch 'console-scripts' into hillas-params-tests
ellijobst Jan 18, 2022
626babe
Add imports for mars script directory.
ellijobst Jan 18, 2022
41d87db
Fix import.
ellijobst Jan 18, 2022
2603945
update gitignore
ellijobst Mar 14, 2022
338eaba
renamed file and changed output path
ellijobst Mar 14, 2022
0c35d62
changed paths for config file
ellijobst Mar 14, 2022
739800e
Updated test for hillas params comparison
ellijobst Mar 14, 2022
8049270
Updated script for image comparison
ellijobst Mar 14, 2022
c622f3f
Test for image_comparison.py
ellijobst Mar 14, 2022
615a30c
Merge branch 'master' into hillas-image-test
ellijobst Mar 14, 2022
f0d8d85
Changed name
ellijobst Mar 14, 2022
f84a675
Updated way to retrieve bad and dead pixels
ellijobst Mar 14, 2022
bb5a948
Deleted unnecessary comments
ellijobst Mar 16, 2022
1de605c
Cleaned and improved the code
ellijobst Mar 16, 2022
63c73e4
Removed unnecessary information from config file
ellijobst Mar 16, 2022
7dcfdbd
Test image comparison for both telescopes
ellijobst Mar 16, 2022
f464aba
Use EventSeeker to loop over events
ellijobst Mar 16, 2022
d10c9ae
Changed hillas comparison script
ellijobst Mar 21, 2022
19d7478
Removed unnecessary arguments of function
ellijobst Mar 21, 2022
52b8b81
Removed unneeded file paths
ellijobst Mar 21, 2022
f452204
Deleted unnecessary arguments of function
ellijobst Mar 21, 2022
8981ef6
Deleted unnecessary parentheses
ellijobst Mar 21, 2022
28f7509
Renamed output HDF5 file and keys
ellijobst Mar 24, 2022
901434a
Added copy of input image and changed name
ellijobst Mar 24, 2022
1829432
Added import
ellijobst Apr 6, 2022
68b0498
Adapted script to new cleaning (cleaning.py)
ellijobst Apr 6, 2022
d2fe4e9
Updated image comparison
ellijobst Apr 6, 2022
2b1f279
Updated gitignore
ellijobst Apr 6, 2022
4fa6f5a
Merge branch 'master' into hillas-image-test
ellijobst Apr 6, 2022
96bc242
Fixed typo
ellijobst Apr 8, 2022
f788cb3
Added all parameters that can be compared at the moment
ellijobst Apr 26, 2022
075275a
Added parameter information and configuration for stereo parameter co…
ellijobst Apr 26, 2022
3511771
Fixed typo
ellijobst Apr 26, 2022
31be103
Adapted script to compare stereo params, changed telescope id to fit …
ellijobst Apr 26, 2022
6122c54
Merge branch 'master' into hillas-image-test
ellijobst Apr 26, 2022
dd7be16
Updated script to compare StereoDisp parameters
ellijobst Apr 26, 2022
a4551a4
Adapted key for .h5 file-format
ellijobst May 2, 2022
c7b971e
Move Hillas and image comparison scripts to a different directory.
ellijobst May 2, 2022
1da0df2
Merge branch 'master' into hillas-image-test
ellijobst May 2, 2022
ca78d9b
Take different camera geometries into account
ellijobst May 2, 2022
8d3f645
Merge branch 'master' into hillas-image-test
ellijobst May 20, 2022
e99ed93
Added comparison of stereo parameters and changed names
ellijobst Jul 4, 2022
3b9cdb1
Merge branch 'master' into hillas-image-test
ellijobst Jul 11, 2022
76c6fc1
Update download script.
ellijobst Jul 11, 2022
e21b358
Adapt script for automatic tests.
ellijobst Jul 11, 2022
8861611
First adaptation for automatic tests.
ellijobst Jul 11, 2022
bd9fd66
Uncomment steps needed for automatic tests.
ellijobst Jul 11, 2022
4b79537
Add image and superstar files in download script.
aleberti Jul 12, 2022
6a1b3e9
Fix errors, add missing imports.
aleberti Jul 12, 2022
c57960f
Change pytest parametrization.
aleberti Jul 12, 2022
48424fa
Put image and superstar files in different output directories.
aleberti Jul 12, 2022
57db237
Change superstar input directory.
aleberti Jul 12, 2022
9026668
Add missing imports and fix errors.
aleberti Jul 12, 2022
8c8a78e
Change order of tests, put static checks at the end.
aleberti Jul 12, 2022
cc1706a
Rename file.
aleberti Jul 12, 2022
32e2648
Reformat and change scaling factors.
aleberti Jul 12, 2022
f5f3a3c
Do not remove keys from config file.
aleberti Jul 12, 2022
19e6f39
Remove cuts on theta2 and impact; reformat; print out number of event…
aleberti Jul 12, 2022
16f321d
Reformat and add output directories.
aleberti Jul 12, 2022
230bb40
Reformat code.
aleberti Jul 12, 2022
a04c8a2
Use "use_all" option.
aleberti Jul 12, 2022
db13b10
Change output directory.
aleberti Jul 12, 2022
0628acb
Create output directory if needed.
aleberti Jul 12, 2022
791fc04
Fix input files.
aleberti Jul 12, 2022
1979bc8
Reformat code with black.
aleberti Jul 12, 2022
baff48e
Add try except to avoid errors when image file is not produced from s…
aleberti Jul 12, 2022
058c3da
Add opening of login shell for tests.
aleberti Jul 13, 2022
149a2ae
Try to downgrade protobuf.
aleberti Jul 13, 2022
dabdba3
Add maximum number of events for image comparison.
aleberti Jul 13, 2022
e064a78
Get bad and dead pixels in the correct way.
aleberti Jul 13, 2022
992fe88
Add download of MC data.
aleberti Jul 14, 2022
66d9663
Adapt script to run also on MC files.
aleberti Jul 14, 2022
c1a0728
Add MC files to tests.
aleberti Jul 14, 2022
d6eb3d2
Adapt parameters comparison test for MCs.
aleberti Jul 14, 2022
fbae704
Remove cut on impact.
aleberti Jul 14, 2022
bf6e487
Reformat.
aleberti Jul 14, 2022
6916ccc
Create CameraDisplay just once and update image data.
aleberti Jul 15, 2022
f570fa4
Reuse CameraDisplay and increase size of figure.
aleberti Jul 15, 2022
7716855
Save MC and real data output in different directories
ellijobst Jul 15, 2022
1519790
Merge branch 'master' into hillas-image-test
aleberti Jul 27, 2022
6bcc678
Merge branch 'master' into hillas-image-test
aleberti Jul 27, 2022
571c4df
Fixed issue with save_pandas_to_table
ellijobst Aug 31, 2022
a416bd4
Merge branch 'master' into hillas-image-test
ellijobst Aug 31, 2022
f49adf1
simplified the script to avoid repeating the wget commands multiple t…
jsitarek Sep 2, 2022
2770671
number of fixes:
jsitarek Sep 2, 2022
1f2abc1
work on MARS/MCP image parameter matching
jsitarek Sep 2, 2022
13b0d4e
added missing absolute value to the check of relative error
jsitarek Sep 2, 2022
bf74353
Removed unnecessary parts and added comments for clarification
ellijobst Sep 5, 2022
14d2453
Changed percentage and fixed issue with numpy array
ellijobst Sep 5, 2022
ba841ea
Remove unused imports.
aleberti Oct 4, 2022
6e2957e
Style changes.
aleberti Oct 4, 2022
801ebc9
Use ctapipe functions to apply time average cleaning.
aleberti Oct 4, 2022
f9488dc
Add unit comments.
aleberti Oct 4, 2022
e47073b
Do not use time slices, but times in nanoseconds.
aleberti Oct 4, 2022
7f982b3
Print cleaning configuration.
aleberti Oct 4, 2022
f21e206
Add comments.
aleberti Oct 4, 2022
5ff2d52
Style changes.
aleberti Oct 4, 2022
efdb7be
Use hot pixels interpolation for real data.
aleberti Oct 4, 2022
28ef88e
Use different configs for real data and MCs.
aleberti Oct 4, 2022
3f260ef
Add reduction of precision for charge values as in MARS.
aleberti Oct 5, 2022
326138b
Print cleaning configuration only once.
aleberti Oct 5, 2022
22fa94d
Add option to plot or not the images.
aleberti Oct 5, 2022
5bff1ea
Remove event IDs that appear twice from list
ellijobst Oct 5, 2022
8204323
Improved way the comparison data gets saved in the HDF5 files.
ellijobst Oct 5, 2022
0602887
Find unsuitable pixels for MC as well.
aleberti Oct 7, 2022
e150bac
Print charge differences.
aleberti Oct 7, 2022
c2b6c80
Print number of different images.
aleberti Oct 7, 2022
617fa0a
Merge remote-tracking branch 'origin/hillas-image-test' into hillas-i…
aleberti Oct 7, 2022
ab208ae
Fix indentation.
aleberti Oct 7, 2022
6b5e0df
Merge branch 'master' into hillas-image-test
aleberti Oct 7, 2022
7f5bafd
Define cleaning once.
aleberti Oct 7, 2022
2193c52
Reduce precision for times.
aleberti Oct 7, 2022
4d086cd
Added cut on trigger pattern for Event IDs
ellijobst Oct 11, 2022
6bef561
Removed unnecessary configuration.
ellijobst Oct 11, 2022
a89a3b7
Update reader of MARS images with time information.
aleberti Oct 12, 2022
daa929d
Fix functions to fill containers.
aleberti Oct 12, 2022
07207a9
Update naming of container column.
aleberti Oct 12, 2022
26eec9b
Apply black to script.
aleberti Oct 12, 2022
845526b
Changed way output file gets saved.
ellijobst Oct 12, 2022
0adcfaa
Added image time comparison.
ellijobst Oct 12, 2022
ee268cc
Write output path.
aleberti Oct 16, 2022
bcfd169
Fix time comparison between arrays.
aleberti Oct 16, 2022
97cd5bc
Do not use EventSeeker.
aleberti Oct 19, 2022
c658095
Open output file before looping through events
ellijobst Oct 24, 2022
cfd3d75
Added a threshold of 3 pixels to the time comparison of the images
ellijobst Oct 28, 2022
7688cef
Added threshold of 0.03% to image charge and time comparison
ellijobst Oct 28, 2022
26d614e
Merge branch 'master' into hillas-image-test
aleberti Nov 2, 2022
7d0de0a
Do not save plots by default.
aleberti Nov 2, 2022
0a32424
Run black.
aleberti Nov 2, 2022
924829b
Run black over parameter comparison test scripts.
aleberti Nov 2, 2022
74a561b
Change name for consistency.
aleberti Nov 2, 2022
db8050b
Add test for comparing the slope in bins of the cleaned image size
ellijobst Nov 10, 2022
488553e
Correct name of class member.
aleberti Nov 14, 2022
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
36 changes: 19 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,28 @@ jobs:
# we install ctapipe using pip to be able to select any commit, e.g. the current master
pip install pytest-cov "git+https://github.com/cta-observatory/ctapipe@$CTAPIPE_VERSION"
pip install pyflakes
pip install --upgrade "protobuf<=3.20.1"
pip install -e .
git describe --tags

- name: Download test data
env:
TEST_DATA_USER: ${{ secrets.test_data_user }}
TEST_DATA_PASSWORD: ${{ secrets.test_data_password }}
run: |
chmod +x ./download_test_data.sh
./download_test_data.sh

- name: Tests
shell: bash -leo pipefail {0}
run: |
# github actions starts a new shell for each "step", so we need to
# activate our env again
source $CONDA/etc/profile.d/conda.sh
conda activate ci
coverage run -m pytest -v
coverage xml

- name: Static codechecks
# need to use a login shell for the conda setup to work
shell: bash -leo pipefail {0}
Expand All @@ -50,21 +69,4 @@ jobs:
conda activate ci
pyflakes magicctapipe

#- name: Download test data
# env:
# TEST_DATA_USER: ${{ secrets.test_data_user }}
# TEST_DATA_PASSWORD: ${{ secrets.test_data_password }}
# run: |
# chmod +x ./download_test_data.sh
# ./download_test_data.sh

#- name: Tests
# run: |
# # github actions starts a new shell for each "step", so we need to
# # activate our env again
# source $CONDA/etc/profile.d/conda.sh
# conda activate ci
# coverage run -m pytest -v
# coverage xml

#- uses: codecov/codecov-action@v1
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ test_data
*.o
*.so
__pycache__
.vscode
RFs

# Files cretaed when running pip
magicctapipe/_version.py
magicctapipe/_version_cache.py

.coverage
# Eclipse editor project files
.project
.pydevproject
Expand All @@ -20,6 +23,7 @@ magicctapipe/_version_cache.py
*.png
*.pdf
*.eps
*.ipynb

# MAGIC/CTA files
*.root
Expand All @@ -29,6 +33,9 @@ magicctapipe/_version_cache.py

# Other
TODO.txt
magicctapipe/scripts/magic/tests/old_image_comparison
magicctapipe/scripts/magic/tests/image_comp_output
magicctapipe/scripts/magic/tests/hillas_comp_output
test.ipynb
.ipynb_checkpoints
*.tmp
Expand Down
47 changes: 0 additions & 47 deletions download_data.sh

This file was deleted.

59 changes: 59 additions & 0 deletions download_test_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -e

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/calibrated/20210314_M1_05095172.001_Y_CrabNebula-W0.40+035.root" > test_data_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/calibrated/20210314_M1_05095172.002_Y_CrabNebula-W0.40+035.root" >> test_data_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/calibrated/20210314_M2_05095172.001_Y_CrabNebula-W0.40+035.root" >> test_data_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/calibrated/20210314_M2_05095172.002_Y_CrabNebula-W0.40+035.root" >> test_data_real.txt

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/images/20210314_M1_05095172.001_I_CrabNebula-W0.40+035.h5" > test_data_images_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/images/20210314_M1_05095172.002_I_CrabNebula-W0.40+035.h5" >> test_data_images_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/images/20210314_M2_05095172.001_I_CrabNebula-W0.40+035.h5" >> test_data_images_real.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/images/20210314_M2_05095172.002_I_CrabNebula-W0.40+035.h5" >> test_data_images_real.txt

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/real/superstar/20210314_05095172_S_CrabNebula-W0.40+035.root" > test_data_superstar_real.txt

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/calibrated/GA_M1_za35to50_8_824318_Y_w0.root" > test_data_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/calibrated/GA_M1_za35to50_8_824319_Y_w0.root" >> test_data_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/calibrated/GA_M2_za35to50_8_824318_Y_w0.root" >> test_data_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/calibrated/GA_M2_za35to50_8_824319_Y_w0.root" >> test_data_simulated.txt

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/images/GA_M1_za35to50_8_824318_I_w0.h5" > test_data_images_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/images/GA_M1_za35to50_8_824319_I_w0.h5" >> test_data_images_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/images/GA_M2_za35to50_8_824318_I_w0.h5" >> test_data_images_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/images/GA_M2_za35to50_8_824319_I_w0.h5" >> test_data_images_simulated.txt

echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/superstar/GA_za35to50_8_824318_S_w0.root" > test_data_superstar_simulated.txt
echo "https://webdav-magic.pic.es:8451/Users/ctapipe_io_magic/test_data/simulated/superstar/GA_za35to50_8_824319_S_w0.root" >> test_data_superstar_simulated.txt

if [ -z "$TEST_DATA_USER" ]; then
echo -n "Username: "
read TEST_DATA_USER
echo
fi

if [ -z "$TEST_DATA_PASSWORD" ]; then
echo -n "Password: "
read -s TEST_DATA_PASSWORD
echo
fi

files=( "test_data_real.txt" "test_data_images_real.txt" "test_data_superstar_real.txt" "test_data_simulated.txt" "test_data_images_simulated.txt" "test_data_superstar_simulated.txt")
dirs=( "real/calibrated" "real/images" "real/superstar" "simulated/calibrated" "simulated/images" "simulated/superstar")

for i in "${!files[@]}"; do
if ! wget \
-i ${files[i]} \
--user="$TEST_DATA_USER" \
--password="$TEST_DATA_PASSWORD" \
--no-check-certificate \
--no-verbose \
--timestamping \
--directory-prefix=test_data/${dirs[i]}; then
echo "Problem in downloading the test data set (${dirs[i]})"
fi
rm -f ${files[i]}
done
unset TEST_DATA_USER
unset TEST_DATA_PASSWORD
81 changes: 49 additions & 32 deletions magicctapipe/image/cleaning.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import copy
import itertools
import numpy as np
import struct
from scipy.sparse.csgraph import connected_components

from ctapipe.image import (
tailcuts_clean,
number_of_islands,
hillas_parameters,
timing_parameters,
leakage_parameters,
apply_time_delta_cleaning,
brightest_island,
number_of_islands,
)

__all__ = [
Expand All @@ -20,6 +21,21 @@
]


def float_to_bin_int(num):
return ''.join('{:0>8b}'.format(c) for c in struct.pack('!f', num))


def bin_to_float(binary):
return struct.unpack('!f', struct.pack('!I', int(binary, 2)))[0]


def reduce_precision(charge):
return bin_to_float(bin((int(float_to_bin_int(charge), 2) + int(bin(0x00004000), 2)) & 0xffff8000))


reduce_precision_vector = np.vectorize(reduce_precision)


class MAGICClean:

def __init__(self, camera, configuration):
Expand Down Expand Up @@ -55,17 +71,17 @@ def __init__(self, camera, configuration):
if 'Window2NN' in configuration:
self.Window2NN = configuration['Window2NN']
else:
self.Window2NN = 0.82/1.639
self.Window2NN = 0.82 / 1.639

if 'Window3NN' in configuration:
self.Window3NN = configuration['Window3NN']
else:
self.Window3NN = 1.15/1.639
self.Window3NN = 1.15 / 1.639

if 'Window4NN' in configuration:
self.Window4NN = configuration['Window4NN']
else:
self.Window4NN = 1.80/1.639
self.Window4NN = 1.80 / 1.639

if 'clipping' in configuration:
self.clipping = configuration['clipping']
Expand Down Expand Up @@ -231,11 +247,11 @@ def group_calculation(self, mask, NN, clipNN, windowNN, thresholdNN):
charge[charge > clipNN] = clipNN

totcharge = np.sum(charge, axis=1)
meantime = np.sum(charge * self.event_pulse_time[NN],axis=1)/totcharge
meantime = np.sum(charge * self.event_pulse_time[NN], axis=1) / totcharge

meantime_proper = np.tile(meantime,(len(NN[0]),1)).transpose()
meantime_proper = np.tile(meantime, (len(NN[0]), 1)).transpose()

timeok = np.all(np.fabs(meantime_proper - self.event_pulse_time[NN]) < windowNN,axis=1)
timeok = np.all(np.fabs(meantime_proper - self.event_pulse_time[NN]) < windowNN, axis=1)

selection = (timeok) * (totcharge > thresholdNN)
mask[NN[selection]] = True
Expand All @@ -248,11 +264,11 @@ def magic_clean_step1Sum(self):
sumthresh3NN = self.SumThresh3NNPerPixel * 3 * self.configuration['picture_thresh']
sumthresh4NN = self.SumThresh4NNPerPixel * 4 * self.configuration['picture_thresh']

clip2NN = 2.2 * sumthresh2NN/2.
clip3NN = 1.05 * sumthresh3NN/3.
clip4NN = 1.05 * sumthresh4NN/4.
clip2NN = 2.2 * sumthresh2NN / 2.
clip3NN = 1.05 * sumthresh3NN / 3.
clip4NN = 1.05 * sumthresh4NN / 4.

mask = np.asarray([False]*len(self.event_image))
mask = np.asarray([False] * len(self.event_image))

if self.find_hotpixels:

Expand Down Expand Up @@ -360,31 +376,29 @@ def magic_clean_step2b(self, mask):

neighbors = copy.copy(self.camera.neighbor_matrix)
neighbors[self.unmapped_mask] = False
clean_neighbors = neighbors[mask][:, mask]

num_islands, labels = connected_components(clean_neighbors, directed=False)

island_ids = np.zeros(self.camera.n_pixels)
island_ids[mask] = labels + 1
n_islands, island_labels = number_of_islands(self.camera, mask)

# Finding the islands "sizes" (total charges)
island_sizes = np.zeros(num_islands)
for i in range(num_islands):
island_sizes[i] = self.event_image[mask][labels == i].sum()
mask_main = brightest_island(n_islands, island_labels, self.event_image)

# Disabling pixels for all islands save the brightest one
brightest_id = island_sizes.argmax() + 1
# print(f"Main islands pixels: {np.where(mask_main == True)[0]}")

if self.configuration['use_time']:
brightest_pixel_times = self.event_pulse_time[mask & (island_ids == brightest_id)]
brightest_pixel_charges = self.event_image[mask & (island_ids == brightest_id)]

brightest_time = np.sum(brightest_pixel_times * brightest_pixel_charges**2) / np.sum(brightest_pixel_charges**2)
time_ave = np.average(self.event_pulse_time[mask_main], weights=self.event_image[mask_main] ** 2)

time_diff = np.abs(self.event_pulse_time - brightest_time)
# print(f"mean time main island (using ctapipe): {time_ave}")

mask[(self.event_image > 2*self.configuration['picture_thresh']) & (time_diff > 2*self.configuration['max_time_off'])] = False
mask[(self.event_image < 2*self.configuration['picture_thresh']) & (time_diff > self.configuration['max_time_off'])] = False
# print(f"Low charge pixels: {np.where(self.event_image[mask_main] < 2. * self.configuration['picture_thresh'])[0]}")

time_diffs = np.abs(self.event_pulse_time[mask] - time_ave)
time_limit_pixwise = np.where(
self.event_image < (2. * self.configuration['picture_thresh']),
self.configuration['max_time_off'],
self.configuration['max_time_off'] * 2.
)[mask]

mask[mask] &= time_diffs < time_limit_pixwise

for pix_id in np.where(mask)[0]:
if len(set(np.where(neighbors[pix_id] & mask)[0])) == 0:
Expand Down Expand Up @@ -453,16 +467,16 @@ def magic_clean_step3b(self, mask):
if self.configuration['use_time']:
boundary_pixels = copy.copy(pixels)
neighbors = pixels_with_picture_neighbors_matrix[boundary_pixels]
neighbors[:,~core_mask]=False
neighbors[:, ~core_mask] = False

time_broadcast = np.tile(self.event_pulse_time,(len(self.event_image),1))
time_broadcast = np.tile(self.event_pulse_time, (len(self.event_image), 1))
boundary_times = np.transpose(time_broadcast)[boundary_pixels]
neighbor_times = time_broadcast[boundary_pixels]

time_diff = np.abs(neighbor_times - boundary_times)
time_selection = time_diff < self.configuration['max_time_diff']

hasNeighbor = np.minimum(np.sum(time_selection*neighbors,axis=1),1).astype(bool)
hasNeighbor = np.minimum(np.sum(time_selection * neighbors, axis=1), 1).astype(bool)
pixels = boundary_pixels[hasNeighbor]

selection = pixels[pixels_with_picture_neighbors_matrix.dot(core_mask)[pixels]]
Expand Down Expand Up @@ -552,6 +566,8 @@ def interpolate_signals(self):

self.event_image[self.unsuitable_mask] = np.nanmean(image_broadcast,axis=1)

self.event_image[self.unsuitable_mask] = reduce_precision_vector(self.event_image[self.unsuitable_mask])

self.unmapped_mask = copy.copy(unmapped_mask)

self.unsuitable_mask_new = unsuitable_mask
Expand Down Expand Up @@ -586,6 +602,7 @@ def interpolate_times_slow(self):

if p0>=0 and p1>=0 and np.fabs(times[p0] - times[p1]) < 250:
self.event_pulse_time[ipixel] = (times[p0] + times[p1])/2.0
self.event_pulse_time[ipixel] = reduce_precision_vector(self.event_pulse_time[ipixel])

def interpolate_times_fast(self):

Expand Down
8 changes: 4 additions & 4 deletions magicctapipe/scripts/lst1_magic/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ MAGIC:
magic_clean:
use_time: true
use_sum: true
picture_thresh: 6
boundary_thresh: 3.5
max_time_off: 4.5
max_time_diff: 1.5
picture_thresh: 6.0 # phe
boundary_thresh: 3.5 # phe
max_time_off: 4.5 # ns
max_time_diff: 1.5 # ns
find_hotpixels: true
pedestal_type: "from_extractor_rndm"

Expand Down
13 changes: 13 additions & 0 deletions magicctapipe/scripts/mars/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .mars_images_to_hdf5 import (
read_images,
save_images,
ImageContainerCalibrated,
ImageContainerCleaned,
)

__all__ = [
"read_images",
"save_images",
"ImageContainerCalibrated",
"ImageContainerCleaned",
]
Loading