11
2- import json
3-
42import numpy as np
53
64from .base import GravitationalWaveTransient
7- from ...core .utils import BilbyJsonEncoder , decode_bilby_json
85from ...core .utils import (
96 logger , create_frequency_series , speed_of_light , radius_of_earth
107)
@@ -992,32 +989,22 @@ def _set_weights_quadratic_multiband(self, quadratic_matrix, basis_idxs):
992989
993990 def save_weights (self , filename , format = 'hdf5' ):
994991 """
995- Save ROQ weights into a single file. format should be npz, or hdf5.
996- For weights from multiple bases, hdf5 is only the possible option.
997- Support for json format is deprecated as of :code:`v2.1` and will be
998- removed in :code:`v2.2`, another method should be used by default.
992+ Save ROQ weights into a single file.
993+ Support for json format was removed in :code:`v2.7`, only hdf5 and npz are supported.
999994
1000995 Parameters
1001996 ==========
1002997 filename : str
1003998 The name of the file to save the weights to.
1004999 format : str
1005- The format to save the data to, this should be one of
1006- :code:`"hdf5"`, :code:`"npz"`, default=:code:`"hdf5"`.
1000+ The format to save the weight in, should be in :code:`hdf5, npz`.
10071001 """
1008- if format not in ['json ' , 'npz' , 'hdf5 ' ]:
1002+ if format not in ['hdf5 ' , 'npz' ]:
10091003 raise IOError (f"Format { format } not recognized." )
1010- if format == "json" :
1011- import warnings
1012-
1013- warnings .warn (
1014- "json format for ROQ weights is deprecated, use hdf5 instead." ,
1015- DeprecationWarning
1016- )
10171004 if format not in filename :
10181005 filename += "." + format
10191006 logger .info (f"Saving ROQ weights to { filename } " )
1020- if format == 'json' or format == ' npz' :
1007+ if format == 'npz' :
10211008 if self .number_of_bases_linear > 1 or self .number_of_bases_quadratic > 1 :
10221009 raise ValueError (f'Format { format } not compatible with multiple bases' )
10231010 weights = dict ()
@@ -1026,11 +1013,7 @@ def save_weights(self, filename, format='hdf5'):
10261013 for ifo in self .interferometers :
10271014 key = f'{ ifo .name } _{ basis_type } '
10281015 weights [key ] = self .weights [key ][0 ]
1029- if format == 'json' :
1030- with open (filename , 'w' ) as file :
1031- json .dump (weights , file , indent = 2 , cls = BilbyJsonEncoder )
1032- else :
1033- np .savez (filename , ** weights )
1016+ np .savez (filename , ** weights )
10341017 else :
10351018 import h5py
10361019 with h5py .File (filename , 'w' ) as f :
@@ -1058,18 +1041,14 @@ def save_weights(self, filename, format='hdf5'):
10581041
10591042 def load_weights (self , filename , format = None ):
10601043 """
1061- Load ROQ weights. format should be json, npz, or hdf5.
1062- json or npz file is assumed to contain weights from a single basis.
1063- Support for json format is deprecated as of :code:`v2.1` and will be
1064- removed in :code:`v2.2`, another method should be used by default.
1044+ Load ROQ weights. Support for json format was removed in :code:`v2.7`.
10651045
10661046 Parameters
10671047 ==========
10681048 filename : str
10691049 The name of the file to save the weights to.
10701050 format : str
1071- The format to save the data to, this should be one of
1072- :code:`"hdf5"`, :code:`"npz"`, default=:code:`"hdf5"`.
1051+ The format of the weight file, should be in :code:`hdf5, npz`.
10731052
10741053 Returns
10751054 =======
@@ -1078,24 +1057,19 @@ def load_weights(self, filename, format=None):
10781057 """
10791058 if format is None :
10801059 format = filename .split ("." )[- 1 ]
1081- if format not in ["json" , "npz" , "hdf5" ]:
1082- raise IOError (f"Format { format } not recognized." )
10831060 if format == "json" :
10841061 import warnings
10851062
10861063 warnings .warn (
10871064 "json format for ROQ weights is deprecated, use hdf5 instead." ,
10881065 DeprecationWarning
10891066 )
1067+ elif format not in ["npz" , "hdf5" ]:
1068+ raise IOError (f"Format { format } not recognized." )
1069+
10901070 logger .info (f"Loading ROQ weights from { filename } " )
1091- if format == "json" or format == "npz" :
1092- # Old file format assumed to contain only a single basis
1093- if format == "json" :
1094- with open (filename , 'r' ) as file :
1095- weights = json .load (file , object_hook = decode_bilby_json )
1096- else :
1097- # Wrap in dict to load data into memory
1098- weights = dict (np .load (filename ))
1071+ if format == "npz" :
1072+ weights = dict (np .load (filename ))
10991073 for basis_type in ['linear' , 'quadratic' ]:
11001074 for ifo in self .interferometers :
11011075 key = f'{ ifo .name } _{ basis_type } '
0 commit comments