当前位置: 首页>>代码示例>>Python>>正文


Python tables.File方法代码示例

本文整理汇总了Python中tables.File方法的典型用法代码示例。如果您正苦于以下问题:Python tables.File方法的具体用法?Python tables.File怎么用?Python tables.File使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tables的用法示例。


在下文中一共展示了tables.File方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fps_from_timestamp

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def fps_from_timestamp(file_name):
    #try to calculate the frames per second from the timestamp
    with tables.File(file_name, 'r') as fid:
        timestamp_time = fid.get_node('/timestamp/time')[:]
        if np.all(np.isnan(timestamp_time)):
            raise ValueError

        delT = np.nanmedian(np.diff(timestamp_time))
        if delT == 0:
            raise ValueError
        fps = 1 / delT

        if np.isnan(fps) or fps < 1:
            raise ValueError

        time_units = 'seconds'

    return fps, time_units 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:20,代码来源:read_attrs.py

示例2: save_modified_table

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def save_modified_table(file_name, modified_table, table_name):
    tab_recarray = modified_table.to_records(index=False)
    with tables.File(file_name, "r+") as fid:
        dum_name = table_name + '_d'
        if '/' + dum_name in fid:
            fid.remove_node('/', dum_name)

        newT = fid.create_table(
            '/',
            dum_name,
            obj=tab_recarray,
            filters=TABLE_FILTERS)

        oldT = fid.get_node('/' + table_name)
        old_args = [x for x in dir(oldT._v_attrs) if not x.startswith('_')]
        for key in old_args:
            
            if not key in newT._v_attrs and not key.startswith('FIELD'):
                newT.attrs[key] = oldT.attrs[key]
                
        fid.remove_node('/', table_name)
        newT.rename(table_name) 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:24,代码来源:file_processing.py

示例3: load_eigen_worms

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def load_eigen_worms():
    """
    Load the eigen_worms, which are stored in a Matlab data file

    The eigenworms were computed by the Schafer lab based on N2 worms

    Returns
    ----------
    eigen_worms: [7 x 48]

    From http://stackoverflow.com/questions/50499/

    """

    eigen_worm_file_path = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    config.EIGENWORM_FILE)

    with tables.File(eigen_worm_file_path, 'r'):
        eigen_worms = h.get_node('/eigenWorms')[:]
    
    return np.transpose(eigen_worms) 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:24,代码来源:posture_features.py

示例4: getROIfromInd

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def getROIfromInd(masked_file, trajectories_data, frame_number, worm_index, roi_size=-1):
    good = (trajectories_data['frame_number']==frame_number) & (trajectories_data['worm_index_joined']==worm_index)
    row = trajectories_data[good]
    if len(row) < 1:
        return None
    
    assert len(row) == 1
    
    row = row.iloc[0]
    
    with tables.File(masked_file, 'r') as fid:
        img_data = fid.get_node('/mask')
        img = img_data[frame_number]

    if roi_size <= 0:
        roi_size = row['roi_size']
    worm_roi, roi_corner = getWormROI(img, row['coord_x'], row['coord_y'], roi_size)
    return row, worm_roi, roi_corner 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:20,代码来源:helperIterROI.py

示例5: getFrameDiffVar

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def getFrameDiffVar(masked_file, progress_refresh_rate_s=100):
    base_name = get_base_name(masked_file)
    progress_prefix = '{} Calculating variance of the difference between frames.'.format(base_name)
    
    with tables.File(masked_file, 'r') as fid:
        masks = fid.get_node('/mask')

        tot, w, h = masks.shape
        progress_time = TimeCounter(progress_prefix, tot)
        fps = read_fps(masked_file, dflt=25)
        progress_refresh_rate = int(round(fps*progress_refresh_rate_s))

        img_var_diff = np.zeros(tot-1)
        frame_prev = masks[0]
        for ii in range(1, tot):
            frame_current = masks[ii]
            img_var_diff[ii-1] = get_mask_diff_var(frame_current, frame_prev)
            frame_prev = frame_current;

            if ii % progress_refresh_rate == 0:
                print_flush(progress_time.get_str(ii))

        if tot>1:
            print_flush(progress_time.get_str(ii))
    return img_var_diff 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:27,代码来源:findStageMovement.py

示例6: __init__

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def __init__(self, fileName, full_img_period=np.inf):
        # to be used when added to the plugin
        self.vid_frame_pos = []
        self.vid_time_pos = []

        try:
            self.fid = tables.File(fileName, 'r')
            self.dataset = self.fid.get_node('/mask')
        except:
            raise OSError

        self.tot_frames = self.dataset.shape[0]

        self.width = self.dataset.shape[2]
        self.height = self.dataset.shape[1]
        self.dtype = self.dataset.dtype
        
        self.tot_pix = self.height * self.width

        # initialize pointer for frames
        self.curr_frame = -1

        # how often we get a full frame
        self.full_img_period = full_img_period 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:26,代码来源:readVideoHDF5.py

示例7: _h_nodes2Array

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def _h_nodes2Array(skeletons_file, nodes4fit, valid_index=-1):
    '''
    Read the groups in skeletons file and save them as a matrix.
    Used by _h_readFeat2Check
    '''
    with tables.File(skeletons_file, 'r') as fid:
        assert all(node in fid for node in nodes4fit)

        if isinstance(valid_index, (float, int)) and valid_index < 0:
            valid_index = np.arange(fid.get_node(nodes4fit[0]).shape[0])

        n_samples = len(valid_index)
        n_features = len(nodes4fit)

        X = np.zeros((n_samples, n_features))

        if valid_index.size > 0:
            for ii, node in enumerate(nodes4fit):
                X[:, ii] = fid.get_node(node)[valid_index]

        return X 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:23,代码来源:getFilteredSkels.py

示例8: _addMissingFields

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def _addMissingFields(skeletons_file):
    '''
    Add missing fields that might have not been calculated before in older videos.
    '''
    with tables.File(skeletons_file, 'r+') as fid:
        if not '/contour_area' in fid:
            contour_side1 = fid.get_node('/contour_side1')[:]
            contour_side2 = fid.get_node('/contour_side2')[:]
            cnt_area = _h_calAreaArray(contour_side1, contour_side2)
            fid.create_carray('/', "contour_area", obj=cnt_area, filters=TABLE_FILTERS)

        if not '/width_midbody' in fid:
            midbody_ind = (17, 32)
            contour_width = fid.get_node('/contour_width')[:]
            width_midbody = np.median(contour_width[:, midbody_ind[0]:midbody_ind[1]+1], axis=1)
            fid.create_carray('/', "width_midbody", obj=width_midbody, filters=TABLE_FILTERS) 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:18,代码来源:getFilteredSkels.py

示例9: storeAdditionalDataSW

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def storeAdditionalDataSW(video_file, masked_image_file):
    assert(os.path.exists(video_file))
    assert(os.path.exists(masked_image_file))

    info_file, stage_file = getAdditionalFiles(video_file)

    assert(os.path.exists(video_file))
    assert(os.path.exists(stage_file))

    # store data
    storeXMLInfo(info_file, masked_image_file)
    storeStageData(stage_file, masked_image_file)

    with tables.File(masked_image_file, 'r+') as mask_fid:
        mask_fid.get_node('/mask').attrs['has_finished'] = 2


# DEPRECATED 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:20,代码来源:getAdditionalData.py

示例10: read_images

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def read_images(mask_file, batch_size, frames2check = None):
    with tables.File(mask_file, 'r') as fid:
        masks = fid.get_node('/mask')
        
        if frames2check is None:
            frames2check = range(masks.shape[0])
        
        batch = []
        for frame in frames2check:
            img = masks[frame]
            
            batch.append((frame, img))
            if len(batch) == batch_size:
                yield batch
                batch = []
        if batch:
            yield batch 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:19,代码来源:extract_poses.py

示例11: _add_ventral_side

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def _add_ventral_side(skeletons_file, ventral_side=''):
    #I am giving priority to a contour stored in experiments_info, rather than one read by the json file.
    #currently i am only using the experiments_info in the re-analysis of the old schafer database
    try:
        ventral_side_f = single_db_ventral_side(skeletons_file)
    except (tables.exceptions.NoSuchNodeError, KeyError):
        ventral_side_f = ''

    if ventral_side_f in VALID_CNT:
        if not ventral_side or (ventral_side == ventral_side_f):
            ventral_side = ventral_side_f
        else:
            raise ValueError('The given contour orientation ({}) and the orientation stored in /experiments_info group ({}) differ. Change /experiments_info or the parameters file to solve this issue.'.format(ventral_side, ventral_side_f) )

    #add ventral side if given
    if ventral_side in VALID_CNT:
        with tables.File(skeletons_file, 'r+') as fid:
            fid.get_node('/trajectories_data').attrs['ventral_side'] = ventral_side
    return ventral_side 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:21,代码来源:correctVentralDorsal.py

示例12: updateSkelFile

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def updateSkelFile(self, skeletons_file):

        super().updateSkelFile(skeletons_file)
        if not self.skeletons_file or self.trajectories_data is None:
            self.food_coordinates = None
            return

        with tables.File(self.skeletons_file, 'r') as fid:
            if not '/food_cnt_coord' in fid:
                self.food_coordinates = None
                self.ui.checkBox_showFood.setEnabled(False)
            else:
                #change from microns to pixels
                self.food_coordinates = fid.get_node('/food_cnt_coord')[:]
                self.food_coordinates /= self.microns_per_pixel
                
                self.ui.checkBox_showFood.setEnabled(True) 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:19,代码来源:MWTrackerViewer.py

示例13: change_attrs

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def change_attrs(fname, field_name):
    print(os.path.basename(fname))
    read_unit_conversions(fname)
    with tables.File(fname, 'r+') as fid:
        group_to_save = fid.get_node(field_name)
        set_unit_conversions(group_to_save, 
                             expected_fps=expected_fps, 
                             microns_per_pixel=microns_per_pixel)
        
    read_unit_conversions(fname)


#for fname in masked_files:
#    change_attrs(fname, '/mask')
#for fname in skeletons_files:
#    change_attrs(fname, '/trajectories_data') 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:18,代码来源:check_default_attrs.py

示例14: __init__

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def __init__(self, filename, filter_kwds=None, mode="r", title='', metadata=None, create_directories=False):
        self._opened = False
        if isinstance(filename, (str, os.PathLike)):
            # filename is a path to open
            self.filename = filename
            # Note sure how else to deal with str / unicode requirements in pytables
            # See this issue: https://github.com/PyTables/PyTables/issues/522
            import sys
            if filter_kwds:
                if sys.version_info[0] == 2 and 'complib' in filter_kwds:
                    filter_kwds['complib'] = filter_kwds['complib'].encode()
                filters = tables.Filters(**filter_kwds)
            else:
                filters = None

            # Create directories for the filename if required
            if create_directories:
                try:
                    os.makedirs(os.path.dirname(filename))
                except OSError as exception:
                    import errno
                    if exception.errno != errno.EEXIST:
                        raise

            self.file = tables.open_file(filename, mode=mode, filters=filters, title=title)
            self._opened = True
        elif isinstance(filename, tables.File):
            # filename is a pytables file
            self.file = filename
            assert(self.file.isopen)
            self.filename = self.file.filename
            self._opened = False
        else:
            raise TypeError("{} must be initalised with a filename to open or an open tables.File".format(self.__class__.__name__))

        # now update metadata if given
        if metadata is not None and self.file.mode != 'r':
            for k, v in metadata.items():
                setattr(self.file.root._v_attrs, k, v) 
开发者ID:pywr,项目名称:pywr,代码行数:41,代码来源:h5tools.py

示例15: open_hdf

# 需要导入模块: import tables [as 别名]
# 或者: from tables import File [as 别名]
def open_hdf(self, mode='r+'):
        """
        Opens the hdf5 file.

        This should be called at the start of every method that access the h5 file
        and :meth:`~.Subject.close_hdf` should be called at the end. Otherwise
        the file will close and we risk file corruption.

        See the pytables docs
        `here <https://www.pytables.org/cookbook/threading.html>`_ and
        `here <https://www.pytables.org/FAQ.html#can-pytables-be-used-in-concurrent-access-scenarios>`_

        Args:
            mode (str): a file access mode, can be:

                * 'r': Read-only - no data can be modified.
                * 'w': Write - a new file is created (an existing file with the same name would be deleted).
                * 'a' Append - an existing file is opened for reading and writing, and if the file does not exist it is created.
                * 'r+' (default) - Similar to 'a', but file must already exist.

        Returns:
            :class:`tables.File`: Opened hdf file.
        """
        # TODO: Use a decorator around methods instead of explicitly calling
        with self.lock:
            return tables.open_file(self.file, mode=mode) 
开发者ID:wehr-lab,项目名称:autopilot,代码行数:28,代码来源:subject.py


注:本文中的tables.File方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。