Quickstart#
This takes one config through the three things the package does most: check it, explain what is wrong, and repair it.
A config with a typo#
Save this as my_config.yaml. It describes a small CCD exposure, with one
mistake: the dark current model is spelled dark_curent.
exposure:
readout:
times: [1.0]
ccd_detector:
geometry:
row: 64
col: 64
total_thickness: 40.0
pixel_vert_size: 10.0
pixel_horz_size: 10.0
environment:
temperature: 150.0
characteristics:
quantum_efficiency: 0.9
charge_to_volt:
value: 3.0e-6
pre_amplification: 100.0
adc_bit_resolution: 16
adc_voltage_range: [0.0, 10.0]
pipeline:
photon_collection:
- func: pyxel.models.photon_collection.illumination
name: illumination
enabled: true
arguments:
level: 1000.0
charge_generation:
- func: pyxel.models.charge_generation.simple_conversion
name: photoelectric_effect
enabled: true
- func: pyxel.models.charge_generation.dark_curent
name: dark_current
enabled: true
arguments:
figure_of_merit: 1.0
charge_collection:
- func: pyxel.models.charge_collection.simple_collection
name: simple_collection
enabled: true
charge_measurement:
- func: pyxel.models.charge_measurement.simple_measurement
name: simple_measurement
enabled: true
readout_electronics:
- func: pyxel.models.readout_electronics.simple_adc
name: simple_adc
enabled: true
Check it#
from pyxel_config_core import validate_config
result = validate_config(open("my_config.yaml").read())
print(result.valid)
for d in result.diagnostics:
print(d.severity, d.path)
print(d.message)
False
error /pipeline/charge_generation/1/func
Unknown model 'dark_curent' in stage 'charge_generation'. Did you mean 'dark_current'?
Each finding is a Diagnostic: how much it
matters, where it is (a JSON pointer into the config), what is wrong, and for
a mistyped model, the suggestion it most likely meant. result.pyxel_version
names the Pyxel release whose schema judged the config.
Ask for an explanation#
explain_config() runs the same checks and adds a
summary and one instruction per finding:
from pyxel_config_core import explain_config
explanation = explain_config(open("my_config.yaml").read())
print(explanation.summary)
print(explanation.diagnostics[0].next_step)
This CCD exposure config has 1 problem in the charge_generation stage.
Rename func to 'pyxel.models.charge_generation.dark_current'.
Repair it#
autofix() renames mistyped models and moves
misplaced ones. It returns a corrected copy and leaves the original alone:
from pyxel_config_core import autofix, validate_config
fix = autofix(open("my_config.yaml").read())
for change in fix.changes:
print(change.action, change.before, "->", change.after)
print(validate_config(fix.config).valid)
rename_func pyxel.models.charge_generation.dark_curent -> pyxel.models.charge_generation.dark_current
True
The same from the command line#
pyxel-config validate my_config.yaml # exits with 1: the config has errors
pyxel-config explain my_config.yaml # adds the summary and next steps
pyxel-config fix my_config.yaml -o fixed.yaml # writes the corrected copy
pyxel-config validate fixed.yaml # exits with 0: valid
The exit code is the verdict, so these lines work in CI as they are. See the command line for report formats and a ready-made GitLab CI job.
Going further#
validate_config(config, deep=True), orpyxel-config validate --deep, also hands the config to Pyxel’s own loader. It needs Pyxel installed; see the deep check.How validation works lists every kind of check, and what is deliberately left to Pyxel.