def test_ftest_wb(): """Test for wideband fitter class F-test.""" wb_m = tm.get_model(os.path.join(datadir, "J0023+0923_ell1_simple.par")) wb_t = toa.make_fake_toas( 56000.0, 56001.0, 10, wb_m, freq=1400.0, obs="GBT", dm=wb_m.DM.value ) wb_f = fitter.WidebandTOAFitter(wb_t, wb_m) wb_f.fit_toas() # Parallax PX = param.floatParameter( parameter_type="float", name="PX", value=0.0, units=u.mas, frozen=False ) PX_Component = "AstrometryEcliptic" # A1DOT A1DOT = param.floatParameter( parameter_type="float", name="A1DOT", value=0.0, units=ls / u.second, frozen=False, ) A1DOT_Component = "BinaryELL1" # Test adding A1DOT Ftest_dict = wb_f.ftest(A1DOT, A1DOT_Component, remove=False, full_output=True) assert isinstance(Ftest_dict["ft"], float) or isinstance(Ftest_dict["ft"], bool) # Test removing parallax Ftest_dict = wb_f.ftest(PX, PX_Component, remove=True, full_output=True) assert isinstance(Ftest_dict["ft"], float) or isinstance(Ftest_dict["ft"], bool)
def __init__(self, ): super(BinaryDDK, self).__init__() self.binary_model_name = "DDK" self.binary_model_class = DDKmodel self.add_param( floatParameter(name="KIN", value=0.0, units="deg", description="Inclination angle")) self.add_param( floatParameter( name="KOM", value=0.0, units="deg", description="The longitude of the ascending node", )) self.add_param( boolParameter( name="K96", description="Flag for Kopeikin binary model proper motion" " correction", )) self.remove_param("SINI") self.internal_params += ["PMRA_DDK", "PMDEC_DDK"]
def __init__(self): # Get the attruibutes that initilzed in the parent class super().__init__() # Add parameters using the add_params in the TimingModel # Add spin period as parameter self.add_param( p.floatParameter( name="P0", value=None, units=u.s, description="Spin period", longdouble=True, )) # Add spin period derivative P1. Since it is not all rquired, we are setting the # default value to 0.0 self.add_param( p.floatParameter( name="P1", value=0.0, units=u.s / u.s, description="Spin period derivative", longdouble=True, )) # Add reference epoch time. self.add_param( p.MJDParameter( name="PEPOCH_P0", description="Reference epoch for spin-down", time_scale="tdb", )) # Add spindown phase model function to phase functions self.phase_funcs_component += [self.spindown_phase_period] # Add the d_phase_d_delay derivative to the list self.phase_derivs_wrt_delay += [self.d_spindown_phase_period_d_delay]
def test_ftest_wb(): """Test for wideband fitter class F-test.""" wb_m = tm.get_model( os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.gls.par")) wb_t = toa.get_TOAs( os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.tim")) wb_f = fitter.WidebandTOAFitter(wb_t, wb_m) wb_f.fit_toas() # Parallax PX = param.floatParameter(parameter_type="float", name="PX", value=0.0, units=u.mas, frozen=False) PX_Component = "AstrometryEcliptic" # A1DOT A1DOT = param.floatParameter( parameter_type="float", name="A1DOT", value=0.0, units=ls / u.second, frozen=False, ) A1DOT_Component = "BinaryELL1" # Test adding A1DOT Ftest_dict = wb_f.ftest(A1DOT, A1DOT_Component, remove=False, full_output=True) assert isinstance(Ftest_dict["ft"], float) or isinstance( Ftest_dict["ft"], bool) # Test removing parallax Ftest_dict = wb_f.ftest(PX, PX_Component, remove=True, full_output=True) assert isinstance(Ftest_dict["ft"], float) or isinstance( Ftest_dict["ft"], bool)
def __init__(self): super(AstrometryEcliptic, self).__init__() self.add_param( AngleParameter( name="ELONG", units="deg", description="Ecliptic longitude", aliases=["LAMBDA"], ) ) self.add_param( AngleParameter( name="ELAT", units="deg", description="Ecliptic latitude", aliases=["BETA"], ) ) self.add_param( floatParameter( name="PMELONG", units="mas/year", value=0.0, description="Proper motion in ecliptic longitude", aliases=["PMLAMBDA"], ) ) self.add_param( floatParameter( name="PMELAT", units="mas/year", value=0.0, description="Proper motion in ecliptic latitude", aliases=["PMBETA"], ) ) self.add_param( strParameter( name="ECL", value="IERS2010", description="Obliquity of the ecliptic (reference)", ) ) self.set_special_params(["ELONG", "ELAT", "PMELONG", "PMELAT"]) for param in ["ELAT", "ELONG", "PMELAT", "PMELONG"]: deriv_func_name = "d_delay_astrometry_d_" + param func = getattr(self, deriv_func_name) self.register_deriv_funcs(func, param)
def simple_model_alias_overlap(): simple_model = SimpleModel() simple_model.add_param( floatParameter(name="TESTPARAM2", aliases=["F0"], value=0.0, unit="1/s")) simple_model.add_param( floatParameter(name="TESTPARAM3", aliases=["LAMBDA"], value=0.0, unit="deg")) return simple_model
def __init__(self): super().__init__() self.binary_model_name = "ELL1" self.binary_model_class = ELL1model self.add_param( MJDParameter(name="TASC", description="Epoch of ascending node", time_scale="tdb")) self.add_param( floatParameter( name="EPS1", units="", description= "First Laplace-Lagrange parameter, ECC x sin(OM) for ELL1 model", long_double=True, )) self.add_param( floatParameter( name="EPS2", units="", description= "Second Laplace-Lagrange parameter, ECC x cos(OM) for ELL1 model", long_double=True, )) self.add_param( floatParameter( name="EPS1DOT", units="1e-12/s", description= "First derivative of first Laplace-Lagrange parameter", long_double=True, )) self.add_param( floatParameter( name="EPS2DOT", units="1e-12/s", description= "Second derivative of first Laplace-Lagrange parameter", long_double=True, )) self.remove_param("ECC") self.remove_param("OM") self.remove_param("T0") self.warn_default_params = []
def __init__(self): super(Spindown, self).__init__() self.add_param( floatParameter( name="F0", value=0.0, units="Hz", description="Spin-frequency", long_double=True, )) self.add_param( prefixParameter( name="F1", value=0.0, units="Hz/s^1", description="Spindown-rate", unit_template=self.F_unit, description_template=self.F_description, type_match="float", long_double=True, )) self.add_param( MJDParameter( name="PEPOCH", description="Reference epoch for spin-down", time_scale="tdb", )) self.phase_funcs_component += [self.spindown_phase] self.phase_derivs_wrt_delay += [self.d_spindown_phase_d_delay]
def __init__(self): super(SimpleModel2, self).__init__() self.add_param( floatParameter(name="TESTPARAMF0", aliases=["F0"], value=0.0, unit="s"))
def __init__(self): super(Wave, self).__init__() self.add_param( floatParameter( name="WAVE_OM", description="Base frequency of wave solution", units="1/d", ) ) self.add_param( prefixParameter( name="WAVE1", units="s", description="Wave components", type_match="pair", long_double=True, parameter_type="pair", ) ) self.add_param( MJDParameter( name="WAVEEPOCH", description="Reference epoch for wave solution", time_scale="tdb", ) ) self.phase_funcs_component += [self.wave_phase]
def __init__(self): super(DispersionDM, self).__init__() self.add_param( floatParameter( name="DM", units="pc cm^-3", value=0.0, description="Dispersion measure", long_double=True, )) self.add_param( prefixParameter( name="DM1", value=0.0, units="pc cm^-3/yr^1", description= "First order time derivative of the dispersion measure", unit_template=self.DM_dervative_unit, description_template=self.DM_dervative_description, type_match="float", long_double=True, )) self.add_param( MJDParameter(name="DMEPOCH", description="Epoch of DM measurement", time_scale="tdb")) self.dm_value_funcs += [self.base_dm] self.delay_funcs_component += [self.constant_dispersion_delay]
def __init__(self,): super(PLRedNoise, self).__init__() self.introduces_correlated_errors = True self.add_param( floatParameter( name="RNAMP", units="", aliases=[], description="Amplitude of powerlaw " "red noise.", ) ) self.add_param( floatParameter( name="RNIDX", units="", aliases=[], description="Spectral index of " "powerlaw red noise.", ) ) self.add_param( floatParameter( name="TNRedAmp", units="", aliases=[], description="Amplitude of powerlaw " "red noise in tempo2 format", ) ) self.add_param( floatParameter( name="TNRedGam", units="", aliases=[], description="Spectral index of powerlaw " "red noise in tempo2 format", ) ) self.add_param( floatParameter( name="TNRedC", units="", aliases=[], description="Number of red noise frequencies.", ) ) self.covariance_matrix_funcs += [self.pl_rn_cov_matrix] self.basis_funcs += [self.pl_rn_basis_weight_pair]
def F1(self): return p.floatParameter( name="F1", value=self.d_F0_d_P0 * self.P1.quantity, units=u.Hz / u.s, description="Spin down frequency", long_double=True, )
def __init__(self): super(SolarWindDispersion, self).__init__() self.add_param( floatParameter( name="NE_SW", units="cm^-3", value=0.0, aliases=["NE1AU", "SOLARN0"], description="Solar Wind Parameter", )) self.add_param( floatParameter(name="SWM", value=0.0, units="", description="Solar Wind Model")) self.delay_funcs_component += [self.solar_wind_delay] self.set_special_params(["NE_SW", "SWM"])
def PMDEC_DDK(self): params = self._parent.get_params_as_ICRS() par_obj = floatParameter( name="PMDEC", units="mas/year", value=params["PMDEC"], description="Proper motion in DEC", ) return par_obj
def __init__(self, ): super(BinaryDD, self).__init__() self.binary_model_name = "DD" self.binary_model_class = DDmodel self.add_param( floatParameter( name="A0", value=0.0, units="s", description="DD model aberration parameter A0", )) self.add_param( floatParameter( name="B0", value=0.0, units="s", description="DD model aberration parameter B0", )) self.add_param( floatParameter( name="GAMMA", value=0.0, units="second", description="Time dilation & gravitational redshift", )) self.add_param( floatParameter( name="DR", value=0.0, units="", description="Relativistic deformation of the orbit", )) self.add_param( floatParameter( name="DTH", value=0.0, units="", description="Relativistic deformation of the orbit", ))
def F0(self): # We return F0 as parameter here since the other place of PINT code use F0 # in the format of PINT parameter. return p.floatParameter( name="F0", value=1.0 / self.P0.quantity, units="Hz", description="Spin-frequency", long_double=True, )
def __init__(self): super(AstrometryEquatorial, self).__init__() self.add_param( AngleParameter( name="RAJ", units="H:M:S", description="Right ascension (J2000)", aliases=["RA"], ) ) self.add_param( AngleParameter( name="DECJ", units="D:M:S", description="Declination (J2000)", aliases=["DEC"], ) ) self.add_param( floatParameter( name="PMRA", units="mas/year", value=0.0, description="Proper motion in RA", ) ) self.add_param( floatParameter( name="PMDEC", units="mas/year", value=0.0, description="Proper motion in DEC", ) ) self.set_special_params(["RAJ", "DECJ", "PMRA", "PMDEC"]) for param in ["RAJ", "DECJ", "PMRA", "PMDEC"]: deriv_func_name = "d_delay_astrometry_d_" + param func = getattr(self, deriv_func_name) self.register_deriv_funcs(func, param)
def test_model_builder_class(): """Test if AllComponents collected components information correctly""" mb = AllComponents() category = mb.category_component_map assert set(mb.param_component_map["PX"]) == set(category["astrometry"]) assert set(mb.component_category_map.keys()) == set(mb.components) # test for new components assert "SimpleModel" in mb.components simple_comp = mb.components["SimpleModel"] simple_comp.add_param( floatParameter(name="TESTPARAM2", aliases=["F0"], value=0.0, unit="s"))
def __init__(self): super().__init__() self.binary_model_name = "ELL1H" self.binary_model_class = ELL1Hmodel self.add_param( floatParameter( name="H3", units="second", description= "Shapiro delay parameter H3 as in Freire and Wex 2010 Eq(20)", long_double=True, )) self.add_param( floatParameter( name="H4", units="second", description= "Shapiro delay parameter H4 as in Freire and Wex 2010 Eq(21)", long_double=True, )) self.add_param( floatParameter( name="STIGMA", units="", description= "Shapiro delay parameter STIGMA as in Freire and Wex 2010 Eq(12)", long_double=True, aliases=["VARSIGMA"], )) self.add_param( intParameter( name="NHARMS", units="", value=3, description="Number of harmonics for ELL1H shapiro delay.", )) self.remove_param("M2") self.remove_param("SINI")
def __init__(self): super(Astrometry, self).__init__() self.add_param( MJDParameter(name="POSEPOCH", description="Reference epoch for position") ) self.add_param( floatParameter(name="PX", units="mas", value=0.0, description="Parallax") ) self.delay_funcs_component += [self.solar_system_geometric_delay] self.register_deriv_funcs(self.d_delay_astrometry_d_PX, "PX")
def __init__(self): super().__init__() self.add_param( floatParameter( name="NE_SW", units="cm^-3", value=0.0, aliases=["NE1AU", "SOLARN0"], description="Solar Wind density at 1 AU", )) self.add_param( floatParameter( name="SWM", value=0.0, units="", description= "Solar Wind Model (0 is from Edwards+ 2006, others to come)", )) self.dm_value_funcs += [self.solar_wind_dm] self.delay_funcs_component += [self.solar_wind_delay] self.set_special_params(["NE_SW", "SWM"])
def __init__(self): super().__init__() self.binary_model_name = "BT" self.binary_model_class = BTmodel self.add_param( floatParameter( name="GAMMA", value=0.0, units="second", description="Time dilation & gravitational redshift", )) self.remove_param("M2") self.remove_param("SINI")
def __init__(self): super(AbsPhase, self).__init__() self.add_param( MJDParameter(name="TZRMJD", description="Epoch of the zero phase.")) self.add_param( strParameter( name="TZRSITE", description="Observatory of the zero phase measured.")) self.add_param( floatParameter( name="TZRFRQ", units=u.MHz, description="The frequency of the zero phase mearsured.", ))
def __init__(self): super().__init__() # DMX is for info output right now self.add_param( floatParameter( name="DMX", units="pc cm^-3", value=0.0, description="Dispersion measure", )) self.add_DMX_range(None, None, dmx=0, frozen=False, index=1) self.dm_value_funcs += [self.dmx_dm] self.set_special_params(["DMX_0001", "DMXR1_0001", "DMXR2_0001"]) self.delay_funcs_component += [self.DMX_dispersion_delay]
def __init__(self): super(DispersionDMX, self).__init__() # DMX is for info output right now self.add_param( floatParameter( name="DMX", units="pc cm^-3", value=0.0, description="Dispersion measure", ) ) self.add_param( prefixParameter( name="DMX_0001", units="pc cm^-3", value=0.0, unit_template=lambda x: "pc cm^-3", description="Dispersion measure variation", description_template=lambda x: "Dispersion measure", paramter_type="float", ) ) self.add_param( prefixParameter( name="DMXR1_0001", units="MJD", unit_template=lambda x: "MJD", description="Beginning of DMX interval", description_template=lambda x: "Beginning of DMX interval", parameter_type="MJD", time_scale="utc", ) ) self.add_param( prefixParameter( name="DMXR2_0001", units="MJD", unit_template=lambda x: "MJD", description="End of DMX interval", description_template=lambda x: "End of DMX interval", parameter_type="MJD", time_scale="utc", ) ) self.dm_value_funcs += [self.dmx_dm] self.set_special_params(["DMX_0001", "DMXR1_0001", "DMXR2_0001"]) self.delay_funcs_component += [self.DMX_dispersion_delay]
def __init__(self): super(IFunc, self).__init__() self.add_param( floatParameter(name="SIFUNC", description="Type of interpolation", units="")) self.add_param( prefixParameter( name="IFUNC1", units="s", description="Interpolation Components (MJD+delay)", type_match="pair", long_double=True, parameter_type="pair", )) self.phase_funcs_component += [self.ifunc_phase]
def __init__(self,): super(PulsarBinary, self).__init__() self.binary_model_name = None self.barycentric_time = None self.binary_model_class = None self.add_param( floatParameter( name="PB", units=u.day, description="Orbital period", long_double=True ) ) self.add_param( floatParameter( name="PBDOT", units=u.day / u.day, description="Orbital period derivitve respect to time", unit_scale=True, scale_factor=1e-12, scale_threshold=1e-7, ) ) self.add_param( floatParameter( name="A1", units=ls, description="Projected semi-major axis, a*sin(i)" ) ) # NOTE: the DOT here takes the value and times 1e-12, tempo/tempo2 can # take both. self.add_param( floatParameter( name="A1DOT", aliases=["XDOT"], units=ls / u.s, description="Derivative of projected semi-major axis, da*sin(i)/dt", unit_scale=True, scale_factor=1e-12, scale_threshold=1e-7, ) ) self.add_param( floatParameter( name="ECC", units="", aliases=["E"], description="Eccentricity" ) ) self.add_param( floatParameter( name="EDOT", units="1/s", description="Eccentricity derivitve respect to time", unit_scale=True, scale_factor=1e-12, scale_threshold=1e-7, ) ) self.add_param( MJDParameter( name="T0", description="Epoch of periastron passage", time_scale="tdb" ) ) self.add_param( floatParameter( name="OM", units=u.deg, description="Longitude of periastron", long_double=True, ) ) self.add_param( floatParameter( name="OMDOT", units="deg/year", description="Longitude of periastron", long_double=True, ) ) self.add_param( floatParameter( name="M2", units=u.M_sun, description="Mass of companian in the unit Sun mass", ) ) self.add_param( floatParameter( name="SINI", units="", description="Sine of inclination angle" ) ) self.add_param( prefixParameter( name="FB0", value=None, units="1/s^1", description="0th time derivative of frequency of orbit", unit_template=self.FBX_unit, aliases=["FB"], description_template=self.FBX_description, type_match="float", long_double=True, ) ) self.interal_params = [] self.warn_default_params = ["ECC", "OM"] # Set up delay function self.delay_funcs_component += [self.binarymodel_delay]
# When you print the parameter it looks like the `param_comp` type. # %% # Note that for each instance of a prefix parameter is of type `prefixParameter` print("Type = ", type(model.DMX_0016)) print("param_comp type = ", type(model.DMX_0016.param_comp)) print("Printing gives : ", model.DMX_0016) # %% [markdown] # ## Constructing a parameter # # You can make a Parameter instance by calling its constructor # %% {"jupyter": {"outputs_hidden": false}} # You can specify the vaue as a number t = pp.floatParameter(name="TEST", value=100, units="Hz", uncertainty=0.03) print(t) # %% {"jupyter": {"outputs_hidden": false}} # Or as a string that will be parsed t2 = pp.floatParameter(name="TEST", value="200", units="Hz", uncertainty=".04") print(t2) # %% {"jupyter": {"outputs_hidden": false}} # Or as an astropy Quantity with units (this is the preferred method!) t3 = pp.floatParameter(name="TEST", value=0.3 * u.kHz, units="Hz", uncertainty=4e-5 * u.kHz) print(t3) print(t3.quantity)
def simple_model_overlap(simple_model): simple_model.add_param( floatParameter(name="F0", aliases=[], value=0.0, unit="1/s")) return simple_model