Ejemplo n.º 1
0
def add_interpolated_field(name,
                           units,
                           table_data,
                           axes_data,
                           axes_fields,
                           ftype="gas",
                           particle_type=False,
                           validators=None,
                           truncate=True):

    if len(table_data.shape) not in _int_class:
        raise RuntimeError(
            "Interpolated field can only be created from 1d, 2d, or 3d data.")

    if len(axes_fields) != len(axes_data) or len(axes_fields) != len(
            table_data.shape):
        raise RuntimeError(
            "Data dimension mismatch: data is %d, %d axes data provided, and %d axes fields provided."
            % (len(table_data.shape), len(axes_data), len(axes_fields)))

    int_class = _int_class[len(table_data.shape)]
    my_interpolator = int_class(table_data,
                                axes_data,
                                axes_fields,
                                truncate=truncate)

    def _interpolated_field(field, data):
        return my_interpolator(data)

    add_field((ftype, name),
              function=_interpolated_field,
              units=units,
              validators=validators,
              particle_type=particle_type)
Ejemplo n.º 2
0
def setup():
    return
    from yt.config import ytcfg
    ytcfg["yt","__withintesting"] = "True"
    def _ID(field, data):
        width = data.ds.domain_right_edge - data.ds.domain_left_edge
        min_dx = YTArray(1.0/8192, input_units='code_length',
                         registry=data.ds.unit_registry)
        delta = width / min_dx
        x = data['x'] - min_dx / 2.
        y = data['y'] - min_dx / 2.
        z = data['z'] - min_dx / 2.
        xi = x / min_dx
        yi = y / min_dx
        zi = z / min_dx
        index = xi + delta[0] * (yi + delta[1] * zi)
        index = index.astype('int64')
        return index

    add_field("ID", function=_ID)
def add_interpolated_field(name, units, table_data, axes_data, axes_fields,
                           ftype="gas", particle_type=False, validators=None,
                           truncate=True):
    
    if len(table_data.shape) not in _int_class:
        raise RuntimeError("Interpolated field can only be created from 1d, 2d, or 3d data.")

    if len(axes_fields) != len(axes_data) or len(axes_fields) != len(table_data.shape):
        raise RuntimeError("Data dimension mismatch: data is %d, %d axes data provided, and %d axes fields provided." %
                           (len(table_data.shape), len(axes_data), len(axes_fields)))

    int_class = _int_class[len(table_data.shape)]
    my_interpolator = int_class(table_data, axes_data, axes_fields, truncate=truncate)

    def _interpolated_field(field, data):
        return my_interpolator(data)
    add_field((ftype, name), 
              function=_interpolated_field,
              units=units,
              validators=validators, particle_type=particle_type)