Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/changes/2034.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not include mirror_reflection_random_angle in derivation of mirror alignment parameters.
20 changes: 6 additions & 14 deletions src/simtools/applications/derive_psf_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
r"""
Derives the mirror alignment parameters using cumulative PSF measurement.

This includes parameters mirror_reflection_random_angle, \
mirror_align_random_horizontal and mirror_align_random_vertical.
This includes parameters mirror_align_random_horizontal and mirror_align_random_vertical.

The measured cumulative PSF should be provided by using the command line argument data. \
A file name is expected, in which the file should contain 3 columns: radial distance in mm, \
Expand Down Expand Up @@ -54,8 +53,6 @@
Name of the data file with the measured cumulative PSF.
plot_all (activation mode, optional)
If activated, plots will be generated for all values tested during tuning.
fixed (activation mode, optional)
Keep the first entry of mirror_reflection_random_angle fixed.
test (activation mode, optional)
If activated, application will be faster by simulating fewer photons.
write_psf_parameters (activation mode, optional)
Expand Down Expand Up @@ -84,7 +81,7 @@

.. code-block:: console

simtools-derive-psf-parameters --site North --telescope LSTN-01 --model_version 6.0.0 \\
simtools-derive-psf-parameters --site North --telescope LSTN-01 --model_version 7.0.0 \\
--plot_all --test --rmsd_threshold 0.01 --learning_rate 0.001 \\
--data tests/resources/PSFcurve_data_v2.ecsv \\
--write_psf_parameters
Expand All @@ -93,7 +90,7 @@

.. code-block:: console

simtools-derive-psf-parameters --site North --telescope LSTN-01 --model_version 6.0.0 \\
simtools-derive-psf-parameters --site North --telescope LSTN-01 --model_version 7.0.0 \\
--plot_all --test --monte_carlo_analysis \\
--data tests/resources/PSFcurve_data_v2.ecsv \\
--write_psf_parameters
Expand All @@ -120,8 +117,8 @@ def _parse():
config = configurator.Configurator(
label=get_application_label(__file__),
description=(
"Derive mirror_reflection_random_angle, mirror_align_random_horizontal "
"and mirror_align_random_vertical using cumulative PSF measurement."
"Derive mirror_align_random_horizontal and mirror_align_random_vertical "
"using cumulative PSF measurement."
),
)
config.parser.add_argument(
Expand All @@ -142,11 +139,6 @@ def _parse():
),
action="store_true",
)
config.parser.add_argument(
"--fixed",
help=("Keep the first entry of mirror_reflection_random_angle fixed."),
action="store_true",
)
config.parser.add_argument(
"--write_psf_parameters",
help=("Write the optimized PSF parameters as simulation model parameter files"),
Expand All @@ -169,7 +161,7 @@ def _parse():
"(not used with --monte_carlo_analysis)."
),
type=float,
default=0.01,
default=0.0001,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an unusual small learning rate, or? Just a comment, no need to change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is small, but after removing rnda from this function the larger learning rate was too large. The learning rate is adaptive anyway so it's not going to stay the same, this is just the starting rate for the first step.

)
config.parser.add_argument(
"--monte_carlo_analysis",
Expand Down
17 changes: 4 additions & 13 deletions src/simtools/ray_tracing/psf_parameter_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,11 @@ def run_gradient_descent(self, rmsd_threshold, learning_rate, max_iterations=200
current_lr = learning_rate

while iteration < max_iterations:
if current_metric <= rmsd_threshold:
tolerance = 0.1 * rmsd_threshold
if current_metric <= (rmsd_threshold + tolerance):
logger.info(
f"Optimization converged: RMSD {current_metric:.6f} <= "
f"threshold {rmsd_threshold:.6f}"
f"threshold {rmsd_threshold:.6f} (tolerance {tolerance:.6f})"
)
break

Expand Down Expand Up @@ -835,14 +836,10 @@ def get_previous_values(tel_model):
-------
dict
Dictionary containing current values of PSF optimization parameters:
- 'mirror_reflection_random_angle': Random reflection angle parameters
- 'mirror_align_random_horizontal': Horizontal alignment parameters
- 'mirror_align_random_vertical': Vertical alignment parameters
"""
return {
"mirror_reflection_random_angle": tel_model.get_parameter_value(
"mirror_reflection_random_angle"
),
"mirror_align_random_horizontal": tel_model.get_parameter_value(
"mirror_align_random_horizontal"
),
Expand Down Expand Up @@ -1056,13 +1053,7 @@ def _add_units_to_psf_parameters(best_pars):
"""Add astropy units to PSF parameters based on their schemas."""
psf_pars_with_units = {}
for param_name, param_values in best_pars.items():
if param_name == "mirror_reflection_random_angle":
psf_pars_with_units[param_name] = [
param_values[0] * u.deg,
param_values[1] * u.dimensionless_unscaled,
param_values[2] * u.deg,
]
elif param_name in ["mirror_align_random_horizontal", "mirror_align_random_vertical"]:
if param_name in ["mirror_align_random_horizontal", "mirror_align_random_vertical"]:
psf_pars_with_units[param_name] = [
param_values[0] * u.deg,
param_values[1] * u.deg,
Expand Down
2 changes: 0 additions & 2 deletions src/simtools/visualization/plot_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,6 @@ def create_psf_vs_offaxis_plot(tel_model, site_model, args_dict, best_pars, outp

parameters_text = (
f"Best Parameters: \n"
f"reflection=["
f"{', '.join(f'{x:.4f}' for x in best_pars['mirror_reflection_random_angle'])}],\n"
f"align_horizontal=["
f"{', '.join(f'{x:.4f}' for x in best_pars['mirror_align_random_horizontal'])}]\n"
f"align_vertical=["
Expand Down
Loading