# Buggy code
def add_deposited_particle_field(
    self, deposit_field, method, kernel_name="cubic", weight_field="particle_mass"
):
    """Add a new deposited particle field

    Creates a new deposited field based on the particle *deposit_field*.

    Parameters
    ----------

    deposit_field : tuple
       The field name tuple of the particle field the deposited field will
       be created from.  This must be a field name tuple so yt can
       appropriately infer the correct particle type.
    method : string
       This is the "method name" which will be looked up in the
       `particle_deposit` namespace as `methodname_deposit`.  Current
       methods include `simple_smooth`, `sum`, `std`, `cic`, `weighted_mean`,
       `mesh_id`, and `nearest`.
    kernel_name : string, default 'cubic'
       This is the name of the smoothing kernel to use. It is only used for
       the `simple_smooth` method and is otherwise ignored. Current
       supported kernel names include `cubic`, `quartic`, `quintic`,
       `wendland2`, `wendland4`, and `wendland6`.
    weight_field : string, default 'particle_mass'
       Weighting field name for deposition method `weighted_mean`.

    Returns
    -------

    The field name tuple for the newly created field.
    """
    self.index
    if isinstance(deposit_field, tuple):
        ptype, deposit_field = deposit_field[0], deposit_field[1]
    else:
        raise RuntimeError

    units = self.field_info[ptype, deposit_field].units
    take_log = self.field_info[ptype, deposit_field].take_log
    name_map = {
        "sum": "sum",
        "std": "std",
        "cic": "cic",
        "weighted_mean": "avg",
        "nearest": "nn",
        "simple_smooth": "ss",
        "count": "count",
    }
    field_name = "%s_" + name_map[method] + "_%s"
    field_name = field_name % (ptype, deposit_field.replace("particle_", ""))

    if method == "count":
        field_name = "%s_count" % ptype
        if ("deposit", field_name) in self.field_info:
            mylog.warning("The deposited field %s already exists" % field_name)
            return ("deposit", field_name)
        else:
            units = "dimensionless"
            take_log = False

    def _deposit_field(field, data):
        """
        Create a grid field for particle quantities using given method.
        """
        pos = data[ptype, "particle_position"]
        if method == "weighted_mean":
            d = data.ds.arr(
                data.deposit(
                    pos,
                    [data[ptype, deposit_field], data[ptype, weight_field]],
                    method=method,
                    kernel_name=kernel_name,
                ),
                input_units=units,
            )
            d[np.isnan(d)] = 0.0
        else:
            d = data.ds.arr(
                data.deposit(
                    pos,
                    [data[ptype, deposit_field]],
                    method=method,
                    kernel_name=kernel_name,
                ),
                input_units=units,
            )
        return d

    self.add_field(
        ("deposit", field_name),
        function=_deposit_field,
        units=units,
        take_log=take_log,
        validators=[ValidateSpatial()],
    )
    return ("deposit", field_name)


# Traceback (ValueError)
jam:scratch desika$ python vel_proj_idealized.py
yt : [INFO     ] 2017-02-07 11:14:47,621 Omega Lambda is 0.0, so we are turning off Cosmology.
yt : [INFO     ] 2017-02-07 11:14:47,630 Parameters: current_time              = 0.25
yt : [INFO     ] 2017-02-07 11:14:47,630 Parameters: domain_dimensions         = [2 2 2]
yt : [INFO     ] 2017-02-07 11:14:47,631 Parameters: domain_left_edge          = [-1000. -1000. -1000.]
yt : [INFO     ] 2017-02-07 11:14:47,631 Parameters: domain_right_edge         = [ 1000.  1000.  1000.]
yt : [INFO     ] 2017-02-07 11:14:47,632 Parameters: cosmological_simulation   = 0
yt : [INFO     ] 2017-02-07 11:14:47,634 Allocating for 2.515e+07 particles (index particle type 'all')
yt : [INFO     ] 2017-02-07 11:14:51,665 Identified 1.540e+06 octs
[ 0.  0.  0. ...,  0.  0.  0.] code_velocity
Traceback (most recent call last):
File "vel_proj_idealized.py", line 23, in <module>
vy = arb[ ('deposit', 'PartType0_sum_velocity_y')]
File "/Users/desika/yt/yt/data_objects/data_containers.py", line 281, in __getitem__
self.get_data(f)
File "/Users/desika/yt/yt/data_objects/construction_data_containers.py", line 635, in get_data
if len(gen) > 0: self._generate_fields(gen)
File "/Users/desika/yt/yt/data_objects/data_containers.py", line 1353, in _generate_fields
fd = self._generate_field(field)
File "/Users/desika/yt/yt/data_objects/data_containers.py", line 318, in _generate_field
tr = self._generate_fluid_field(field)
File "/Users/desika/yt/yt/data_objects/data_containers.py", line 338, in _generate_fluid_field
rv = finfo(gen_obj)
File "/Users/desika/yt/yt/fields/derived_field.py", line 220, in __call__
dd = self._function(self, data)
File "/Users/desika/yt/yt/data_objects/static_output.py", line 1260, in _deposit_field
method=method, kernel_name=kernel_name),
File "/Users/desika/yt/yt/data_objects/construction_data_containers.py", line 728, in deposit
op.process_grid(self, positions, fields)
File "yt/geometry/particle_deposit.pyx", line 120, in yt.geometry.particle_deposit.ParticleDepositOperation.process_grid (yt/geometry/particle_deposit.c:5181)
ValueError: Buffer and memoryview are not contiguous in the same dimension.

# Fixed code
def add_deposited_particle_field(
    self, deposit_field, method, kernel_name="cubic", weight_field="particle_mass"
):
    """Add a new deposited particle field

    Creates a new deposited field based on the particle *deposit_field*.

    Parameters
    ----------

    deposit_field : tuple
       The field name tuple of the particle field the deposited field will
       be created from.  This must be a field name tuple so yt can
       appropriately infer the correct particle type.
    method : string
       This is the "method name" which will be looked up in the
       `particle_deposit` namespace as `methodname_deposit`.  Current
       methods include `simple_smooth`, `sum`, `std`, `cic`, `weighted_mean`,
       `mesh_id`, and `nearest`.
    kernel_name : string, default 'cubic'
       This is the name of the smoothing kernel to use. It is only used for
       the `simple_smooth` method and is otherwise ignored. Current
       supported kernel names include `cubic`, `quartic`, `quintic`,
       `wendland2`, `wendland4`, and `wendland6`.
    weight_field : string, default 'particle_mass'
       Weighting field name for deposition method `weighted_mean`.

    Returns
    -------

    The field name tuple for the newly created field.
    """
    self.index
    if isinstance(deposit_field, tuple):
        ptype, deposit_field = deposit_field[0], deposit_field[1]
    else:
        raise RuntimeError

    units = self.field_info[ptype, deposit_field].units
    take_log = self.field_info[ptype, deposit_field].take_log
    name_map = {
        "sum": "sum",
        "std": "std",
        "cic": "cic",
        "weighted_mean": "avg",
        "nearest": "nn",
        "simple_smooth": "ss",
        "count": "count",
    }
    field_name = "%s_" + name_map[method] + "_%s"
    field_name = field_name % (ptype, deposit_field.replace("particle_", ""))

    if method == "count":
        field_name = "%s_count" % ptype
        if ("deposit", field_name) in self.field_info:
            mylog.warning("The deposited field %s already exists" % field_name)
            return ("deposit", field_name)
        else:
            units = "dimensionless"
            take_log = False

    def _deposit_field(field, data):
        """
        Create a grid field for particle quantities using given method.
        """
        pos = data[ptype, "particle_position"]
        fields = [data[ptype, deposit_field]]
        if method == "weighted_mean":
            fields.append(data[ptype, weight_field])
        fields = [np.ascontiguousarray(f) for f in fields]
        d = data.deposit(pos, fields, method=method, kernel_name=kernel_name)
        d = data.ds.arr(d, input_units=units)
        if method == "weighted_mean":
            d[np.isnan(d)] = 0.0
        return d

    self.add_field(
        ("deposit", field_name),
        function=_deposit_field,
        units=units,
        take_log=take_log,
        validators=[ValidateSpatial()],
    )
    return ("deposit", field_name)