Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper update of logging incl. test files #767

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/sorcha/sorcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import argparse
import os
import logging

from sorcha.ephemeris.simulation_driver import create_ephemeris
from sorcha.ephemeris.simulation_setup import precompute_pointing_information
Expand Down Expand Up @@ -49,7 +50,7 @@
cite_sorcha()


def runLSSTSimulation(args, configs, pplogger=None):
def runLSSTSimulation(args, configs):
"""
Runs the post processing survey simulator functions that apply a series of
filters to bias a model Solar System small body population to what the
Expand All @@ -68,25 +69,12 @@
None.

"""
# Set up logging if it hasn't happened already.
if pplogger is None:
if type(args) is dict:
pplogger = PPGetLogger(args["outpath"])
else:
pplogger = PPGetLogger(args.outpath)
pplogger = logging.getLogger(__name__)
pplogger.info("Post-processing begun.")

update_lc_subclasses()
update_activity_subclasses()

# Initialise argument parser, assign command line arguments, and validate.
if type(args) is dict:
try:
args = sorchaArguments(args, pplogger)
except Exception as err:
pplogger.error(err)
sys.exit(err)

try:
args.validate_arguments()
except Exception as err:
Expand Down Expand Up @@ -454,7 +442,7 @@

if cmd_args["surveyname"] in ["LSST", "lsst"]:
try:
args = sorchaArguments(cmd_args, pplogger)
args = sorchaArguments(cmd_args)

Check warning on line 445 in src/sorcha/sorcha.py

View check run for this annotation

Codecov / codecov/patch

src/sorcha/sorcha.py#L445

Added line #L445 was not covered by tests
except Exception as err:
pplogger.error(err)
sys.exit(err)
Expand All @@ -463,7 +451,7 @@
except Exception as err:
pplogger.error(err)
sys.exit(err)
runLSSTSimulation(args, configs, pplogger)
runLSSTSimulation(args, configs)

Check warning on line 454 in src/sorcha/sorcha.py

View check run for this annotation

Codecov / codecov/patch

src/sorcha/sorcha.py#L454

Added line #L454 was not covered by tests
else:
pplogger.error(
"ERROR: Survey name not recognised. Current allowed surveys are: {}".format(["LSST", "lsst"])
Expand Down
10 changes: 4 additions & 6 deletions src/sorcha/utilities/sorchaArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass
import time
from os import path
import logging

from sorcha.modules.PPModuleRNG import PerModuleRNG
from sorcha.modules.PPGetLogger import PPGetLogger
Expand Down Expand Up @@ -37,10 +38,10 @@ class sorchaArguments:
"""A collection of per-module random number generators"""

pplogger = None
"""The Python logger instance"""

def __init__(self, cmd_args_dict=None, pplogger=None):
if pplogger is not None:
self.pplogger = pplogger
def __init__(self, cmd_args_dict=None):
self.pplogger = logging.getLogger(__name__)
if cmd_args_dict is not None:
self.read_from_dict(cmd_args_dict)

Expand All @@ -62,9 +63,6 @@ def read_from_dict(self, args):
if "complex_physical_parameters" in args.keys():
self.complex_parameters = args["complex_physical_parameters"]

if self.pplogger is None:
self.pplogger = PPGetLogger(self.outpath)

# WARNING: Take care if manually setting the seed. Re-using seeds between
# simulations may result in hard-to-detect correlations in simulation
# outputs.
Expand Down
Loading