@@ -40,13 +40,13 @@ def calc_chunkshape(chunksize, shape, kind='bytes'):
4040 if chunksize is None :
4141 return None
4242
43+ divisor = 1
4344 if kind == 'bytes' :
44- divisor = 1
4545 for dimsize in shape [:- 1 ]:
4646 divisor *= dimsize
4747
4848 if len (shape ) == 1 :
49- chunkshape = (chunksize ,)
49+ chunkshape = (chunksize / divisor ,)
5050 elif len (shape ) == 2 :
5151 chunkshape = (shape [0 ], chunksize / divisor )
5252 elif len (shape ) == 3 :
@@ -89,16 +89,18 @@ def open(self):
8989 def set_sim_params (self , nparams , attr_params ):
9090 """Store parameters in `params` in `h5file.root.parameters`.
9191
92- `nparams` (dict)
93- A dict as returned by `get_params()` in `ParticlesSimulation()`
94- The format is:
95- keys:
96- used as parameter name
97- values: (2-elements tuple)
98- first element is the parameter value
99- second element is a string used as "title" (description)
100- `attr_params` (dict)
101- A dict whole items are stored as attributes in '/parameters'
92+ Argument:
93+ nparams (dict): a dict of parameters from
94+ `ParticlesSimulation().nparams`. The format is:
95+
96+ keys:
97+ used as parameter name
98+ values: (2-elements tuple)
99+ first element is the parameter value
100+ second element is a string used as "title" (description)
101+
102+ attr_params (dict): dict items will be stored as attributes in
103+ '/parameters'
102104 """
103105 for name , value in nparams .items ():
104106 val = value [0 ] if value [0 ] is not None else 'none'
@@ -112,24 +114,25 @@ def numeric_params(self):
112114 """Return a dict containing all (key, values) stored in '/parameters'
113115 """
114116 nparams = dict ()
115- for p in self .h5file .root .parameters :
116- nparams [p .name ] = p .read ()
117+ for par in self .h5file .root .parameters :
118+ nparams [par .name ] = par .read ()
117119 return nparams
118120
119121 @property
120122 def numeric_params_meta (self ):
121123 """Return a dict with all parameters and metadata in '/parameters'.
122124
123- This returns the same dict format as returned by get_params() method
124- in ParticlesSimulation().
125+ This returns the same dict format as `ParticlesSimulation().nparams`.
125126 """
126127 nparams = dict ()
127- for p in self .h5file .root .parameters :
128- nparams [p .name ] = (p .read (), p .title )
128+ for par in self .h5file .root .parameters :
129+ nparams [par .name ] = (par .read (), par .title )
129130 return nparams
130131
131132
132133class TrajectoryStore (BaseStore ):
134+ """An on-disk HDF5 store for trajectories.
135+ """
133136 def __init__ (self , datafile , path = './' , nparams = dict (), attr_params = dict (),
134137 mode = 'r' ):
135138 """Return a new HDF5 file to store simulation results.
@@ -152,9 +155,9 @@ def __init__(self, datafile, path='./', nparams=dict(), attr_params=dict(),
152155 self .h5file .create_group ('/' , 'psf' , 'PSFs used in the simulation' )
153156
154157 def add_trajectory (self , name , overwrite = False , shape = (0 ,), title = '' ,
155- chunksize = 2 ** 19 , comp_filter = default_compression ,
156- atom = tables . Float64Atom (), params = dict () ,
157- chunkslice = 'bytes' ):
158+ chunksize = 2 ** 19 , chunkslice = 'bytes' ,
159+ comp_filter = default_compression ,
160+ atom = tables . Float64Atom (), params = dict () ):
158161 """Add an trajectory array in '/trajectories'.
159162 """
160163 group = self .h5file .root .trajectories
@@ -186,25 +189,28 @@ def add_trajectory(self, name, overwrite=False, shape=(0,), title='',
186189 store_array .set_attr ('creation_time' , current_time ())
187190 return store_array
188191
189- def add_emission_tot (self , chunksize = 2 ** 19 , comp_filter = default_compression ,
190- overwrite = False , params = dict () ,
191- chunkslice = 'bytes' ):
192+ def add_emission_tot (self , chunksize = 2 ** 19 , chunkslice = 'bytes' ,
193+ comp_filter = default_compression ,
194+ overwrite = False , params = dict () ):
192195 """Add the `emission_tot` array in '/trajectories'.
193196 """
194- kwargs = dict (overwrite = overwrite , chunksize = chunksize , params = params ,
197+ kwargs = dict (overwrite = overwrite , params = params ,
198+ chunksize = chunksize , chunkslice = chunkslice ,
195199 comp_filter = comp_filter , atom = tables .Float32Atom (),
196200 title = 'Summed emission trace of all the particles' )
197201 return self .add_trajectory ('emission_tot' , ** kwargs )
198202
199- def add_emission (self , chunksize = 2 ** 19 , comp_filter = default_compression ,
200- overwrite = False , params = dict (), chunkslice = 'bytes' ):
203+ def add_emission (self , chunksize = 2 ** 19 , chunkslice = 'bytes' ,
204+ comp_filter = default_compression ,
205+ overwrite = False , params = dict ()):
201206 """Add the `emission` array in '/trajectories'.
202207 """
203208 nparams = self .numeric_params
204209 num_particles = nparams ['np' ]
205210
206211 return self .add_trajectory ('emission' , shape = (num_particles , 0 ),
207212 overwrite = overwrite , chunksize = chunksize ,
213+ chunkslice = chunkslice ,
208214 comp_filter = comp_filter ,
209215 atom = tables .Float32Atom (),
210216 title = 'Emission trace of each particle' ,
@@ -224,13 +230,16 @@ def add_position(self, radial=False, chunksize=2**19, chunkslice='bytes',
224230 title = '%s position trace of each particle' % prefix
225231 return self .add_trajectory (name , shape = (num_particles , ncoords , 0 ),
226232 overwrite = overwrite , chunksize = chunksize ,
233+ chunkslice = chunkslice ,
227234 comp_filter = comp_filter ,
228235 atom = tables .Float32Atom (),
229236 title = title ,
230237 params = params )
231238
232239
233240class TimestampStore (BaseStore ):
241+ """An on-disk HDF5 store for timestamps.
242+ """
234243 def __init__ (self , datafile , path = './' , nparams = dict (), attr_params = dict (),
235244 mode = 'r' ):
236245 """Return a new HDF5 file to store simulation results.
@@ -248,7 +257,6 @@ def __init__(self, datafile, path='./', nparams=dict(), attr_params=dict(),
248257 attr_params = attr_params , mode = mode )
249258 if mode != 'r' :
250259 if 'timestamps' not in self .h5file .root :
251- # Create the groups
252260 self .h5file .create_group ('/' , 'timestamps' ,
253261 'Simulated timestamps' )
254262
0 commit comments