Skip to content

Writing table models#190

Closed
phajy wants to merge 10 commits into
JuliaAstro:mainfrom
phajy:andy/table-model
Closed

Writing table models#190
phajy wants to merge 10 commits into
JuliaAstro:mainfrom
phajy:andy/table-model

Conversation

@phajy

@phajy phajy commented Oct 11, 2025

Copy link
Copy Markdown
Contributor

I have had a go at writing a routine to write table models to a FITS file following "OGIP Memo 92-009 (XSPEC Table Model File Format)". I've put the routine in table-models.jl and there's a test, some documentation, and an example. You might not want to merge the example. It seems to work - I have tried creating a 1D power-law table model and reading it into XSPEC. However, you might want to make sure models you create use bin integrated quantities (might not be obvious in the examples because they have evenly spaced linear grids).

Please note that, as an experiment, and because this is a very well-defined task (and I was somewhat time-limited) I enlisted the help of an AI (Claude Sonnet 4.5) to write this. It required some iteration but seems to have worked. I was quite impressed with its performance. Obviously this means that I would really appreciate the code being human-checked! In particular, there may be some stylistic inconsistencies, or practices you would rather not follow. If that's the case please let me know and/or edit. A specific example might be the use of, isfile(path) && rm(path), for example - I'm not sure what we want to do if the user requests a table model overwrites an existing file (currently it will just go ahead and replace it). I will also do some more testing myself.

This is a draft pull request and needs reviewing.

@fjebaker - how does this sit with the rest of the code base?
@DariusMichienzi - you might want to experiment creating your own table models from, e.g., Gradus line profiles.

@codecov

codecov Bot commented Oct 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (b41858f) to head (d4b7134).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/meta-models/table-models.jl 0.00% 82 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (b41858f) and HEAD (d4b7134). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (b41858f) HEAD (d4b7134)
4 2
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #190       +/-   ##
==========================================
- Coverage   56.81%   0.00%   -56.82%     
==========================================
  Files          39      39               
  Lines        2654    2690       +36     
==========================================
- Hits         1508       0     -1508     
- Misses       1146    2690     +1544     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@fjebaker fjebaker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this Andy (and for the AI disclaimer!)

It all looks good, just a few stylistic changes, and a request to move the code in the examples folder into the documentation somewhere. See the various other little comments too.

Comment thread examples/create_powerlaw_table.jl Outdated
Comment thread src/meta-models/table-models.jl Outdated
Comment thread src/meta-models/table-models.jl
Comment thread src/meta-models/table-models.jl Outdated
Comment thread src/meta-models/table-models.jl Outdated
Comment thread src/meta-models/table-models.jl Outdated
Comment thread test/models/test-table-models.jl Outdated
Comment thread test/models/test-table-models.jl Outdated
@phajy

phajy commented Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

When testing the broken power law model I found a mistake in that the parameters were not ordered as expected. I think I have now updated things to that the FITS writing routine takes an array in Julia order (i.e., first index changes fastest) and then reorders it into an XSPEC order (i.e., last index changes fastest). This means that the arrays passed into the writer and the arrays returned by the reader are in the same order. If my logic is correct. But please watch out for bugs related to this; if the parameter orders ever seem "wrong" I've likely made a mistake!

@phajy phajy marked this pull request as ready for review October 14, 2025 11:58
@phajy

phajy commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

I am going to consider this superseded by Darius's #200 and close without merging. Thanks for your help with this in any case!

@phajy phajy closed this Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants