Skip to content

Commit

Permalink
Merge branch 'master' into publish
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisrkckl authored Sep 5, 2023
2 parents bde240c + 25f38ca commit f303989
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ the released changes.

## Unreleased
### Changed
- WAVE parameters can be added to a Wave model with `add_wave_component()` in wave.py
- `WAVE` parameters can be added to a `Wave` model with `add_wave_component()` in `wave.py`
- Moved design matrix normalization code from `pint.fitter` to the new `pint.utils.normalize_designmatrix()` function.
- Made `Residuals` independent of `GLSFitter` (GLS chi2 is now computed using the new function `Residuals._calc_gls_chi2()`).
### Added
- Added WaveX model as DelayComponent with wave amplitudes as fitted parameters
- Added `WaveX` model as a `DelayComponent` with Fourier amplitudes as fitted parameters
- `Parameter.as_latex` method for latex representation of a parameter.
- `pint.output.publish` module and `pintpublish` script for generating publication (LaTeX) output.
### Fixed
- Wave model `validate()` can correctly use PEPOCH to assign WAVEEPOCH parameter
- Fixed RTD by specifying theme explicitly.
- `.value()` now works for pairParameters
- Setting `model.PARAM1 = model.PARAM2` no longer overrides the name of `PARAM1`
- Fixed an incorrect docstring in pbprime() functions.
- Fixed an incorrect docstring in `pbprime()` functions.
- Fix ICRS -> ECL conversion when parameter uncertainties are not set.
- `get_TOAs` raises an exception upon finding mixed narrowband and wideband TOAs in a tim file. `TOAs.is_wideband` returns True only if *ALL* TOAs have the -pp_dm flag.
### Removed
11 changes: 10 additions & 1 deletion src/pint/toa.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def get_TOAs(
if "pulse_number" in t.table.colnames and not include_pn:
log.warning("'pulse_number' column exists but not being read in")
t.remove_pulse_numbers()

dm_data, valid_data = t.get_flag_value("pp_dm", as_type=float)
if len(valid_data) not in [0, len(t)]:
raise ValueError(
"Mixing narrowband and wideband toas in a TOAs object is not allowed. "
"Make sure that either all or no TOAs have the -pp_dm flag."
)

return t


Expand Down Expand Up @@ -1631,7 +1639,7 @@ def is_wideband(self):

# there may be a more elegant way to do this
dm_data, valid_data = self.get_flag_value("pp_dm", as_type=float)
return valid_data != []
return len(valid_data) == len(self)

def get_all_flags(self):
"""Return a list of all the flags used by any TOA."""
Expand Down Expand Up @@ -2986,4 +2994,5 @@ def get_TOAs_array(
t.compute_TDBs(method=tdb_method, ephem=ephem)
if "ssb_obs_pos" not in t.table.colnames:
t.compute_posvels(ephem, planets)

return t
12 changes: 12 additions & 0 deletions tests/test_toa.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,15 @@ def test_merge_toas():
toas_out = pint.toa.merge_TOAs([toas, toas2])
toas_outb = toas + toas2
assert np.all(toas_out.table == toas_outb.table)


def test_mix_nb_wb():
with pytest.raises(ValueError):
t1 = pint.toa.get_TOAs(
io.StringIO(
"""
fake.ff 1430.000000 53393.561383615118386 0.178 ao -fe L-wide -be ASP -pp_dm 10.0
fake.ff 1430.000000 53394.561383615118386 0.178 ao -fe L-wide -be ASP
"""
)
)
46 changes: 18 additions & 28 deletions tests/test_wideband_dm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ def wb_model(tmpdir):
return get_model(str(parfile))


@pytest.fixture
def wb_toas(wb_model):
toas = get_TOAs(io.StringIO(tim))
for i in range(9):
r = Residuals(toas, wb_model)
if np.all(r.time_resids < 1 * u.ns):
break
toas.adjust_TOAs(TimeDelta(-r.time_resids))
else:
raise ValueError
return toas


@pytest.fixture
def wb_toas_all(wb_model):
toas = get_TOAs(io.StringIO(tim_all))
Expand Down Expand Up @@ -162,14 +149,18 @@ def test_dmjump_derivative(self):
assert self.model.dm_derivs[dmj_param.name] == [self.model.d_dm_d_dmjump]


def test_wideband_residuals(wb_model, wb_toas):
r = WidebandTOAResiduals(wb_toas, wb_model, dm_resid_args=dict(subtract_mean=False))
assert len(r.toa.time_resids) == len(wb_toas)
assert len(r.dm.dm_data) < len(wb_toas)
def test_wideband_residuals(wb_model, wb_toas_all):
r = WidebandTOAResiduals(
wb_toas_all, wb_model, dm_resid_args=dict(subtract_mean=False)
)
assert len(r.toa.time_resids) == len(wb_toas_all)
assert len(r.dm.dm_data) == len(wb_toas_all)


def test_wideband_residuals_dmjump(wb_model, wb_toas):
r = WidebandTOAResiduals(wb_toas, wb_model, dm_resid_args=dict(subtract_mean=False))
def test_wideband_residuals_dmjump(wb_model, wb_toas_all):
r = WidebandTOAResiduals(
wb_toas_all, wb_model, dm_resid_args=dict(subtract_mean=False)
)
model = deepcopy(wb_model)
assert wb_model.DMJUMP1.value == 0
model.DMJUMP1.value = 10
Expand All @@ -178,10 +169,17 @@ def test_wideband_residuals_dmjump(wb_model, wb_toas):
model.DMJUMP0
with pytest.raises(AttributeError):
model.DMJUMP2
r2 = WidebandTOAResiduals(wb_toas, model, dm_resid_args=dict(subtract_mean=False))
r2 = WidebandTOAResiduals(
wb_toas_all, model, dm_resid_args=dict(subtract_mean=False)
)
assert 0 < np.sum(r.dm.resids_value != r2.dm.resids_value) < len(r.dm.resids_value)


def test_read_mixed_timfile():
with pytest.raises(ValueError):
get_TOAs(io.StringIO(tim))


def test_wideband_residuals_dof(wb_model, wb_toas_all):
wb_model.free_params = ["DMJUMP1"]
r = WidebandTOAResiduals(
Expand All @@ -192,14 +190,6 @@ def test_wideband_residuals_dof(wb_model, wb_toas_all):
assert_allclose(r.reduced_chi2, r.chi2 / r.dof)


@pytest.mark.xfail(reason="All TOAs must have DMs, currently")
def test_wideband_fit_dmjump(wb_model, wb_toas):
wb_model.free_params = ["DMJUMP1"]
fitter = WidebandTOAFitter(wb_toas, wb_model)
fitter.fit_toas()
assert_allclose(fitter.model.DMJUMP1.value, -10, atol=1e-3)


def test_wideband_fit_dmjump_all(wb_model, wb_toas_all):
wb_model.free_params = ["DMJUMP1"]
fitter = WidebandTOAFitter(wb_toas_all, wb_model)
Expand Down

0 comments on commit f303989

Please sign in to comment.