|
16 | 16 | from laue_portal.components.form_base import _field |
17 | 17 | from laue_portal.components.validation_alerts import validation_alerts |
18 | 18 | 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 |
20 | 20 | from laue_portal.pages.validation_helpers import ( |
21 | 21 | apply_validation_highlights, |
22 | 22 | update_validation_alerts, |
@@ -105,17 +105,68 @@ def build_output_folder_template(scan_num_int, data_path): |
105 | 105 | "finish_time": datetime.datetime.now(), |
106 | 106 | } |
107 | 107 |
|
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 |
119 | 170 |
|
120 | 171 | CATALOG_DEFAULTS = { |
121 | 172 | "filefolder": "tests/data/gdata", |
@@ -1072,6 +1123,12 @@ def load_scan_data_from_url(href): |
1072 | 1123 |
|
1073 | 1124 | root_path = DEFAULT_VARIABLES.get("root_path", "") |
1074 | 1125 |
|
| 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 | + |
1075 | 1132 | if scan_id_str: |
1076 | 1133 | with Session(session_utils.get_engine()) as session: |
1077 | 1134 | try: |
@@ -1161,12 +1218,10 @@ def load_scan_data_from_url(href): |
1161 | 1218 |
|
1162 | 1219 | # Create defaults if no wirerecon_id or if loading failed |
1163 | 1220 | 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 | + }) |
1170 | 1225 |
|
1171 | 1226 | # Add root_path from DEFAULT_VARIABLES |
1172 | 1227 | wirerecon_form_data.root_path = root_path |
@@ -1249,40 +1304,9 @@ def load_scan_data_from_url(href): |
1249 | 1304 | 'color': 'danger' |
1250 | 1305 | }) |
1251 | 1306 |
|
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 | + }) |
1286 | 1310 |
|
1287 | 1311 | # Populate the form with the defaults |
1288 | 1312 | set_wire_recon_form_props(wirerecon_form_data) |
|
0 commit comments