Skip to content

Add SpectrumFileProcessor class for automated spectral data conversion and formatting - #257

Open
krishnatejavedula wants to merge 11 commits into
cositools:developfrom
krishnatejavedula:SpectrumFileProcessor
Open

Add SpectrumFileProcessor class for automated spectral data conversion and formatting#257
krishnatejavedula wants to merge 11 commits into
cositools:developfrom
krishnatejavedula:SpectrumFileProcessor

Conversation

@krishnatejavedula

Copy link
Copy Markdown
Contributor
  • Implemented SpectrumFileProcessor class to handle energy and flux data conversion for spectrum files not in the MEGAlib spectrum file format.
  • Added energy conversion feature: converts frequency (Hz) to energy (keV) and flux from ergs/cm²/sec to ph/cm²/sec/keV using astropy units.
  • Implemented data filtering to restrict energy range to 100 keV - 10,000 keV for accurate source injector functionality.
  • Reformatted output to ensure compatibility with SpecFromDat class and consistency across cosipy and DCs spectral files.

…n and formatting

- Implemented SpectrumFileProcessor class to handle energy and flux data conversion for spectrum files not in the MEGAlib spectrum file format.
- Added energy conversion feature: converts frequency (Hz) to energy (keV) and flux from ergs/cm²/sec to ph/cm²/sec/keV using astropy units.
- Implemented data filtering to restrict energy range to 100 keV - 10,000 keV for accurate source injector functionality.
- Reformatted output to ensure compatibility with SpecFromDat class and consistency across cosipy and DCs spectral files.
@codecov

codecov Bot commented Oct 24, 2024

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.19%. Comparing base (e3d4d83) to head (4449ffd).

Files with missing lines Patch % Lines
cosipy/data_io/custom_functions.py 0.00% 75 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Files with missing lines Coverage Δ
cosipy/data_io/custom_functions.py 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hiyoneda

Copy link
Copy Markdown
Contributor

@krishnatejavedula Thanks for this work. Looks good. I have a quick comment. threeml/custom_function.py, to which you added this new class, is used to implement new spectral and spatial functions for astromodels in threeml fitting. I think that your new class can be used more generally. Can you think of a better directory for this class, maybe dataIO?

@israelmcmc

Copy link
Copy Markdown
Collaborator

Thanks @krishnatejavedula. Any updates to this?

  • I think what @hiyoneda suggested makes sense. Since there don't seem to be any interactions of SpectrumFileProcessor with 3ML, you can move this class to its own file inside the DataIO module.
  • Besides that, the other thing to resolve is to add unit tests to cover this new class.

@israelmcmc israelmcmc added the pull-request-waiting-for-author The ball is on the author's side. label Sep 11, 2025
@israelmcmc
israelmcmc requested a review from hiyoneda September 11, 2025 18:16
@israelmcmc israelmcmc added the Feature / Enhancement New functionality or improvement label Sep 15, 2025
@Yong2Sheng
Yong2Sheng self-requested a review November 19, 2025 18:39

@Yong2Sheng Yong2Sheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the module and it works well.

@israelmcmc

Copy link
Copy Markdown
Collaborator

@krishnatejavedula What's the status of this PR? are the unit tests the only thing missing?

@krishnatejavedula

Copy link
Copy Markdown
Contributor Author

@israelmcmc It believe the code needs some refactoring and must be checked to see if it conflicts with any new changes to the source injector.

@israelmcmc

Copy link
Copy Markdown
Collaborator

Got it, thanks for the update @krishnatejavedula!

…o-column spectrum files for use with SpecFromDat and the source injector tutorials. The processor supports frequency plus nuFnu inputs, already-converted keV plus dN/dE inputs, filtering to the source-injector energy range, normalization calculation, plotting, and MEGAlib-style output formatting. Added focused unit tests for conversions, filtering, formatting, and SpecFromDat compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature / Enhancement New functionality or improvement pull-request-waiting-for-author The ball is on the author's side.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants