Update PBPS calibration guide

arrell_c 2025-03-20 10:20:17 +01:00
parent e46d342b12
commit 77b2c985e3

@ -55,6 +55,136 @@ Once completed (approx 1 minute) the plots are updated with the calibration resp
If you are happy with the calibration, press the "Push results/elog" button where the new calibration data is sent to the required data processing pipelines. After an automated restart (~30 seconds) both PV and BS position and intensity data will be calculated with the new calibration. An elog entry is made detailing the calibration data. If you are happy with the calibration, press the "Push results/elog" button where the new calibration data is sent to the required data processing pipelines. After an automated restart (~30 seconds) both PV and BS position and intensity data will be calculated with the new calibration. An elog entry is made detailing the calibration data.
## Calibration value updates from saved values
In addition to the calibration procedure described above, you can save and later reload the calibration values using the provided Python scripts. These scripts allow you to back up the dynamic calibration parameters and update the pipeline configuration with saved values without altering the other configuration parameters.
### Saving calibration values
This script retrieves the current pipeline configuration, extracts the dynamic calibration fields, and saves them into a JSON file. You can use this to archive a known-good calibration setup.
**Usage:**
1. Save the following script as, for example, `save_calibration.py`.
2. Run the script from the command line:
```bash
python save_calibration.py --output calibration_fields.json
The script will create (or overwrite) a file named calibration_fields.json with the calibration parameters.
**Script:**
```python
import json
import argparse
from cam_server_client import PipelineClient
def main(output_file):
# Create a PipelineClient instance
client = PipelineClient()
# Define the pipeline name and get its configuration
pipeline_name = 'SAROP31-PBPS113_proc'
config = client.get_pipeline_config(pipeline_name)
# Extract the dynamic calibration fields from the configuration
calibration_fields = {
'up_calib': config.get('up_calib'),
'down_calib': config.get('down_calib'),
'left_calib': config.get('left_calib'),
'right_calib': config.get('right_calib'),
'horiz_calib': config.get('horiz_calib'),
'vert_calib': config.get('vert_calib'),
'uJ_calib': config.get('uJ_calib')
}
# Save the dynamic fields to a JSON file with the given file name
with open(output_file, 'w') as f:
json.dump(calibration_fields, f, indent=4)
print(f"Calibration fields saved to {output_file}")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Retrieve pipeline configuration and save dynamic calibration fields to a JSON file.'
)
parser.add_argument(
'-o', '--output',
type=str,
default='calibration_fields.json',
help='Output JSON file name (default: calibration_fields.json)'
)
args = parser.parse_args()
main(args.output)
```
### Reloading calibration values and restarting the pipeline
This script loads the saved calibration values from a JSON file and updates the pipeline configuration with these values. The script then uploads the new configuration and restarts the pipeline (by stopping its instance).
**Usage:**
1. Save the following script as, for example, reload_calibration.py.
2. Run the script from the command line, specifying the JSON file with calibration values:
```bash
python reload_calibration.py --file calibration_fields.json --pipeline SAROP31-PBPS113_proc
```
If no pipeline name is provided, it defaults to `SAROP31-PBPS113_proc`.
**Script:**
```python
import json
import argparse
from cam_server_client import PipelineClient
def main(calib_file, pipeline_name):
# Load the saved calibration values from the JSON file
with open(calib_file, 'r') as f:
calib_values = json.load(f)
# Create a PipelineClient instance and get the current configuration
client = PipelineClient()
config = client.get_pipeline_config(pipeline_name)
# Update only the calibration fields from the saved values
calibration_keys = [
'up_calib', 'down_calib', 'left_calib', 'right_calib',
'horiz_calib', 'vert_calib', 'uJ_calib'
]
for key in calibration_keys:
if key in calib_values:
config[key] = calib_values[key]
else:
print(f"Warning: {key} not found in {calib_file}.")
# Upload the updated configuration
updated_config = client.set_config(pipeline_name, config)
print("Updated pipeline configuration:")
print(updated_config)
# Restart the pipeline by stopping its current instance.
client.stop_instance(pipeline_name)
print(f"Pipeline '{pipeline_name}' has been restarted.")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Update pipeline calibration values from a JSON file and restart the pipeline.'
)
parser.add_argument(
'-f', '--file',
type=str,
required=True,
help='Path to the JSON file containing calibration values'
)
parser.add_argument(
'-p', '--pipeline',
type=str,
default='SAROP31-PBPS113_proc',
help='Pipeline name (default: SAROP31-PBPS113_proc)'
)
args = parser.parse_args()
main(args.file, args.pipeline)
```
## Troubleshooting ## Troubleshooting
### **Soft Limits Error** ### **Soft Limits Error**