Skip to content

Commit bfdda0c

Browse files
committed
feat: Move wire recon to yaml and prefill defaults. Add additional checks for indexing prefill
1 parent 5c9dca6 commit bfdda0c

5 files changed

Lines changed: 96 additions & 55 deletions

File tree

config.yaml.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ PEAKINDEX_DEFAULTS:
8282
beamline: "34ID-E"
8383
depth: .nan # YAML nan value
8484

85+
# Wire reconstruction default parameters
86+
WIRERECON_DEFAULTS:
87+
# Recon constraints
88+
geoFile: "Run1/geofiles/geoN_2023-04-06_03-07-11_cor6.xml"
89+
percent_brightest: 100
90+
wire_edges: "leading"
91+
92+
# Depth parameters
93+
depth_start: -50
94+
depth_end: 150
95+
depth_resolution: 1
96+
97+
# Output
98+
outputFolder: "analysis/scan_%d/rec_%d/data"
99+
85100
# Motor groups configuration
86101
MOTOR_GROUPS:
87102
sample:

laue_portal/components/wire_recon_form.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def set_wire_recon_form_props(wirerecon, read_only=False):
235235
filename_value = ', '.join(filename_value)
236236
set_props("filenamePrefix", {'value':filename_value, 'readonly':read_only})
237237

238+
set_props("author", {'value':wirerecon.author, 'readonly':read_only})
238239
set_props("notes", {'value':wirerecon.notes, 'readonly':read_only})
239240

240241
set_props("geoFile", {'value':wirerecon.geoFile, 'readonly':read_only})

laue_portal/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ def _load_config():
5454
MOTOR_GROUPS = _config.get('MOTOR_GROUPS', {})
5555
VALID_HDF_EXTENSIONS = _config.get('VALID_HDF_EXTENSIONS', [])
5656
PEAKINDEX_DEFAULTS = _config.get('PEAKINDEX_DEFAULTS', {})
57+
WIRERECON_DEFAULTS = _config.get('WIRERECON_DEFAULTS', {})

laue_portal/pages/create_peakindexing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,9 +1854,9 @@ def load_scan_data_from_url(href):
18541854
recon_id=current_recon_id,
18551855
wirerecon_id=current_wirerecon_id,
18561856
# Energy-related fields from source
1857-
indexKeVmaxCalc=metadata_data.source_energy if metadata_data else PEAKINDEX_DEFAULTS["indexKeVmaxCalc"],
1858-
indexKeVmaxTest=metadata_data.source_energy if metadata_data else PEAKINDEX_DEFAULTS["indexKeVmaxTest"],
1859-
energyUnit=metadata_data.source_energy_unit if metadata_data else PEAKINDEX_DEFAULTS["energyUnit"],
1857+
indexKeVmaxCalc=metadata_data.source_energy if (metadata_data and metadata_data.source_energy is not None) else PEAKINDEX_DEFAULTS["indexKeVmaxCalc"],
1858+
indexKeVmaxTest=metadata_data.source_energy if (metadata_data and metadata_data.source_energy is not None) else PEAKINDEX_DEFAULTS["indexKeVmaxTest"],
1859+
energyUnit=metadata_data.source_energy_unit if (metadata_data and metadata_data.source_energy_unit is not None) else PEAKINDEX_DEFAULTS["energyUnit"],
18601860
outputFolder=outputFolder,
18611861
**{k: v for k, v in PEAKINDEX_DEFAULTS.items() if k not in ['scanNumber', 'outputFolder', 'indexKeVmaxCalc', 'indexKeVmaxTest', 'energyUnit']}
18621862
)

laue_portal/pages/create_wire_reconstruction.py

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from laue_portal.components.form_base import _field
1717
from laue_portal.components.validation_alerts import validation_alerts
1818
from laue_portal.processing.redis_utils import enqueue_wire_reconstruction, STATUS_REVERSE_MAPPING
19-
from laue_portal.config import DEFAULT_VARIABLES
19+
from laue_portal.config import DEFAULT_VARIABLES, WIRERECON_DEFAULTS
2020
from laue_portal.pages.validation_helpers import (
2121
apply_validation_highlights,
2222
update_validation_alerts,
@@ -105,17 +105,68 @@ def build_output_folder_template(scan_num_int, data_path):
105105
"finish_time": datetime.datetime.now(),
106106
}
107107

108-
WIRERECON_DEFAULTS = {
109-
"scanNumber": 276994,
110-
"geoFile": "Run1/geofiles/geoN_2023-04-06_03-07-11_cor6.xml",
111-
"percent_brightest": 100,
112-
"depth_start": -50,
113-
"depth_end": 150,
114-
"depth_resolution": 1,
115-
"outputFolder": "analysis/scan_%d/rec_%d/data",
116-
"scanPoints": "7",
117-
"wire_edges": "leading",
118-
}
108+
def create_default_wirerecon(overrides=None):
109+
"""
110+
Create a WireRecon object populated with defaults from config.
111+
112+
This is the single source of truth for default WireRecon creation.
113+
All defaults come from WIRERECON_DEFAULTS (config.yaml) and DEFAULT_VARIABLES.
114+
115+
Args:
116+
overrides: Dict of values to override defaults (e.g., from metadata or URL params).
117+
Keys should match WireRecon model field names.
118+
119+
Returns:
120+
db_schema.WireRecon with all defaults set, plus extra attributes:
121+
- root_path: from DEFAULT_VARIABLES
122+
- data_path: empty string (to be populated later)
123+
- filenamePrefix: empty string (to be populated later)
124+
"""
125+
# Start with config defaults
126+
defaults = {
127+
# User text from DEFAULT_VARIABLES
128+
'author': DEFAULT_VARIABLES.get('author', ''),
129+
'notes': DEFAULT_VARIABLES.get('notes', ''),
130+
131+
# Recon constraints from WIRERECON_DEFAULTS
132+
'geoFile': WIRERECON_DEFAULTS.get('geoFile'),
133+
'percent_brightest': WIRERECON_DEFAULTS.get('percent_brightest'),
134+
'wire_edges': WIRERECON_DEFAULTS.get('wire_edges'),
135+
136+
# Depth parameters
137+
'depth_start': WIRERECON_DEFAULTS.get('depth_start'),
138+
'depth_end': WIRERECON_DEFAULTS.get('depth_end'),
139+
'depth_resolution': WIRERECON_DEFAULTS.get('depth_resolution'),
140+
141+
# Compute parameters from DEFAULT_VARIABLES
142+
'num_threads': DEFAULT_VARIABLES.get('num_threads'),
143+
'memory_limit_mb': DEFAULT_VARIABLES.get('memory_limit_mb'),
144+
145+
# Files
146+
'scanPoints': WIRERECON_DEFAULTS.get('scanPoints', ''),
147+
148+
# Output
149+
'outputFolder': WIRERECON_DEFAULTS.get('outputFolder'),
150+
'verbose': DEFAULT_VARIABLES.get('verbose'),
151+
}
152+
153+
# Apply overrides
154+
if overrides:
155+
defaults.update(overrides)
156+
157+
# Calculate scanPoints length
158+
scanPoints_str = defaults.get('scanPoints', '') or ''
159+
defaults['scanPointslen'] = srange(scanPoints_str).len() if scanPoints_str else 0
160+
161+
# Create WireRecon object
162+
wirerecon = db_schema.WireRecon(**defaults)
163+
164+
# Add extra attributes for form display (not in database model)
165+
wirerecon.root_path = DEFAULT_VARIABLES.get('root_path', '')
166+
wirerecon.data_path = ''
167+
wirerecon.filenamePrefix = ''
168+
169+
return wirerecon
119170

120171
CATALOG_DEFAULTS = {
121172
"filefolder": "tests/data/gdata",
@@ -1072,6 +1123,12 @@ def load_scan_data_from_url(href):
10721123

10731124
root_path = DEFAULT_VARIABLES.get("root_path", "")
10741125

1126+
# Handle case where no query parameters are provided - load defaults
1127+
if not scan_id_str and not wirerecon_id_str:
1128+
wirerecon_form_data = create_default_wirerecon()
1129+
set_wire_recon_form_props(wirerecon_form_data)
1130+
return datetime.datetime.now().isoformat()
1131+
10751132
if scan_id_str:
10761133
with Session(session_utils.get_engine()) as session:
10771134
try:
@@ -1161,12 +1218,10 @@ def load_scan_data_from_url(href):
11611218

11621219
# Create defaults if no wirerecon_id or if loading failed
11631220
if not current_wirerecon_id:
1164-
# Create a WireRecon object with populated defaults from metadata/scan
1165-
wirerecon_form_data = db_schema.WireRecon(
1166-
scanNumber=current_scan_id,
1167-
outputFolder=output_folder,
1168-
**{k: v for k, v in WIRERECON_DEFAULTS.items() if k not in ['scanNumber', 'outputFolder']}
1169-
)
1221+
wirerecon_form_data = create_default_wirerecon(overrides={
1222+
'scanNumber': current_scan_id,
1223+
'outputFolder': output_folder,
1224+
})
11701225

11711226
# Add root_path from DEFAULT_VARIABLES
11721227
wirerecon_form_data.root_path = root_path
@@ -1249,40 +1304,9 @@ def load_scan_data_from_url(href):
12491304
'color': 'danger'
12501305
})
12511306

1252-
wirerecon_form_data = db_schema.WireRecon(
1253-
scanNumber=str(scan_id_str).replace(',','; '),
1254-
1255-
# User text
1256-
author=DEFAULT_VARIABLES["author"],
1257-
notes=DEFAULT_VARIABLES["notes"],
1258-
1259-
# Recon constraints
1260-
geoFile=WIRERECON_DEFAULTS["geoFile"],
1261-
percent_brightest=WIRERECON_DEFAULTS["percent_brightest"],
1262-
wire_edges=WIRERECON_DEFAULTS["wire_edges"],
1263-
1264-
# Depth parameters
1265-
depth_start=WIRERECON_DEFAULTS["depth_start"],
1266-
depth_end=WIRERECON_DEFAULTS["depth_end"],
1267-
depth_resolution=WIRERECON_DEFAULTS["depth_resolution"],
1268-
1269-
# Compute parameters
1270-
num_threads=DEFAULT_VARIABLES["num_threads"],
1271-
memory_limit_mb=DEFAULT_VARIABLES["memory_limit_mb"],
1272-
1273-
# Files
1274-
scanPoints=WIRERECON_DEFAULTS["scanPoints"],
1275-
scanPointslen=srange(WIRERECON_DEFAULTS["scanPoints"]).len(),
1276-
1277-
# Output
1278-
outputFolder=WIRERECON_DEFAULTS["outputFolder"],
1279-
verbose=DEFAULT_VARIABLES["verbose"],
1280-
)
1281-
1282-
# Set root_path
1283-
wirerecon_form_data.root_path = root_path
1284-
wirerecon_form_data.data_path = ""
1285-
wirerecon_form_data.filenamePrefix = ""
1307+
wirerecon_form_data = create_default_wirerecon(overrides={
1308+
'scanNumber': str(scan_id_str).replace(',', '; '),
1309+
})
12861310

12871311
# Populate the form with the defaults
12881312
set_wire_recon_form_props(wirerecon_form_data)

0 commit comments

Comments
 (0)