yt.utilities.sdf module

class yt.utilities.sdf.DataStruct(dtypes, num, filename)[source]

Bases: object

docstring for DataStruct

build_memmap()[source]
set_offset(offset)[source]
class yt.utilities.sdf.HTTPDataStruct(*args, **kwargs)[source]

Bases: DataStruct

docstring for HTTPDataStruct

build_memmap()[source]
set_offset(offset)[source]
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_header()[source]

docstring for parse_header

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_particles(myiter, myfilter)[source]
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.

find_max_cell()[source]
find_max_cell_center()[source]
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_cell_width(level)[source]
get_contiguous_chunk(left_key, right_key, fields)[source]
get_data(chunk, fields)[source]
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_ind_from_key(key, dim='r')[source]
get_key(iarr, level=None)[source]
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_key_data(key, fields)[source]
get_key_ijk(i1, i2, i3, level=None)[source]
get_key_slow(iarr, level=None)[source]
get_keyv(iarr, level=None)[source]
get_next_nonzero_chunk(key, stop=None)[source]
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:

list

Examples

>>> chunks = midx.get_padded_bbox_data(
...     6, np.array([128] * 3), 8.0, ["x", "y", "z", "ident"]
... )
get_previous_nonzero_chunk(key, stop=None)[source]
get_slice_chunks(slice_dim, slice_index)[source]
get_slice_key(ind, dim='r')[source]
iter_bbox_data(left, right, fields)[source]

Iterate over all data within a bounding box defined by a left and a right.

iter_data(inds, fields)[source]
iter_filtered_bbox_fields(left, right, data, pos_fields, fields)[source]

This function should be destroyed, as it will only work with units.

iter_ibbox_data(left, right, fields)[source]
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

iter_slice_data(slice_dim, slice_index, fields)[source]
iter_sphere_data(center, radius, fields)[source]

Iterate over all data within some sphere defined by a center and a radius.

set_bounds()[source]
spread_bits(ival, level=None)[source]
spread_bitsv(ival, level=None)[source]
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
load_memmaps()[source]
parse_header()[source]

docstring for parse_header

parse_line(line, ascfile)[source]

Parse a line of sdf

parse_struct(line, ascfile)[source]
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()[source]
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)[source]
yt.utilities.sdf.bbox_filter(left, right, domain_width)[source]
yt.utilities.sdf.get_keyv(iarr, level)[source]
yt.utilities.sdf.get_thingking_deps()[source]
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"])
yt.utilities.sdf.sphere_filter(center, radius, domain_width)[source]
yt.utilities.sdf.spread_bitsv(ival, level)[source]