Exemple #1
0
    def prep_output(self):
        ''' Assign output paths to image object (will be used by various modules
    to write out files in appropriate locations) '''

        # Get bases
        input_base = self.info.input_base if self.info else self.init.input_base
        obj_base = self.info.obj_base if self.info else self.init.obj_base
        fin_base = self.info.fin_base if self.info else self.init.fin_base
        log_base = self.info.log_base if self.info else self.init.log_base
        viz_base = self.info.viz_base if self.info else self.init.viz_base

        # Object path (may not need)
        self.img_object.obj_path = util.make_image_path(
            self.img_object.img_path, input_base, obj_base)
        fname = util.make_filename(self.img_object.img_path, new_ext='int')
        self.img_object.obj_file = os.path.join(self.img_object.obj_path,
                                                fname)

        # Final integration pickle path
        self.img_object.int_path = util.make_image_path(
            self.img_object.img_path, input_base, fin_base)
        fname = util.make_filename(self.img_object.img_path,
                                   prefix='int',
                                   new_ext='pickle')
        self.img_object.int_file = os.path.join(self.img_object.int_path,
                                                fname)

        # Processing log path for image
        self.img_object.log_path = util.make_image_path(
            self.img_object.img_path, input_base, log_base)
        fname = util.make_filename(self.img_object.img_path, new_ext='log')
        self.img_object.int_log = os.path.join(self.img_object.log_path, fname)

        # Visualization path (may need to deprecate)
        self.img_object.viz_path = util.make_image_path(
            self.img_object.img_path, input_base, viz_base)
        fname = util.make_filename(self.img_object.img_path,
                                   prefix='int',
                                   new_ext='png')
        self.viz_file = os.path.join(self.img_object.viz_path, fname)

        # Make paths if they don't exist already
        for path in [
                self.img_object.obj_path, self.img_object.int_path,
                self.img_object.log_path, self.img_object.viz_path
        ]:
            try:
                os.makedirs(path)
            except OSError:
                pass

        # Populate the 'final' dictionary
        self.img_object.final['final'] = self.img_object.int_file
        self.img_object.final['img'] = self.img_object.img_path
  def prep_output(self):
    ''' Assign output paths to image object (will be used by various modules
    to write out files in appropriate locations) '''

    # Object path (may not need)
    self.img_object.obj_path = util.make_image_path(self.img_object.img_path,
                                                    self.init.input_base,
                                                    self.init.obj_base)
    fname = util.make_filename(self.img_object.img_path, new_ext='int')
    self.img_object.obj_file = os.path.join(self.img_object.obj_path, fname)

    # Final integration pickle path
    self.img_object.int_path = util.make_image_path(self.img_object.img_path,
                                                    self.init.input_base,
                                                    self.init.fin_base)
    fname = util.make_filename(self.img_object.img_path, prefix='int',
                               new_ext='pickle')
    self.img_object.int_file = os.path.join(self.img_object.int_path, fname)

    # Processing log path for image
    self.img_object.log_path = util.make_image_path(self.img_object.img_path,
                                                    self.init.input_base,
                                                    self.init.log_base)
    fname = util.make_filename(self.img_object.img_path, new_ext='tmp')
    self.img_object.int_log = os.path.join(self.img_object.log_path, fname)

    # Visualization path (may need to deprecate)
    self.img_object.viz_path = util.make_image_path(self.img_object.img_path,
                                                    self.init.input_base,
                                                    self.init.viz_base)
    fname = util.make_filename(self.img_object.img_path, prefix='int',
                               new_ext='png')
    self.viz_file = os.path.join(self.img_object.viz_path, fname)

    # Populate the 'final' dictionary
    self.img_object.final['final'] = self.img_object.int_file
    self.img_object.final['img'] = self.img_object.img_path
 def rename_converted_image(self, filepath):
     # Generate converted image pickle filename
     rename_choice = str(
         self.params.cctbx_ha14.image_conversion.rename_pickle).lower()
     if rename_choice in ("keep_file_structure", "none"):
         img_dir = util.make_image_path(filepath, self.input_base,
                                        self.conv_base)
         img_filename = util.make_filename(filepath, new_ext='pickle')
     else:
         self.input_base = self.conv_base
         if rename_choice == "auto_filename":
             prefix = self.init.user_id
         elif rename_choice == "custom_filename":
             prefix = self.params.cctbx_ha14.image_conversion.rename_pickle_prefix
         else:
             prefix = 'iota'
         img_dir = self.conv_base
         number = int(os.path.basename(self.conv_base))
         img_filename = "{}_{}_{:05d}.pickle" \
                    "".format(prefix, number, self.img_object.img_index)
     return os.path.abspath(os.path.join(img_dir, img_filename))
Exemple #4
0
  def prep_output(self):
    ''' Assign output paths to image object (will be used by various modules
    to write out files in appropriate locations) '''

    # Get bases
    input_base = self.info.input_base if self.info else self.init.input_base
    obj_base = self.info.obj_base if self.info else self.init.obj_base
    fin_base = self.info.fin_base if self.info else self.init.fin_base
    log_base = self.info.log_base if self.info else self.init.log_base
    dials_log_base = self.info.dials_log_base if self.info else None
    viz_base = self.info.viz_base if self.info else self.init.viz_base

    # Set prefix (image index in multi-image files, or None otherwise)
    if self.img_object.is_multi_image:
      image_index = self.img_object.img_index
    else:
      image_index = None

    # Object path (may not need)
    self.img_object.obj_path = util.make_image_path(self.img_object.img_path,
                                                    input_base, obj_base)
    fname = util.make_filename(prefix=image_index,
                               path=self.img_object.img_path,
                               new_ext='int')
    self.img_object.obj_file = os.path.join(self.img_object.obj_path, fname)

    # DIALS process filepaths
    # Indexed reflections
    ridx_path = util.make_filename(
      prefix=image_index,
      path=self.img_object.img_path,
      suffix='indexed',
      new_ext='refl'
    )
    self.img_object.ridx_path = os.path.join(self.img_object.obj_path,
                                             ridx_path)

    # Spotfinding (strong) reflections
    rspf_path = util.make_filename(
      prefix=image_index,
      path=self.img_object.img_path,
      suffix='strong',
      new_ext='refl'
    )
    self.img_object.rspf_path = os.path.join(self.img_object.obj_path,
                                             rspf_path)

    # Refined experiments
    eref_path = util.make_filename(
      prefix=image_index,
      path=self.img_object.img_path,
      suffix='refined',
      new_ext='expt'
    )
    self.img_object.eref_path = os.path.join(self.img_object.obj_path,
                                             eref_path)

    # Integrated experiments
    eint_path = util.make_filename(
      prefix=image_index,
      path=self.img_object.img_path,
      suffix='integrated',
      new_ext='expt'
    )
    self.img_object.eint_path = os.path.join(self.img_object.obj_path,
                                             eint_path)

    # Integrated reflections
    rint_path = util.make_filename(
      prefix=image_index,
      path=self.img_object.img_path,
      suffix='integrated',
      new_ext='refl'
    )
    self.img_object.rint_path = os.path.join(self.img_object.obj_path,
                                             rint_path)


    # Final integration pickle path
    self.img_object.int_path = util.make_image_path(self.img_object.img_path,
                                                    input_base, fin_base)
    fname = util.make_filename(path=self.img_object.img_path,
                               prefix='int',
                               suffix=image_index,
                               new_ext='pickle')
    self.img_object.int_file = os.path.join(self.img_object.int_path, fname)

    # Processing log path for image
    self.img_object.log_path = util.make_image_path(self.img_object.img_path,
                                                    input_base, log_base)
    fname = util.make_filename(prefix=image_index,
                               path=self.img_object.img_path,
                               new_ext='log')
    self.img_object.int_log = os.path.join(self.img_object.log_path, fname)

    # DIALS log path for image
    if dials_log_base:
      self.img_object.dials_log_path = util.make_image_path(
        self.img_object.img_path, input_base, dials_log_base)
      fname = util.make_filename(prefix=image_index,
                                 path=self.img_object.img_path,
                                 new_ext='log')
      self.img_object.dials_log = os.path.join(
        self.img_object.dials_log_path, fname)

    # Visualization path (may need to deprecate)
    self.img_object.viz_path = util.make_image_path(self.img_object.img_path,
                                                    input_base, viz_base)
    fname = util.make_filename(prefix='int',
                               suffix=image_index,
                               path=self.img_object.img_path,
                               new_ext='png')
    self.viz_file = os.path.join(self.img_object.viz_path, fname)

    # Make paths if they don't exist already
    for path in [self.img_object.obj_path, self.img_object.int_path,
                 self.img_object.log_path, self.img_object.viz_path,
                 self.img_object.dials_log_path]:
      try:
        os.makedirs(path)
      except OSError:
        pass

    # Populate the 'final' dictionary
    self.img_object.final['final'] = self.img_object.int_file
    self.img_object.final['img'] = self.img_object.img_path
    def process(self, img_object, single_image=False):
        """ Image processing; selects method, runs requisite modules """
        self.img_object = img_object

        if self.img_object.status != 'bypass grid search':
            self.img_object.status = 'processing'

        #for CCTBX indexing / integration
        terminate = False
        prev_status = self.img_object.status
        prev_fail = 'first cycle'
        prev_final = self.img_object.final
        prev_epv = 9999

        while not terminate:
            # Run grid search if haven't already
            if (self.img_object.fail is None
                    and 'grid search' not in self.img_object.status):
                self.integrate_cctbx('grid search', single_image=single_image)

            # Run selection if haven't already
            if (self.img_object.fail is None
                    and self.img_object.status != 'selection'):
                self.select_cctbx()

            # If smart grid search is active run multiple rounds until convergence
            if self.params.cctbx_ha14.grid_search.type == 'smart':
                if (self.img_object.fail is None
                        and self.img_object.final['epv'] < prev_epv):
                    prev_epv = self.img_object.final['epv']
                    prev_final = self.img_object.final
                    prev_status = self.img_object.status
                    prev_fail = self.img_object.fail
                    self.hmed = self.img_object.final['sph']
                    self.amed = self.img_object.final['spa']
                    self.img_object.generate_grid()
                    self.img_object.final['final'] = self.img_object.int_file
                    if len(self.img_object.grid) == 0:
                        self.img_object.final = prev_final
                        self.img_object.status = prev_status
                        self.img_object.fail = prev_fail
                        terminate = True
                        continue
                    if self.verbose:
                        log_entry = '\nNew starting point: H = {}, A = {}\n'\
                                    ''.format(self.hmed, self.amed)
                        self.img_object.log_info.append(log_entry)
                else:
                    if prev_fail != 'first cycle':
                        self.img_object.final = prev_final
                        self.img_object.status = prev_status
                        self.img_object.fail = prev_fail
                        if self.verbose:
                            log_entry = '\nFinal set of parameters: H = {}, A = {}'\
                                        ''.format(self.img_object.final['sph'],
                                                  self.img_object.final['spa'])
                            self.img_object.log_info.append(log_entry)
                    terminate = True

            # If brute force grid search is selected run one round
            else:
                terminate = True

        # Run final integration if haven't already
        if self.img_object.fail is None and self.img_object.status != 'final':
            self.integrate_cctbx('integrate', single_image=single_image)

        # If verbose output selected (default), write to main log
        if self.verbose:
            log_entry = "\n".join(self.img_object.log_info)
            util.main_log(self.init.logfile, log_entry)
            util.main_log(self.init.logfile, '\n\n')

        # Make a temporary process log into a final process log
        if os.path.isfile(self.img_object.int_log):
            l_fname = util.make_filename(self.img_object.int_log,
                                         new_ext='log')
            final_int_log = os.path.join(self.img_object.log_path, l_fname)
            os.rename(self.img_object.int_log, final_int_log)

        # Save results into a pickle file
        self.img_object.status = 'final'
        from libtbx import easy_pickle as ep
        ep.dump(self.img_object.obj_file, self.img_object)

        return self.img_object