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


Python h5py.File类代码示例

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


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

示例1: TestSimpleSlicing

class TestSimpleSlicing(TestCase):

    """
        Feature: Simple NumPy-style slices (start:stop:step) are supported.
    """

    def setUp(self):
        self.f = File(self.mktemp(), 'w')
        self.arr = np.arange(10)
        self.dset = self.f.create_dataset('x', data=self.arr)

    def tearDown(self):
        if self.f:
            self.f.close()

    def test_negative_stop(self):
        """ Negative stop indexes work as they do in NumPy """
        self.assertArrayEqual(self.dset[2:-2], self.arr[2:-2])

    def test_write(self):
        """Assigning to a 1D slice of a 2D dataset
        """
        dset = self.f.create_dataset('x2', (10, 2))

        x = np.zeros((10, 1))
        dset[:, 0] = x[:, 0]
        with self.assertRaises(TypeError):
            dset[:, 1] = x
开发者ID:aragilar,项目名称:h5py,代码行数:28,代码来源:test_slicing.py

示例2: test_blocksize

 def test_blocksize(self):
     """ Core driver supports variable block size """
     fname = self.mktemp()
     fid = File(fname, 'w', driver='core', block_size=1024,
                backing_store=False)
     self.assertTrue(fid)
     fid.close()
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:7,代码来源:test_file.py

示例3: dump

def dump( histogram, filename = None, pathinfile = '/', 
          mode = 'c', fs = None, compression = 'lzf'):
    '''dump( histogram, hdf_filename, path_in_hdf_file, mode ) -> save histogram into a hdf file.

    histogram:
      The histogram to be written
    hdf_filename:
      The hdf filename in which the histogram will be saved
    path_in_hdf_file:
      The path inside the hdf file where the histogram is located.
    mode:
      The mode to be used to write to the hdf file.
      'c': create new hdf file. If hdf file of the same name exists, this command will fail.
      'w': write to existing hdf file. If the path_in_hdf_file already exists in the hdf file, this command will fail.
    compression:
      The compression ratio. If it is 0, no compression will be done.
      The valid values are integers from 0 to 9 (inclusive).
    '''
    from Renderer import Renderer
    #g = graphFromHDF5File( filename, pathinfile, fs = fs )
    pathinfile = pathinfile.split( '/' )
    p = pathinfile + [histogram.name()]
    p = '/'.join( p )
    if not p.startswith('/'): 
        p = '/' + p
    writeCodes = {'c':'w','w':'a'}
    if fs is None:
        from h5py import File
        fs = File(filename, writeCodes[mode])
        Renderer(fs, compression).render(histogram)
        fs.close()
    else:
        Renderer(fs, compression).render(histogram)
开发者ID:danse-inelastic,项目名称:histogram,代码行数:33,代码来源:__init__.py

示例4: __init__

    def __init__(self, fname):
        from h5py import File
        from numpy import array, log10
        import json

        h5f = File(fname, "r")
        log = sorted(json.loads(h5f["measure"].value).values(),
                 key=lambda e: e["Status"]["Iteration"])
        runargs = json.loads(h5f["runargs"].value)
        self.N       = runargs["N"]
        self.zeta    = runargs.get("zeta", 1.0)
        self.time    = array([entry["Status" ]["CurrentTime"] for entry in log])
        self.mean_T  = array([entry["mean_T" ] for entry in log])
        self.max_T   = array([entry["max_T"  ] for entry in log])
        self.mean_Ms = array([entry["mean_Ms"] for entry in log])
        self.max_Ms  = array([entry["max_Ms" ] for entry in log])
        self.mean_Ma = array([entry["mean_Ma"] for entry in log])
        self.min_Ma  = array([entry["min_Ma" ] for entry in log])
        self.kin     = array([entry["energies"]["kinetic" ] for entry in log])
        self.tie     = array([entry["energies"]["internal"] for entry in log])
        self.mag     = array([entry["energies"]["magnetic"] for entry in log])
        self.tot     = array([entry["energies"]["total"   ] for entry in log])
        self.mean_gamma = array([entry["mean_velocity"][0] for entry in log])
        self.max_gamma = array([entry["max_lorentz_factor"] for entry in log])
        self.runargs = runargs
        h5f.close()
开发者ID:julywater,项目名称:mara-tools,代码行数:26,代码来源:chkptlog.py

示例5: BaseDataset

class BaseDataset(TestCase):

    """
    data is a 3-dimensional dataset with dimensions [z, y, x]

    The z dimension is labeled. It does not have any attached scales.
    The y dimension is not labeled. It has one attached scale.
    The x dimension is labeled. It has two attached scales.

    data2 is a 3-dimensional dataset with no associated dimension scales.
    """

    def setUp(self):
        self.f = File(self.mktemp(), 'w')
        self.f['data'] = np.ones((4, 3, 2), 'f')
        self.f['data2'] = np.ones((4, 3, 2), 'f')
        self.f['x1'] = np.ones((2), 'f')
        h5py.h5ds.set_scale(self.f['x1'].id)
        h5py.h5ds.attach_scale(self.f['data'].id, self.f['x1'].id, 2)
        self.f['x2'] = np.ones((2), 'f')
        h5py.h5ds.set_scale(self.f['x2'].id, b'x2 name')
        h5py.h5ds.attach_scale(self.f['data'].id, self.f['x2'].id, 2)
        self.f['y1'] = np.ones((3), 'f')
        h5py.h5ds.set_scale(self.f['y1'].id, b'y1 name')
        h5py.h5ds.attach_scale(self.f['data'].id, self.f['y1'].id, 1)
        self.f['z1'] = np.ones((4), 'f')

        h5py.h5ds.set_label(self.f['data'].id, 0, b'z')
        h5py.h5ds.set_label(self.f['data'].id, 2, b'x')

    def tearDown(self):
        if self.f:
            self.f.close()
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:33,代码来源:test_dimension_scales.py

示例6: BasH5

class BasH5(object):
    """
    This class is deprecated.

    .. deprecated:: 0.3.0
        Use `BasH5Reader` instead.

    """
    def __init__(self, filename, readType='Raw'):
        self._h5f = File(filename, 'r')
        self.rgnTable = RegionTable(self._h5f)
        self.baseCallsDG = None        
        if readType == 'Raw':
            self.baseCallsDG = BaseCallsDataGroup(self._h5f, '/PulseData/BaseCalls')
        elif readType == 'CCS':
            self.baseCallsDG = CCSBaseCallsDataGroup(self._h5f, '/PulseData/ConsensusBaseCalls') 
            self.rbaseCallsDG = BaseCallsDataGroup(self._h5f, '/PulseData/BaseCalls')


    def __del__(self):
        self._h5f.close()
                
    def getZMWs(self):
        for hn in self.baseCallsDG.holeNumber:
            yield hn            

    def getSequencingZMWs(self):
        for hn in self.getZMWs():
            if self.baseCallsDG.getStatusStringForZMW(hn) == 'SEQUENCING' and self.baseCallsDG.getBaseCallLenForZMW(hn):
                yield hn
开发者ID:jgurtowski,项目名称:pbcore_python,代码行数:30,代码来源:BasH5IO.py

示例7: BaseDataset

class BaseDataset(TestCase):
    def setUp(self):
        self.f = File(self.mktemp(), 'w')

    def tearDown(self):
        if self.f:
            self.f.close()
开发者ID:aragilar,项目名称:h5py,代码行数:7,代码来源:test_dataset.py

示例8: hasVersion

def hasVersion(filename):
  """Check filename as sassena version"""
  from h5py import File
  f = File(filename,'r')
  value=False
  if 'sassena_version' in f.attrs.keys(): value=True
  f.close()
  return value
开发者ID:camm,项目名称:code,代码行数:8,代码来源:sassenatasks.py

示例9: test_create_exclusive

 def test_create_exclusive(self):
     """ Mode 'w-' opens file in exclusive mode """
     fname = self.mktemp()
     fid = File(fname, 'w-')
     self.assertTrue(fid)
     fid.close()
     with self.assertRaises(IOError):
         File(fname, 'w-')
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:8,代码来源:test_file.py

示例10: test_core

 def test_core(self):
     """ Core driver is supported (no backing store) """
     fname = self.mktemp()
     fid = File(fname, 'w', driver='core', backing_store=False)
     self.assertTrue(fid)
     self.assertEqual(fid.driver, 'core')
     fid.close()
     self.assertFalse(os.path.exists(fname))
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:8,代码来源:test_file.py

示例11: test_mode

 def test_mode(self):
     """ Retrieved File objects have a meaningful mode attribute """
     hfile = File(self.mktemp(),'w')
     try:
         grp = hfile.create_group('foo')
         self.assertEqual(grp.file.mode, hfile.mode)
     finally:
         hfile.close()
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:8,代码来源:test_file.py

示例12: test_iter_zero

 def test_iter_zero(self):
     """ Iteration works properly for the case with no group members """
     hfile = File(self.mktemp(), 'w')
     try:
         lst = [x for x in hfile]
         self.assertEqual(lst, [])
     finally:
         hfile.close()
开发者ID:whqkdhfh13,项目名称:sswp,代码行数:8,代码来源:test_group.py

示例13: get_dataset

def get_dataset(h5file: File, path: DatasetPath) -> Dataset:
    res = None
    if isinstance(path, DatasetPathContains):
        res = h5file.visititems(partial(_v_item, path.path))
    elif isinstance(path, DatasetPathWithAttribute):
        res = h5file.visititems(partial(_v_attrs,
                                        path.attribute, path.value))
    return res
开发者ID:vallsv,项目名称:pyFAI,代码行数:8,代码来源:soleil.py

示例14: ReadFiniteRadiusWaveform

def ReadFiniteRadiusWaveform(n, filename, WaveformName, ChMass, InitialAdmEnergy, YLMRegex, LModes, DataType, Ws) :
    """
    This is just a worker function defined for ReadFiniteRadiusData,
    below, reading a single waveform from an h5 file of many
    waveforms.  You probably don't need to call this directly.

    """
    from scipy.integrate import cumtrapz as integrate
    from numpy import setdiff1d, empty, delete, sqrt, log, array
    from h5py import File
    import GWFrames
    try :
        f = File(filename, 'r')
    except IOError :
        print("ReadFiniteRadiusWaveform could not open the file '{0}'".format(filename))
        raise
    try :
        W = f[WaveformName]
        NTimes_Input = W['AverageLapse.dat'].shape[0]
        T = W['AverageLapse.dat'][:,0]
        Indices = MonotonicIndices(T)
        T = T[Indices]
        Radii = array(W['ArealRadius.dat'])[Indices,1]
        AverageLapse = array(W['AverageLapse.dat'])[Indices,1]
        CoordRadius = W['CoordRadius.dat'][0,1]
        YLMdata = [DataSet for DataSet in list(W) for m in [YLMRegex.search(DataSet)] if (m and int(m.group('L')) in LModes)]
        YLMdata = sorted(YLMdata, key=lambda DataSet : [int(YLMRegex.search(DataSet).group('L')), int(YLMRegex.search(DataSet).group('M'))])
        LM = sorted([[int(m.group('L')), int(m.group('M'))] for DataSet in YLMdata for m in [YLMRegex.search(DataSet)] if m])
        NModes = len(LM)
        # Lapse is given by 1/sqrt(-g^{00}), where g is the full 4-metric
        T[1:] = integrate(AverageLapse/sqrt(((-2.0*InitialAdmEnergy)/Radii) + 1.0), T) + T[0]
        T -= (Radii + (2.0*InitialAdmEnergy)*log((Radii/(2.0*InitialAdmEnergy))-1.0))
        Ws[n].SetTime(T/ChMass)
        # WRONG!!!: # Radii /= ChMass
        NTimes = Ws[n].NTimes()
        # Ws[n].SetFrame is not done, because we assume the inertial frame
        Ws[n].SetFrameType(GWFrames.Inertial) # Assumption! (but this should be safe)
        Ws[n].SetDataType(DataType)
        Ws[n].SetRIsScaledOut(True) # Assumption! (but it should be safe)
        Ws[n].SetMIsScaledOut(True) # We have made this true
        Ws[n].SetLM(LM)
        Data = empty((NModes, NTimes), dtype='complex')
        if(DataType == GWFrames.h) :
            UnitScaleFactor = 1.0 / ChMass
        elif(DataType == GWFrames.hdot) :
            UnitScaleFactor = 1.0
        elif(DataType == GWFrames.Psi4) :
            UnitScaleFactor = ChMass
        else :
            raise ValueError('DataType "{0}" is unknown.'.format(DataType))
        RadiusRatio = Radii / CoordRadius
        for m,DataSet in enumerate(YLMdata) :
            modedata = array(W[DataSet])
            Data[m,:] = (modedata[Indices,1] + 1j*modedata[Indices,2]) * RadiusRatio * UnitScaleFactor
        Ws[n].SetData(Data)
    finally :
        f.close()
    return Radii/ChMass
开发者ID:Cyberface,项目名称:GWFrames,代码行数:58,代码来源:Extrapolation.py

示例15: test_filename

 def test_filename(self):
     """ .filename behaves properly for string data """
     fname = self.mktemp()
     fid = File(fname, 'w')
     try:
         self.assertEqual(fid.filename, fname)
         self.assertIsInstance(fid.filename, six.text_type)
     finally:
         fid.close()
开发者ID:ajelenak-thg,项目名称:h5py,代码行数:9,代码来源:test_file.py


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