def make_merging_stats_plots(script): """Make merging stats plots for HTML report""" d = { "scaling_tables": ([], []), "resolution_plots": {}, "batch_plots": {}, "misc_plots": {}, "anom_plots": {}, "image_range_tables": [], } ( batches, rvb, isigivb, svb, batch_data, ) = reflection_tables_to_batch_dependent_properties( # pylint: disable=unbalanced-tuple-unpacking script.reflections, script.experiments, script.scaled_miller_array, ) bm = batch_manager(batches, batch_data) image_range_tables = make_image_range_table(script.experiments, bm) if script.merging_statistics_result: stats = script.merging_statistics_result anom_stats = script.anom_merging_statistics_result is_centric = script.scaled_miller_array.space_group().is_centric() # Now calculate batch data plotter = ResolutionPlotsAndStats(stats, anom_stats, is_centric) d["resolution_plots"].update(plotter.make_all_plots()) d["scaling_tables"] = plotter.statistics_tables() d["batch_plots"].update(scale_rmerge_vs_batch_plot(bm, rvb, svb)) d["batch_plots"].update(i_over_sig_i_vs_batch_plot(bm, isigivb)) plotter = IntensityStatisticsPlots( script.scaled_miller_array, run_xtriage_analysis=False ) d["resolution_plots"].update(plotter.generate_resolution_dependent_plots()) if d["resolution_plots"]["cc_one_half"]["data"][2]: cc_anom = d["resolution_plots"]["cc_one_half"]["data"][2]["y"] significance = d["resolution_plots"]["cc_one_half"]["data"][3]["y"] sig = flex.double(cc_anom) > flex.double(significance) max_anom = 0 for i, v in enumerate(sig): if v: max_anom = i else: break d_min = uctbx.d_star_sq_as_d(plotter.binner.limits())[max_anom + 1] else: d_min = 0.0 d["misc_plots"].update(plotter.generate_miscellanous_plots()) intensities_anom = script.scaled_miller_array.as_anomalous_array() intensities_anom = intensities_anom.map_to_asu().customized_copy( info=script.scaled_miller_array.info() ) anom_plotter = AnomalousPlotter(intensities_anom, strong_cutoff=d_min) d["anom_plots"].update(anom_plotter.make_plots()) d["image_range_tables"] = [image_range_tables] return d
def update(self, scaling_script): if scaling_script.merging_statistics_result: self.data = { "statistics": scaling_script.merging_statistics_result, "anomalous_statistics": scaling_script.anom_merging_statistics_result, "is_centric": scaling_script.scaled_miller_array.space_group().is_centric(), } # Now calculate batch data ( batches, rvb, isigivb, svb, batch_data, ) = reflection_tables_to_batch_dependent_properties( # pylint: disable=unbalanced-tuple-unpacking scaling_script.reflections, scaling_script.experiments, scaling_script.scaled_miller_array, ) self.data[ "scaled_miller_array"] = scaling_script.scaled_miller_array self.data["bm"] = batch_manager(batches, batch_data) self.data["r_merge_vs_batch"] = rvb self.data["scale_vs_batch"] = svb self.data["isigivsbatch"] = isigivb self.data["image_range_tables"] = [ make_image_range_table(scaling_script.experiments, self.data["bm"]) ]
def test_reflections_to_batch_properties( data_array, example_miller_set, example_crystal ): """Test the helper functions that provide the batch properties from reflection tables and experiments.""" # first make a reflection table. reflections = flex.reflection_table() reflections["intensity.scale.value"] = data_array.data() * flex.double(9, 2.0) reflections["inverse_scale_factor"] = flex.double(9, 2.0) reflections["intensity.scale.variance"] = flex.double(9, 4.0) * flex.double(9, 4.0) reflections["xyzobs.px.value"] = flex.vec3_double( [(0, 0, 0.1)] * 3 + [(0, 0, 1.1)] * 3 + [(0, 0, 2.1)] * 2 + [(0, 0, 3.1)] ) reflections["miller_index"] = example_miller_set.indices() reflections["id"] = flex.int(9, 1) reflections.set_flags(flex.bool(9, True), reflections.flags.integrated) experiments = [mock.Mock()] experiments[0].scan.get_image_range.return_value = [1, 10] experiments[0].crystal = example_crystal bins, rmerge, isigi, scalesvsbatch, batch_data = reflection_tables_to_batch_dependent_properties( # pylint: disable=unbalanced-tuple-unpacking [reflections], experiments ) assert bins == expected_results["bins"] assert rmerge == pytest.approx(expected_results["rmergevb"], 1e-4) assert isigi == pytest.approx(expected_results["isigivb"], 1e-4) assert scalesvsbatch == pytest.approx([2.0] * 4, 1e-4) assert batch_data == [{"range": (1, 10), "id": 0}] # now try a two experiment dataset in a combined table. import copy reflections_2 = copy.deepcopy(reflections) reflections_2["id"] = flex.int(9, 2) reflections.extend(reflections_2) experiments = [mock.Mock(), mock.Mock()] experiments[0].scan.get_image_range.return_value = [1, 10] experiments[0].crystal = example_crystal experiments[1].scan.get_image_range.return_value = [1, 10] experiments[1].crystal = example_crystal bins, rmerge, isigi, scalesvsbatch, batch_data = combined_table_to_batch_dependent_properties( # pylint: disable=unbalanced-tuple-unpacking reflections, experiments ) assert bins == [1, 2, 3, 4, 101, 102, 103, 104] assert rmerge == pytest.approx(expected_results["rmergevb"] * 2, 1e-4) assert isigi == pytest.approx(expected_results["isigivb"] * 2, 1e-4) assert scalesvsbatch == pytest.approx([2.0] * 8, 1e-4) assert batch_data == [{"range": (1, 10), "id": 0}, {"range": (101, 110), "id": 1}]