def get_header_data(arg, blockname=None, hdrkeys=None): """ checked for new crates """ filename = '' close_dataset = False if type(arg) == str: # arg = get_filename_from_dmsyntax(arg, blockname) arg = get_filename_from_dmsyntax(arg) tbl = None try: tbl = open_crate(arg) except Exception as e: raise e close_dataset = True filename = tbl.get_filename() # Make a copy of the data, since we don't know that pycrates will # do something sensible wrt reference counting elif isinstance(arg, pycrates.TABLECrate): tbl = arg filename = arg.get_filename() else: raise IOErr('badfile', arg, 'TABLECrate obj') # Crates "caches" open files by their filename in memory. If you try # to open a file multiple times (with DM syntax) it corrupts the Crate # in memory. This is a work-around to open the CrateDataset without # DM syntax and iterate through the crates looking for the block # name that matches. if blockname is not None: crate = _get_crate_by_blockname(tbl.get_dataset(), blockname) tbl = crate or tbl hdr = {} if hdrkeys is None: # hdrkeys = tbl.get_keynames() hdrkeys = pycrates.get_key_names(tbl) for key in hdrkeys: hdr[key] = _require_hdr_key(tbl, key) if close_dataset: close_crate_dataset(tbl.get_dataset()) return hdr
def _get_meta_data(crate): """ checked for new crates """ meta = Meta() names = pycrates.get_key_names(crate) if names is not None and numpy.iterable(names): for name in names: val = pycrates.get_keyval(crate, name) # empty numpy strings are not recognized by load pickle! if type(val) is numpy.str_ and val == '': val = '' meta[name] = val return meta
else: raise IOErr('badfile', arg, 'TABLECrate obj') # Crates "caches" open files by their filename in memory. If you try # to open a file multiple times (with DM syntax) it corrupts the Crate # in memory. This is a work-around to open the CrateDataset without # DM syntax and iterate through the crates looking for the block # name that matches. if blockname is not None: crate = _get_crate_by_blockname(tbl.get_dataset(), blockname) tbl = crate or tbl hdr = {} if hdrkeys is None: # hdrkeys = tbl.get_keynames() hdrkeys = pycrates.get_key_names(tbl) for key in hdrkeys: hdr[key] = _require_hdr_key(tbl, key) if close_dataset: close_crate_dataset(tbl.get_dataset()) return hdr def get_column_data(*args): """ checked for new crates get_column_data( *NumPy_args )
else: raise IOErr('badfile', arg, 'TABLECrate obj') # Crates "caches" open files by their filename in memory. If you try # to open a file multiple times (with DM syntax) it corrupts the Crate # in memory. This is a work-around to open the CrateDataset without # DM syntax and iterate through the crates looking for the block # name that matches. if blockname is not None: crate = _get_crate_by_blockname(tbl.get_dataset(), blockname) tbl = crate or tbl hdr = {} if hdrkeys is None: #hdrkeys = tbl.get_keynames() hdrkeys = pycrates.get_key_names(tbl) for key in hdrkeys: hdr[key] = _require_hdr_key(tbl, key) if close_dataset: close_crate_dataset(tbl.get_dataset()) return hdr def get_column_data( *args ): """ checked for new crates get_column_data( *NumPy_args )