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

RHESSI fits sum_flag=0 breaks code #132

Open
ianan opened this issue Nov 28, 2023 · 3 comments
Open

RHESSI fits sum_flag=0 breaks code #132

ianan opened this issue Nov 28, 2023 · 3 comments

Comments

@ianan
Copy link

ianan commented Nov 28, 2023

Describe the bug

At the moment the code returns an error and breaks when trying to load a RHESSI srm/spec fits file with sum_flag != 1 in the header. I guess @KriSun95 did this is to avoid issues of multiple detectors that aren't summed, i.e. expecting always to have a single srm and single spectrogram in each fits file. But even if there is a single srm/spec in there (say only using a single RHESSI detector) will get the error/break if sum_flag=0 in the fits header.

Short term solution is just to make sure sum_flag=1 when generating RHESSI srm/spec fits from the hsi_spectrum() in sswidl, whether summed over multiple detectors or "summed" over a single detector.

Longer term might want a smarter way to deal with this? Maybe @settwi might have some ideas given your work on loading in RHESSI spec/srm.

To Reproduce

Load in a RHESSI spec/srm fits file where have a single detector spectrogram/srm but sum_flag=0 in the header, i.e. https://github.com/ianan/rhessi_spectra/blob/main/mfstats9_fits/20030725_082642_srm_org_d1.fits https://github.com/ianan/rhessi_spectra/blob/main/mfstats9_fits/20030725_082642_spec_org_d1.fits

from sunkit_spex.sunxspex_fitting.fitter import Fitter
spec = Fitter(pha_file="20030725_082642_spec_org_d1.fits", srm_file="20030725_082642_srm_org_d1")

Gives error/breaks in sunxspex_fitting/instruments.py:662 with warning:
"Apparently spectrum file's SUMFLAG should be one and I don't know what to do otherwise at the moment."

Screenshots

No response

System Details

No response

Installation method

No response

@settwi
Copy link
Contributor

settwi commented Nov 28, 2023

I believe OSPEX only allows spectroscopy to be performed when SUMFLAG=1 (see here):

sum_flag = fxpar (hdr, 'SUMFLAG', count=count)
if count gt 0 and sum_flag eq 0 then begin
  if n_elements(str2arr(detused, ' ')) gt 1 then begin   ; check for > 1 det
	  err_code = 1
	  err_msg = 'OSPEX can not handle SRM files with >1 detectors that are not summed (sum_flag=0). Aborting'
	  return
	endif
endif

Summing counts from the different RHESSI detectors is kind of fraught so that makes sense.
I guess we could just add a special case if there is only one detector. OSPEX does that a few lines above.

-WS

@KriSun95
Copy link
Collaborator

The spex_hessi_fits2drm.pro file that @settwi has linked is likely why my error very helpfully reads:
"Apparently spectrum file's SUMFLAG should be one and I don't know what to do otherwise at the moment.".

Looking at it again, would this not most likely be because OSPEX can't do simultaneous fitting? I.e., it would have no idea what to do if the detectors weren't summed into a single spectrum with only one SRM. Obviously, if this is the only reason why SUMFLAG must be 1, then there would be no issue on our side by supporting SRM files with >1 detectors that are not summed.

@settwi
Copy link
Contributor

settwi commented Nov 29, 2023

Good idea!

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

No branches or pull requests

3 participants