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

Lidar corr #95

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3bc1bf2
Reading of uncalibrated reports from Magic lidar and implementation o…
nzywucka Nov 23, 2023
fbd80b1
Removed print.
nzywucka Nov 23, 2023
7a97565
In __init__.py, more parameters were added to ReportLaserContainer() …
nzywucka Nov 29, 2023
3398c84
__init__.py changed regarding Laser test #84 comments in ReportLaser…
nzywucka Dec 4, 2023
867aa73
Unnecessary spaces are removed from the file.
nzywucka Feb 26, 2024
aad168a
Unnecessary spaces are removed
nzywucka Feb 26, 2024
9cebd79
Unnecessary spaces removed
nzywucka Feb 26, 2024
74d5c62
Typo removed
nzywucka Feb 26, 2024
8bc6487
If statement for self.laser = self.parse_laser_info() added
nzywucka Feb 26, 2024
e0c1118
Typo removed
nzywucka Feb 26, 2024
7e0252f
BGSamples parameter added
nzywucka Feb 26, 2024
be6a536
The [0]s have been removed from the arrays while reading the Lidar re…
nzywucka Mar 12, 2024
6c424c8
Unindent that does not match any outer indentation level has been cor…
nzywucka Mar 12, 2024
f5e1669
Filtering for the unique reports has been corrected.
nzywucka Mar 12, 2024
27d8a8f
Unused variable has been removed.
nzywucka Mar 12, 2024
4135a5e
Reading of the unnecesary parameters from the lidar reports are removed.
nzywucka Mar 12, 2024
7d6e7ce
Unused import has been removed
nzywucka Mar 12, 2024
ec4c4b7
Trailing whitespace has been removed
nzywucka Mar 12, 2024
2b2dd17
Reading the unique reports has been improved to keep all the unique p…
nzywucka Mar 12, 2024
08b5101
The definitions of the container parameters have been improved.
nzywucka Mar 12, 2024
f1024fa
Appending the unique parameters to the container was improved.
nzywucka Mar 12, 2024
4625c5d
AttributeError has been fixed.
nzywucka Mar 13, 2024
102aa85
Merge remote-tracking branch 'origin/master' into laser_test
nzywucka Mar 15, 2024
bb14523
Filtering of lidar parameters has been improved.
nzywucka Mar 25, 2024
bcaaef2
Filtering of lidar parameters has been improved
nzywucka Mar 27, 2024
1864e76
test_lidar_parameters was removed
nzywucka Mar 27, 2024
61f4a75
Implementation of some tests of reading lidar parameters
nzywucka Mar 27, 2024
94efd5e
test_lidar_parameters test has been improved.
nzywucka Mar 27, 2024
d46221f
Unnecessary comments and whitespaces have been removed.
nzywucka Mar 27, 2024
338a7a9
Implementation of some corrections of lidar parameters.
nzywucka Mar 27, 2024
2ef3ecd
Improvements to read external files have been added
nzywucka Mar 28, 2024
d699a68
External files have been added
nzywucka Mar 28, 2024
fadf6d4
Reading BadReport and State parameters added.
nzywucka Mar 28, 2024
fce7374
Reading unique reports changed.
nzywucka Apr 2, 2024
25136f0
Remove assert from tests in codacy
nzywucka Apr 2, 2024
9f14bb5
Skipping assert checks in the test files.
nzywucka Apr 2, 2024
20091c7
Skipping assert checks in the test files.
nzywucka Apr 2, 2024
4f8597c
Tests for reading lidar parameters have been removed.
nzywucka Apr 3, 2024
7ce9794
Merge branch 'laser_test' into lidar_corr
nzywucka Apr 3, 2024
5221ce4
laser_test_new.py: improved implementation of corrections of LIDAR pa…
nzywucka Oct 30, 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
2 changes: 2 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ engines:
pyflakes:
disable:
- F999
assert_used: skips: ['*/*/test_*.py', '*/test_*.py', 'test_*.py']

216 changes: 213 additions & 3 deletions ctapipe_io_magic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import uproot
import logging
import numpy as np
from typing import List, Any
from pathlib import Path
from decimal import Decimal
from astropy import units as u
from astropy.time import Time
from pkg_resources import resource_filename

from ctapipe.io import EventSource, DataLevel
from ctapipe.core import Provenance
from ctapipe.core import Provenance, Container, Field
from ctapipe.core.traits import Bool, UseEnum
from ctapipe.coordinates import CameraFrame

Expand Down Expand Up @@ -92,6 +93,68 @@
DATA_MAGIC_LST_TRIGGER: EventType.SUBARRAY,
}

class ReportLaserContainer(Container):
""" Container for Magic laser parameters """
UniqueID = Field(Any, 'No.')
Bits = Field(Any, 'ID')
MJD = Field(np.float64, 'Modified Julian Date')
BadReport = Field(Any, 'Bad Report')
State = Field(Any, 'State')
IsOffsetCorrection = Field(Any, 'Is Offset Correction')
IsOffsetFitted = Field(Any, 'Is Offset Fitted')
IsBGCorrection = Field(Any, 'Is BG Correction')
IsT0ShiftFitted = Field(Any, 'Is T0 Shift Fitted')
IsUseGDAS = Field(Any, 'Is Use GDAS')
IsUpwardMoving = Field(Any, 'Is Upward Moving')
OverShoot = Field(Any, 'Over Shoot')
UnderShoot = Field(Any, 'Under Shoot')
BGSamples = Field(Any, 'BG Samples')
Transmission3km = Field(Any, 'Transmission at 3 km')
Transmission6km = Field(Any, 'Transmission at 6 km')
Transmission9km = Field(Any, 'Transmission at 9 km')
Transmission12km = Field(Any, 'Transmission at 12 km')
Zenith = Field(Any, 'Zenith angle', unit=u.deg)
Azimuth = Field(Any, 'Azimuth angle', unit=u.deg)
FullOverlap = Field(Any, 'Full Overlap')
EndGroundLayer = Field(Any, 'End Ground Layer')
GroundLayerTrans = Field(Any, 'Ground Layer Trans')
Calimaness = Field(Any, 'Calimaness')
CloudLayerAlt = Field(Any, 'Altitude of cloud layer')
CloudLayerDens = Field(Any, 'Density of cloud layer')
Klett_k = Field(Any, 'Klett k')
PheCounts = Field(List[int], 'Phe Counts')
Offset = Field(Any, 'Offset')
Offset_Calculated = Field(Any, 'Offset calculated')
Offset_Fitted = Field(Any, 'Offset fitted')
Offset2 = Field(Any, 'Offset 2')
Offset3 = Field(Any, 'Offset 3')
Background1 = Field(Any, 'Background 1')
Background2 = Field(Any, 'Background 2')
BackgroundErr1 = Field(Any, 'Background error 1')
BackgroundErr2 = Field(Any, 'Background error 2')
RangeMax = Field(Any, 'Range max')
RangeMax_Clouds = Field(Any, 'Range max clouds')
ErrorCode = Field(Any, 'Error code')
ScaleHeight_fit = Field(Any, 'Scale Height fit')
Alpha_fit = Field(Any, 'Alpha fit')
Chi2Alpha_fit = Field(Any, 'Chi2 Alpha fit')
Alpha_firstY = Field(Any, 'Alpha first Y')
Alpha_Junge = Field(Any, 'Alpha Junge')
PBLHeight = Field(Any, 'PBL Height')
Chi2Full_fit = Field(Any, 'Chi2 Full fit')
SignalSamples = Field(Any, 'Signal Samples')
HWSwitch = Field(Any, 'HW Switch')
HWSwitchMaxOffset = Field(Any, 'HW Switch Max Offset')
NCollapse = Field(Any, 'N Collapse')
Shots = Field(Any, 'Shots')
T0Shift = Field(Any, 'T0 Shift')
Interval_0 = Field(Any, 'Interval 0')
RCS_min_perfect = Field(Any, 'RCS min perfect')
RCS_min_clouds = Field(Any, 'RCS min cloud')
RCS_min_mol = Field(Any, 'RCS min mol')
LIDAR_ratio = Field(Any, 'LIDAR ratio')
LIDAR_ratio_Cloud = Field(Any, 'LIDAR ratio cloud')
LIDAR_ratio_Junge = Field(Any, 'LIDAR ratio Junge')

def load_camera_geometry():
"""Load camera geometry from bundled resources of this repo"""
Expand Down Expand Up @@ -223,6 +286,9 @@

self.metadata = self.parse_metadata_info()

if not self.is_simulation:
self.laser = self.parse_laser_info()

# Retrieving the data level (so far HARDCODED Sorcerer)
self.datalevel = DataLevel.DL0

Expand Down Expand Up @@ -381,13 +447,13 @@
elif re.match(mask_data_superstar, file_name) is not None:
parsed_info = re.match(mask_data_superstar, file_name)
telescope = None
run_number = int(parsed_info.grou(1))
run_number = int(parsed_info.group(1))

Check warning on line 450 in ctapipe_io_magic/__init__.py

View check run for this annotation

Codecov / codecov/patch

ctapipe_io_magic/__init__.py#L450

Added line #L450 was not covered by tests
datalevel = MARSDataLevel.SUPERSTAR
is_mc = False
elif re.match(mask_data_melibea, file_name) is not None:
parsed_info = re.match(mask_data_melibea, file_name)
telescope = None
run_number = int(parsed_info.grou(1))
run_number = int(parsed_info.group(1))

Check warning on line 456 in ctapipe_io_magic/__init__.py

View check run for this annotation

Codecov / codecov/patch

ctapipe_io_magic/__init__.py#L456

Added line #L456 was not covered by tests
datalevel = MARSDataLevel.MELIBEA
is_mc = False
elif re.match(mask_mc_calibrated, file_name) is not None:
Expand Down Expand Up @@ -1035,6 +1101,150 @@

return metadata

def parse_laser_info(self):
laser_info_array_list_runh = [
'MReportLaser.MReport.fUniqueID',
'MReportLaser.MReport.fBits',
'MTimeLaser.fMjd',
'MTimeLaser.fTime.fMilliSec',
'MReportLaser.MReport.fBadReport',
'MReportLaser.MReport.fState',
'MReportLaser.fIsOffsetCorrection',
'MReportLaser.fIsOffsetFitted',
'MReportLaser.fIsBGCorrection',
'MReportLaser.fIsT0ShiftFitted',
'MReportLaser.fIsUseGDAS',
'MReportLaser.fIsUpwardMoving',
'MReportLaser.fOverShoot',
'MReportLaser.fUnderShoot',
'MReportLaser.fBGSamples',
'MReportLaser.fTransmission3km',
'MReportLaser.fTransmission6km',
'MReportLaser.fTransmission9km',
'MReportLaser.fTransmission12km',
'MReportLaser.fZenith',
'MReportLaser.fAzimuth',
'MReportLaser.fFullOverlap',
'MReportLaser.fEndGroundLayer',
'MReportLaser.fGroundLayerTrans',
'MReportLaser.fKlett_k',
'MReportLaser.fPheCounts',
'MReportLaser.fCalimaness',
'MReportLaser.fCloudLayerAlt',
'MReportLaser.fCloudLayerDens',
'MReportLaser.fOffset',
'MReportLaser.fOffset_Calculated',
'MReportLaser.fOffset_Fitted',
'MReportLaser.fOffset2',
'MReportLaser.fOffset3',
'MReportLaser.fBackground1',
'MReportLaser.fBackground2',
'MReportLaser.fBackgroundErr1',
'MReportLaser.fBackgroundErr2',
'MReportLaser.fRangeMax',
'MReportLaser.fRangeMax_Clouds',
'MReportLaser.fErrorCode',
'MReportLaser.fScaleHeight_fit',
'MReportLaser.fChi2Alpha_fit',
'MReportLaser.fChi2Alpha_fit',
'MReportLaser.fAlpha_firstY',
'MReportLaser.fAlpha_Junge',
'MReportLaser.fPBLHeight',
'MReportLaser.fChi2Full_fit',
'MReportLaser.fHWSwitchMaxOffset',
'MReportLaser.fNCollapse',
'MReportLaser.fShots',
'MReportLaser.fT0Shift',
'MReportLaser.fInterval_0',
'MReportLaser.fRCS_min_perfect',
'MReportLaser.fRCS_min_clouds',
'MReportLaser.fRCS_min_mol',
'MReportLaser.fLIDAR_ratio',
'MReportLaser.fLIDAR_ratio_Cloud',
'MReportLaser.fLIDAR_ratio_Junge',
]

old_mjd = None
unique_reports = []
for rootf in self.files_:
try:
laser_info_runh = rootf['Laser'].arrays(
laser_info_array_list_runh, library="np")
mjd_value = laser_info_runh['MTimeLaser.fMjd']
millisec_value = laser_info_runh['MTimeLaser.fTime.fMilliSec']
millisec_seconds = millisec_value * msec2sec
combined_mjd_value = mjd_value + millisec_seconds / 86400
for index in range(len(mjd_value)):
if combined_mjd_value[index] != old_mjd:
laser = ReportLaserContainer()
laser.MJD = combined_mjd_value[index]
laser.UniqueID = laser_info_runh['MReportLaser.MReport.fUniqueID'][index]
laser.Bits = laser_info_runh['MReportLaser.MReport.fBits'][index]
laser.BadReport = laser_info_runh['MReportLaser.MReport.fBadReport'][index]
laser.State = laser_info_runh['MReportLaser.MReport.fState'][index]
laser.IsOffsetCorrection = laser_info_runh['MReportLaser.fIsOffsetCorrection'][index]
laser.IsOffsetFitted = laser_info_runh['MReportLaser.fIsOffsetFitted'][index]
laser.IsBGCorrection = laser_info_runh['MReportLaser.fIsBGCorrection'][index]
laser.IsT0ShiftFitted = laser_info_runh['MReportLaser.fIsT0ShiftFitted'][index]
laser.IsUseGDAS = laser_info_runh['MReportLaser.fIsUseGDAS'][index]
laser.IsUpwardMoving = laser_info_runh['MReportLaser.fIsUpwardMoving'][index]
laser.OverShoot = laser_info_runh['MReportLaser.fOverShoot'][index]
laser.UnderShoot = laser_info_runh['MReportLaser.fUnderShoot'][index]
laser.BGSamples = laser_info_runh['MReportLaser.fBGSamples'][index]
laser.Transmission3km = laser_info_runh['MReportLaser.fTransmission3km'][index]
laser.Transmission6km = laser_info_runh['MReportLaser.fTransmission6km'][index]
laser.Transmission9km = laser_info_runh['MReportLaser.fTransmission9km'][index]
laser.Transmission12km = laser_info_runh['MReportLaser.fTransmission12km'][index]
laser.Zenith = laser_info_runh['MReportLaser.fZenith'][index] * u.deg
laser.Azimuth = laser_info_runh['MReportLaser.fAzimuth'][index] * u.deg
laser.FullOverlap = laser_info_runh['MReportLaser.fFullOverlap'][index]
laser.EndGroundLayer = laser_info_runh['MReportLaser.fEndGroundLayer'][index]
laser.GroundLayerTrans = laser_info_runh['MReportLaser.fGroundLayerTrans'][index]
laser.Klett_k = laser_info_runh['MReportLaser.fKlett_k'][index]
laser.PheCounts = laser_info_runh['MReportLaser.fPheCounts'][index]
laser.Calimaness = laser_info_runh['MReportLaser.fCalimaness'][index]
laser.CloudLayerAlt = laser_info_runh['MReportLaser.fCloudLayerAlt'][index]
laser.CloudLayerDens = laser_info_runh['MReportLaser.fCloudLayerDens'][index]
laser.Offset = laser_info_runh['MReportLaser.fOffset'][index]
laser.Offset_Calculated = laser_info_runh['MReportLaser.fOffset_Calculated'][index]
laser.Offset_Fitted = laser_info_runh['MReportLaser.fOffset_Fitted'][index]
laser.Offset2 = laser_info_runh['MReportLaser.fOffset2'][index]
laser.Offset3 = laser_info_runh['MReportLaser.fOffset3'][index]
laser.Background1 = laser_info_runh['MReportLaser.fBackground1'][index]
laser.Background2 = laser_info_runh['MReportLaser.fBackground2'][index]
laser.BackgroundErr1 = laser_info_runh['MReportLaser.fBackgroundErr1'][index]
laser.BackgroundErr2 = laser_info_runh['MReportLaser.fBackgroundErr2'][index]
laser.RangeMax = laser_info_runh['MReportLaser.fRangeMax'][index]
laser.RangeMax_Clouds = laser_info_runh['MReportLaser.fRangeMax_Clouds'][index]
laser.ErrorCode = laser_info_runh['MReportLaser.fErrorCode'][index]
laser.ScaleHeight_fit = laser_info_runh['MReportLaser.fScaleHeight_fit'][index]
laser.Alpha_fit = laser_info_runh['MReportLaser.fChi2Alpha_fit'][index]
laser.Chi2Alpha_fit = laser_info_runh['MReportLaser.fChi2Alpha_fit'][index]
laser.Alpha_firstY = laser_info_runh['MReportLaser.fAlpha_firstY'][index]
laser.Alpha_Junge = laser_info_runh['MReportLaser.fAlpha_Junge'][index]
laser.PBLHeight = laser_info_runh['MReportLaser.fPBLHeight'][index]
laser.Chi2Full_fit = laser_info_runh['MReportLaser.fChi2Full_fit'][index]
laser.HWSwitchMaxOffset = laser_info_runh['MReportLaser.fHWSwitchMaxOffset'][index]
laser.NCollapse = laser_info_runh['MReportLaser.fNCollapse'][index]
laser.Shots = laser_info_runh['MReportLaser.fShots'][index]
laser.T0Shift = laser_info_runh['MReportLaser.fT0Shift'][index]
laser.Interval_0 = laser_info_runh['MReportLaser.fInterval_0'][index]
laser.RCS_min_perfect = laser_info_runh['MReportLaser.fRCS_min_perfect'][index]
laser.RCS_min_clouds = laser_info_runh['MReportLaser.fRCS_min_clouds'][index]
laser.RCS_min_mol = laser_info_runh['MReportLaser.fRCS_min_mol'][index]
laser.LIDAR_ratio = laser_info_runh['MReportLaser.fLIDAR_ratio'][index]
laser.LIDAR_ratio_Cloud = laser_info_runh['MReportLaser.fLIDAR_ratio_Cloud'][index]
laser.LIDAR_ratio_Junge = laser_info_runh['MReportLaser.fLIDAR_ratio_Junge'][index]

unique_reports.append(laser)
print(mjd_value)
old_mjd = combined_mjd_value[index]

except KeyError as e:
print(f"Required key not found in the file {rootf}: {e}")
continue
return unique_reports

def parse_simulation_header(self):
"""
Parse the simulation information from the RunHeaders tree.
Expand Down
15 changes: 15 additions & 0 deletions ctapipe_io_magic/azimuth_conditions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# zenith conditions (1,2)
# azimuth conditions (3,4)
# correction (5)
0. 50. 157.5 202.5 0.17
0. 40. 135. 225. 0.24
0. 30. 112.5 247.5 0.24
0. 20. 90. 270. 0.24
10. 90. 337.5 360. 0.2
10. 50. 292.5 360. 0.11
10. 40. 0. 4.5 0.11
10. 30. 0. 67.5 0.11
20. 40. 247.5 270. 0.11
15. 50. 225. 247.5 0.05
30. 60. 202.5 225. 0.05

Loading