From 573dcf1b852868fdbb56efe760a64c233fa2ed62 Mon Sep 17 00:00:00 2001 From: Colm Talbot <colm.talbot@ligo.org> Date: Fri, 11 Feb 2022 19:40:15 +0000 Subject: [PATCH] remove deprecated functions --- bilby/core/result.py | 61 ------------------------- bilby/core/utils/__init__.py | 1 - bilby/core/utils/conversion.py | 53 --------------------- bilby/core/utils/progress.py | 18 -------- bilby/gw/detector/interferometer.py | 26 ----------- bilby/gw/detector/networks.py | 31 ------------- bilby/gw/likelihood/base.py | 9 ---- test/gw/detector/interferometer_test.py | 26 ----------- test/gw/detector/networks_test.py | 23 ---------- 9 files changed, 248 deletions(-) delete mode 100644 bilby/core/utils/progress.py diff --git a/bilby/core/result.py b/bilby/core/result.py index 48797a4f1..e2608932e 100644 --- a/bilby/core/result.py +++ b/bilby/core/result.py @@ -422,65 +422,6 @@ class Result(object): self.prior_values = None self._kde = None - @classmethod - def _from_hdf5_old(cls, filename=None, outdir=None, label=None): - """ Read in a saved .h5 data file in the old format. - - Parameters - ========== - filename: str - If given, try to load from this filename - outdir, label: str - If given, use the default naming convention for saved results file - - Returns - ======= - result: bilby.core.result.Result - - Raises - ======= - ValueError: If no filename is given and either outdir or label is None - If no bilby.core.result.Result is found in the path - - """ - import deepdish - filename = _determine_file_name(filename, outdir, label, 'hdf5', False) - - if os.path.isfile(filename): - dictionary = deepdish.io.load(filename) - # Some versions of deepdish/pytables return the dictionary as - # a dictionary with a key 'data' - if len(dictionary) == 1 and 'data' in dictionary: - dictionary = dictionary['data'] - - if "priors" in dictionary: - # parse priors from JSON string (allowing for backwards - # compatibility) - if not isinstance(dictionary["priors"], PriorDict): - try: - priordict = PriorDict() - for key, value in dictionary["priors"].items(): - if key not in ["__module__", "__name__", "__prior_dict__"]: - try: - priordict[key] = decode_bilby_json(value) - except AttributeError: - continue - dictionary["priors"] = priordict - except Exception as e: - raise IOError( - "Unable to parse priors from '{}':\n{}".format( - filename, e, - ) - ) - try: - if isinstance(dictionary.get('posterior', None), dict): - dictionary['posterior'] = pd.DataFrame(dictionary['posterior']) - return cls(**dictionary) - except TypeError as e: - raise IOError("Unable to load dictionary, error={}".format(e)) - else: - raise IOError("No result '{}' found".format(filename)) - _load_doctstring = """ Read in a saved .{format} data file Parameters @@ -516,8 +457,6 @@ class Result(object): filename = _determine_file_name(filename, outdir, label, 'hdf5', False) with h5py.File(filename, "r") as ff: data = recursively_load_dict_contents_from_group(ff, '/') - if list(data.keys()) == ["data"]: - return cls._from_hdf5_old(filename=filename) data["posterior"] = pd.DataFrame(data["posterior"]) data["priors"] = PriorDict._get_from_json_dict( json.loads(data["priors"], object_hook=decode_bilby_json) diff --git a/bilby/core/utils/__init__.py b/bilby/core/utils/__init__.py index 85c3fb1f4..10509641a 100644 --- a/bilby/core/utils/__init__.py +++ b/bilby/core/utils/__init__.py @@ -9,7 +9,6 @@ from .introspection import * from .io import * from .log import * from .plotting import * -from .progress import * from .samples import * from .series import * diff --git a/bilby/core/utils/conversion.py b/bilby/core/utils/conversion.py index 978e34346..c89e2a9ec 100644 --- a/bilby/core/utils/conversion.py +++ b/bilby/core/utils/conversion.py @@ -1,6 +1,3 @@ -import warnings -from math import fmod - import numpy as np @@ -31,53 +28,3 @@ def theta_phi_to_ra_dec(theta, phi, gmst): ra = phi + gmst dec = np.pi / 2 - theta return ra, dec - - -def gps_time_to_gmst(gps_time): - """ - Convert gps time to Greenwich mean sidereal time in radians - - This method assumes a constant rotation rate of earth since 00:00:00, 1 Jan. 2000 - A correction has been applied to give the exact correct value for 00:00:00, 1 Jan. 2018 - Error accumulates at a rate of ~0.0001 radians/decade. - - Parameters - ---------- - gps_time: float - gps time - - Returns - ------- - float: Greenwich mean sidereal time in radians - - """ - warnings.warn( - "Function gps_time_to_gmst deprecated, use " - "lal.GreenwichMeanSiderealTime(time) instead", - DeprecationWarning) - omega_earth = 2 * np.pi * (1 / 365.2425 + 1) / 86400. - gps_2000 = 630720013. - gmst_2000 = (6 + 39. / 60 + 51.251406103947375 / 3600) * np.pi / 12 - correction_2018 = -0.00017782487379358614 - sidereal_time = omega_earth * (gps_time - gps_2000) + gmst_2000 + correction_2018 - gmst = fmod(sidereal_time, 2 * np.pi) - return gmst - - -def spherical_to_cartesian(radius, theta, phi): - """ Convert from spherical coordinates to cartesian. - - Parameters - ========== - radius: float - radial coordinate - theta: float - axial coordinate - phi: float - azimuthal coordinate - - Returns - ======= - list: cartesian vector - """ - return [radius * np.sin(theta) * np.cos(phi), radius * np.sin(theta) * np.sin(phi), radius * np.cos(theta)] diff --git a/bilby/core/utils/progress.py b/bilby/core/utils/progress.py deleted file mode 100644 index 9db1752b2..000000000 --- a/bilby/core/utils/progress.py +++ /dev/null @@ -1,18 +0,0 @@ -def get_progress_bar(module='tqdm'): - """ - TODO: Write proper docstring - """ - if module in ['tqdm']: - try: - from tqdm import tqdm - except ImportError: - def tqdm(x, *args, **kwargs): - return x - return tqdm - elif module in ['tqdm_notebook']: - try: - from tqdm import tqdm_notebook as tqdm - except ImportError: - def tqdm(x, *args, **kwargs): - return x - return tqdm diff --git a/bilby/gw/detector/interferometer.py b/bilby/gw/detector/interferometer.py index 8447c16ef..06b298386 100644 --- a/bilby/gw/detector/interferometer.py +++ b/bilby/gw/detector/interferometer.py @@ -771,32 +771,6 @@ class Interferometer(object): """ - @docstring(_save_ifo_docstring.format( - format="hdf5", extra=""".. deprecated:: 1.1.0 - Use :func:`to_pickle` instead.""" - )) - def to_hdf5(self, outdir='outdir', label=None): - import deepdish - if label is None: - label = self.name - utils.check_directory_exists_and_if_not_mkdir('outdir') - try: - filename = self._filename_from_outdir_label_extension(outdir, label, "h5") - deepdish.io.save(filename, self) - except AttributeError: - logger.warning("Saving to hdf5 using deepdish failed. Pickle dumping instead.") - self.to_pickle(outdir=outdir, label=label) - - @classmethod - @docstring(_load_docstring.format(format="hdf5")) - def from_hdf5(cls, filename=None): - import deepdish - - res = deepdish.io.load(filename) - if res.__class__ != cls: - raise TypeError('The loaded object is not an Interferometer') - return res - @docstring(_save_ifo_docstring.format( format="pickle", extra=".. versionadded:: 1.1.0" )) diff --git a/bilby/gw/detector/networks.py b/bilby/gw/detector/networks.py index db0d4743b..4f03b948b 100644 --- a/bilby/gw/detector/networks.py +++ b/bilby/gw/detector/networks.py @@ -272,31 +272,6 @@ class InterferometerList(list): """ - def to_hdf5(self, outdir="outdir", label="ifo_list"): - import deepdish - - label = label + "_" + "".join(ifo.name for ifo in self) - utils.check_directory_exists_and_if_not_mkdir(outdir) - try: - filename = self._filename_from_outdir_label_extension(outdir, label, "h5") - deepdish.io.save(filename, self) - except AttributeError: - logger.warning( - "Saving to hdf5 using deepdish failed. Pickle dumping instead." - ) - self.to_pickle(outdir=outdir, label=label) - - @classmethod - def from_hdf5(cls, filename=None): - import deepdish - - res = deepdish.io.load(filename) - if res.__class__ == list: - res = cls(res) - if res.__class__ != cls: - raise TypeError("The loaded object is not a InterferometerList") - return res - def to_pickle(self, outdir="outdir", label="ifo_list"): import dill @@ -318,15 +293,9 @@ class InterferometerList(list): raise TypeError("The loaded object is not an InterferometerList") return res - to_hdf5.__doc__ = _save_docstring.format( - format="hdf5", - extra=""".. deprecated:: 1.1.0 - Use :func:`to_pickle` instead.""", - ) to_pickle.__doc__ = _save_docstring.format( format="pickle", extra=".. versionadded:: 1.1.0" ) - from_hdf5.__doc__ = _load_docstring.format(format="hdf5") from_pickle.__doc__ = _load_docstring.format(format="pickle") diff --git a/bilby/gw/likelihood/base.py b/bilby/gw/likelihood/base.py index 55845c093..d4d8eca34 100644 --- a/bilby/gw/likelihood/base.py +++ b/bilby/gw/likelihood/base.py @@ -936,15 +936,6 @@ class GravitationalWaveTransient(Likelihood): "to use bilby.gw.utils.ln_i0" ) - @staticmethod - def _bessel_function_interped(xx): - logger.warning( - "The _bessel_function_interped method is deprecated and will be removed, " - "please update the implementation of phase marginalization " - "to use bilby.gw.utils.ln_i0" - ) - return ln_i0(xx) + xx - def _setup_time_marginalization(self): self._delta_tc = 2 / self.waveform_generator.sampling_frequency self._times = \ diff --git a/test/gw/detector/interferometer_test.py b/test/gw/detector/interferometer_test.py index 2a37830fc..3eea3c59d 100644 --- a/test/gw/detector/interferometer_test.py +++ b/test/gw/detector/interferometer_test.py @@ -3,13 +3,9 @@ from unittest import mock import lal import lalsimulation -import pytest -from packaging import version from shutil import rmtree -import deepdish as dd import numpy as np -import pandas import bilby @@ -371,28 +367,6 @@ class TestInterferometer(unittest.TestCase): ) self.assertEqual(expected, repr(self.ifo)) - pandas_version_test = version.parse(pandas.__version__) >= version.parse("1.2.0") - skip_reason = "Deepdish requires pandas < 1.2" - - @pytest.mark.skipif(pandas_version_test, reason=skip_reason) - def test_to_and_from_hdf5_loading(self): - self.ifo.to_hdf5(outdir="outdir", label="test") - filename = self.ifo._filename_from_outdir_label_extension( - outdir="outdir", label="test", extension="h5" - ) - recovered_ifo = bilby.gw.detector.Interferometer.from_hdf5(filename) - self.assertEqual(self.ifo, recovered_ifo) - - @pytest.mark.skipif(pandas_version_test, reason=skip_reason) - def test_to_and_from_hdf5_wrong_class(self): - bilby.core.utils.check_directory_exists_and_if_not_mkdir("outdir") - dd.io.save("./outdir/psd.h5", self.power_spectral_density) - filename = self.ifo._filename_from_outdir_label_extension( - outdir="outdir", label="psd", extension="h5" - ) - with self.assertRaises(TypeError): - bilby.gw.detector.Interferometer.from_hdf5(filename) - def test_to_and_from_pkl_loading(self): self.ifo.to_pickle(outdir="outdir", label="test") filename = "outdir/test.pkl" diff --git a/test/gw/detector/networks_test.py b/test/gw/detector/networks_test.py index 971254b24..744d872a1 100644 --- a/test/gw/detector/networks_test.py +++ b/test/gw/detector/networks_test.py @@ -1,13 +1,9 @@ import unittest from unittest import mock -import pytest from shutil import rmtree -from packaging import version from itertools import combinations -import deepdish as dd import numpy as np -import pandas import bilby @@ -326,25 +322,6 @@ class TestInterferometerList(unittest.TestCase): names = [ifo.name for ifo in self.ifo_list] self.assertListEqual([self.ifo1.name, new_ifo.name, self.ifo2.name], names) - pandas_version_test = version.parse(pandas.__version__) >= version.parse("1.2.0") - skip_reason = "Deepdish requires pandas < 1.2" - - @pytest.mark.skipif(pandas_version_test, reason=skip_reason) - def test_to_and_from_hdf5_loading(self): - self.ifo_list.to_hdf5(outdir="outdir", label="test") - filename = "outdir/test_name1name2.h5" - recovered_ifo = bilby.gw.detector.InterferometerList.from_hdf5(filename) - self.assertListEqual(self.ifo_list, recovered_ifo) - - @pytest.mark.skipif(pandas_version_test, reason=skip_reason) - def test_to_and_from_hdf5_wrong_class(self): - dd.io.save("./outdir/psd.h5", self.ifo_list[0].power_spectral_density) - filename = self.ifo_list._filename_from_outdir_label_extension( - outdir="outdir", label="psd", extension="h5" - ) - with self.assertRaises(TypeError): - bilby.gw.detector.InterferometerList.from_hdf5(filename) - def test_to_and_from_pkl_loading(self): self.ifo_list.to_pickle(outdir="outdir", label="test") filename = "outdir/test_name1name2.pkl" -- GitLab