@@ -141,17 +141,18 @@ int main(int argc, char **argv) {
141141 == 1 ); // only considering single panel detectors initially.
142142 Panel panel = detector.panels ()[0 ];
143143
144- // Read data from a reflection table. Again, this should be moved to
145- // dx2 and only require the data array name (xyzobs.px.value) with some
146- // logic to step through the directory structure
147- std::string array_name = " /dials/processing/group_0/xyzobs.px.value" ;
148- // Note, xyzobs_px is the flattened, on-disk representation of the array
149- // i.e. if there are 100 spots, the length of xyzobs_px is 300, and
150- // contains the elements [x0, y0, z0, x1, y1, z1, ..., x99, y99, z99]
151- std::vector<double > xyzobs_px_data =
152- read_array_from_h5_file<double >(filename, array_name);
153- mdspan_type<double > xyzobs_px =
154- mdspan_type<double >(xyzobs_px_data.data (), xyzobs_px_data.size () / 3 , 3 );
144+ // Read data from a reflection table.
145+ ReflectionTable strong_reflections (filename);
146+ auto xyzobs_px_ = strong_reflections.column <double >(" xyzobs.px.value" );
147+ if (!xyzobs_px_.has_value ()) {
148+ throw std::runtime_error (
149+ " No xyzobs.px.value column found in input reflection table." );
150+ }
151+ mdspan_type<double > xyzobs_px = xyzobs_px_.value ();
152+ if (xyzobs_px.rank () != 2 || xyzobs_px.extent (1 ) != 3 ) {
153+ throw std::runtime_error (
154+ " Input xyzobs.px.value column does not have the expected shape of (N,3)." );
155+ }
155156
156157 // The diffraction spots form a lattice in reciprocal space (if the experimental
157158 // geometry is accurate). So use the experimental models to transform the spot
@@ -225,9 +226,6 @@ int main(int argc, char **argv) {
225226 }
226227
227228 // Now we need to generate candidate crystals from the lattice vectors and evaluate them
228-
229- // std::string flags_array_name = "/dials/processing/group_0/flags";
230- // read_array_from_h5_file<std::size_t>(filename, flags_array_name);
231229 // FFS output does not yet have flags - so set all to strong.
232230 std::vector<std::size_t > flags (results.rlp .extent (0 ), strong_flag);
233231 // calculate entering array
@@ -391,85 +389,80 @@ int main(int argc, char **argv) {
391389
392390 bool no_output = parser.get <bool >(" no-output" );
393391 if (!no_output) {
394- // Create an indexed reflection table.
395- std::vector<uint64_t > ids = {0 };
392+ // Load the strong refls, to persist existing data items
396393 std::vector<std::string> labels = {expt.identifier ()};
397- ReflectionTable final_reflections (ids, labels);
394+ strong_reflections. set_identifiers ( labels);
398395
399396 // Recalculate the rlp and s1 vectors based on the updated models.
400397 xyz_to_rlp_results final_results =
401398 xyz_to_rlp (xyzobs_px, detector.panels ()[0 ], expt.beam (), scan, gonio);
402- final_reflections .add_column (std::string (" xyzobs.mm.value" ),
403- final_results.xyzobs_mm .extent (0 ),
404- 3 ,
405- final_results.xyzobs_mm_data );
406- final_reflections .add_column (
399+ strong_reflections .add_column (std::string (" xyzobs.mm.value" ),
400+ final_results.xyzobs_mm .extent (0 ),
401+ 3 ,
402+ final_results.xyzobs_mm_data );
403+ strong_reflections .add_column (
407404 std::string (" s1" ), final_results.s1 .extent (0 ), 3 , final_results.s1_data );
408- final_reflections .add_column (
405+ strong_reflections .add_column (
409406 std::string (" rlp" ), final_results.rlp .extent (0 ), 3 , final_results.rlp_data );
410407
411408 // Add required columns for next steps (DIALS compatibility)
412- std::string xyzvar_name = " /dials/processing/group_0/xyzobs.px.variance" ;
413- bool has_xyzobs_px_var = false ;
414- // FFS does not currently determine px.variance, but dials.find_spots does.
415- try {
416- H5Eset_auto (H5E_DEFAULT, NULL , NULL );
417- std::vector<double > xyzobs_px_var_data =
418- read_array_from_h5_file<double >(filename, xyzvar_name);
419- final_reflections.add_column (std::string (" xyzobs.px.variance" ),
420- final_results.xyzobs_mm .extent (0 ),
421- 3 ,
422- xyzobs_px_var_data);
423- has_xyzobs_px_var = true ;
424- } catch (...) {
409+ // if not panel, add
410+ auto panels = strong_reflections.column <uint64_t >(" panel" );
411+ if (!panels.has_value ()) {
412+ std::vector<uint64_t > panel_column (final_results.rlp .extent (0 ), 0 );
413+ strong_reflections.add_column (
414+ std::string (" panel" ), final_results.xyzobs_mm .extent (0 ), 1 , panel_column);
425415 }
426- final_reflections.add_column (
427- std::string (" xyzobs.px.value" ), xyzobs_px.extent (0 ), 3 , xyzobs_px_data);
428- std::vector<uint64_t > panel_column (final_results.rlp .extent (0 ), 0 );
429- final_reflections.add_column (
430- std::string (" panel" ), final_results.xyzobs_mm .extent (0 ), 1 , panel_column);
431-
432- // Need to convert the px variance to mm variance
433- if (has_xyzobs_px_var) {
416+ auto xyzobs_px_var_ = strong_reflections.column <double >(" xyzobs.px.variance" );
417+ if (xyzobs_px_var_.has_value ()) {
418+ // Need to convert the px variance to mm variance
434419 std::vector<double > xyzobs_mm_var_data (final_results.rlp .size ());
435420 mdspan_type<double > xyzobs_mm_variance = mdspan_type<double >(
436421 xyzobs_mm_var_data.data (), xyzobs_mm_var_data.size () / 3 , 3 );
437422 auto xyzobs_px_var_ =
438- final_reflections .column <double >(" xyzobs.px.variance" );
423+ strong_reflections .column <double >(" xyzobs.px.variance" );
439424 const auto &xyzobs_px_variance = xyzobs_px_var_.value ();
440425 px_to_mm (xyzobs_px_variance, xyzobs_mm_variance, scan, best_panel);
441- final_reflections .add_column (" xyzobs.mm.variance" ,
442- xyzobs_mm_variance.extent (0 ),
443- 3 ,
444- xyzobs_mm_var_data);
426+ strong_reflections .add_column (" xyzobs.mm.variance" ,
427+ xyzobs_mm_variance.extent (0 ),
428+ 3 ,
429+ xyzobs_mm_var_data);
445430 }
446-
447431 // Index the data with the refined models.
448432 assign_indices_results assign_results = assign_indices_global (
449433 expt.crystal ().get_A_matrix (), final_results.rlp , final_results.xyzobs_mm );
450434 logger.info (" Indexed {}/{} reflections using the refined models" ,
451435 assign_results.number_indexed ,
452436 xyzobs_px.extent (0 ));
453- final_reflections .add_column (std::string (" miller_index" ),
454- assign_results.miller_indices .extent (0 ),
455- assign_results.miller_indices .extent (1 ),
456- assign_results.miller_indices_data );
437+ strong_reflections .add_column (std::string (" miller_index" ),
438+ assign_results.miller_indices .extent (0 ),
439+ assign_results.miller_indices .extent (1 ),
440+ assign_results.miller_indices_data );
457441 // Set the indexed flag in the output.
458- for (int i = 0 ; i < assign_results.miller_indices .extent (0 ); ++i) {
459- if ((assign_results.miller_indices (i, 0 )) != 0
460- | (assign_results.miller_indices (i, 1 ) != 0 )
461- | (assign_results.miller_indices (i, 2 ) != 0 )) {
462- flags[i] |= indexed_flag;
442+ auto flags_ = strong_reflections.column <std::size_t >(" flags" );
443+ if (!flags_.has_value ()) {
444+ for (int i = 0 ; i < assign_results.miller_indices .extent (0 ); ++i) {
445+ if ((assign_results.miller_indices (i, 0 )) != 0
446+ | (assign_results.miller_indices (i, 1 ) != 0 )
447+ | (assign_results.miller_indices (i, 2 ) != 0 )) {
448+ flags[i] |= indexed_flag;
449+ }
450+ }
451+ strong_reflections.add_column (std::string (" flags" ), flags);
452+ } else {
453+ auto flag_span = flags_.value ();
454+ for (int i = 0 ; i < assign_results.miller_indices .extent (0 ); ++i) {
455+ if ((assign_results.miller_indices (i, 0 )) != 0
456+ | (assign_results.miller_indices (i, 1 ) != 0 )
457+ | (assign_results.miller_indices (i, 2 ) != 0 )) {
458+ flag_span (i, 0 ) |= indexed_flag;
459+ }
463460 }
464461 }
465- final_reflections.add_column (std::string (" flags" ), flags);
466- // Generate an id column.
467- std::vector<int > id_column (final_results.rlp .extent (0 ), 0 );
468- final_reflections.add_column (" id" , final_results.rlp .extent (0 ), 1 , id_column);
469462
470463 // Save the indexed reflection table.
471464 std::string output_filename = " indexed.refl" ;
472- final_reflections .write (output_filename);
465+ strong_reflections .write (output_filename);
473466 logger.info (" Saved reflection table to {}" , output_filename);
474467 }
475468
0 commit comments