threshold_set module
Define an object to hold all thresholds of a multipactor test.
- class ThresholdSet(thresholds, power_extrema)[source]
Bases:
object- Parameters:
power_extrema (
Iterable[PowerExtremum])
- classmethod from_instruments(multipac_detector, detecting_instruments, growth_array, threshold_predicate=None, threshold_reducer=None)[source]
Create a ThresholdSet using the specified detection strategy.
- Parameters:
multipac_detector (
Callable[[ndarray[tuple[Any,...],dtype[double]]],ndarray[tuple[Any,...],dtype[bool]]]) – Function that takes in thedataof anInstrumentand returns an array, where True means multipactor and False no multipactor.detecting_instruments (
Iterable[Instrument]) – Instruments to applymultipac_detectoron.growth_array (
ndarray[tuple[Any,...],dtype[double]]) – Holds1.0where power increases,0.0where it is stable,-1.0where it decreases.threshold_reducer (
Literal['any','all'] |None, default:None) –not provided: thresholds are computed for each instrument independently.
”any”: thresholds appear when multipactor is detected by any of the provided detecting instrument.
”all”: thresholds appear when multipactor is detected by all the provided detecting instrument.
threshold_predicate (
Callable[[Threshold],bool] |None, default:None) – Function filtering the thresholds. Applied afterthreshold_reducer.
- Return type:
Self
- classmethod last(threshold_set, threshold_predicate=None)[source]
Create object holding the last threshold measured by every instrument.
See also
- Parameters:
- Return type:
Self- Returns:
Holds only one lower and one upper
Thresholdper detecting instrument: the last one measured during the test.
- classmethod subset(threshold_set, threshold_predicate)[source]
Return object holding a subset of
threshold_set.threshold_predicateis used to filter on theThreshold.
- classmethod extreme(threshold_set, threshold_predicate=None)[source]
Create object holding only the most extreme
Threshold.For each half cycle:
If power increases: keep first lower and last upper threshold.
If power decreases: keep first upper and last lower threshold.
If there was still multipactor somewhere when the half power cycle ended (e.g. instrument with a lower but no upper threshold), no upper threshold is added.
If direction is undetermined: skip the cycle.
- remove_singularities(min_consecutive=1)[source]
Remove fugitive
Threshold.If two
Thresholdare detected by the sameInstrumentand theirThreshold.sample_indexare separated bymin_consecutive - 1or less, both objects are removed.
- _remove_thresholds_at_seesaw()[source]
Clean incorrect
Thresholdif power follows seesaw profile.Consider this: -
i - 1: max power of the seesaw profile, there is MP -i: new seesaw (min power of the profile), no MPAt
i - 1, we did not reach a threshold. But we have aThresholdcorresponding to it. So we have to remove it.- Return type:
- _warn_instruments_at_same_position()[source]
Verify bijection between detecting instruments pos and name.
- Return type:
- sample_indexes(*, threshold_predicate=None)[source]
Return sample indexes matching optional filter.
- at(position, tol=1e-10, return_global=False)[source]
Gather all thresholds measured at
position.- Parameters:
position (
float) – Where you want the thresholds.tol (
float, default:1e-10) – Tolerance over the position.return_global (
bool, default:False) – To return global multipactors, and also return all thresholds whenpositionisnp.nan.np.nanposition are associated with “global” instruments, such asForwardPower, and with “global” multipactors, such as obtained by crossing severalInstrumentdata.
- Return type:
- Returns:
All multipactor thresholds detected at this position.
- data_at_thresholds(instruments, tol=1e-10, global_instruments=False, global_multipactor=False, xdata_instrument=None, unique_x_value=None)[source]
Return instrument values at threshold sample indices.
We match
ThresholdandInstrumentobjects by position.- Parameters:
instruments (
Iterable[Instrument]) – Instruments to which data must be plotted. Must have.positionand.dataattributes.tol (
float, default:1e-10) – Tolerance for position matching.global_instruments (
bool, default:False) – If instruments not position-specific (egForwardPower) should be returned.global_multipactor (
bool, default:False) – If multipactor not position-specific (eg thresholds created by merging several other multipactor arrays) should be returned.xdata_instrument (
Instrument|None, default:None) – Its data is returned at every threshold. It results in a uniquexdatacolumn, withoutnan, that can be used as a common x-data for plotting.unique_x_value (
float|None, default:None) – If given, this value will replace every value of thexdata_instrumentcolumn.
- Return type:
- Returns:
Columns are named by detecting instrument + threshold nature:
"NI9205_E4 @ upper threshold (according to NI9205_MP4l)". Ifxdata_instrumentwas given, also return this instrument values at every sample index (can be unique value ifunique_x_valuewas given). Indexes are the sample indices at every threshold.
- according_to(instrument)[source]
Give thresholds measured by
instrument.- Parameters:
instrument (
Instrument|str|Literal['any','all'])- Return type:
- remove_detected_by(instrument)[source]
Remove thresholds detected by
instrument.- Parameters:
instrument (
Instrument|str|Literal['any','all'])- Return type:
- get_threshold_label_color_map(instruments)[source]
Maps threshold dataframe column headers to corresponding colors.
Assumes
Threshold.coloris already set to the correspondingInstrumentcolor.
- _thresholds_by_half_power_cycle(threshold_predicate=None)[source]
Group thresholds by half power cycle, based on sample index range.
Each group includes thresholds between two consecutive extrema:
[extremum_i.sample_index, extremum_{i+1}.sample_index)The dictionary key is of the form:
“0 (increasing)” if power increases over the interval
“1 (decreasing)” if power decreases over the interval
“2 (undetermined)” if direction cannot be determined
Note
Not ultra efficient. To update if necessary.
- class AveragedThresholdSet(thresholds, power_extrema)[source]
Bases:
ThresholdSetHolds average of several thresholds.
The main difference with a classic
ThresholdSetis that itsdata_at_thresholds()is overriden to return data averaged from severalThreshold.- Parameters:
power_extrema (
Iterable[PowerExtremum])
- classmethod from_threshold_set(threshold_set, threshold_predicate=None)[source]
Create an object holding averaged thresholds.
- Parameters:
threshold_set (
ThresholdSet) – The thresholds to average.threshold_predicate (
Callable[[Threshold],bool] |None, default:None) – To filter thresholds to average. A typical example would belambda t: t.sample_index > 200to keep only conditioned thresholds.
- Return type:
Self- Returns:
Object containing “averaged” thresholds. It contains one lower and one upper threshold per detecting instrument (if already present in the original
ThresholdSet).
- data_at_thresholds(*args, **kwargs)[source]
Return average of instrument values at threshold sample indices.
Keep the xdata column as a representative index: for each y-column, compute the median of its xdata values.
- Parameters:
instruments – Instruments to which data must be plotted. Must have
.positionand.dataattributes.tol – Tolerance for position matching.
global_instruments – If instruments not position-specific (eg
ForwardPower) should be returned.global_multipactor – If multipactor not position-specific (eg thresholds created by merging several other multipactor arrays) should be returned.
xdata_instrument – Its data is returned at every threshold. It results in a unique
xdatacolumn, withoutnan, that can be used as a common x-data for plotting.
- Return type:
- Returns:
Columns are named by detecting instrument + threshold nature. Only index is average (median) of instruments values at the various thresholds.
- _remove_thresholds_at_seesaw()
Clean incorrect
Thresholdif power follows seesaw profile.Consider this: -
i - 1: max power of the seesaw profile, there is MP -i: new seesaw (min power of the profile), no MPAt
i - 1, we did not reach a threshold. But we have aThresholdcorresponding to it. So we have to remove it.- Return type:
- _thresholds_by_half_power_cycle(threshold_predicate=None)
Group thresholds by half power cycle, based on sample index range.
Each group includes thresholds between two consecutive extrema:
[extremum_i.sample_index, extremum_{i+1}.sample_index)The dictionary key is of the form:
“0 (increasing)” if power increases over the interval
“1 (decreasing)” if power decreases over the interval
“2 (undetermined)” if direction cannot be determined
Note
Not ultra efficient. To update if necessary.
- _warn_instruments_at_same_position()
Verify bijection between detecting instruments pos and name.
- Return type:
- according_to(instrument)
Give thresholds measured by
instrument.- Parameters:
instrument (
Instrument|str|Literal['any','all'])- Return type:
- apply_to(instrument)
Extract instrument data at threshold sample indexes.
- at(position, tol=1e-10, return_global=False)
Gather all thresholds measured at
position.- Parameters:
position (
float) – Where you want the thresholds.tol (
float, default:1e-10) – Tolerance over the position.return_global (
bool, default:False) – To return global multipactors, and also return all thresholds whenpositionisnp.nan.np.nanposition are associated with “global” instruments, such asForwardPower, and with “global” multipactors, such as obtained by crossing severalInstrumentdata.
- Return type:
- Returns:
All multipactor thresholds detected at this position.
- detecting_instruments()
Return instruments that detected at least one threshold.
- classmethod extreme(threshold_set, threshold_predicate=None)
Create object holding only the most extreme
Threshold.For each half cycle:
If power increases: keep first lower and last upper threshold.
If power decreases: keep first upper and last lower threshold.
If there was still multipactor somewhere when the half power cycle ended (e.g. instrument with a lower but no upper threshold), no upper threshold is added.
If direction is undetermined: skip the cycle.
- classmethod from_instruments(multipac_detector, detecting_instruments, growth_array, threshold_predicate=None, threshold_reducer=None)
Create a ThresholdSet using the specified detection strategy.
- Parameters:
multipac_detector (
Callable[[ndarray[tuple[Any,...],dtype[double]]],ndarray[tuple[Any,...],dtype[bool]]]) – Function that takes in thedataof anInstrumentand returns an array, where True means multipactor and False no multipactor.detecting_instruments (
Iterable[Instrument]) – Instruments to applymultipac_detectoron.growth_array (
ndarray[tuple[Any,...],dtype[double]]) – Holds1.0where power increases,0.0where it is stable,-1.0where it decreases.threshold_reducer (
Literal['any','all'] |None, default:None) –not provided: thresholds are computed for each instrument independently.
”any”: thresholds appear when multipactor is detected by any of the provided detecting instrument.
”all”: thresholds appear when multipactor is detected by all the provided detecting instrument.
threshold_predicate (
Callable[[Threshold],bool] |None, default:None) – Function filtering the thresholds. Applied afterthreshold_reducer.
- Return type:
Self
- get_threshold_label_color_map(instruments)
Maps threshold dataframe column headers to corresponding colors.
Assumes
Threshold.coloris already set to the correspondingInstrumentcolor.
- classmethod last(threshold_set, threshold_predicate=None)
Create object holding the last threshold measured by every instrument.
See also
- Parameters:
- Return type:
Self- Returns:
Holds only one lower and one upper
Thresholdper detecting instrument: the last one measured during the test.
- remove_detected_by(instrument)
Remove thresholds detected by
instrument.- Parameters:
instrument (
Instrument|str|Literal['any','all'])- Return type:
- remove_singularities(min_consecutive=1)
Remove fugitive
Threshold.If two
Thresholdare detected by the sameInstrumentand theirThreshold.sample_indexare separated bymin_consecutive - 1or less, both objects are removed.
- sample_indexes(*, threshold_predicate=None)
Return sample indexes matching optional filter.