From e7a4d372fcf71c6b013b47dcbe4ad3cf00147851 Mon Sep 17 00:00:00 2001 From: Felix Soubelet <19598248+fsoubelet@users.noreply.github.com> Date: Wed, 2 Mar 2022 10:27:00 +0000 Subject: [PATCH] Loglevels reduction in cpymadtools (#75) --- docker/environment.yml | 4 +-- docs/release.rst | 14 ++++++++++ pyhdtoolkit/__init__.py | 2 +- pyhdtoolkit/cpymadtools/correctors.py | 4 +-- pyhdtoolkit/cpymadtools/coupling.py | 6 ++--- pyhdtoolkit/cpymadtools/errors.py | 2 +- pyhdtoolkit/cpymadtools/lhc.py | 38 +++++++++++++-------------- pyhdtoolkit/cpymadtools/matching.py | 10 +++---- pyhdtoolkit/cpymadtools/orbit.py | 2 +- pyhdtoolkit/cpymadtools/parameters.py | 2 +- pyhdtoolkit/cpymadtools/plotters.py | 36 ++++++++++++------------- pyhdtoolkit/cpymadtools/ptc.py | 16 +++++------ pyhdtoolkit/cpymadtools/track.py | 4 +-- pyhdtoolkit/cpymadtools/tune.py | 6 ++--- pyhdtoolkit/cpymadtools/twiss.py | 6 ++--- pyproject.toml | 2 +- 16 files changed, 84 insertions(+), 70 deletions(-) diff --git a/docker/environment.yml b/docker/environment.yml index f4fbe2c4..154075b7 100644 --- a/docker/environment.yml +++ b/docker/environment.yml @@ -221,9 +221,9 @@ dependencies: - zlib=1.2.11 - zstd=1.5.2 - pip: - - cpymad==1.9.2 + - cpymad==1.9.3 - importlib-resources==5.4.0 - minrpc==0.1.0 - - pyhdtoolkit==0.16.0 + - pyhdtoolkit==0.16.1 - pynaff==1.1.4 - rich==11.1.0 diff --git a/docs/release.rst b/docs/release.rst index e709cca4..6c8819c8 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -3,6 +3,20 @@ Release Notes The full list of releases can be found in the Github repository's `releases page `. +.. _release_0.16.1: + +0.16.1 +------ + +Maintenance +~~~~~~~~~~~ + +* The **info** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been adjusted to **debug** level. Info logging is left to the user. +* The **warning** level logging statements in the `pyhdtoolkit.cpymadtools` modules have been modified to give a bit more information. + +See `v0.16.1 release notes on GitHub `_ and the `full changes since v0.16.0 `_. + + .. _release_0.16.0: 0.16.0 diff --git a/pyhdtoolkit/__init__.py b/pyhdtoolkit/__init__.py index 77f6aa9a..6c4f122b 100644 --- a/pyhdtoolkit/__init__.py +++ b/pyhdtoolkit/__init__.py @@ -13,7 +13,7 @@ __title__ = "pyhdtoolkit" __description__ = "An all-in-one toolkit package to easy my Python work in my PhD." __url__ = "https://github.com/fsoubelet/PyhDToolkit" -__version__ = "0.16.0" +__version__ = "0.16.1" __author__ = "Felix Soubelet" __author_email__ = "felix.soubelet@cern.ch" __license__ = "MIT" diff --git a/pyhdtoolkit/cpymadtools/correctors.py b/pyhdtoolkit/cpymadtools/correctors.py index 9cf67e97..d4cda0a9 100644 --- a/pyhdtoolkit/cpymadtools/correctors.py +++ b/pyhdtoolkit/cpymadtools/correctors.py @@ -53,7 +53,7 @@ def query_triplet_correctors_powering(madx: Madx) -> Dict[str, float]: >>> triplet_knobs = query_triplet_correctors_powering(madx) """ - logger.info("Querying triplets correctors powering") + logger.debug("Querying triplets correctors powering") result: Dict[str, float] = {} logger.debug("Querying triplet skew quadrupole correctors (MQSXs) powering") @@ -99,7 +99,7 @@ def query_arc_correctors_powering(madx: Madx) -> Dict[str, float]: >>> arc_knobs = query_arc_correctors_powering(madx) """ - logger.info("Querying triplets correctors powering") + logger.debug("Querying triplets correctors powering") result: Dict[str, float] = {} logger.debug("Querying arc tune trim quadrupole correctors (MQTs) powering") diff --git a/pyhdtoolkit/cpymadtools/coupling.py b/pyhdtoolkit/cpymadtools/coupling.py index 759d8097..d9253fb5 100644 --- a/pyhdtoolkit/cpymadtools/coupling.py +++ b/pyhdtoolkit/cpymadtools/coupling.py @@ -112,7 +112,7 @@ def get_closest_tune_approach( qy_target = int(q2) + middle_of_fractional_tunes logger.debug(f"Targeting tunes Qx = {qx_target} | Qy = {qy_target}") - logger.info("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin") + logger.debug("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin") match_tunes_and_chromaticities( madx, accelerator, @@ -130,7 +130,7 @@ def get_closest_tune_approach( cminus = abs(dqmin) logger.debug(f"Matching got to a Closest Tune Approach of {cminus:.5f}") - logger.info("Restoring saved knobs") + logger.debug("Restoring saved knobs") with madx.batch(): madx.globals.update(saved_knobs) madx.command.twiss(chrom=True) # make sure TWISS and SUMM tables are returned to their original state @@ -151,7 +151,7 @@ def match_no_coupling_through_ripkens( location (str): the name of the element at which one wants the cross-term Ripkens to be 0. vary_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` routine. """ - logger.info(f"Matching Ripken parameters for no coupling at location {location}") + logger.debug(f"Matching Ripken parameters for no coupling at location {location}") logger.debug("Creating macro to update Ripkens") madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros diff --git a/pyhdtoolkit/cpymadtools/errors.py b/pyhdtoolkit/cpymadtools/errors.py index 4d51d744..32ae2591 100644 --- a/pyhdtoolkit/cpymadtools/errors.py +++ b/pyhdtoolkit/cpymadtools/errors.py @@ -166,7 +166,7 @@ def misalign_lhc_ir_quadrupoles( logger.trace("Clearing error flag") madx.select(flag="error", clear=True) - logger.info(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}") + logger.debug(f"Applying alignment errors to IR quads '{quadrupoles}', with arguments {kwargs}") for ip in ips: logger.debug(f"Applying errors for IR{ip}") for side in sides: diff --git a/pyhdtoolkit/cpymadtools/lhc.py b/pyhdtoolkit/cpymadtools/lhc.py index 453438f0..772d28fc 100644 --- a/pyhdtoolkit/cpymadtools/lhc.py +++ b/pyhdtoolkit/cpymadtools/lhc.py @@ -63,7 +63,7 @@ def make_lhc_beams(madx: Madx, energy: float = 7000, emittance: float = 3.75e-6, >>> make_lhc_beams(madx, energy=6800, emittance=2.5e-6) """ - logger.info("Making default beams for 'lhcb1' and 'lhbc2' sequences") + logger.debug("Making default beams for 'lhcb1' and 'lhbc2' sequences") madx.globals["NRJ"] = energy madx.globals["brho"] = energy * 1e9 / madx.globals.clight geometric_emit = madx.globals["geometric_emit"] = emittance / (energy / 0.938) @@ -104,7 +104,7 @@ def power_landau_octupoles(madx: Madx, beam: int, mo_current: float, defective_a logger.exception("The global MAD-X variable 'NRJ' should have been set in the optics files but is not defined.") raise EnvironmentError("No 'NRJ' variable found in scripts") from madx_error - logger.info(f"Powering Landau Octupoles, beam {beam} @ {madx.globals.nrj} GeV with {mo_current} A.") + logger.debug(f"Powering Landau Octupoles, beam {beam} @ {madx.globals.nrj} GeV with {mo_current} A.") strength = mo_current / madx.globals.Imax_MO * madx.globals.Kmax_MO / brho beam = 2 if beam == 4 else beam @@ -134,7 +134,7 @@ def deactivate_lhc_arc_sextupoles(madx: Madx, beam: int) -> None: # KSF1 and KSD2 - Strong sextupoles of sectors 81/12/45/56 # KSF2 and KSD1 - Weak sextupoles of sectors 81/12/45/56 # Rest: Weak sextupoles in sectors 78/23/34/67 - logger.info(f"Deactivating all arc sextupoles for beam {beam}.") + logger.debug(f"Deactivating all arc sextupoles for beam {beam}.") beam = 2 if beam == 4 else beam for arc in _all_lhc_arcs(beam): @@ -165,8 +165,8 @@ def apply_lhc_colinearity_knob(madx: Madx, colinearity_knob_value: float = 0, ir >>> apply_lhc_colinearity_knob(madx, colinearity_knob_value=5, ir=1) """ - logger.info(f"Applying Colinearity knob with a unit setting of {colinearity_knob_value}") - logger.warning("You should re-match tunes & chromaticities after this") + logger.debug(f"Applying Colinearity knob with a unit setting of {colinearity_knob_value}") + logger.warning("You should re-match tunes & chromaticities after this colinearity knob is applied") knob_variables = (f"KQSX3.R{ir:d}", f"KQSX3.L{ir:d}") # MQSX IP coupling correctors right_knob, left_knob = knob_variables @@ -211,8 +211,8 @@ def apply_lhc_rigidity_waist_shift_knob( >>> apply_lhc_rigidity_waist_shift_knob(madx, rigidty_waist_shift_value=1.5, ir=5) >>> matching.match_tunes_and_chromaticities(madx, "lhc", "lhcb1", 62.31, 60.32) """ - logger.info(f"Applying Rigidity Waist Shift knob with a unit setting of {rigidty_waist_shift_value}") - logger.warning("You should re-match tunes & chromaticities after this") + logger.debug(f"Applying Rigidity Waist Shift knob with a unit setting of {rigidty_waist_shift_value}") + logger.warning("You should re-match tunes & chromaticities after this rigid waist shift knob is applied") right_knob, left_knob = f"kqx.r{ir:d}", f"kqx.l{ir:d}" # IP triplet default knob (no trims) current_right_knob = madx.globals[right_knob] @@ -251,8 +251,8 @@ def apply_lhc_coupling_knob( >>> apply_lhc_coupling_knob(madx, coupling_knob=5e-4, beam=1) """ - logger.info("Applying coupling knob") - logger.warning("You should re-match tunes & chromaticities after this") + logger.debug("Applying coupling knob") + logger.warning("You should re-match tunes & chromaticities after this coupling knob is applied") suffix = "_sq" if telescopic_squeeze else "" knob_name = f"CMRS.b{beam:d}{suffix}" @@ -317,7 +317,7 @@ def install_ac_dipole_as_kicker( ... ) """ logger.warning("This AC Dipole is implemented as a kicker and will not affect TWISS functions!") - logger.info("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam") + logger.debug("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam") if top_turns > 6600: logger.warning( @@ -353,7 +353,7 @@ def install_ac_dipole_as_kicker( f"ramp2={ramp2}, ramp3={ramp3}, ramp4={ramp4};" ) - logger.info(f"Installing AC Dipole kicker with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}") + logger.debug(f"Installing AC Dipole kicker with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}") madx.command.seqedit(sequence=f"lhcb{beam:d}") madx.command.flatten() # The kicker version is meant for a thin lattice and is installed a right at MKQA.6L4.B[12] (at=0) @@ -362,7 +362,7 @@ def install_ac_dipole_as_kicker( madx.command.endedit() logger.warning( - f"Sequence LHCB{beam:d} is now re-used for changes to take effect. Beware that this will reset it, " + f"Sequence LHCB{beam:d} is now re-USEd for changes to take effect. Beware that this will reset it, " "remove errors etc." ) madx.use(sequence=f"lhcb{beam:d}") @@ -396,7 +396,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam >>> install_ac_dipole_as_matrix(madx, deltaqx=-0.01, deltaqy=0.012, beam=1) """ logger.warning("This AC Dipole is implemented as a matrix and will not affect particle tracking!") - logger.info("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam.") + logger.debug("This routine should be done after 'match', 'twiss' and 'makethin' for the appropriate beam.") logger.debug("Retrieving tunes from internal tables") q1, q2 = madx.table.summ.q1[0], madx.table.summ.q2[0] @@ -416,7 +416,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam madx.input(f"hacmap: matrix, l=0, rm21=hacmap21;") madx.input(f"vacmap: matrix, l=0, rm43=vacmap43;") - logger.info(f"Installing AC Dipole matrix with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}") + logger.debug(f"Installing AC Dipole matrix with driven tunes of Qx_D = {q1_dipole:.5f} | Qy_D = {q2_dipole:.5f}") madx.command.seqedit(sequence=f"lhcb{beam:d}") madx.command.flatten() # The matrix version is meant for a thick lattice and is installed a little after MKQA.6L4.B[12] @@ -425,7 +425,7 @@ def install_ac_dipole_as_matrix(madx: Madx, deltaqx: float, deltaqy: float, beam madx.command.endedit() logger.warning( - f"Sequence LHCB{beam:d} is now re-used for changes to take effect. Beware that this will reset it, " + f"Sequence LHCB{beam:d} is now re-USEd for changes to take effect. Beware that this will reset it, " "remove errors etc." ) madx.use(sequence=f"lhcb{beam:d}") @@ -503,7 +503,7 @@ def reset_lhc_bump_flags(madx: Madx) -> None: >>> reset_lhc_bump_flags(madx) """ - logger.info("Resetting all LHC IP bump flags") + logger.debug("Resetting all LHC IP bump flags") ALL_BUMPS = ( LHC_ANGLE_FLAGS + LHC_CROSSING_ANGLE_FLAGS @@ -533,7 +533,7 @@ def make_sixtrack_output(madx: Madx, energy: int) -> None: >>> make_sixtrack_output(madx, energy=6800) """ - logger.info("Preparing outputs for SixTrack") + logger.debug("Preparing outputs for SixTrack") logger.debug("Powering RF cavities") madx.globals["VRF400"] = 8 if energy < 5000 else 16 # is 6 at injection for protons iirc? @@ -571,7 +571,7 @@ def make_lhc_thin(madx: Madx, sequence: str, slicefactor: int = 1, **kwargs) -> >>> make_lhc_thin(madx, sequence="lhcb1", slicefactor=4) """ - logger.info(f"Slicing sequence '{sequence}'") + logger.debug(f"Slicing sequence '{sequence}'") madx.select(flag="makethin", clear=True) four_slices_patterns = [r"mbx\.", r"mbrb\.", r"mbrc\.", r"mbrs\."] four_slicefactor_patterns = [ @@ -675,7 +675,7 @@ def match_no_coupling_through_ripkens( location (str): the name of the element at which one wants the cross-term Ripkens to be 0. vary_knobs (Sequence[str]): the variables names to ``VARY`` in the ``MAD-X`` routine. """ - logger.info(f"Matching Ripken parameters for no coupling at location {location}") + logger.debug(f"Matching Ripken parameters for no coupling at location {location}") logger.debug("Creating macro to update Ripkens") madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros diff --git a/pyhdtoolkit/cpymadtools/matching.py b/pyhdtoolkit/cpymadtools/matching.py index f2bdf593..6a92643e 100644 --- a/pyhdtoolkit/cpymadtools/matching.py +++ b/pyhdtoolkit/cpymadtools/matching.py @@ -184,7 +184,7 @@ def match(*args, **kwargs): madx.twiss(chrom=True) # prevents errors if the user forgets to TWISS before querying tables if q1_target is not None and q2_target is not None and dq1_target is not None and dq2_target is not None: - logger.info( + logger.debug( f"Doing combined matching to Qx={q1_target}, Qy={q2_target}, " f"dqx={dq1_target}, dqy={dq2_target} for sequence '{sequence}'" ) @@ -193,13 +193,13 @@ def match(*args, **kwargs): match(*varied_knobs, q1=q1_target, q2=q2_target, dq1=dq1_target, dq2=dq2_target) elif q1_target is not None and q2_target is not None: - logger.info(f"Matching tunes to Qx={q1_target}, Qy={q2_target} for sequence '{sequence}'") + logger.debug(f"Matching tunes to Qx={q1_target}, Qy={q2_target} for sequence '{sequence}'") tune_knobs = varied_knobs or tune_knobs # if accelerator was given we've extracted this already logger.trace(f"Vary knobs sent are {tune_knobs}") match(*tune_knobs, q1=q1_target, q2=q2_target) # sent varied_knobs should be tune knobs elif dq1_target is not None and dq2_target is not None: - logger.info(f"Matching chromaticities to dq1={dq1_target}, dq2={dq2_target} for sequence {sequence}") + logger.debug(f"Matching chromaticities to dq1={dq1_target}, dq2={dq2_target} for sequence {sequence}") chroma_knobs = varied_knobs or chroma_knobs # if accelerator was given we've extracted this already logger.trace(f"Vary knobs sent are {chroma_knobs}") match(*chroma_knobs, dq1=dq1_target, dq2=dq2_target) # sent varied_knobs should be chromaticity knobs @@ -296,7 +296,7 @@ def get_closest_tune_approach( qy_target = int(q2) + middle_of_fractional_tunes logger.debug(f"Targeting tunes Qx = {qx_target} | Qy = {qy_target}") - logger.info("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin") + logger.debug("Performing closest tune approach routine, matching should fail at DeltaQ = dqmin") match_tunes_and_chromaticities( madx, accelerator, @@ -314,7 +314,7 @@ def get_closest_tune_approach( cminus = abs(dqmin) logger.debug(f"Matching got to a Closest Tune Approach of {cminus:.5f}") - logger.info("Restoring saved knobs") + logger.debug("Restoring saved knobs") with madx.batch(): madx.globals.update(saved_knobs) madx.command.twiss(chrom=True) # make sure TWISS and SUMM tables are returned to their original state diff --git a/pyhdtoolkit/cpymadtools/orbit.py b/pyhdtoolkit/cpymadtools/orbit.py index ef342173..7b389932 100644 --- a/pyhdtoolkit/cpymadtools/orbit.py +++ b/pyhdtoolkit/cpymadtools/orbit.py @@ -175,7 +175,7 @@ def correct_lhc_orbit( >>> correct_lhc_orbit(madx, sequence="lhcb1", plane="y") """ - logger.info("Starting orbit correction") + logger.debug("Starting orbit correction") for default_kicker in ("kicker", "hkicker", "vkicker", "virtualcorrector"): logger.trace(f"Disabling default corrector class '{default_kicker}'") madx.command.usekick(sequence=sequence, status="off", class_=default_kicker) diff --git a/pyhdtoolkit/cpymadtools/parameters.py b/pyhdtoolkit/cpymadtools/parameters.py index e22e26f4..5dad89c8 100644 --- a/pyhdtoolkit/cpymadtools/parameters.py +++ b/pyhdtoolkit/cpymadtools/parameters.py @@ -29,5 +29,5 @@ def query_beam_attributes(madx: Madx) -> MADXBeam: Returns: A validated `~.models.madx.MADXBeam` object. """ - logger.info("Retrieving BEAM attributes from the MAD-X process") + logger.debug("Retrieving BEAM attributes from the MAD-X process") return MADXBeam(**dict(madx.beam)) diff --git a/pyhdtoolkit/cpymadtools/plotters.py b/pyhdtoolkit/cpymadtools/plotters.py index c83ec1d8..27cee86b 100644 --- a/pyhdtoolkit/cpymadtools/plotters.py +++ b/pyhdtoolkit/cpymadtools/plotters.py @@ -114,7 +114,7 @@ def plot_aperture( accessed with ``fig.get_axes()``. """ # pylint: disable=too-many-arguments - logger.info("Plotting aperture limits and machine layout") + logger.debug("Plotting aperture limits and machine layout") logger.debug("Getting Twiss dataframe from cpymad") madx.command.twiss(centre=True) twiss_df: pd.DataFrame = madx.table.twiss.dframe().copy() @@ -165,7 +165,7 @@ def plot_aperture( plt.xlim(xlimits) if savefig: - logger.info(f"Saving latwiss plot as {savefig}") + logger.debug(f"Saving latwiss plot as {savefig}") plt.savefig(savefig) return figure @@ -207,7 +207,7 @@ def plot_envelope( """ # pylint: disable=too-many-arguments # We need to interpolate in order to get high resolution along the S direction - logger.info("Plotting estimated machine aperture and beam envelope") + logger.debug("Plotting estimated machine aperture and beam envelope") logger.debug("Running interpolation in MAD-X") madx.command.select(flag="interpolate", class_="drift", slice_=4, range_="#s/#e") madx.command.select(flag="interpolate", class_="quadrupole", slice_=8, range_="#s/#e") @@ -274,7 +274,7 @@ def plot_envelope( axis3.set_title(f"Stay-clear envelope at {beam_params.pc_GeV} GeV/c") if savefig: - logger.info(f"Saving aperture plot at '{Path(savefig).absolute()}'") + logger.debug(f"Saving aperture plot at '{Path(savefig).absolute()}'") plt.savefig(Path(savefig)) return figure @@ -428,7 +428,7 @@ def plot_two_lhc_ips_crossings( plotted per IP and per plane (orbit X and orbit Y). The underlying axes can be accessed with ``fig.get_axes()``. """ - logger.warning("You should re-call the 'USE' command on your wanted sequence after this!") + logger.warning("You should re-call the 'USE' command on your wanted sequence after this plot!") # ----- Getting Twiss table dframe for each beam ----- # logger.debug("Getting TWISS table for LHCB1") madx.use(sequence="lhcb1") @@ -445,7 +445,7 @@ def plot_two_lhc_ips_crossings( second_ip_s = twiss_df_b1.s[f"ip{second_ip}"] # ----- Plotting figure ----- # - logger.info(f"Plotting crossing schemes for IP{first_ip} and IP{second_ip}") + logger.debug(f"Plotting crossing schemes for IP{first_ip} and IP{second_ip}") figure, axes = plt.subplots(2, 2, figsize=figsize) logger.debug(f"Plotting for IP{first_ip}") @@ -505,7 +505,7 @@ def plot_two_lhc_ips_crossings( plt.tight_layout() if savefig: - logger.info(f"Saving crossing schemes for IP{first_ip} and IP{second_ip} plot as '{savefig}'") + logger.debug(f"Saving crossing schemes for IP{first_ip} and IP{second_ip} plot as '{savefig}'") figure.savefig(savefig) return figure @@ -538,7 +538,7 @@ def plot_dynamic_aperture( The `~matplotlib.figure.Figure` on which the points are drawn. The underlying axes can be accessed with ``fig.get_axes()``. """ - logger.info(f"Plotting the '{len(x_coords)} turns' aperture") + logger.debug(f"Plotting the '{len(x_coords)} turns' aperture") figure = plt.figure(figsize=(12, 7)) turn_lost_at = [] amp_lost = [] @@ -562,7 +562,7 @@ def plot_dynamic_aperture( plt.ylabel("Initial amplitude $[mm]$") if savefig: - logger.info(f"Saving dynamic aperture plot at '{Path(savefig).absolute()}'") + logger.debug(f"Saving dynamic aperture plot at '{Path(savefig).absolute()}'") plt.savefig(Path(savefig)) return figure @@ -646,7 +646,7 @@ def plot_latwiss( """ # pylint: disable=too-many-arguments # Restrict the span of twiss_df to avoid plotting all elements then cropping when xlimits is given - logger.info("Plotting optics functions and machine layout") + logger.debug("Plotting optics functions and machine layout") twiss_df = _get_twiss_table_with_offsets_and_limits(madx, xoffset, xlimits) xlimits = (twiss_df.s.min(), twiss_df.s.max()) if xlimits is None else xlimits @@ -700,7 +700,7 @@ def plot_latwiss( plt.xlim(xlimits) if savefig: - logger.info(f"Saving latwiss plot as {savefig}") + logger.debug(f"Saving latwiss plot as {savefig}") plt.savefig(savefig) return figure @@ -736,7 +736,7 @@ def plot_machine_survey( The `~matplotlib.figure.Figure` on which the plots are drawn. The underlying axes can be accessed with ``fig.get_axes()``. """ - logger.info("Plotting machine survey") + logger.debug("Plotting machine survey") logger.trace("Getting machine survey from cpymad") madx.command.survey() survey = madx.table.survey.dframe() @@ -779,7 +779,7 @@ def plot_machine_survey( plt.title(title) if savefig: - logger.info(f"Saving machine survey plot as {savefig}") + logger.debug(f"Saving machine survey plot as {savefig}") plt.savefig(savefig) return figure @@ -821,7 +821,7 @@ def plot_courant_snyder_phase_space( logger.error(f"Plane should be either Horizontal or Vertical but '{plane}' was given") raise ValueError("Invalid plane value") - logger.info("Plotting phase space for normalized Courant-Snyder coordinates") + logger.debug("Plotting phase space for normalized Courant-Snyder coordinates") figure = plt.figure(figsize=figsize) plt.title("Courant-Snyder Phase Space") @@ -845,7 +845,7 @@ def plot_courant_snyder_phase_space( plt.axis("Equal") if savefig: - logger.info(f"Saving Courant-Snyder phase space plot at '{Path(savefig).absolute()}'") + logger.debug(f"Saving Courant-Snyder phase space plot at '{Path(savefig).absolute()}'") plt.savefig(Path(savefig)) return figure @@ -890,7 +890,7 @@ def plot_courant_snyder_phase_space_colored( while len(colors) > len(u_coordinates): colors.pop() - logger.info("Plotting colored phase space for normalized Courant-Snyder coordinates") + logger.debug("Plotting colored phase space for normalized Courant-Snyder coordinates") figure = plt.figure(figsize=figsize) plt.title("Courant-Snyder Phase Space") @@ -914,7 +914,7 @@ def plot_courant_snyder_phase_space_colored( plt.axis("Equal") if savefig: - logger.info(f"Saving colored Courant-Snyder phase space plot at '{Path(savefig).absolute()}'") + logger.debug(f"Saving colored Courant-Snyder phase space plot at '{Path(savefig).absolute()}'") plt.savefig(Path(savefig)) return figure @@ -1047,7 +1047,7 @@ def plot_tune_diagram( logger.error("Plotting is not supported outside of 1st-6th order (and not recommended)") raise ValueError("The 'max_order' argument should be between 1 and 6 included") - logger.info(f"Plotting resonance lines up to {TuneDiagramPlotter.order_to_label[max_order]}") + logger.debug(f"Plotting resonance lines up to {TuneDiagramPlotter.order_to_label[max_order]}") figure, axis = plt.subplots(figsize=figsize) for order in range(max_order, 0, -1): # high -> low so most importants ones (low) are plotted on top diff --git a/pyhdtoolkit/cpymadtools/ptc.py b/pyhdtoolkit/cpymadtools/ptc.py index f992385b..b38258b4 100644 --- a/pyhdtoolkit/cpymadtools/ptc.py +++ b/pyhdtoolkit/cpymadtools/ptc.py @@ -8,7 +8,7 @@ `~cpymad.madx.Madx` object. """ from pathlib import Path -from typing import Dict, Sequence, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union import pandas as pd import tfs @@ -60,7 +60,7 @@ def get_amplitude_detuning( logger.error(f"Maximum amplitude detuning order in PTC is 2, but {order:d} was requested") raise NotImplementedError("PTC amplitude detuning is not implemented for order > 2") - logger.info("Creating PTC universe") + logger.debug("Creating PTC universe") madx.ptc_create_universe() logger.trace("Creating PTC layout") @@ -146,7 +146,7 @@ def get_rdts( >>> rdts_df = get_rdts(madx, order=3, fringe=True) """ - logger.info("Creating PTC universe") + logger.debug("Creating PTC universe") madx.ptc_create_universe() logger.trace("Creating PTC layout") @@ -208,7 +208,7 @@ def ptc_twiss( >>> twiss_ptc_df = ptc_twiss(madx, order=3) """ - logger.info(f"Creating PTC universe") + logger.debug(f"Creating PTC universe") madx.ptc_create_universe() logger.trace("Creating PTC layout") @@ -235,7 +235,7 @@ def ptc_track_particle( madx: Madx, initial_coordinates: Tuple[float, float, float, float, float, float], nturns: int, - sequence: str = None, + sequence: Optional[str] = None, observation_points: Sequence[str] = None, onetable: bool = False, fringe: bool = False, @@ -294,16 +294,16 @@ def ptc_track_particle( ... madx, nturns=1023, initial_coordinates=(2e-4, 0, 1e-4, 0, 0, 0) ... ) """ - logger.info("Performing single particle PTC (thick) tracking") + logger.debug("Performing single particle PTC (thick) tracking") start = initial_coordinates if initial_coordinates else [0, 0, 0, 0, 0, 0] observation_points = observation_points if observation_points else [] if isinstance(sequence, str): - logger.warning(f"Sequence '{sequence}' was provided and will be used, beware that this will erase errors etc.") + logger.warning(f"Sequence '{sequence}' was provided and will be USEd, beware that this will erase errors etc.") logger.debug(f"Using sequence '{sequence}' for tracking") madx.use(sequence=sequence) - logger.info(f"Creating PTC universe") + logger.debug(f"Creating PTC universe") madx.ptc_create_universe() logger.trace("Creating PTC layout") diff --git a/pyhdtoolkit/cpymadtools/track.py b/pyhdtoolkit/cpymadtools/track.py index be39fd9a..07e5950a 100644 --- a/pyhdtoolkit/cpymadtools/track.py +++ b/pyhdtoolkit/cpymadtools/track.py @@ -68,13 +68,13 @@ def track_single_particle( ... madx, nturns=1023, initial_coordinates=(2e-4, 0, 1e-4, 0, 0, 0) ... ) """ - logger.info("Performing single particle MAD-X (thin) tracking") + logger.debug("Performing single particle MAD-X (thin) tracking") onetable = kwargs.get("onetable", False) if "onetable" in kwargs else kwargs.get("ONETABLE", False) start = initial_coordinates if initial_coordinates else [0, 0, 0, 0, 0, 0] observation_points = observation_points if observation_points else [] if isinstance(sequence, str): - logger.warning(f"Sequence '{sequence}' was provided and will be used, beware that this will erase errors etc.") + logger.warning(f"Sequence '{sequence}' was provided and will be USEd, beware that this will erase errors etc.") logger.debug(f"Using sequence '{sequence}' for tracking") madx.use(sequence=sequence) diff --git a/pyhdtoolkit/cpymadtools/tune.py b/pyhdtoolkit/cpymadtools/tune.py index 91cbbf5d..6564ef33 100644 --- a/pyhdtoolkit/cpymadtools/tune.py +++ b/pyhdtoolkit/cpymadtools/tune.py @@ -58,7 +58,7 @@ def make_footprint_table( >>> dynap_dframe = make_footprint_table(madx) """ - logger.info(f"Initiating particules up to {sigma:d} bunch sigma to create a tune footprint table") + logger.debug(f"Initiating particules up to {sigma:d} bunch sigma to create a tune footprint table") small, big = 0.05, math.sqrt(1 - 0.05 ** 2) sigma_multiplier, angle_multiplier = 0.1, 0.0 @@ -146,7 +146,7 @@ def get_footprint_lines(dynap_dframe: tfs.TfsDataFrame) -> Tuple[np.ndarray, np. >>> qxs, qys = get_footprint_lines(dynap_tfs) >>> plt.plot(qxs, qys, "o--", label="Tune Footprint from DYNAP Table") """ - logger.info("Determining footprint plottable") + logger.debug("Determining footprint plottable") logger.debug("Retrieving AMPLITUDE, ANGLE and DSIGMA data from TfsDataFrame headers") amplitude = dynap_dframe.headers["AMPLITUDE"] angle = dynap_dframe.headers["ANGLE"] @@ -187,7 +187,7 @@ def get_footprint_patches(dynap_dframe: tfs.TfsDataFrame) -> matplotlib.collecti >>> footprint_polygons = get_footprint_patches(dynap_tfs) >>> axis.add_collection(footprint_polygons) """ - logger.info("Determining footprint polygons") + logger.debug("Determining footprint polygons") angle = dynap_dframe.headers["ANGLE"] amplitude = dynap_dframe.headers["AMPLITUDE"] diff --git a/pyhdtoolkit/cpymadtools/twiss.py b/pyhdtoolkit/cpymadtools/twiss.py index a400b7dc..cd42987b 100644 --- a/pyhdtoolkit/cpymadtools/twiss.py +++ b/pyhdtoolkit/cpymadtools/twiss.py @@ -118,7 +118,7 @@ def get_twiss_tfs(madx: Madx, **kwargs) -> tfs.TfsDataFrame: madx.select(flag="twiss", clear=True) madx.command.twiss(**kwargs) - logger.info("Exporting internal TWISS and SUMM tables to TfsDataFrame") + logger.debug("Exporting internal TWISS and SUMM tables to TfsDataFrame") twiss_tfs = tfs.TfsDataFrame(madx.table.twiss.dframe()) twiss_tfs.name = twiss_tfs.name.apply(lambda x: x[:-2]) # remove :1 from names twiss_tfs.columns = twiss_tfs.columns.str.upper() @@ -147,7 +147,7 @@ def get_ips_twiss(madx: Madx, columns: Sequence[str] = DEFAULT_TWISS_COLUMNS, ** >>> ips_df = get_ips_twiss(madx, chrom=True, ripken=True) """ - logger.info("Getting Twiss at IPs") + logger.debug("Getting Twiss at IPs") return get_pattern_twiss(madx=madx, patterns=["IP"], columns=columns, **kwargs) @@ -172,7 +172,7 @@ def get_ir_twiss(madx: Madx, ir: int, columns: Sequence[str] = DEFAULT_TWISS_COL >>> ir_df = get_ir_twiss(madx, chrom=True, ripken=True) """ - logger.info(f"Getting Twiss for IR{ir:d}") + logger.debug(f"Getting Twiss for IR{ir:d}") return get_pattern_twiss( madx=madx, patterns=[ diff --git a/pyproject.toml b/pyproject.toml index c437a2fc..59585f90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyhdtoolkit" -version = "0.16.0" +version = "0.16.1" description = "An all-in-one toolkit package to easy my Python work in my PhD." authors = ["Felix Soubelet "] license = "MIT"