def __init__(self, pp=None): """ A class to wrap the SWIG-wrapped ``lalpulsar.PulsarParameters`` structure. This class lets you access the structure in a more Pythonic way, as well as providing a nice format for holding pulsar (``.par``) parameter files. The class can be used to set numerical values (double precision, unsigned integers), strings, or vectors of floating point values, e.g.: >>> pp = PulsarParameters() # an empty structure >>> pp['DECJ'] = 0.23 # set a numerical value >>> pp['BINARY'] = 'BT' # set a string value >>> pp['F'] = [10.2, 1.4e-11] # set a vector of float values Examples -------- An example of initialising the class using a parameter file is: >>> pppy = PulsarParameters('apulsar.par') or, equivalently with: >>> pppy = PulsarParameters() >>> pppy.read('apulsar.par') Parameters ---------- pp: PulsarParameters, str A ``lalpulsar.PulsarParameters`` structure, or a string giving the path to a Tempo-style (``.par``) pulsar parameter file. If nothing is given then an empty :class:`~cwinpy.parfile.PulsarParameters` structure is created. The :meth:`~cwinpy.parfile.PulsarParameters.read` method can subsequently be used to read in a ``.par`` file, or parameters can be added. """ # if pp is None create empty PulsarParameters structure if pp is None: self._pulsarparameters = lalpulsar.PulsarParameters() else: # check if pp is a pulsar parameters type or a (par file) if not isinstance(pp, lalpulsar.PulsarParameters) and ( isinstance(pp, str) or isinstance(pp, pathlib.Path) ): if os.path.isfile(pp): # try reading in file self.read(pp) else: raise ValueError("Input string does not point to a file") elif isinstance(pp, lalpulsar.PulsarParameters): self._pulsarparameters = pp else: raise ValueError( "Expected 'lalpulsar.PulsarParameters' type, string, or None" )
def __init__(self, pp=None): # if pp is None create empty PulsarParameters structure if pp is None: self._pulsarparameters = lalpulsar.PulsarParameters() else: # check if pp is a pulsar parameters type or a (par file) if not isinstance(pp, lalpulsar.PulsarParameters) and isinstance(pp, string_types): if os.path.isfile(pp): # try reading in file self.read(pp) else: raise ValueError("Input string does not point to a file") elif isinstance(pp, lalpulsar.PulsarParameters): self._pulsarparameters = pp else: raise ValueError("Expected 'lalpulsar.PulsarParameters' type, string, or None")