def reflection_tables_to_batch_dependent_properties(reflection_tables, experiments, scaled_array=None): """Extract batch dependent properties from a reflection table list.""" offsets = calculate_batch_offsets(experiments) reflection_tables = assign_batches_to_reflections(reflection_tables, offsets) # filter bad refls and negative scales batches = flex.int() scales = flex.double() for r in reflection_tables: sel = ~r.get_flags(r.flags.bad_for_scaling, all=False) sel &= r["inverse_scale_factor"] > 0 batches.extend(r["batch"].select(sel)) scales.extend(r["inverse_scale_factor"].select(sel)) if not scaled_array: scaled_array = scaled_data_as_miller_array(reflection_tables, experiments) ms = scaled_array.customized_copy() batch_array = miller.array(ms, data=batches) batch_ranges = get_batch_ranges(experiments, offsets) batch_data = [{"id": i, "range": r} for i, r in enumerate(batch_ranges)] properties = batch_dependent_properties(batch_array, scaled_array, miller.array(ms, data=scales)) return properties + (batch_data, )
def test_get_batch_ranges(): """Test for namesake function""" scan = Scan(image_range=[1, 200], oscillation=[0.0, 1.0]) exp1 = Experiment(scan=scan) exp2 = Experiment(scan=scan) batch_offsets = [0, 300] experiments = [exp1, exp2] batch_ranges = get_batch_ranges(experiments, batch_offsets) assert batch_ranges == [(1, 200), (301, 500)]