示例#1
0
def reset_max_error(itvc_entry, fit):
  sel = international_tables_stols <= fit.stol + 1.e-6
  gaussian_fit = scitbx.math.gaussian.fit(
    international_tables_stols.select(sel),
    itvc_entry.table_y.select(sel),
    itvc_entry.table_sigmas.select(sel),
    fit)
  fit.max_error = flex.max(gaussian_fit.significant_relative_errors())
def run(gaussian_fit_pickle_file_names, itvc_file_name, kissel_dir):
  itvc_tab = None
  if (itvc_file_name is not None):
    itvc_tab = itvc_section61_io.read_table6111(itvc_file_name)
  fits = read_pickled_fits(gaussian_fit_pickle_file_names)
  #easy_pickle.dump("all_fits.pickle", fits)
  for k,v in fits.parameters.items():
    print "# %s:" % k, v
  print
  max_errors = flex.double()
  labeled_fits = []
  n_processed = 0
  for label in expected_labels(kissel_dir):
    try:
      fit_group = fits.all[label]
    except Exception:
      print "# Warning: Missing scattering_type:", label
    else:
      print "scattering_type:", label
      prev_fit = None
      for fit in fit_group:
        if (prev_fit is not None):
          if (fit.stol > prev_fit.stol):
            print "# Warning: decreasing stol"
          elif (fit.stol == prev_fit.stol):
            if (fit.max_error < prev_fit.max_error):
              print "# Warning: same stol but previous has larger error"
        prev_fit = fit
        fit.sort().show()
        gaussian_fit = None
        if (itvc_tab is not None and label != "O2-"):
          entry = itvc_tab.entries[label]
          sel = international_tables_stols <= fit.stol + 1.e-6
          gaussian_fit = scitbx.math.gaussian.fit(
            international_tables_stols.select(sel),
            entry.table_y.select(sel),
            entry.table_sigmas.select(sel),
            fit)
        elif (kissel_dir is not None):
          file_name = os.path.join(kissel_dir, "%02d_%s_rf" % (
            tiny_pse.table(label).atomic_number(), label))
          tab = kissel_io.read_table(file_name)
          sel = tab.itvc_sampling_selection() & (tab.x <= fit.stol + 1.e-6)
          gaussian_fit = scitbx.math.gaussian.fit(
            tab.x.select(sel),
            tab.y.select(sel),
            tab.sigmas.select(sel),
            fit)
        if (gaussian_fit is not None):
          max_errors.append(
            flex.max(gaussian_fit.significant_relative_errors()))
          labeled_fits.append(labeled_fit(label, gaussian_fit))
      n_processed += 1
  print
  if (n_processed != len(fits.all)):
    print "# Warning: %d fits were not processed." % (
      len(fits.all) - n_processed)
    print
  if (max_errors.size() > 0):
    print "Summary:"
    perm = flex.sort_permutation(data=max_errors, reverse=True)
    max_errors = max_errors.select(perm)
    labeled_fits = flex.select(labeled_fits, perm)
    quick_summary = {}
    for me,lf in zip(max_errors, labeled_fits):
      print lf.label, "n_terms=%d max_error: %.4f" % (
        lf.gaussian_fit.n_terms(), me)
      quick_summary[lf.label + "_" + str(lf.gaussian_fit.n_terms())] = me
      if (me > 0.01):
        fit = lf.gaussian_fit
        re = fit.significant_relative_errors()
        for s,y,a,r in zip(fit.table_x(),fit.table_y(),fit.fitted_values(),re):
          comment = ""
          if (r > 0.01): comment = " large error"
          print "%4.2f %7.4f %7.4f %7.4f %7.4f%s" % (s,y,a,a-y,r,comment)
        print
    print