original_docstring: 
      This program is a high-level encapsulation of all of the gridding typically
      used by one of the probe programs. 
      
      The default output of this function is: 
           shotgridind, xaxis, yaxis, zaxis, nx, ny, nz, nreps, nshots
           
      Where shotgridind is an array [nshots, 4]
      where each shot entry contains [xind, yind, zind, irep]. These indicies can
      then be used to place shot data in the correct grid locations.
      
      pos (array): Position array from the source file [nshots, 3] where the
      third dimension is xyz
  
      attrs (dict): Attribute dictionary for the dataset. Used to get probe
      origin, etc.
      
      strict_axes: If true, strict axis creation will be used.
      
      strict_grid: If true, strict gridding will be used. 
      
      grid_precision (float): If fuzzy gridding is used, values will be rounded
      to this precision before sorting into the grid.
      
      invert (bool): If true, returns an 'inverted' version of the shotgridind
      array which has size [nx, ny, nz, nreps], and each value in the array is
      the shot number that belongs there. This is useful when you need to load
      all reps at once, eg. if you need to average Langmuir traces prior to 
      the full analysis phase.
      
      
      
      
docstring: This program is a high-level encapsulation of all of the gridding typically
  used by one of the probe programs.
  
  The default output of this function is:
  shotgridind, xaxis, yaxis, zaxis, nx, ny, nz, nreps, nshots
  
  
  
  pos (array): Position array from the source file [nshots, 3] where the
  third dimension is xyz
  
  attrs (dict): Attribute dictionary for the dataset. Used to get probe
  origin, etc.
  
  If true, strict axis creation will be used.
  
  If true, strict gridding will be used.
  
  grid_precision (float): If fuzzy gridding is used, values will be rounded
  to this precision before sorting into the grid.
  
  invert (bool): If true, returns an 'inverted' version of the shotgridind
  array which has size [nx, ny, nz, nreps], and each value in the array is
  the shot number that belongs there. This is useful when you need to load
  all reps at once, eg. if you need to average Langmuir traces prior to
  the full analysis phase.
docstring_tokens: This program is a high - level encapsulation of all of the gridding typically used by one of the probe programs . The default output of this function is : shotgridind xaxis yaxis zaxis nx ny nz nreps nshots pos ( array ) : Position array from the source file [ nshots 3 ] where the third dimension is xyz attrs ( dict ) : Attribute dictionary for the dataset . Used to get probe origin etc . If true strict axis creation will be used . If true strict gridding will be used . grid_precision ( float ) : If fuzzy gridding is used values will be rounded to this precision before sorting into the grid . invert ( bool ) : If true returns an ' inverted ' version of the shotgridind array which has size [ nx ny nz nreps ] and each value in the array is the shot number that belongs there . This is useful when you need to load all reps at once eg . if you need to average Langmuir traces prior to the full analysis phase .
code: def grid(pos, attrs, strict_axes=False, strict_grid=False, grid_precision=0.1,
           invert=False):
      """
      This program is a high-level encapsulation of all of the gridding typically
      used by one of the probe programs. 
      
      The default output of this function is: 
           shotgridind, xaxis, yaxis, zaxis, nx, ny, nz, nreps, nshots
           
      Where shotgridind is an array [nshots, 4]
      where each shot entry contains [xind, yind, zind, irep]. These indicies can
      then be used to place shot data in the correct grid locations.
      
      pos (array): Position array from the source file [nshots, 3] where the
      third dimension is xyz
  
      attrs (dict): Attribute dictionary for the dataset. Used to get probe
      origin, etc.
      
      strict_axes: If true, strict axis creation will be used.
      
      strict_grid: If true, strict gridding will be used. 
      
      grid_precision (float): If fuzzy gridding is used, values will be rounded
      to this precision before sorting into the grid.
      
      invert (bool): If true, returns an 'inverted' version of the shotgridind
      array which has size [nx, ny, nz, nreps], and each value in the array is
      the shot number that belongs there. This is useful when you need to load
      all reps at once, eg. if you need to average Langmuir traces prior to 
      the full analysis phase.
      
      
      
      """
  
      req_keys = []
          
      #Determine the motion format: default is cartesian
      if 'motion_format' in attrs.keys():
          motion_format = attrs['motion_format'][0]
      else:
          attrs['motion_format'] = 'cartesian'
        
      #Require any necessary keywords
      if motion_format == 'cartesian':
          pass
      elif motion_format == 'fixed_pivot':
          req_keys = req_keys + ['rot_center_x', 'rot_center_y', 'rot_center_z']
          
          
          
      csvtools.missingKeys(attrs, req_keys, fatal_error=True)
          
          
      #Set default values for keywords if they aren't present
      
      #origin is the location of the probe's origin in the main coordinates system
      origin = np.zeros(3)
      origin_keys = ['probe_origin_x','probe_origin_y','probe_origin_z']
      for i, key in enumerate(origin_keys):
           if key in attrs.keys():
                origin[i] = attrs[key][0]
           else:
                origin[i] = 0.0
  
      #probe_ax pol is the polarization of the probe's axes relative to the main
      #coordinates. 1 means they are aligned, -1 means anti-aligned.
      ax_pol = np.ones(3)
      ax_pol_keys = ['ax_pol_x','ax_pol_y','ax_pol_z']
      for i, key in enumerate(ax_pol_keys):
           if key in attrs.keys():
                ax_pol[i] = attrs[key][0]
           else:
                ax_pol[i] = 1
      
  
      #Adjust the probe for the origin and possible direction reversal
      pos[:,0] = pos[:,0]*ax_pol[0] + origin[0]
      pos[:,1] = pos[:,1]*ax_pol[1] + origin[1]
      pos[:,2] = pos[:,2]*ax_pol[2] + origin[2]
          
  
      #Generate the grid axes
      #TODO support non-cartesian axis gridding here? With a keyword or something?
      if strict_axes is True:
          try:
              print("Applying stric axis creation")
              nx = attrs['nx'][0]
              ny = attrs['ny'][0]
              nz = attrs['nz'][0]
              dx = attrs['dx'][0]
              dy = attrs['dy'][0]
              dz = attrs['dz'][0]
              x0 = attrs['x0'][0]
              y0 = attrs['y0'][0]
              z0 = attrs['z0'][0]
              xaxis, yaxis, zaxis = makeAxes(nx,ny,nz,
                                                      dx,dy,dz,
                                                      x0,y0,z0)
              
              #Apply these transformations to the made axes
              xaxis = xaxis*ax_pol[0] + origin[0]
              yaxis = yaxis*ax_pol[1] + origin[1]
              zaxis = zaxis*ax_pol[2] + origin[2]
              
          except KeyError:
              print("Missing axis parameters: attempting fuzzy axis creation")
              #Continue through to the strict_axes =False case if this happens
              strict_axes = False
                      
      if strict_axes is False:
          print("Applying fuzzy axis creation")
          xaxis,yaxis,zaxis = guessAxes(pos, precision=grid_precision)
          
                  
      #Calculate length of axes
      nx, ny, nz, nreps = calcNpoints(pos, xaxis, yaxis, zaxis)
              
  
              
      #This line SHOULD be redundent, but sometimes it's necessary.
      #It is possible, when combining two motion lists, to get
      #some extra shots at the end of the datarun that don't have
      #positions associated. Recalculating this here ensures we only
      #take the ones relevant to this grid
      nshots = nx*ny*nz*nreps
              
      #If grid precision is zero, apply strict gridding
      #Otherwise, apply fuzzy gridding
      if strict_grid:
          print("Applying strict gridding")
          shotgridind = strictGrid(nx,ny,nz,nreps)  
      else:
          print("Applying fuzzy gridding")
          shotgridind = fuzzyGrid(pos, xaxis, yaxis, zaxis, 
                                           precision=grid_precision)
          
          
      if invert:
           shotgridind = invertShotGrid(shotgridind, xaxis, yaxis, zaxis)
  
      return shotgridind, xaxis, yaxis, zaxis, nx, ny, nz, nreps, nshots
code_tokens: def grid ( pos , attrs , strict_axes = False , strict_grid = False , grid_precision = 0.1 , invert = False ) : req_keys = [ ] if 'motion_format' in attrs . keys ( ) : motion_format = attrs [ 'motion_format' ] [ 0 ] else : attrs [ 'motion_format' ] = 'cartesian' if motion_format == 'cartesian' : pass elif motion_format == 'fixed_pivot' : req_keys = req_keys + [ 'rot_center_x' , 'rot_center_y' , 'rot_center_z' ] csvtools . missingKeys ( attrs , req_keys , fatal_error = True ) origin = np . zeros ( 3 ) origin_keys = [ 'probe_origin_x' , 'probe_origin_y' , 'probe_origin_z' ] for i , key in enumerate ( origin_keys ) : if key in attrs . keys ( ) : origin [ i ] = attrs [ key ] [ 0 ] else : origin [ i ] = 0.0 ax_pol = np . ones ( 3 ) ax_pol_keys = [ 'ax_pol_x' , 'ax_pol_y' , 'ax_pol_z' ] for i , key in enumerate ( ax_pol_keys ) : if key in attrs . keys ( ) : ax_pol [ i ] = attrs [ key ] [ 0 ] else : ax_pol [ i ] = 1 pos [ : , 0 ] = pos [ : , 0 ] * ax_pol [ 0 ] + origin [ 0 ] pos [ : , 1 ] = pos [ : , 1 ] * ax_pol [ 1 ] + origin [ 1 ] pos [ : , 2 ] = pos [ : , 2 ] * ax_pol [ 2 ] + origin [ 2 ] if strict_axes is True : try : print ( "Applying stric axis creation" ) nx = attrs [ 'nx' ] [ 0 ] ny = attrs [ 'ny' ] [ 0 ] nz = attrs [ 'nz' ] [ 0 ] dx = attrs [ 'dx' ] [ 0 ] dy = attrs [ 'dy' ] [ 0 ] dz = attrs [ 'dz' ] [ 0 ] x0 = attrs [ 'x0' ] [ 0 ] y0 = attrs [ 'y0' ] [ 0 ] z0 = attrs [ 'z0' ] [ 0 ] xaxis , yaxis , zaxis = makeAxes ( nx , ny , nz , dx , dy , dz , x0 , y0 , z0 ) xaxis = xaxis * ax_pol [ 0 ] + origin [ 0 ] yaxis = yaxis * ax_pol [ 1 ] + origin [ 1 ] zaxis = zaxis * ax_pol [ 2 ] + origin [ 2 ] except KeyError : print ( "Missing axis parameters: attempting fuzzy axis creation" ) strict_axes = False if strict_axes is False : print ( "Applying fuzzy axis creation" ) xaxis , yaxis , zaxis = guessAxes ( pos , precision = grid_precision ) nx , ny , nz , nreps = calcNpoints ( pos , xaxis , yaxis , zaxis ) nshots = nx * ny * nz * nreps if strict_grid : print ( "Applying strict gridding" ) shotgridind = strictGrid ( nx , ny , nz , nreps ) else : print ( "Applying fuzzy gridding" ) shotgridind = fuzzyGrid ( pos , xaxis , yaxis , zaxis , precision = grid_precision ) if invert : shotgridind = invertShotGrid ( shotgridind , xaxis , yaxis , zaxis ) return shotgridind , xaxis , yaxis , zaxis , nx , ny , nz , nreps , nshots
short_docstring: This program is a high-level encapsulation of all of the gridding typically
  used by one of the probe programs.
short_docstring_tokens: This program is a high - level encapsulation of all of the gridding typically used by one of the probe programs .
comment: """
      This program is a high-level encapsulation of all of the gridding typically
      used by one of the probe programs. 
      
      The default output of this function is: 
           shotgridind, xaxis, yaxis, zaxis, nx, ny, nz, nreps, nshots
           
      Where shotgridind is an array [nshots, 4]
      where each shot entry contains [xind, yind, zind, irep]. These indicies can
      then be used to place shot data in the correct grid locations.
      
      pos (array): Position array from the source file [nshots, 3] where the
      third dimension is xyz
  
      attrs (dict): Attribute dictionary for the dataset. Used to get probe
      origin, etc.
      
      strict_axes: If true, strict axis creation will be used.
      
      strict_grid: If true, strict gridding will be used. 
      
      grid_precision (float): If fuzzy gridding is used, values will be rounded
      to this precision before sorting into the grid.
      
      invert (bool): If true, returns an 'inverted' version of the shotgridind
      array which has size [nx, ny, nz, nreps], and each value in the array is
      the shot number that belongs there. This is useful when you need to load
      all reps at once, eg. if you need to average Langmuir traces prior to 
      the full analysis phase.
      
      
      
      """$SEP$#Determine the motion format: default is cartesian
  $SEP$#Require any necessary keywords
  $SEP$#Set default values for keywords if they aren't present
  $SEP$#origin is the location of the probe's origin in the main coordinates system
  $SEP$#probe_ax pol is the polarization of the probe's axes relative to the main
  $SEP$#coordinates. 1 means they are aligned, -1 means anti-aligned.
  $SEP$#Adjust the probe for the origin and possible direction reversal
  $SEP$#Generate the grid axes
  $SEP$#TODO support non-cartesian axis gridding here? With a keyword or something?
  $SEP$#Apply these transformations to the made axes
  $SEP$#Continue through to the strict_axes =False case if this happens
  $SEP$#Calculate length of axes
  $SEP$#This line SHOULD be redundent, but sometimes it's necessary.
  $SEP$#It is possible, when combining two motion lists, to get
  $SEP$#some extra shots at the end of the datarun that don't have
  $SEP$#positions associated. Recalculating this here ensures we only
  $SEP$#take the ones relevant to this grid
  $SEP$#If grid precision is zero, apply strict gridding
  $SEP$#Otherwise, apply fuzzy gridding
  