Skip to content

Commit

Permalink
add named loggers to bank modules
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Dec 19, 2023
1 parent c042b71 commit a355ab7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 12 deletions.
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/bank_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
specific values from PyCBC template banks.
"""

import logging
import numpy as np
from pycbc import conversions as conv
from pycbc import pnutils

logger = logging.getLogger('pycbc.tmpltbank.bank_conversions')

# Convert from parameter name to helper function
# some multiple names are used for the same function
conversion_options = ['mass1', 'mass2', 'spin1z', 'spin2z', 'duration',
Expand Down
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/bank_output_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy
import h5py
import logging
from lal import PI, MTSUN_SI, TWOPI, GAMMA
from ligo.lw import ligolw, lsctables, utils as ligolw_utils
from pycbc import pnutils
Expand All @@ -10,6 +11,8 @@

from pycbc.waveform import get_waveform_filter_length_in_time as gwflit

logger = logging.getLogger('pycbc.tmpltbank.bank_output_utils')

def convert_to_sngl_inspiral_table(params, proc_id):
'''
Convert a list of m1,m2,spin1z,spin2z values into a basic sngl_inspiral
Expand Down
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/brute_force_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
import numpy
from pycbc.tmpltbank.coord_utils import get_cov_params

logger = logging.getLogger('pycbc.tmpltbank.brute_force_methods')


def get_physical_covaried_masses(xis, bestMasses, bestXis, req_match,
massRangeParams, metricParams, fUpper,
Expand Down
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/calc_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import logging
import numpy
from pycbc.tmpltbank.lambda_mapping import generate_mapping

logger = logging.getLogger('pycbc.tmpltbank.calc_moments')


def determine_eigen_directions(metricParams, preserveMoments=False,
vary_fmax=False, vary_density=None):
Expand Down
8 changes: 5 additions & 3 deletions pycbc/tmpltbank/coord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from pycbc import pnutils
from pycbc.neutron_stars import load_ns_sequence

logger = logging.getLogger('pycbc.tmpltbank.coord_utils')

def estimate_mass_range(numPoints, massRangeParams, metricParams, fUpper,\
covary=True):
"""
Expand Down Expand Up @@ -235,7 +237,7 @@ def get_random_mass(numPoints, massRangeParams, eos='2H'):
warn_msg += "(%s). " %(max_ns_g_mass)
warn_msg += "The code will proceed using the latter value "
warn_msg += "as the boundary mass."
logging.warn(warn_msg)
logger.warn(warn_msg)
boundary_mass = max_ns_g_mass

# Empty arrays to store points that pass all cuts
Expand Down Expand Up @@ -711,15 +713,15 @@ def find_max_and_min_frequencies(name, mass_range_params, freqs):
warn_msg += "for the metric: %s Hz. " %(freqs.min())
warn_msg += "Distances for these waveforms will be calculated at "
warn_msg += "the lowest available metric frequency."
logging.warn(warn_msg)
logger.warn(warn_msg)
if upper_f_cutoff > freqs.max():
warn_msg = "WARNING: "
warn_msg += "Highest frequency cutoff is %s Hz " %(upper_f_cutoff,)
warn_msg += "which is larger than the highest frequency calculated "
warn_msg += "for the metric: %s Hz. " %(freqs.max())
warn_msg += "Distances for these waveforms will be calculated at "
warn_msg += "the largest available metric frequency."
logging.warn(warn_msg)
logger.warn(warn_msg)
return find_closest_calculated_frequencies(cutoffs, freqs)


Expand Down
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/lambda_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import re
import logging
import numpy
import pycbc.libutils
from lal import MTSUN_SI, PI, CreateREAL8Vector

logger = logging.getLogger('pycbc.tmpltbank.lambda_mapping')

lalsimulation = pycbc.libutils.import_optional('lalsimulation')

# PLEASE ENSURE THESE ARE KEPT UP TO DATE WITH THE REST OF THIS FILE
Expand Down
3 changes: 3 additions & 0 deletions pycbc/tmpltbank/lattice_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import copy
import numpy
import lal
import logging

logger = logging.getLogger('pycbc.tmpltbank.lattice_utils')

def generate_hexagonal_lattice(maxv1, minv1, maxv2, minv2, mindist):
"""
Expand Down
18 changes: 10 additions & 8 deletions pycbc/tmpltbank/option_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from pycbc.neutron_stars import load_ns_sequence
from pycbc.types import positive_float, nonnegative_float

logger = logging.getLogger('pycbc.tmpltbank.option_utils')

class IndentedHelpFormatterWithNL(argparse.ArgumentDefaultsHelpFormatter):
"""
This class taken from
Expand Down Expand Up @@ -589,21 +591,21 @@ def verify_mass_range_options(opts, parser, nonSpin=False):
# inform him/her about the caveats involved in this.
if hasattr(opts, 'remnant_mass_threshold') \
and opts.remnant_mass_threshold is not None:
logging.info("""You have asked to exclude EM dim NS-BH systems from the
target parameter space. The script will assume that m1 is
the BH and m2 is the NS: make sure that your settings
respect this convention. The script will also treat the
NS as non-spinning: use NS spins in the template bank
at your own risk!""")
logger.info("""You have asked to exclude EM dim NS-BH systems from the
target parameter space. The script will assume that m1 is
the BH and m2 is the NS: make sure that your settings
respect this convention. The script will also treat the
NS as non-spinning: use NS spins in the template bank
at your own risk!""")
if opts.use_eos_max_ns_mass:
logging.info("""You have asked to take into account the maximum NS
logger.info("""You have asked to take into account the maximum NS
mass value for the EOS in use.""")
# Find out if the EM constraint surface data already exists or not
# and inform user whether this will be read from file or generated.
# This is the minumum eta as a function of BH spin and NS mass
# required to produce an EM counterpart
if os.path.isfile('constraint_em_bright.npz'):
logging.info("""The constraint surface for EM bright binaries
logger.info("""The constraint surface for EM bright binaries
will be read in from constraint_em_bright.npz.""")

# Assign min/max total mass from mass1, mass2 if not specified
Expand Down
4 changes: 3 additions & 1 deletion pycbc/tmpltbank/partitioned_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import logging
from pycbc.tmpltbank import coord_utils

logger = logging.getLogger('pycbc.tmpltbank.partitioned_bank')

class PartitionedTmpltbank(object):
"""
This class is used to hold a template bank partitioned into numerous bins
Expand Down Expand Up @@ -524,7 +526,7 @@ def add_point_by_masses(self, mass1, mass2, spin1z, spin2z,
warn_msg += "convention is that mass1 > mass2. Swapping mass1 "
warn_msg += "and mass2 and adding point to bank. This message "
warn_msg += "will not be repeated."
logging.warn(warn_msg)
logger.warn(warn_msg)
self.spin_warning_given = True

# These that masses obey the restrictions of mass_range_params
Expand Down

0 comments on commit a355ab7

Please sign in to comment.