def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) runs = [] all_results = [] if params.rungroup is None: assert len(params.run) == 0 trial = app.get_trial(trial_number=params.trial) for rungroup in trial.rungroups: for run in rungroup.runs: stats = HitrateStats(app, run.run, trial.trial, rungroup.id, params.d_min)() if len(stats[0]) > 0: runs.append(run.run) all_results.append(stats) else: for run_no in params.run: runs.append(run_no) all_results.append( HitrateStats(app, run_no, params.trial, params.rungroup, params.d_min)()) plot_multirun_stats(all_results, runs, params.d_min, n_strong_cutoff=params.n_strong_cutoff, \ i_sigi_cutoff=params.i_sigi_cutoff, run_tags=params.run_tags, title=params.title, \ minimalist=params.minimalist, interactive=True, compress_runs=params.compress_runs)
def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) if params.tag is not None and len(params.tag) > 0: tags = [] for tag in app.get_all_tags(): for t in params.tag: if t == tag.name: tags.append(tag) extra_title = ",".join([t.name for t in tags]) else: tags = None extra_title = None if params.run is not None and len(params.run) > 0: assert params.rungroup is not None runs = [app.get_run(run_number=r) for r in params.run] rungroup = app.get_rungroup(rungroup_id=params.rungroup) else: runs = None rungroup = None if extra_title is None and runs is not None: extra_title = "%s" % (",".join(["%s" % r.run for r in runs])) trial = app.get_trial(trial_number=params.trial) info = [] print("Reading data...") cells = app.get_stats(trial=trial, tags=tags, isigi_cutoff=1.0, tag_selection_mode=params.tag_selection_mode, selected_runs=runs, selected_rungroup=rungroup)() for cell in cells: info.append({ 'a': cell.cell_a, 'b': cell.cell_b, 'c': cell.cell_c, 'alpha': cell.cell_alpha, 'beta': cell.cell_beta, 'gamma': cell.cell_gamma, 'n_img': 0 }) import xfel.ui.components.xfel_gui_plotter as pltr plotter = pltr.PopUpCharts() plotter.plot_uc_histogram(info_list=[info], extra_title=extra_title, legend_list=[""], iqr_ratio=params.iqr_ratio) plotter.plot_uc_3Dplot(info=info, iqr_ratio=params.iqr_ratio) plotter.plt.show()
def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) trial = app.get_trial(trial_number=params.trial) jobs = app.get_all_jobs() for rungroup in trial.rungroups: for run in rungroup.runs: if params.output_folder is None: job = None all_path = None else: job_found = None for job in jobs: if job.trial.id == trial.id and job.rungroup.id == rungroup.id and job.run.id == run.id: all_path = os.path.join( os.path.sep.join(job.get_log_path().split( os.path.sep)[:-2]), "all") assert job_found is None job_found = job assert job_found is not None job = job_found where = "WHERE event.n_strong >= %d" % params.hit_cutoff events = app.get_all_events(trial=trial, runs=[run], only_indexed=False, where=where) for e in events: t = e.timestamp ts = t[0:4] + t[5:7] + t[8:10] + t[11:13] + t[14:16] + t[ 17:19] + t[20:23] if all_path is None: print "%04d" % run.run, ts else: print os.path.join(all_path, "shot-" + ts + ".pickle")
def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument %s"%arg) params = phil_scope.fetch(sources=user_phil).extract() print("Printing results for trial", params.trial, "using a hit cutoff of", params.n_strong_cutoff, "reflections") print() print(" Run N Drop Hits (%) N Hits (%) N Indexed (%) N Lattices N High qual (%) %HQR N Frames") drop_hits_total = 0 hit_total = 0 indexed_total = 0 lattices_total = 0 high_quality_total = 0 overall_total = 0 ratio_cutoff = 1 app = xfel_db_application(params) if params.run is None or len(params.run) == 0: trial = app.get_trial(trial_number=params.trial) runs = [] run_ids = [] rungroups = [] for rg in trial.rungroups: for run in rg.runs: if run.id in run_ids: continue runs.append(run.run) run_ids.append(run.id) rungroups.append(rg.id) else: runs = params.run assert params.rungroup is not None rungroups = [params.rungroup] * len(runs) for run_no, rungroup_id in zip(runs, rungroups): try: timestamps, two_theta_low, two_theta_high, n_strong, average_i_sigi, n_lattices = HitrateStats(app, run_no, params.trial, rungroup_id, params.d_min)() except Exception as e: print("Couldn't get run", run_no) continue n_hit = (n_strong >= params.n_strong_cutoff).count(True) n_indexed = (n_lattices > 0).count(True) n_lattices = flex.sum(n_lattices) n_total = len(timestamps) n_high_quality = ((average_i_sigi > 0) & (n_strong >= params.n_strong_cutoff)).count(True) invalid = (two_theta_low <= 0) or (two_theta_high < 0) # <= to prevent /0 numerator = two_theta_high.set_selected(invalid, 0) denominator = two_theta_low.set_selected(two_theta_low == 0, 1) # prevent /0 drop_ratios = numerator/denominator drop_hits = drop_ratios >= ratio_cutoff n_drop_hits = drop_hits.count(True) try: print("% 20s % 7d % 5.1f % 7d % 5.1f % 7d % 5.1f % 7d % 7d % 5.1f % 5.1f % 7d " % (run_no, n_drop_hits, 100*n_drop_hits/n_total, n_hit, 100*n_hit/n_total, n_indexed, 100*n_indexed/n_total, n_lattices, n_high_quality, 100*n_high_quality/n_total, 100*n_high_quality/n_indexed, n_total)) except ZeroDivisionError: print("% 20s % 7d % 5.1f % 7d % 5.1f % 7d % 5.1f % 7d % 7d % 5.1f % 5.1f % 7d " % (run_no, n_drop_hits, 0, n_hit, 0, n_indexed, 0, n_lattices, n_high_quality, 0, 0, n_total)) drop_hits_total += n_drop_hits hit_total += n_hit indexed_total += n_indexed lattices_total += n_lattices high_quality_total += n_high_quality overall_total += n_total if len(runs) > 1: print("-" * 80) try: print("Total % 7d % 5.1f % 7d % 5.1f % 7d % 5.1f % 7d % 7d % 5.1f % 5.1f % 7d " % (drop_hits_total, 100*drop_hits_total/overall_total, hit_total, 100*hit_total/overall_total, indexed_total, 100*indexed_total/overall_total, lattices_total, high_quality_total, 100*high_quality_total/overall_total, 100*high_quality_total/indexed_total, overall_total)) except ZeroDivisionError: if overall_total == 0: print("Total % 7d % 5.1f % 7d % 5.1f % 7d % 5.1f % 7d % 7d % 5.1f % 5.1f % 7d " % (drop_hits_total, 0, hit_total, 0, indexed_total, 0, lattices_total, 0, 0, 0, overall_total)) else: print("Total % 7d % 5.1f % 7d % 5.1f % 7d % 5.1f % 7d % 7d % 5.1f % 5.1f % 7d " % (drop_hits_total, 100*drop_hits_total/overall_total, hit_total, 100*hit_total/overall_total, indexed_total, 100*indexed_total/overall_total, lattices_total, high_quality_total, 100*high_quality_total/overall_total, 0, overall_total))
.type = bool .help = When plotting multiple runs, adjust timestamps so there is no blank space between them. .help = Thise mode is not compatible with fetching events from timestamps. """ phil_scope = parse(phil_str + db_phil_str) def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception, e: raise Sorry("Unrecognized argument %s"%arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) runs = [] all_results = [] if params.rungroup is None: assert len(params.run) == 0 trial = app.get_trial(trial_number = params.trial) for rungroup in trial.rungroups: for run in rungroup.runs: stats = HitrateStats(app, run.run, trial.trial, rungroup.id, params.d_min)() if len(stats[0]) > 0: runs.append(run.run) all_results.append(stats) else: for run_no in params.run: runs.append(run_no) all_results.append(HitrateStats(app, run_no, params.trial, params.rungroup, params.d_min)())
.type = float .help = Interquartile range multiplier for outlier rejection. Use None to disable outlier rejection. """ phil_scope = parse(phil_str + db_phil_str) def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception, e: raise Sorry("Unrecognized argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) if params.tag is not None and len(params.tag) > 0: tags = [] for tag in app.get_all_tags(): for t in params.tag: if t == tag.name: tags.append(tag) extra_title = ",".join([t.name for t in tags]) else: tags = None extra_title = None if params.run is not None and len(params.run) > 0: assert params.rungroup is not None runs = [app.get_run(run_number=r) for r in params.run]
def run(args): user_phil = [] for arg in args: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() app = xfel_db_application(params) trial_ni = app.get_trial(trial_number=params.trial_noisoforms) trial_i = app.get_trial(trial_number=params.trial_isoforms) tags = [] if params.tag is not None and len(params.tag) > 0: for tag in app.get_all_tags(): if params.tag == tag.name: tags.append(tag) extra_title = ",".join([t.name for t in tags]) tag_ids = [t.id for t in tags] runs_ni = [ r for r in trial_ni.runs if any([t.id in tag_ids for t in r.tags]) ] runs_i = [ r for r in trial_i.runs if any([t.id in tag_ids for t in r.tags]) ] else: extra_title = None runs_ni = trial_ni.runs runs_i = trial_i.runs runs_ni_str = "(%s)" % (", ".join([str(r.id) for r in runs_ni])) exp_tag = params.experiment_tag isoforms = app.get_trial_isoforms(trial_i.id) print "Reading data..." info_list = [] legend_list = [] for isoform in isoforms: events_i = app.get_all_events(trial=trial_i, runs=runs_i, isoform=isoform) if len(events_i) == 0: print "No events of isoform %s found" % isoform.name continue legend_list.append(isoform.name) events_i_str = "(%s)" % (", ".join( ["'%s'" % e.timestamp for e in events_i])) query = """SELECT crystal.cell_id FROM `%s_crystal` crystal JOIN `%s_experiment` exp ON exp.crystal_id = crystal.id JOIN `%s_imageset` imgset ON imgset.id = exp.imageset_id JOIN `%s_imageset_event` ie ON ie.imageset_id = imgset.id JOIN `%s_event` evt ON evt.id = ie.event_id JOIN `%s_trial` trial ON trial.id = evt.trial_id JOIN `%s_run` run ON run.id = evt.run_id WHERE run.id in %s AND trial.id = %d AND evt.timestamp IN %s""" % ( exp_tag, exp_tag, exp_tag, exp_tag, exp_tag, exp_tag, exp_tag, runs_ni_str, trial_ni.id, events_i_str) cell_ids = [str(i[0]) for i in app.execute_query(query).fetchall()] if len(cell_ids) == 0: cells = [] else: from xfel.ui.db.experiment import Cell cells = app.get_all_x(Cell, 'cell', where="WHERE id IN (%s)" % ", ".join(cell_ids)) print len(cells) info = [] for cell in cells: info.append({ 'a': cell.cell_a, 'b': cell.cell_b, 'c': cell.cell_c, 'alpha': cell.cell_alpha, 'beta': cell.cell_beta, 'gamma': cell.cell_gamma, 'n_img': 0 }) info_list.append(info) import xfel.ui.components.xfel_gui_plotter as pltr plotter = pltr.PopUpCharts() plotter.plot_uc_histogram(info_list=info_list, legend_list=legend_list, extra_title=extra_title) plotter.plt.show()