yt.utilities.sdf module¶
- class yt.utilities.sdf.DataStruct(dtypes, num, filename)[source]¶
Bases:
object
docstring for DataStruct
- class yt.utilities.sdf.HTTPDataStruct(*args, **kwargs)[source]¶
Bases:
DataStruct
docstring for HTTPDataStruct
- class yt.utilities.sdf.HTTPSDFRead(*args, **kwargs)[source]¶
Bases:
SDFRead
Read an SDF file hosted on the internet.
Given an SDF file (see https://bitbucket.org/JohnSalmon/sdf), parse the ASCII header and construct numpy memmap array access.
- Parameters:
filename (string) – The filename associated with the data to be loaded.
header (string, optional) – If separate from the data file, a file containing the header can be specified. Default: None.
- Returns:
self – Dict-like container of parameters and data.
- Return type:
SDFRead object
References
SDF is described here:
J. K. Salmon and M. S. Warren. Self-Describing File (SDF) Library. Zenodo, Jun 2014. URL https://bitbucket.org/JohnSalmon/sdf.
Examples
>>> sdf = SDFRead("data.sdf", header="data.hdr") >>> print(sdf.parameters) >>> print(sdf["x"])
- clear() None. Remove all items from D. ¶
- copy()¶
- classmethod fromkeys(iterable, value=None)¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- load_memmaps()¶
- parse_line(line, ascfile)¶
Parse a line of sdf
- parse_struct(line, ascfile)¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- set_offsets()¶
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶
- write(filename)¶
- class yt.utilities.sdf.RedirectArray(http_array, key)[source]¶
Bases:
object
docstring for RedirectArray
- class yt.utilities.sdf.SDFIndex(sdfdata, indexdata, level=None)[source]¶
Bases:
object
docstring for SDFIndex
This provides an index mechanism into the full SDF Dataset.
- Most useful class methods:
get_cell_data(level, cell_iarr, fields) iter_bbox_data(left, right, fields) iter_bbox_data(left, right, fields)
- filter_bbox(left, right, myiter)[source]¶
Filter data by masking out data outside of a bbox defined by left/right. Account for periodicity of data, allowing left/right to be outside of the domain.
- filter_sphere(center, radius, myiter)[source]¶
Filter data by masking out data outside of a sphere defined by a center and radius. Account for periodicity of data, allowing left/right to be outside of the domain.
- get_bbox(left, right)[source]¶
Given left and right indices, return a mask and set of offsets+lengths into the sdf data.
- get_cell_bbox(level, cell_iarr)[source]¶
Get floating point bounding box for a given midx cell
- Returns:
array-like of shape (3,2)
- Return type:
bbox
- get_cell_data(level, cell_iarr, fields)[source]¶
Get data from requested cell
This uses the raw cell index, and doesn’t account for periodicity or an expanded domain (non-power of 2).
- level: int
Requested level
- cell_iarr: array-like, length 3
Requested cell from given level. fields: list Requested fields
- Returns:
- dict
Dictionary of field_name, field_data
- Return type:
cell_data
- get_ibbox(ileft, iright)[source]¶
Given left and right indices, return a mask and set of offsets+lengths into the sdf data.
- get_ibbox_slow(ileft, iright)[source]¶
Given left and right indices, return a mask and set of offsets+lengths into the sdf data.
- get_key_bounds(level, cell_iarr)[source]¶
Get index keys for index file supplied.
- level: int
Requested level
- cell_iarr: array-like, length 3
Requested cell from given level.
- Returns:
lmax_lk, lmax_rk
- get_nparticles_bbox(left, right)[source]¶
Given left and right edges, return total number of particles present.
- get_padded_bbox_data(level, cell_iarr, pad, fields)[source]¶
Return list of data chunks for a cell on the given level plus a padding around the cell, for a list of fields.
- Returns:
data – A list of dictionaries of data.
- Return type:
Examples
>>> chunks = midx.get_padded_bbox_data( ... 6, np.array([128] * 3), 8.0, ["x", "y", "z", "ident"] ... )
- iter_bbox_data(left, right, fields)[source]¶
Iterate over all data within a bounding box defined by a left and a right.
- iter_filtered_bbox_fields(left, right, data, pos_fields, fields)[source]¶
This function should be destroyed, as it will only work with units.
- iter_padded_bbox_data(level, cell_iarr, pad, fields)[source]¶
Yields data chunks for a cell on the given level plus a padding around the cell, for a list of fields.
- Yields:
dd – A dictionaries of data.
Example:
- for chunk in midx.iter_padded_bbox_data(
6, np.array([128]*3), 8.0, [‘x’,’y’,’z’,’ident’]):
print(chunk[‘x’].max())
- iter_padded_bbox_keys(level, cell_iarr, pad)[source]¶
- Returns:
array-like of shape (3,2)
- Return type:
bbox
- class yt.utilities.sdf.SDFRead(filename=None, header=None)[source]¶
Bases:
UserDict
- clear() None. Remove all items from D. ¶
- copy()¶
- classmethod fromkeys(iterable, value=None)¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶
- yt.utilities.sdf.load_sdf(filename, header=None)[source]¶
Load an SDF file.
Given an SDF file (see https://bitbucket.org/JohnSalmon/sdf), parse the ASCII header and construct numpy memmap array access. The file can be either local (on a hard drive, for example), or remote (on the World Wide Web).
- Parameters:
filename (string) – The filename or WWW address associated with the data to be loaded.
header (string, optional) – If separate from the data file, a file containing the header can be specified. Default: None.
- Returns:
sdf – Dict-like container of parameters and data.
- Return type:
SDFRead object
References
SDF is described here:
J. K. Salmon and M. S. Warren. Self-Describing File (SDF) Library. Zenodo, Jun 2014. URL https://bitbucket.org/JohnSalmon/sdf.
Examples
>>> sdf = SDFRead("data.sdf", header="data.hdr") >>> print(sdf.parameters) >>> print(sdf["x"])