def validate(self): """ Validate parameters input. """ super(Glitch, self).validate() for idx in set(self.glitch_indices): if not hasattr(self, "GLEP_%d" % idx): msg = "Glitch Epoch is needed for Glitch %d." % idx raise MissingParameter("Glitch", "GLEP_%d" % idx, msg) else: # Check to see if both the epoch and phase are to be fit if hasattr(self, "GLPH_%d" % idx): if (not getattr(self, "GLEP_%d" % idx).frozen) and ( not getattr(self, "GLPH_%d" % idx).frozen): raise ValueError( "Both the glitch epoch and phase cannot be fit for Glitch %d." % idx) # Check the Decay Term. glf0dparams = [x for x in self.params if x.startswith("GLF0D_")] for glf0dnm in glf0dparams: glf0d = getattr(self, glf0dnm) idx = glf0d.index if glf0d.value != 0.0 and getattr(self, "GLTD_%d" % idx).value == 0.0: msg = ("None zero GLF0D_%d parameter needs a none" " zero GLTD_%d parameter" % (idx, idx)) raise MissingParameter("Glitch", "GLTD_%d" % idx, msg)
def setup(self): super(Glitch, self).setup() # Check for required glitch epochs, set not specified parameters to 0 self.glitch_prop = ["GLPH_", "GLF0_", "GLF1_", "GLF2_", "GLF0D_", "GLTD_"] self.glitch_indices = [ getattr(self, y).index for x in self.glitch_prop for y in self.params if x in y ] for idx in set(self.glitch_indices): if not hasattr(self, "GLEP_%d" % idx): msg = "Glicth Epoch is needed for Glicth %d." % idx raise MissingParameter("Glitch", "GLEP_%d" % idx, msg) for param in self.glitch_prop: if not hasattr(self, param + "%d" % idx): param0 = getattr(self, param + "1") self.add_param(param0.new_param(idx)) getattr(self, param + "%d" % idx).value = 0.0 self.register_deriv_funcs( getattr(self, "d_phase_d_" + param[0:-1]), param + "%d" % idx ) # Check the Decay Term. glf0dparams = [x for x in self.params if x.startswith("GLF0D_")] for glf0dnm in glf0dparams: glf0d = getattr(self, glf0dnm) idx = glf0d.index if glf0d.value != 0.0 and getattr(self, "GLTD_%d" % idx).value == 0.0: msg = ( "None zero GLF0D_%d parameter needs a none" " zero GLTD_%d parameter" % (idx, idx) ) raise MissingParameter("Glitch", "GLTD_%d" % idx, msg)
def setup(self): super(Spindown, self).setup() # Check for required params for p in ("F0", ): if getattr(self, p).value is None: raise MissingParameter("Spindown", p) # Check continuity F_terms = list(self.get_prefix_mapping_component("F").keys()) F_terms.sort() F_in_order = list(range(1, max(F_terms) + 1)) if not F_terms == F_in_order: diff = list(set(F_in_order) - set(F_terms)) raise MissingParameter("Spindown", "F%d" % diff[0]) # If F1 is set, we need PEPOCH if self.F1.value != 0.0: if self.PEPOCH.value is None: raise MissingParameter( "Spindown", "PEPOCH", "PEPOCH is required if F1 or higher are set") self.num_spin_terms = len(F_terms) + 1 # Add derivative functions for fp in list( self.get_prefix_mapping_component("F").values()) + ["F0"]: self.register_deriv_funcs(self.d_phase_d_F, fp)
def validate(self): super().validate() # Check for required params for p in ("F0", ): if getattr(self, p).value is None: raise MissingParameter("Spindown", p) # Check continuity self._parent.get_prefix_list("F", start_index=0) # If F1 is set, we need PEPOCH if hasattr(self, "F1") and self.F1.value != 0.0: if self.PEPOCH.value is None: raise MissingParameter( "Spindown", "PEPOCH", "PEPOCH is required if F1 or higher are set")
def validate(self): """Validate parameters input.""" super().validate() for idx in set(self.pwsol_indices): if not hasattr(self, "PWEP_%d" % idx): msg = "Piecewise solution Epoch is needed for Piece %d." % idx raise MissingParameter("PiecewiseSpindown", "PWEP_%d" % idx, msg) if not hasattr(self, "PWSTART_%d" % idx): msg = "Piecewise solution starting epoch is needed for Piece %d." % idx raise MissingParameter("PiecewiseSpindown", "PWSTART_%d" % idx, msg) if not hasattr(self, "PWSTOP_%d" % idx): msg = "Piecewise solution end epoch is needed for Piece %d." % idx raise MissingParameter("PiecewiseSpindown", "PWSTOP_%d" % idx, msg)
def validate(self): """ Validate the input parameters. """ super(BinaryDD, self).validate() self.check_required_params(["T0", "A1"]) # If any *DOT is set, we need T0 for p in ("PBDOT", "OMDOT", "EDOT", "A1DOT"): if getattr(self, p).value is None: getattr(self, p).set("0") getattr(self, p).frozen = True # TODO This steps seems duplicated. if getattr(self, p).value is not None: if self.T0.value is None: raise MissingParameter("DD", "T0", "T0 is required if *DOT is set") if self.GAMMA.value is None: self.GAMMA.set("0") self.GAMMA.frozen = True # If eccentricity is zero, freeze some parameters to 0 # OM = 0 -> T0 = TASC if self.ECC.value == 0 or self.ECC.value is None: for p in ("ECC", "OM", "OMDOT", "EDOT"): getattr(self, p).set("0") getattr(self, p).frozen = True
def setup(self): super(AstrometryEquatorial, self).setup() # RA/DEC are required for p in ("RAJ", "DECJ"): if getattr(self, p).value is None: raise MissingParameter("Astrometry", p) # If PM is included, check for POSEPOCH if self.PMRA.value != 0.0 or self.PMDEC.value != 0.0: if self.POSEPOCH.quantity is None: if self.PEPOCH.quantity is None: raise MissingParameter( "AstrometryEquatorial", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: self.POSEPOCH.quantity = self.PEPOCH.quantity
def validate(self): """Validate parameters.""" super().validate() if "PMRA" not in self._parent.params or "PMDEC" not in self._parent.params: # Check ecliptic coordinates proper motion. if ("PMELONG" not in self._parent.params or "PMELAT" not in self._parent.params): raise MissingParameter( "DDK", "DDK model needs proper motion parameters.") if hasattr(self._parent, "PX"): if self._parent.PX.value <= 0.0 or self._parent.PX.value is None: raise TimingModelError("DDK model needs a valid `PX` value.") else: raise MissingParameter("Binary_DDK", "PX", "DDK model needs PX from" "Astrometry.")
def validate(self): super(FD, self).validate() FD_terms = list(self.get_prefix_mapping_component("FD").keys()) FD_terms.sort() FD_in_order = list(range(1, max(FD_terms) + 1)) if not FD_terms == FD_in_order: diff = list(set(FD_in_order) - set(FD_terms)) raise MissingParameter("FD", "FD%d" % diff[0])
def setup(self): super(AstrometryEcliptic, self).setup() # RA/DEC are required for p in ("ELONG", "ELAT"): if getattr(self, p).value is None: raise MissingParameter("AstrometryEcliptic", p) # If PM is included, check for POSEPOCH if self.PMELONG.value != 0.0 or self.PMELAT.value != 0.0: if self.POSEPOCH.quantity is None: if self.PEPOCH.quantity is None: raise MissingParameter( "Astrometry", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: self.POSEPOCH.quantity = self.PEPOCH.quantity
def validate(self): super(IFunc, self).validate() if self.SIFUNC.quantity is None: raise MissingParameter( "IFunc", "SIFUNC", "SIFUNC is required if IFUNC entries are present.") if (not hasattr(self._parent, "F0")) or (self._parent.F0.quantity is None): raise MissingParameter( "IFunc", "F0", "F0 is required if IFUNC entries are present.") # this is copied from the wave model, but I don't think this check # is strictly necessary. An ephemeris could remain perfectly valid # if some IFUNC terms were "missing". (The same is true for WAVE.) self.terms.sort() for i, term in enumerate(self.terms): if (i + 1) != term: raise MissingParameter("IFunc", "IFUNC%d" % (i + 1))
def validate(self): super(Spindown, self).validate() # Check for required params for p in ("F0", ): if getattr(self, p).value is None: raise MissingParameter("Spindown", p) # Check continuity sort_F_terms = sorted(self.F_terms) F_in_order = list(range(1, max(self.F_terms) + 1)) if not sort_F_terms == F_in_order: diff = list(set(F_in_order) - set(sort_F_terms)) raise MissingParameter("Spindown", "F%d" % diff[0]) # If F1 is set, we need PEPOCH if self.F1.value != 0.0: if self.PEPOCH.value is None: raise MissingParameter( "Spindown", "PEPOCH", "PEPOCH is required if F1 or higher are set")
def validate(self): """Validate Ecliptic coordinate parameter inputs.""" super().validate() # ELONG/ELAT are required for p in ("ELONG", "ELAT"): if getattr(self, p).value is None: raise MissingParameter("AstrometryEcliptic", p) # Check for POSEPOCH if (self.PMELONG.value != 0 or self.PMELAT.value != 0) and self.POSEPOCH.quantity is None: if self._parent.PEPOCH.quantity is None: raise MissingParameter( "Astrometry", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: self.POSEPOCH.quantity = self._parent.PEPOCH.quantity
def validate(self): """Validate the input parameter.""" super().validate() # RA/DEC are required for p in ("RAJ", "DECJ"): if getattr(self, p).value is None: raise MissingParameter("Astrometry", p) # Check for POSEPOCH if (self.PMRA.quantity != 0 or self.PMDEC.quantity != 0) and self.POSEPOCH.quantity is None: if self._parent.PEPOCH.quantity is None: raise MissingParameter( "AstrometryEquatorial", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: self.POSEPOCH.quantity = self._parent.PEPOCH.quantity
def validate(self): """ Validate Ecliptic coordinate parameter inputs. """ super(AstrometryEcliptic, self).validate() # ELONG/ELAT are required for p in ("ELONG", "ELAT"): if getattr(self, p).value is None: raise MissingParameter("AstrometryEcliptic", p) # Check for POSEPOCH if self.POSEPOCH.quantity is None: if self._parent.PEPOCH.quantity is None: raise MissingParameter( "Astrometry", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: log.warning("POSEPOCH not found; using PEPOCH unless set explicitly!") self.POSEPOCH.quantity = self._parent.PEPOCH.quantity
def validate(self): """ Validate the input parameter. """ super(AstrometryEquatorial, self).validate() # RA/DEC are required for p in ("RAJ", "DECJ"): if getattr(self, p).value is None: raise MissingParameter("Astrometry", p) # Check for POSEPOCH if self.POSEPOCH.quantity is None: if self._parent.PEPOCH.quantity is None: raise MissingParameter( "AstrometryEquatorial", "POSEPOCH", "POSEPOCH or PEPOCH are required if PM is set.", ) else: log.warning("POSEPOCH not found; using PEPOCH unless set explicitly!") self.POSEPOCH.quantity = self._parent.PEPOCH.quantity
def validate(self): """Validate parameters.""" super().validate() if self.TASC.value is None: raise MissingParameter("ELL1", "TASC", "TASC is required for ELL1 model.") for p in ["EPS1", "EPS2"]: pm = getattr(self, p) if pm.value is None: pm.value = 0
def validate(self): """ Validate parameters input. """ super(Glitch, self).validate() for idx in set(self.glitch_indices): if not hasattr(self, "GLEP_%d" % idx): msg = "Glicth Epoch is needed for Glicth %d." % idx raise MissingParameter("Glitch", "GLEP_%d" % idx, msg) # Check the Decay Term. glf0dparams = [x for x in self.params if x.startswith("GLF0D_")] for glf0dnm in glf0dparams: glf0d = getattr(self, glf0dnm) idx = glf0d.index if glf0d.value != 0.0 and getattr(self, "GLTD_%d" % idx).value == 0.0: msg = ( "None zero GLF0D_%d parameter needs a none" " zero GLTD_%d parameter" % (idx, idx) ) raise MissingParameter("Glitch", "GLTD_%d" % idx, msg)
def validate(self): """Validate the DM parameters input.""" super(Dispersion, self).validate() # If DM1 is set, we need DMEPOCH if self.DM1.value != 0.0: if self.DMEPOCH.value is None: raise MissingParameter( "Dispersion", "DMEPOCH", "DMEPOCH is required if DM1 or higher are set", )
def validate(self): """Validate parameters""" super(BinaryELL1Base, self).validate() for p in ["EPS1", "EPS2"]: if getattr(self, p).value is None: raise MissingParameter("ELL1", p, p + " is required for ELL1 model.") # Check TASC if self.TASC.value is None: if self.ECC.value == 0.0: warn("Since ECC is 0.0, using T0 as TASC.") if self.T0.value is not None: self.TASC.value = self.T0.value else: raise MissingParameter( "ELL1", "T0", "T0 or TASC is required for ELL1 model.") else: raise MissingParameter("ELL1", "TASC", "TASC is required for ELL1 model.")
def setup(self): super(IFunc, self).setup() if self.SIFUNC.quantity is None: raise MissingParameter( "IFunc", "SIFUNC", "SIFUNC is required if IFUNC entries are present.") if (not hasattr(self, "F0")) or (self.F0.quantity is None): raise MissingParameter( "IFunc", "F0", "F0 is required if IFUNC entries are present.") # this is copied from the wave model, but I don't think this check # is strictly necessary. An ephemeris could remain perfectly valid # if some IFUNC terms were "missing". (The same is true for WAVE.) terms = list(self.get_prefix_mapping_component("IFUNC").keys()) terms.sort() for i, term in enumerate(terms): if (i + 1) != term: raise MissingParameter("IFunc", "IFUNC%d" % (i + 1)) self.num_terms = len(terms)
def setup(self): super(BinaryBT, self).setup() # If any necessary parameter is missing, raise MissingParameter. # This will probably be updated after ELL1 model is added. for p in ("T0", "A1"): if getattr(self, p).value is None: raise MissingParameter("BT", p, "%s is required for BT" % p) # If any *DOT is set, we need T0 for p in ("PBDOT", "OMDOT", "EDOT", "A1DOT"): if getattr(self, p).value is None: getattr(self, p).set("0") getattr(self, p).frozen = True if getattr(self, p).value is not None: if self.T0.value is None: raise MissingParameter("BT", "T0", "T0 is required if *DOT is set") if self.GAMMA.value is None: self.GAMMA.set("0") self.GAMMA.frozen = True
def validate(self): """ Validate parameters """ super(BinaryDDK, self).validate() if "PMRA" not in self._parent.params or "PMDEC" not in self._parent.params: # Check ecliptic coordinates proper motion. if ( "PMELONG" not in self._parent.params or "PMELAT" not in self._parent.params ): raise MissingParameter( "DDK", "DDK model needs proper motion parameters." )
def validate(self): super(Wave, self).validate() self.setup() if self.WAVEEPOCH.quantity is None: if self.PEPOCH.quantity is None: raise MissingParameter( "Wave", "WAVEEPOCH", "WAVEEPOCH or PEPOCH are required if " "WAVE_OM is set.", ) else: self.WAVEEPOCH = self.PEPOCH if (not hasattr(self._parent, "F0")) or (self._parent.F0.quantity is None): raise MissingParameter( "Wave", "F0", "F0 is required if WAVE entries are present." ) self.wave_terms.sort() wave_in_order = list(range(1, max(self.wave_terms) + 1)) if not self.wave_terms == wave_in_order: diff = list(set(wave_in_order) - set(self.wave_terms)) raise MissingParameter("Wave", "WAVE%d" % diff[0])
def validate(self): """ Validate BT model parameters """ super(BinaryBT, self).validate() for p in ("T0", "A1"): if getattr(self, p).value is None: raise MissingParameter("BT", p, "%s is required for BT" % p) # If any *DOT is set, we need T0 for p in ("PBDOT", "OMDOT", "EDOT", "A1DOT"): if getattr(self, p).value is None: getattr(self, p).set("0") getattr(self, p).frozen = True if getattr(self, p).value is not None: if self.T0.value is None: raise MissingParameter("BT", "T0", "T0 is required if *DOT is set") if self.GAMMA.value is None: self.GAMMA.set("0") self.GAMMA.frozen = True
def check_required_params(self, required_params): # seach for all the possible to get the parameters. for p in required_params: par = getattr(self, p) if par.value is None: # try to search if there is any class method that computes it method_name = p.lower() + "_func" try: par_method = getattr(self.binary_instance, method_name) except AttributeError: raise MissingParameter( self.binary_model_name, p + " is required for '%s'." % self.binary_model_name, ) try: par_method() except: raise MissingParameter( self.binary_model_name, p + " is present but somehow broken for '%s'." % self.binary_model_name, )
def setup(self): super(FD, self).setup() # Check if FD terms are in order. FD_mapping = self.get_prefix_mapping_component("FD") FD_terms = list(FD_mapping.keys()) FD_terms.sort() FD_in_order = list(range(1, max(FD_terms) + 1)) if not FD_terms == FD_in_order: diff = list(set(FD_in_order) - set(FD_terms)) raise MissingParameter("FD", "FD%d" % diff[0]) self.num_FD_terms = len(FD_terms) # set up derivative functions for ii, val in FD_mapping.items(): self.register_deriv_funcs(self.d_delay_FD_d_FDX, val)
def validate(self): """Validate the DM parameters input.""" super().validate() # If DM1 is set, we need DMEPOCH if self.DM1.value is not None and self.DM1.value != 0.0: if self.DMEPOCH.value is None: # Copy PEPOCH (PEPOCH must be set!) self.DMEPOCH.value = self._parent.PEPOCH.value if self.DMEPOCH.value is None: raise MissingParameter( "Dispersion", "DMEPOCH", "DMEPOCH or PEPOCH is required if DM1 or higher are set", )
def validate(self): """ Validate parameters """ super(BinaryDDK, self).validate() if "PMRA" not in self._parent.params or "PMDEC" not in self._parent.params: # Check ecliptic coordinates proper motion. if ("PMELONG" not in self._parent.params or "PMELAT" not in self._parent.params): raise MissingParameter( "DDK", "DDK model needs proper motion parameters.") if self.SINI.quantity is not None: raise ValueError( "DDK model does not accept `SINI` as input. Please" " use `KIN` instead.")
def setup(self): super(Wave, self).setup() if self.WAVEEPOCH.quantity is None: if self.PEPOCH.quantity is None: raise MissingParameter( "Wave", "WAVEEPOCH", "WAVEEPOCH or PEPOCH are required if " "WAVE_OM is set.", ) else: self.WAVEEPOCH = self.PEPOCH if (not hasattr(self, "F0")) or (self.F0.quantity is None): raise MissingParameter( "Wave", "F0", "F0 is required if WAVE entries are present.") wave_terms = list(self.get_prefix_mapping_component("WAVE").keys()) wave_terms.sort() wave_in_order = list(range(1, max(wave_terms) + 1)) if not wave_terms == wave_in_order: diff = list(set(wave_in_order) - set(wave_terms)) raise MissingParameter("Wave", "WAVE%d" % diff[0]) self.num_wave_terms = len(wave_terms)