def write_file(detector, file): """ Writes Mca or Med objects to a disk file. Parameters: ----------- * detector: An med or mca object * file: The name of the disk file to write. Example: -------- >>write_file(mca,'mca.001') """ # Make sure detector is type MED for simplicity... try: if detector.det_type != "MED": if has_attr(detector,'environment'): env = detector.environment del detector.environment #delattr(detector,'environment') else: env = None detector = Med(mca=[detector]) if env: detector.environment = env except: return write_ascii_file(detector, file)
def read_med(file): """ Reads a disk file into an Med object. The file contains the information from the Med object which it makes sense to store permanently, but does not contain all of the internal state information for the Med. Parameters: ----------- * file: The name of the disk file to read. """ r = read_ascii_file(file) if r == None: return None n_detectors = r['n_detectors'] path, fname = os.path.split(file) med = Med(n_detectors=n_detectors, name=fname) med.mca = [] for i in range(n_detectors): med.mca.append(Mca()) med.mca[i].set_rois(r['rois'][i]) med.mca[i].set_data(r['data'][i]) med.mca[i].set_name(fname + ':' + str(i)) med.set_elapsed(r['elapsed']) med.set_calibration(r['calibration']) med.set_environment(r['environment']) return med
def read_med(file,bad_mca_idx=[],total=True,align=True,correct=True,tau=None): """ Reads a disk file into an Med object. The file contains the information from the Med object which makes sense to store permanently, but does not contain all of the internal state information for the Med. Parameters: ----------- * file: The name of the disk file to read. Notes: ------ * If the file includes "Environment data" these wil lbe included in the returned object as med.environment * If the file includes ROI's the will be included with the mca's in the returned object as med.mca[i].rois """ # read the file r = read_ascii_file(file) if r == None: return None # some info n_detectors = r['n_detectors'] path, fname = os.path.split(file) # check for boge detectors check_det = True if check_det == True: for j in range(n_detectors): if r['mca'][j].total_counts < 1.: if j not in bad_mca_idx: bad_mca_idx.append(j) bad_mca_idx.sort() # build the med object med = Med(name=fname, mca=r['mca'], bad_mca_idx=bad_mca_idx, total=total, align=align, correct=correct, tau=tau) # below are set only if defined in file if r['max_rois'] > 0: rois = r['rois'] for d in range(n_detectors): med.mca[d].rois = rois[d] if len(r['environment']) > 0: med.environment = r['environment'] return med