def make_error_model_plots(params, experiments): """Generate normal probability plot data.""" data = {} if experiments[0].scaling_model.error_model: em = experiments[0].scaling_model.error_model if em.filtered_Ih_table: table = em.filtered_Ih_table data["intensity"] = table.intensities sigmaprime = calc_sigmaprime(em.parameters, table) data["delta_hl"] = calc_deltahl(table, table.calc_nh(), sigmaprime) data["inv_scale"] = table.inverse_scale_factors data["sigma"] = sigmaprime * data["inv_scale"] data["binning_info"] = em.binner.binning_info em.clear_Ih_table() if params.weighting.error_model.basic.minimisation == "regression": x, y = calculate_regression_x_y(em.filtered_Ih_table) data["regression_x"] = x data["regression_y"] = y data["model_a"] = em.parameters[0] data["model_b"] = em.parameters[1] data["summary"] = str(em) d = {"error_model_plots": {}, "error_model_summary": "No error model applied"} if "delta_hl" in data: d["error_model_plots"].update(normal_probability_plot(data)) d["error_model_plots"].update( i_over_sig_i_vs_i_plot(data["intensity"], data["sigma"]) ) d["error_model_plots"].update(error_model_variance_plot(data)) if "regression_x" in data: d["error_model_plots"].update(error_regression_plot(data)) if "summary" in data: d["error_model_summary"] = data["summary"] return d
def make_error_model_plots(params, experiments): """Generate normal probability plot data.""" d = { "error_model_plots": {}, "error_model_summary": "No error model applied" } error_model_data = [] # a list of dicts of error model data if experiments[0].scaling_model.error_model: error_models = [e.scaling_model.error_model for e in experiments] unique_error_models = OrderedSet(error_models) if len(unique_error_models) == 1: d["error_model_summary"] = str(error_models[0]) else: d["error_model_summary"] = "" for i, e in enumerate(unique_error_models): indices = [ str(j + 1) for j, x in enumerate(error_models) if e is x ] d["error_model_summary"] += ( f"\nError model {i+1}, applied to sweeps {', '.join(indices)}:" + str(e)) for em in unique_error_models: if em.filtered_Ih_table: data_i = {} table = em.filtered_Ih_table data_i["intensity"] = table.intensities sigmaprime = calc_sigmaprime(em.parameters, table) data_i["delta_hl"] = calc_deltahl(table, table.calc_nh(), sigmaprime) data_i["inv_scale"] = table.inverse_scale_factors data_i["sigma"] = sigmaprime * data_i["inv_scale"] data_i["binning_info"] = em.binner.binning_info em.clear_Ih_table() if params.weighting.error_model.basic.minimisation == "regression": x, y = calculate_regression_x_y(em.filtered_Ih_table) data_i["regression_x"] = x data_i["regression_y"] = y data_i["model_a"] = em.parameters[0] data_i["model_b"] = em.parameters[1] error_model_data.append(data_i) if error_model_data: for i, emd in enumerate(error_model_data): d["error_model_plots"].update( normal_probability_plot(emd, label=i + 1)) d["error_model_plots"].update( i_over_sig_i_vs_i_plot( flumpy.from_numpy(emd["intensity"]), flumpy.from_numpy(emd["sigma"]), label=i + 1, )) d["error_model_plots"].update( error_model_variance_plot(emd, label=i + 1)) if "regression_x" in emd: d["error_model_plots"].update( error_regression_plot(emd, label=i + 1)) return d
def make_plots(self): """Generate normal probability plot data.""" d = {"error_model_plots": {}} if "delta_hl" in self.data: d["error_model_plots"].update(normal_probability_plot(self.data)) d["error_model_plots"].update( i_over_sig_i_vs_i_plot(self.data["intensity"], self.data["sigma"])) return d
def make_output(model, params): """Get relevant data from the model and make html report.""" if not (params.output.html or params.output.json): return data = {} table = model.filtered_Ih_table data["intensity"] = table.intensities sigmaprime = calc_sigmaprime(model.parameters, table) data["delta_hl"] = calc_deltahl(table, table.calc_nh(), sigmaprime) data["inv_scale"] = table.inverse_scale_factors data["sigma"] = sigmaprime * data["inv_scale"] data["binning_info"] = model.binner.binning_info d = {"error_model_plots": {}} d["error_model_plots"].update(normal_probability_plot(data)) d["error_model_plots"].update( i_over_sig_i_vs_i_plot(data["intensity"], data["sigma"]) ) d["error_model_plots"].update(error_model_variance_plot(data)) if params.basic.minimisation == "regression": x, y = calculate_regression_x_y(model.filtered_Ih_table) data["regression_x"] = x data["regression_y"] = y data["model_a"] = model.parameters[0] data["model_b"] = model.parameters[1] d["error_model_plots"].update(error_regression_plot(data)) if params.output.html: logger.info("Writing html report to: %s", params.output.html) loader = ChoiceLoader( [ PackageLoader("dials", "templates"), PackageLoader("dials", "static", encoding="utf-8"), ] ) env = Environment(loader=loader) template = env.get_template("simple_report.html") html = template.render( page_title="DIALS error model refinement report", panel_title="Error distribution plots", panel_id="error_model_plots", graphs=d["error_model_plots"], ) with open(params.output.html, "wb") as f: f.write(html.encode("utf-8", "xmlcharrefreplace")) if params.output.json: logger.info("Writing html report data to: %s", params.output.json) with open(params.output.json, "w") as outfile: json.dump(d, outfile)
def make_plots(self): """Generate normal probability plot data.""" d = {"error_model_plots": {}, "error_model_summary": "No error model applied"} if "delta_hl" in self.data: d["error_model_plots"].update(normal_probability_plot(self.data)) d["error_model_plots"].update( i_over_sig_i_vs_i_plot(self.data["intensity"], self.data["sigma"]) ) d["error_model_plots"].update(error_model_variance_plot(self.data)) if "regression_x" in self.data: d["error_model_plots"].update(error_regression_plot(self.data)) if "summary" in self.data: d["error_model_summary"] = self.data["summary"] return d
def test_normal_probability_plot(): data = {"delta_hl": list(range(20))} d = normal_probability_plot(data) assert "normal_distribution_plot" in d
def test_normal_probability_plot(): data = {"delta_hl": np.arange(20, dtype=float)} d = normal_probability_plot(data) assert "normal_distribution_plot" in d