def from_hdf_file(cls, cine_base_path, h5_fname): ''' Sets up object to process data based on MD in an hdf file. ''' self = cls() tmp_file = h5py.File('/'.join(h5_fname), 'r') keys_lst = list(tmp_file.attrs.keys()) lc_req_args = ['tck0', 'tck1', 'tck2'] h5_req_args = ['cine_path', 'cine_fname'] cls._verify_params(keys_lst, extra_req=(lc_req_args + h5_req_args)) self.params = dict(tmp_file.attrs) for k in lc_req_args: del self.params[k] self.cine_fname = FilePath(cine_base_path, self.params.pop('cine_path'), self.params.pop('cine_fname')) self.cine_ = cine.Cine('/'.join(self.cine_fname)) if 'bck_img' in list(tmp_file.keys()): self.bck_img = tmp_file['bck_img'][:] else: self.bck_img = infra.gen_bck_img('/'.join(self.cine_fname)) seed_curve = infra.SplineCurve.from_hdf(tmp_file) tmp_file.close() return self, seed_curve
def from_args(cls, cine_fname, h5_fname=None, *args, **kwargs): self = cls() '''Sets up the object based on arguments ''' cls._verify_params(kwargs) self.params = kwargs try: self.bck_img = self.params.pop('bck_img') except KeyError: self.bck_img = None self.cine_fname = cine_fname self.cine_ = cine.Cine('/'.join(self.cine_fname)) if self.bck_img is None: # not passed in, try the data base if self.db is not None: self.bck_img = self.db.get_background_img(self.cine_.hash) # if that fails too, run it if self.bck_img is None: self.bck_img = infra.gen_bck_img('/'.join(self.cine_fname)) # if we have a data base, shove in the data if self.db is not None: self.db.store_background_img(self.cine_.hash, self.bck_img) return self
def gen_back_img(self): if self.cine_fname is not None: self.bck_img = infra.gen_bck_img(self.cine_fname.format)