vdmtools.io.ScanResults

class vdmtools.io.ScanResults(path: Path, scan_name: str = '', fits: Optional[Set[str]] = None, detectors: Optional[List[str]] = None, corrections: Optional[Set[str]] = None, read_channels: bool = False)

Container for the results of a scan.

This class provides a convenient way to access the results of a scan given the path to the scan results directory. It also reads the scan conditions from the conditions file which is located in the cond directory of the scan results directory.

Tip

Consider using this class when implementing a new IStrategyPlugin.

Parameters:
  • path (Path) – The path to the scan results directory.

  • scan_name (str, default: "") – The name of the scan. E.g. VdM1.

  • fits (Set[str], default: set()) – The names of the fits to read. If empty, all fits are read.

  • detectors (List[str], default: list()) – The names of the detectors to read. If empty, all detectors are read.

  • corrections (Set[str], default: set()) – The names of the corrections to read. If empty, all corrections are read.

  • read_channels (bool, default: False) – If True, also reads the results from detector channels.

results

The underlying results. It’s a dictionary where the keys are the names of the fits (like SG, DG, etc.) and the values are pandas DataFrames containing the results.

The dataframes all contain the same columns apart from the fit specific ones (SG fits do not require Frac or FracErr since there is only one gaussian). All the columns that were present in the original result files are kept besides the XscanNumber_YscanNumber and Type columns. All other columns were suffixed with _<PLANE>, where <PLANE> is either X or Y depending on the plane in question. There were also added the columns fit, detector and correction which contain the name of the fit, detector and correction in that row.

Summary of the columns present in the results.

Column

Description

fit

The fit for that row.

detector

The detector for that row.

correction

The correction for that row.

<NAME>_X

Quantity <NAME> for the in the X plane.

<NAME>_Y

Quantity <NAME> for the in the Y plane.

<NAME>Err_X

Error on quantity <NAME> for the in the X plane.

<NAME>Err_Y

Error on quantity <NAME> for the in the Y plane.

Note

Some quantities are plane independent. In this case they are not suffixed with _X or _Y.

Some examples of how to access the results:

>>> results = scan_results.results
>>> results.keys()
dict_keys(['SG', 'DG', 'SGConst'])
>>> results["SG"]
          BCID fit   detector            correction  ...        xsec   xsecErr      SBIL   SBILErr
    0      103  SG      BCM1F            Background  ...  135.803567  0.635974  0.069527  0.000388
    1      103  SG      BCM1F  BeamBeam_DynamicBeta  ...  138.506193  0.659651  0.067518  0.000382
    2      103  SG      BCM1F                noCorr  ...  137.865789  0.659816  0.068165  0.000387
    3      103  SG  BCM1FUTCA            Background  ...  127.995151  0.685705  0.068811  0.000435
    4      103  SG  BCM1FUTCA                noCorr  ...  129.702695  0.688118  0.067679  0.000424
    ...    ...  ..        ...                   ...  ...         ...       ...       ...       ...
    1899  3144  SG       HFOC  BeamBeam_DynamicBeta  ...  946.752519  1.674816  0.076859  0.000163
    1900  3144  SG       HFOC                noCorr  ...  941.786213  1.675058  0.077677  0.000165
    1901  3144  SG        PLT            Background  ...  299.420665  1.768880  0.078534  0.000544
    1902  3144  SG        PLT  BeamBeam_DynamicBeta  ...  303.675925  1.779477  0.076760  0.000528
    1903  3144  SG        PLT                noCorr  ...  302.015262  1.780534  0.077613  0.000537
Type:

Dict[str, pd.DataFrame]

conditionsScanConditions

The conditions of the scan.

scan_idstr

The ID of the scan. E.g.``8999_28Jun23_230143_28Jun23_232943``

Methods

filter_results_by(fit, detector, correction)

Return a DataFrame containing the results form the filter criteria.

filter_results_by(fit: str, detector: str, correction: str, fit_status: str = 'as_is', cov_status: str = 'as_is') DataFrame

Return a DataFrame containing the results form the filter criteria.

Parameters:
  • fit (str) – The name of the fit to filter by.

  • detector (str) – The name of the detector to filter by.

  • correction (str) – The name of the correction to filter by.

  • fit_status (str, default: "as_is") – The status of the fit to filter by. Can be one of “as_is”, “good”, “bad”

  • cov_status (str, default: "as_is") – The status of the covariance matrix to filter by. Can be one of “as_is”, “good”, “bad”

Returns:

The filtered results.

Return type:

pd.DataFrame

Raises:

ValueError – If the filtering returns an empty DataFrame.

Examples

Filter for a specific fit, detector and correction:

>>> data = scan_results.filter_results_by("SG", "BCM1F", "Background")
>>> data.head()
        BCID fit detector            correction  ...        xsec   xsecErr      SBIL   SBILErr
    0    103  SG    BCM1F  BeamBeam_DynamicBeta  ...  140.960688  0.883231  0.065656  0.000490
    8    124  SG    BCM1F  BeamBeam_DynamicBeta  ...  140.219116  0.828196  0.072860  0.000513
    16   145  SG    BCM1F  BeamBeam_DynamicBeta  ...  140.614667  0.917215  0.058912  0.000450
    24   166  SG    BCM1F  BeamBeam_DynamicBeta  ...  140.183518  0.815876  0.069397  0.000472
    32   187  SG    BCM1F  BeamBeam_DynamicBeta  ...  139.707410  0.882703  0.059622  0.000443

Filter also by ``fit status``:

>>> data = scan_results.filter_results_by("SG", "BCM1F", "Background", fit_status="good")
>>> data["fitStatus_X"].unique()
    array([0])