positions and velocities for various coordinate systems. Fixes #966

#1381 Merged at def04a2
Repository
ngoldbaum
Branch
yt
Repository
yt_analysis
Branch
yt
Author
  1. Nathan Goldbaum
Reviewers
Description

This PR is a continuation from Benjamin Thompson's PR 1308.

  • The fields currently in yt with names like particle_spherical_position_radius return incorrect results. See #966. This PR ensures these fields return correct results.

  • Adds new particle_position_relative and particle_velocity_relative fields. This makes it possible to get particle positions and velocities in a rotated reference frame.

  • The naming system for particle and mesh vector fields has never been codified. In this PR I implement a proposed naming system.

Particle vector fields will be of the form:

particle_<vector field name>_coordinate

While mesh vector fields should have names following:

<vector_field_name>_coordinate

So the spherical radius particle position field becomes particle_position_spherical_radius. The main advantage is that this matches our current naming system for cartesian coordinates (e.g. particle_position_x, particle_velocity_y).

Where there are fields that are currently in yt that have names that do not match this naming convention, I've stubbed out their implementation and made them aliases for the fields with names following my proposed naming convention. I've also marked these stub fields as deprecated in their docstrings. In a few places (particularly in the fluid velocity fields), I've opted to leave the old fields behind without marking them as deprecated. There are mostly commonly used fields like radial_velocity, which is now just an alias for velocity_spherical_r.

Let me know if you disagree with any decisions I've made about field deprecation.

When no field already existed (e.g. the position fields in cylindrical coordinates), I've simply added the new fields following my proposed naming convention without adding fields that would immediately need to be deprecated.

Update: I've updated this so that all the index and gas velocity fields match the naming convention used for the particle fields.

Comments (3)

  1. Andrew Myers

    Other than my highly tedious docstring complaints, I tried this out and it seems to work as advertised. Looks good to me.

  2. Benjamin Thompson

    Just thinking, for a later PR (which I would be happy to work on). We could probably condense down the number of lines of code (especially after adding the relative fields) by calling again

    def standard_particle_fields(registry, ptype,
                                 spos = "particle_position_%s",
                                 svel = "particle_velocity_%s"):
    

    with something like this

    def standard_particle_fields(registry, ptype,
                                 spos = "particle_position_%s_%s",
                                 svel = "particle_velocity_%s_%s"):
                                 reference = "relative"
    

    So rather than having

     def _particle_specific_angular_momentum_z(field, data):
            if data.has_field_parameter("bulk_velocity"):
                bv = data.get_field_parameter("bulk_velocity")
            else: bv = np.zeros(3, dtype=np.float64)
            center = data.get_field_parameter('center')
            x = data[ptype, spos % "x"] - center[0]
            y = data[ptype, spos % "y"] - center[1]
            xv = data[ptype, svel % "x"] - bv[0]
            yv = data[ptype, svel % "y"] - bv[1]
            return xv*y - yv*x
    

    we could have

     def _particle_specific_angular_momentum_z(field, data):
            if data.has_field_parameter("bulk_velocity"):
                bv = data.get_field_parameter("bulk_velocity")
            else: bv = np.zeros(3, dtype=np.float64)
            center = data.get_field_parameter('center')
            if extra = "relative"
                  normal = data.get_field_parameter
                  x = data[ptype, spos % extra, "x"] - center[0]
                  y = data[ptype, spos % extra, "y"] - center[1]
                  xv = data[ptype, svel % extra, "x"] - bv[0]
                  yv = data[ptype, svel % extra, "y"] - bv[1]
            else:
                  x = data[ptype, spos % "x"] - center[0]
                  y = data[ptype, spos % "y"] - center[1]
                  xv = data[ptype, svel % "x"] - bv[0]
                  yv = data[ptype, svel % "y"] - bv[1]
            return xv*y - yv*x
    
    
      registry.add_field((ptype, "particle_%s_specific_angular_momentum_z" % extra),
                  function=_particle_specific_angular_momentum_z,
                  particle_type=True,
                  units="cm**2/s",
                  validators=[ValidateParameter("center")])
    

    Definatly for another PR. Bonus points if it also rotates the deposit fields around too :)