# Buggy code
def deposit(self, positions, fields=None, method=None, kernel_name="cubic"):
    r"""Operate on the mesh, in a particle-against-mesh fashion, with
    exclusively local input.

    This uses the octree indexing system to call a "deposition" operation
    (defined in yt/geometry/particle_deposit.pyx) that can take input from
    several particles (local to the mesh) and construct some value on the
    mesh.  The canonical example is to sum the total mass in a mesh cell
    and then divide by its volume.

    Parameters
    ----------
    positions : array_like (Nx3)
        The positions of all of the particles to be examined.  A new
        indexed octree will be constructed on these particles.
    fields : list of arrays
        All the necessary fields for computing the particle operation.  For
        instance, this might include mass, velocity, etc.
    method : string
        This is the "method name" which will be looked up in the
        `particle_deposit` namespace as `methodname_deposit`.  Current
        methods include `count`, `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. Current supported
        kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
        `wendland4`, and `wendland6`.

    Returns
    -------
    List of fortran-ordered, mesh-like arrays.
    """
    # Here we perform our particle deposition.
    if fields is None:
        fields = []
    cls = getattr(particle_deposit, "deposit_%s" % method, None)
    if cls is None:
        raise YTParticleDepositionNotImplemented(method)
    nz = self.nz
    nvals = (nz, nz, nz, (self.domain_ind >= 0).sum())
    # We allocate number of zones, not number of octs
    op = cls(nvals, kernel_name)
    op.initialize()
    mylog.debug(
        "Depositing %s (%s^3) particles into %s Octs",
        positions.shape[0],
        positions.shape[0] ** 0.3333333,
        nvals[-1],
    )
    pos = np.asarray(positions.convert_to_units("code_length"), dtype="float64")
    # We should not need the following if we know in advance all our fields
    # need no casting.
    fields = [np.asarray(f, dtype="float64") for f in fields]
    op.process_octree(
        self.oct_handler,
        self.domain_ind,
        pos,
        fields,
        self.domain_id,
        self._domain_offset,
    )
    vals = op.finalize()
    if vals is None:
        return
    return np.asfortranarray(vals)


# Traceback (ValueError)
In [1]: run vel_proj
yt : [INFO     ] 2017-01-17 15:27:33,808 Calculating time from 3.448e-01 to be 1.108e+17 seconds
yt : [INFO     ] 2017-01-17 15:27:33,808 Assuming length units are in kpc/h (comoving)
yt : [INFO     ] 2017-01-17 15:27:33,825 Parameters: current_time              = 1.10758107325e+17 s
yt : [INFO     ] 2017-01-17 15:27:33,825 Parameters: domain_dimensions         = [2 2 2]
yt : [INFO     ] 2017-01-17 15:27:33,825 Parameters: domain_left_edge          = [ 0.  0.  0.]
yt : [INFO     ] 2017-01-17 15:27:33,826 Parameters: domain_right_edge         = [ 64000.  64000.  64000.]
yt : [INFO     ] 2017-01-17 15:27:33,826 Parameters: cosmological_simulation   = 1
yt : [INFO     ] 2017-01-17 15:27:33,826 Parameters: current_redshift          = 1.89999652869
yt : [INFO     ] 2017-01-17 15:27:33,826 Parameters: omega_lambda              = 0.721
yt : [INFO     ] 2017-01-17 15:27:33,827 Parameters: omega_matter              = 0.279
yt : [INFO     ] 2017-01-17 15:27:33,827 Parameters: hubble_constant           = 0.7
yt : [INFO     ] 2017-01-17 15:27:33,830 Allocating for 1.191e+07 particles (index particle type 'all')
yt : [INFO     ] 2017-01-17 15:27:35,746 Identified 8.088e+05 octs
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/desika/Dropbox/scratch/vel_proj.py in <module>()
6
7 ds.add_deposited_particle_field( ('PartType0', 'particle_velocity_y'),"sum")
----> 8 print ad[('deposit', 'PartType0_sum_velocity_y')]
/Users/desika/yt/yt/data_objects/data_containers.pyc in __getitem__(self, key)
279                 return self.field_data[f]
280             else:
--> 281                 self.get_data(f)
282         # fi.units is the unit expression string. We depend on the registry
283         # hanging off the dataset to define this unit object.
/Users/desika/yt/yt/data_objects/data_containers.pyc in get_data(self, fields)
1331
1332         fields_to_generate += gen_fluids + gen_particles
-> 1333         self._generate_fields(fields_to_generate)
1334         for field in list(self.field_data.keys()):
1335             if field not in ofields:
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_fields(self, fields_to_generate)
1351                 fi = self.ds._get_field_info(*field)
1352                 try:
-> 1353                     fd = self._generate_field(field)
1354                     if fd is None:
1355                         raise RuntimeError
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_field(self, field)
316                 tr = self._generate_particle_field(field)
317             else:
--> 318                 tr = self._generate_fluid_field(field)
319             if tr is None:
320                 raise YTCouldNotGenerateField(field, self.ds)
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_fluid_field(self, field)
334             finfo.check_available(gen_obj)
335         except NeedsGridType as ngt_exception:
--> 336             rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)
337         else:
338             rv = finfo(gen_obj)
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_spatial_fluid(self, field, ngz)
354                     o = self._current_chunk.objs[0]
355                     with o._activate_cache():
--> 356                         ind += o.select(self.selector, self[field], rv, ind)
357         else:
358             chunks = self.index._chunk(self, "spatial", ngz = ngz)
/Users/desika/yt/yt/data_objects/data_containers.pyc in __getitem__(self, key)
279                 return self.field_data[f]
280             else:
--> 281                 self.get_data(f)
282         # fi.units is the unit expression string. We depend on the registry
283         # hanging off the dataset to define this unit object.
/Users/desika/yt/yt/data_objects/data_containers.pyc in get_data(self, fields)
1331
1332         fields_to_generate += gen_fluids + gen_particles
-> 1333         self._generate_fields(fields_to_generate)
1334         for field in list(self.field_data.keys()):
1335             if field not in ofields:
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_fields(self, fields_to_generate)
1351                 fi = self.ds._get_field_info(*field)
1352                 try:
-> 1353                     fd = self._generate_field(field)
1354                     if fd is None:
1355                         raise RuntimeError
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_field(self, field)
316                 tr = self._generate_particle_field(field)
317             else:
--> 318                 tr = self._generate_fluid_field(field)
319             if tr is None:
320                 raise YTCouldNotGenerateField(field, self.ds)
/Users/desika/yt/yt/data_objects/data_containers.pyc in _generate_fluid_field(self, field)
336             rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)
337         else:
--> 338             rv = finfo(gen_obj)
339         return rv
340
/Users/desika/yt/yt/fields/derived_field.pyc in __call__(self, data)
218                 "for %s" % (self.name,))
219         with self.unit_registry(data):
--> 220             dd = self._function(self, data)
221         for field_name in data.keys():
222             if field_name not in original_fields:
/Users/desika/yt/yt/data_objects/static_output.pyc in _deposit_field(field, data)
1215             else:
1216                 d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field]],
-> 1217                                              method=method, kernel_name=kernel_name),
1218                                              input_units=units)
1219             return d
/Users/desika/yt/yt/data_objects/octree_subset.pyc in deposit(self, positions, fields, method, kernel_name)
193         fields = [np.asarray(f, dtype="float64") for f in fields]
194         op.process_octree(self.oct_handler, self.domain_ind, pos, fields,
--> 195             self.domain_id, self._domain_offset)
196         vals = op.finalize()
197         if vals is None: return
/Users/desika/yt/yt/geometry/particle_deposit.pyx in yt.geometry.particle_deposit.ParticleDepositOperation.process_octree (yt/geometry/particle_deposit.c:4579)()
61         nf = len(fields)
62         cdef np.float64_t[::cython.view.indirect, ::1] field_pointers
---> 63         if nf > 0: field_pointers = OnceIndirect(fields)
64         cdef np.float64_t pos[3]
65         cdef np.float64_t[:] field_vals = np.empty(nf, dtype="float64")
ValueError: Buffer and memoryview are not contiguous in the same dimension.

# Fixed code
def deposit(self, positions, fields=None, method=None, kernel_name="cubic"):
    r"""Operate on the mesh, in a particle-against-mesh fashion, with
    exclusively local input.

    This uses the octree indexing system to call a "deposition" operation
    (defined in yt/geometry/particle_deposit.pyx) that can take input from
    several particles (local to the mesh) and construct some value on the
    mesh.  The canonical example is to sum the total mass in a mesh cell
    and then divide by its volume.

    Parameters
    ----------
    positions : array_like (Nx3)
        The positions of all of the particles to be examined.  A new
        indexed octree will be constructed on these particles.
    fields : list of arrays
        All the necessary fields for computing the particle operation.  For
        instance, this might include mass, velocity, etc.
    method : string
        This is the "method name" which will be looked up in the
        `particle_deposit` namespace as `methodname_deposit`.  Current
        methods include `count`, `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. Current supported
        kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
        `wendland4`, and `wendland6`.

    Returns
    -------
    List of fortran-ordered, mesh-like arrays.
    """
    # Here we perform our particle deposition.
    if fields is None:
        fields = []
    cls = getattr(particle_deposit, "deposit_%s" % method, None)
    if cls is None:
        raise YTParticleDepositionNotImplemented(method)
    nz = self.nz
    nvals = (nz, nz, nz, (self.domain_ind >= 0).sum())
    # We allocate number of zones, not number of octs
    op = cls(nvals, kernel_name)
    op.initialize()
    mylog.debug(
        "Depositing %s (%s^3) particles into %s Octs",
        positions.shape[0],
        positions.shape[0] ** 0.3333333,
        nvals[-1],
    )
    pos = np.asarray(positions.convert_to_units("code_length"), dtype="float64")
    # We should not need the following if we know in advance all our fields
    # need no casting.
    fields = [np.ascontiguousarray(f, dtype="float64") for f in fields]
    op.process_octree(
        self.oct_handler,
        self.domain_ind,
        pos,
        fields,
        self.domain_id,
        self._domain_offset,
    )
    vals = op.finalize()
    if vals is None:
        return
    return np.asfortranarray(vals)