def __init__(self,config_filepath=None,config=None,section="field parameters",
               time_dependent_function=None, scale=1.0, normalize=None, **kwargs):
    """
    Loads the config_filepath and puts the elements into the objects attributes.
    Also loads and saves the fields. 
    Args:
      config_filepath: filepath to the config file for the field.  Either this or the
        config object needs to be present.
      config: A config parser object.  Allows the reading of this data from an existent
        config parser object.
      section: The name of the section in the filepath with the field info.  Default
        is field parameters.
    Attributes:
      fields: A dict first pointing to the type of field (i.e. electric 
        or magnetic) then pointing to components of the field.
      stepsize: A dict containing the stepsize of each of the coordinates key
        by the coordinate.
      number_of_steps: A dict containing the number of steps of each of the coordinates key
        by the coordinate.
      zmin: The minimum value of the z coordinate in the filepath.
      zmax: The max z in the field.
      zlen: The length over which the field is applied.
      current_position: The position of the center of mass of the pulse
        to be used if a distance needs to be calculated.
      time_dependent_function: An option function callback (function is a function of top.time)
        that can add time dependence to the field.  Default is no such function.
      scale: An option that provides a hook to scale the field(s) being loaded.
    """
    if config_filepath is None and config is None:
      raise Exception("Either the config_filepath needs to be specified or a config parser object " + 
                      "needs to be passed to the init function.")
    if config is None:
      config = ConfigParser()
      config.read(config_filepath)
    self.config = config
    self.section = section
    
    self.xmin = config.get(section,"xmin")
    self.ymin = config.get(section,"ymin")
    self.zmin = config.get(section,"zmin")
    self.zmax = config.get(section,"zmax")
    self.zlen = config.get(section,"zlen")

    self.stepsize = {}
    self.number_of_steps = {}
    self.fields = {}
    for option in config.options(section):
      if option.startswith("d"):
        self.stepsize[option.replace("d","")] = config.get(section,option)
      if option.startswith("n"):
        self.number_of_steps[option.replace("n","")] = config.get(section,option)
      if option.endswith("_pickled_field"):
        field_type = option.replace("_pickled_field","")
        self.fields[field_type] = pickle.load( open(config.get(section,option), "rb") )
        for component in self.fields[field_type]:
          self.fields[field_type][component] = scale*np.array(self.fields[field_type][component],order="FORTRAN")
    self.time_dependent_function = time_dependent_function
Beispiel #2
0
  def __init__(self,config_filepath=None,config=None,section="field parameters",
               time_dependent_function=None, **kwargs):
    """
    Loads the config_filepath and puts the elements into the objects attributes.
    Also loads and saves the fields. 
    Args:
      config_filepath: filepath to the config file for the field.  Either this or the
        config object needs to be present.
      config: A config parser object.  Allows the reading of this data from an existent
        config parser object.
      section: The name of the section in the filepath with the field info.  Default
        is field parameters.
    Attributes:
      fields: A dict first pointing to the type of field (i.e. electric 
        or magnetic) then pointing to components of the field.
      stepsize: A dict containing the stepsize of each of the coordinates key
        by the coordinate.
      number_of_steps: A dict containing the number of steps of each of the coordinates key
        by the coordinate.
      zmin: The minimum value of the z coordinate in the filepath.
      zmax: The max z in the field.
      zlen: The length over which the field is applied.
      current_position: The position of the center of mass of the pulse
        to be used if a distance needs to be calculated.
      time_dependent_function: An option function callback (function is a function of top.time)
        that can add time dependence to the field.  Default is no such function.
    """
    if config_filepath is None and config is None:
      raise Exception("Either the config_filepath needs to be specified or a config parser object " + 
                      "needs to be passed to the init function.")
    if config is None:
      config = ConfigParser()
      config.read(config_filepath)
    self.config = config
    self.section = section
    
    self.xmin = config.get(section,"xmin")
    self.ymin = config.get(section,"ymin")
    self.zmin = config.get(section,"zmin")
    self.zmax = config.get(section,"zmax")
    self.zlen = config.get(section,"zlen")

    self.stepsize = {}
    self.number_of_steps = {}
    self.fields = {}
    for option in config.options(section):
      if option.startswith("d"):
        self.stepsize[option.replace("d","")] = config.get(section,option)
      if option.startswith("n"):
        self.number_of_steps[option.replace("n","")] = config.get(section,option)
      if option.endswith("_pickled_field"):
        field_type = option.replace("_pickled_field","")
        self.fields[field_type] = pickle.load( open(config.get(section,option), "rb") )
        for component in self.fields[field_type]:
          self.fields[field_type][component] = np.array(self.fields[field_type][component],order="FORTRAN")
    self.time_dependent_function = time_dependent_function