docstr: When cutoff_factor is used, it will pool more site than cutoff
  factor specifies. This will rule out non-relevant sites by distance.
  
  Parameters
  ----------
  env_ref: _SiteEnvironment
      Site information of the primitive cell
  env: Dict[str, Any]
      Site information of the data point
  
  Returns
  -------
  env: Dict[str, Union[list, np.ndarray]]
docstr_tok: ["When","cutoff_factor","is","used",",","it","will","pool","more","site","than","cutoff","factor","specifies",".","This","will","rule","out","non-relevant","sites","by","distance",".","Parameters","--","--","--","--","--","env_ref",":","_SiteEnvironment","Site","information","of","the","primitive","cell","env",":","Dict","[","str",",","Any","]","Site","information","of","the","data","point","Returns","--","--","--","-","env",":","Dict","[","str",",","Union","[","list",",","np.ndarray","]","]"]
code: def _truncate(
      cls, env_ref: _SiteEnvironment, env: Dict[str, Any]
  ) -> Dict[str, Any]:
      """
      When cutoff_factor is used, it will pool more site than cutoff
      factor specifies. This will rule out non-relevant sites by distance.
  
      Parameters
      ----------
      env_ref: _SiteEnvironment
          Site information of the primitive cell
      env: Dict[str, Any]
          Site information of the data point
  
      Returns
      -------
      env: Dict[str, Union[list, np.ndarray]]
      """
      # Extract the right number of sites by distance
      dists = defaultdict(list)
      for i, s in enumerate(env["sitetypes"]):
          dists[s].append([i, env["dist"][i]])
      for s in dists:
          dists[s] = sorted(dists[s], key=lambda x: x[1])
      siteidx = []
      for s in dists:
          siteidx += [i[0] for i in dists[s][: env_ref.formula[s]]]
      siteidx = sorted(siteidx)
      env["pos"] = [
          env["pos"][i] for i in range(len(env["pos"])) if i in siteidx
      ]
  
      env["pos"] = np.subtract(env["pos"], np.mean(env["pos"], 0))
      env["sitetypes"] = [
          env["sitetypes"][i]
          for i in range(len(env["sitetypes"]))
          if i in siteidx
      ]
      env["env2config"] = [env["env2config"][i] for i in siteidx]
      del env["dist"]
      return env
  
imports: import numpy
  import logging
  from deepchem.feat import MaterialStructureFeaturizer
  from collections import defaultdict
  from typing import List, Dict, Tuple, DefaultDict, Any
  from deepchem.utils.typing import PymatgenStructure
  from deepchem.feat.graph_data import GraphData
  from scipy.spatial.distance import pdist, squareform, cdist
  from scipy.spatial.transform import Rotation
label_desc: Use image node_id 3 for calling the _SiteEnvironments obj's underlying member method code with example usage: obj._truncate(cls, env_ref, env) and returns: env