Skip to content

Enhance logging throughout the package for improved debugging and logging - #311

Merged
nikhil-sarin merged 16 commits into
masterfrom
claude/improve-logging-011CUyArWBWkX7cyfVNJF3e3
Jan 31, 2026
Merged

nikhil-sarin merged 16 commits into
masterfrom
claude/improve-logging-011CUyArWBWkX7cyfVNJF3e3

Conversation

@nikhil-sarin

Copy link
Copy Markdown
Owner

Added comprehensive logging to improve observability and debugging across the codebase:

Core modules:

  • result.py: Added logging for file I/O operations, transient reconstruction, and error handling
  • model_library.py: Added logging during model dictionary construction and module loading
  • sed.py: Added error logging for bandpass wavelength range mismatches and validation failures
  • constraints.py: Added warning logs for physical constraint violations (energy, distance, timing)

Data retrieval modules:

  • batse.py: Added logging for data downloads, FITS conversions, and trigger number lookups
  • directory.py: Added logging for directory structure creation and validation
  • utils.py: Added logging for GRB trigger number lookups with error handling

Transient classes:

  • kilonova.py, supernova.py, tde.py: Added initialization and directory setup logging
  • prompt.py: Added extensive logging for BATSE data loading, channel selection, and instrument validation

Logging improvements include:

  • INFO level: Successful operations, initialization, data retrieval confirmations
  • DEBUG level: Detailed operation steps, intermediate values, reconstruction details
  • WARNING level: Constraint violations, fallback behaviors
  • ERROR level: Failed operations, validation errors, missing data before exceptions

All modified files pass syntax validation.

…itoring

Added comprehensive logging to improve observability and debugging across the codebase:

Core modules:
- result.py: Added logging for file I/O operations, transient reconstruction, and error handling
- model_library.py: Added logging during model dictionary construction and module loading
- sed.py: Added error logging for bandpass wavelength range mismatches and validation failures
- constraints.py: Added warning logs for physical constraint violations (energy, distance, timing)

Data retrieval modules:
- batse.py: Added logging for data downloads, FITS conversions, and trigger number lookups
- directory.py: Added logging for directory structure creation and validation
- utils.py: Added logging for GRB trigger number lookups with error handling

Transient classes:
- kilonova.py, supernova.py, tde.py: Added initialization and directory setup logging
- prompt.py: Added extensive logging for BATSE data loading, channel selection, and instrument validation

Logging improvements include:
- INFO level: Successful operations, initialization, data retrieval confirmations
- DEBUG level: Detailed operation steps, intermediate values, reconstruction details
- WARNING level: Constraint violations, fallback behaviors
- ERROR level: Failed operations, validation errors, missing data before exceptions

All modified files pass syntax validation.
@nikhil-sarin nikhil-sarin added the enhancement New feature or request label Nov 10, 2025
claude and others added 9 commits November 16, 2025 12:56
Add common test-generated data directories to prevent accidental commits:
- GRBData/
- supernova/
- kilonova/
- tidal_disruption_event/
- spectrum/

These directories are created during test runs when data is downloaded
or simulated, and should not be tracked in version control.
Constraint functions are called with array inputs during bilby prior
sampling, causing TypeError when trying to format arrays with f-string
format specifiers. Removed verbose logging from these hot-path functions
to fix test failures and avoid excessive log output during sampling.
Added extensive unit tests to cover the new logging functionality:

result_test.py:
- Tests for read_in_result with various file formats (JSON, HDF5, pickle, gzip)
- Error cases: file not found, invalid extension, missing extension
- Transient reconstruction success and failure paths
- Plotting with stored model selection

transient_test.py:
- TestKilonovaTransient: Initialization with logging validation
- TestSupernovaTransient: Initialization with logging validation
- TestTDETransient: Initialization with logging validation
- TestPromptTimeSeriesTransient: BATSE/Swift initialization, invalid instrument error handling, data loading

get_data_test.py:
- TestUtilsLogging: Trigger number lookup errors, BATSE trigger lookup
- TestBATSEDataGetterLogging: Data collection success/failure, CSV conversion
- TestDirectoryLogging: Invalid bin size error, spectrum directory creation

utils_test.py:
- TestSEDErrorHandling: Zero-point system validation, wavelength range mismatch errors

These tests exercise:
- INFO level logging for successful operations
- ERROR level logging before exceptions
- DEBUG level logging for detailed operations
- WARNING level logging for constraint violations
- All error handling code paths with proper logging
The tests were failing because batse_prompt_directory_structure internally
calls get_batse_trigger_from_grb when no trigger is provided. Added mock
for get_batse_trigger_from_grb to prevent actual trigger table lookups
during tests.
Patch functions where they are imported (redback.transient.prompt)
rather than where they are defined. Also mock _set_data to avoid
event table lookups.
…d code

- Add tests for plot_spectrum, plot_residual, plot_multiband_lightcurve,
  plot_data, and plot_multiband methods
- Add tests for edge cases in read_in_result (no extension, unsupported type)
- Remove unreachable code path for None extension (os.path.splitext always
  returns string)
- Achieves 100% test coverage for result.py
Separate entries that were incorrectly concatenated without newlines.
…JF3e3

Resolved conflicts prioritizing master's changes:
- .gitignore: Use master's comprehensive coverage ignores
- test/result_test.py: Use master's comprehensive test suite
- test/transient_test.py: Use master's base, append logging tests
- test/get_data_test.py: Append logging tests to master's version
- test/utils_test.py: Append SED error handling tests to master's version

Retained all logging-related test classes:
- TestKilonovaTransient, TestSupernovaTransient, TestTDETransient
- TestPromptTimeSeriesTransient with proper mock patching
- TestBATSEDataGetterLogging, TestDirectoryLogging, TestUtilsLogging
- TestSEDErrorHandling
@nikhil-sarin
nikhil-sarin force-pushed the claude/improve-logging-011CUyArWBWkX7cyfVNJF3e3 branch from 82c6de6 to 0fe017c Compare November 21, 2025 15:34
claude and others added 4 commits November 22, 2025 17:31
Master's tests were failing because logging code checks file existence.
Add mock for os.path.exists(return_value=True) to all read tests.
Add label and model attributes to all mock RedbackResult objects
to support the success logging message.
…JF3e3

# Conflicts:
#	redback/model_library.py
@nikhil-sarin nikhil-sarin added this to the v1.13.2 milestone Jan 29, 2026
@nikhil-sarin
nikhil-sarin marked this pull request as ready for review January 31, 2026 22:58
@nikhil-sarin nikhil-sarin changed the title [WIP] - Enhance logging throughout the package for improved debugging and logging Enhance logging throughout the package for improved debugging and logging Jan 31, 2026
@nikhil-sarin
nikhil-sarin merged commit c8b9755 into master Jan 31, 2026
12 checks passed
@nikhil-sarin
nikhil-sarin deleted the claude/improve-logging-011CUyArWBWkX7cyfVNJF3e3 branch June 7, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants