Skip to content

Commit

Permalink
latest blk
Browse files Browse the repository at this point in the history
  • Loading branch information
relleums committed Feb 22, 2024
1 parent 961367e commit 894796e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 47 deletions.
1 change: 0 additions & 1 deletion airshower_template_generator/bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def full_coverage_xy_supports_on_observationlevel(binning):

for azi, azi_center_deg in enumerate(eb["azimuth_deg"]["supports"]):
for rad, r_m in enumerate(eb["radius_m"]["supports"]):

azi_circumference_m = 2.0 * np.pi * r_m
azi_arc_length_m = (
azi_circumference_m / binning["azimuth_deg"]["num_bins"]
Expand Down
12 changes: 7 additions & 5 deletions airshower_template_generator/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def write_raw(raw_look_up, path):
_tar_append(
tar_obj=tar_obj,
name="airshower.histogram.ene_alt.int64.gz",
payload_bytes=gzip.compress(data=num.tobytes(order="c"),),
payload_bytes=gzip.compress(
data=num.tobytes(order="c"),
),
)
_tar_append(
tar_obj=tar_obj,
Expand Down Expand Up @@ -170,9 +172,10 @@ def write_map_result(
_tar_append(
tar_obj=tar_obj,
name="job.json",
payload_bytes=json_utils.dumps(job, indent=4,).encode(
encoding="ascii"
),
payload_bytes=json_utils.dumps(
job,
indent=4,
).encode(encoding="ascii"),
)
_tar_append(
tar_obj=tar_obj,
Expand Down Expand Up @@ -212,7 +215,6 @@ def write_map_result(
def read_map_result(path):
out = {}
with tarfile.TarFile(path, "r") as tar_obj:

tinfo = tar_obj.next()
assert tinfo.name == "job.json"
out["job"] = json_utils.loads(tar_obj.extractfile(tinfo).read())
Expand Down
16 changes: 11 additions & 5 deletions airshower_template_generator/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ def gaussian_bell_1d(c_deg, peak_deg, width_deg):


def gaussian_bell_1d_max_one(c_deg, peak_deg, width_deg):
return np.exp(-0.5 * (c_deg - peak_deg) ** 2 / width_deg ** 2)
return np.exp(-0.5 * (c_deg - peak_deg) ** 2 / width_deg**2)


def lorentz_transversal(c_deg, peak_deg, width_deg):
return width_deg / (np.pi * (width_deg ** 2 + (c_deg - peak_deg) ** 2))
return width_deg / (np.pi * (width_deg**2 + (c_deg - peak_deg) ** 2))


def lorentz_moyal_longitidinal(
c_deg, peak_deg, width_deg,
c_deg,
peak_deg,
width_deg,
):
lam = (c_deg - peak_deg) / width_deg
return (
Expand All @@ -29,9 +31,13 @@ def lorentz_moyal_longitidinal(

def my_moyal_model(c_deg, moyal_peak_deg, tail_direction, width_deg):
moyal_density = (1.0 - tail_direction) * lorentz_moyal_longitidinal(
c_deg=c_deg, peak_deg=moyal_peak_deg, width_deg=width_deg,
c_deg=c_deg,
peak_deg=moyal_peak_deg,
width_deg=width_deg,
)
gaussian_density = tail_direction * lorentz_moyal_longitidinal(
c_deg=-c_deg, peak_deg=-moyal_peak_deg, width_deg=width_deg,
c_deg=-c_deg,
peak_deg=-moyal_peak_deg,
width_deg=width_deg,
)
return moyal_density + gaussian_density
12 changes: 8 additions & 4 deletions airshower_template_generator/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,32 @@ def write_view(path, energy_GeV, altitude_m, azimuth_deg, radius_m, lut):
0.1,
0.3,
"azimuth-bin [{: 3d}, {: 3d}]".format(
b["azimuth_deg"][0]["bin"], b["azimuth_deg"][1]["bin"],
b["azimuth_deg"][0]["bin"],
b["azimuth_deg"][1]["bin"],
),
)
ax_ap_text.text(
0.1,
0.2,
"radius-bin [{: 3d}, {: 3d}]".format(
b["radius_m"][0]["bin"], b["radius_m"][1]["bin"],
b["radius_m"][0]["bin"],
b["radius_m"][1]["bin"],
),
)
ax_ap_text.text(
0.1,
0.1,
"energy-bin [{: 3d}, {: 3d}]".format(
b["energy_GeV"][0]["bin"], b["energy_GeV"][1]["bin"],
b["energy_GeV"][0]["bin"],
b["energy_GeV"][1]["bin"],
),
)
ax_ap_text.text(
0.1,
0.0,
"altitude-bin [{: 3d}, {: 3d}]".format(
b["altitude_m"][0]["bin"], b["altitude_m"][1]["bin"],
b["altitude_m"][0]["bin"],
b["altitude_m"][1]["bin"],
),
)

Expand Down
17 changes: 9 additions & 8 deletions airshower_template_generator/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def area_of_aperture_m2(binning):
def solid_angle_of_pixel_sr(binning):
assert image_pixels_are_square(binning=binning)
pixel_edge_rad = parallel_pixel_width_rad(binning=binning)
return pixel_edge_rad ** 2
return pixel_edge_rad**2


def time_slice_duration_s(binning):
Expand Down Expand Up @@ -138,7 +138,8 @@ def image_pixels_are_square(binning):

def zeros(binning, keys=[], dtype=np.float32):
return np.zeros(
shape=[binning[key]["num_bins"] for key in keys], dtype=dtype,
shape=[binning[key]["num_bins"] for key in keys],
dtype=dtype,
)


Expand Down Expand Up @@ -277,11 +278,9 @@ def run_job(job):

for azi in range(job["binning"]["azimuth_deg"]["num_bins"]):
for rad in range(job["binning"]["radius_m"]["num_bins"]):

num_probing_apertures = len(xy_supports[azi][rad])
probing_aperture_weight = 1.0 / num_probing_apertures
for probe in range(num_probing_apertures):

meets = xy_tree.query_ball_point(
x=xy_supports[azi][rad][probe],
r=job["binning"]["aperture_radius_m"],
Expand All @@ -299,7 +298,6 @@ def run_job(job):
)

if num_cherenkov_photons_in_surrounding > 0:

med_time_ns = np.median(
cherenkov_bunches[
surround_meets, cpw.I.BUNCH.TIME_NS
Expand Down Expand Up @@ -393,7 +391,6 @@ def reduce(work_dir):

for site_key in sites:
for particle_key in particles:

cer = zeros(
keys=[
"energy_GeV",
Expand Down Expand Up @@ -491,15 +488,19 @@ def reduce(work_dir):

print("estimate leakage")
leakage_mask = zeros(
keys=["energy_GeV", "azimuth_deg", "radius_m", "altitude_m",],
keys=[
"energy_GeV",
"azimuth_deg",
"radius_m",
"altitude_m",
],
binning=binning,
dtype=np.uint8,
)
for ene in range(binning["energy_GeV"]["num_bins"]):
for azi in range(binning["azimuth_deg"]["num_bins"]):
for rad in range(binning["radius_m"]["num_bins"]):
for alt in range(binning["altitude_m"]["num_bins"]):

leak = quality.estimate_leakage(
image=cer[ene, azi, rad, alt],
num_pixel_outer_rim=1,
Expand Down
12 changes: 10 additions & 2 deletions airshower_template_generator/tests/test_bin_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@


binning = {
"energy_GeV": {"start_support": 1e0, "stop_support": 1e3, "num_bins": 3,},
"energy_GeV": {
"start_support": 1e0,
"stop_support": 1e3,
"num_bins": 3,
},
"azimuth_deg": {"num_bins": 3},
"radius_m": {"start_support": 0.0, "stop_support": 3.0, "num_bins": 4},
"altitude_m": {"start_edge": 0, "stop_edge": 30e3, "num_bins": 3},
Expand All @@ -21,7 +25,11 @@
"stop_edge": 0.5,
"num_bins": 32,
},
"time_s": {"start_edge": -32e-9, "stop_edge": 32e-9, "num_bins": 16,},
"time_s": {
"start_edge": -32e-9,
"stop_edge": 32e-9,
"num_bins": 16,
},
"aperture_radius_m": 5.0,
}

Expand Down
40 changes: 20 additions & 20 deletions airshower_template_generator/tests/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def test_core_xy_does_not_matter_when_pointing_to_zero():

def test_parallel_on_x_axis():
"""
cY, c_perpendicular
^
-----|------------
| | |
| | |
-------0-----------------------> cX, c_parallel
| |
| |
------------------
cY, c_perpendicular
^
-----|------------
| | |
| | |
-------0-----------------------> cX, c_parallel
| |
| |
------------------
"""
for cer_cx in np.linspace(-0.1, 0.1, 10):
for cer_cy in np.linspace(-0.1, 0.1, 10):
Expand All @@ -94,17 +94,17 @@ def test_parallel_on_x_axis():

def test_parallel_on_y_axis():
"""
c_perpendicular
^
-----|------------
| | |
| | |
-------0-----------------------> cY, c_parallel
| | |
| | |
-----|------------
V
cX
c_perpendicular
^
-----|------------
| | |
| | |
-------0-----------------------> cY, c_parallel
| | |
| | |
-----|------------
V
cX
"""
offset_y = 1.0
for cer_cx in np.linspace(-0.1, 0.1, 10):
Expand Down
2 changes: 1 addition & 1 deletion airshower_template_generator/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.4"
__version__ = "0.3.5"
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
url="https://github.com/cherenkov-plenoscope/airshower_template_generator.git",
author="Sebastian Achim Mueller",
author_email="sebastian-achim.mueller@mpi-hd.mpg.de",
packages=["airshower_template_generator",],
packages=[
"airshower_template_generator",
],
package_data={"airshower_template_generator": []},
install_requires=[
"json_utils_sebastian-achim-mueller",
Expand Down

0 comments on commit 894796e

Please sign in to comment.