<p>I have managed to extract the response matrix as 2D array. This works perfectly in my case. I filled the empty positions in matrix column with zeros and extracted the matrix out for me. PE format contains the array with variable length. Here is my approach to the solution.</p>
<pre><code>import numpy as np
from astropy.io import fits
from astropy.table import Table
from astropy.table import QTable

# Read RMF
        try:
            RSPdata = Table.read(RSPfile, 'MATRIX')  # FITS extension 'MATRIX'
        except:
            RSPdata = Table.read(RSPfile, 'SPECRESP MATRIX')  # Backup FITS extension 'SPECRESP MATRIX'

        MAT_column = RSPdata['MATRIX']  # Response matrix column in FITS file
        max_length = max(len(row) for row in MAT_column)
        padded_MAT_column = np.array([np.pad(row, (0, max_length - len(row)), 'constant') for row in MAT_column])  # Padding each row to the maximum length

        matrix = np.ascontiguousarray(padded_MAT_column.T, dtype=np.double)
</code></pre>

CC BY-SA 4.0
2024-08-22T01:07:48.923Z
2024-08-22T01:07:48.923Z
Universe_explorer080
<p>The response matrix column in my RMF fits file is in &quot;PE&quot; format. I want to change my matrix as 2D matrix. Is there any solution to this?</p>

CC BY-SA 4.0
2024-08-12T05:13:30.517Z
I’m voting to close this question because it appears to be about resolving a mathematics problem rather than relating directly to astronomy. It might be suited to Mathematics.SE but is off-topic on Astronomy.SE.
Chappo Hasn't Forgotten
CC BY-SA 4.0
2024-08-12T15:04:37.097Z
I think it's likely on-topic but could do with the some additional details in the question from the OP. Brief googling turns a link to the Chandra X-ray tools as it's first [hit for RMF](https://cxc.cfa.harvard.edu/ciao/ahelp/mkrmf.html)
astrosnapper
CC BY-SA 4.0
2024-08-19T10:02:33.670Z
@ChappoHasn'tForgotten [fits](https://en.wikipedia.org/wiki/FITS) is a real staple of astronomy - it's how a lot of astronomers get their astronomy done. Note the [tag:fits] tag! We usually leave software questions relate to specific astronomical packages OPEN as on-topic so that answers can be posted and future readers can benefit. No need to block answers here, but like astrosnapper mentions, the OP might get a better/faster answer if they add some more details. **voting to leave open**
uhoh
CC BY-SA 4.0
2024-08-20T23:48:00.510Z
@uhoh If it's merely a difficulty performing a matrix transform, it should be closed. But you've identified the key requirement: "future readers can benefit". If the OP's issue is one that others might also encounter with fits files & have come here hoping for a solution, then it deserves to stay open. The great thing about the SE model is that I've merely flagged a potential reason for closure, but it's the *Astron.SE community* that makes the final decision. And I value transparency in reasons for closure or keeping open. :-)
Chappo Hasn't Forgotten
<astrophysics><spectra><fits>
How to change fits column format?
Universe_explorer080
# How to change fits column format?

(Asked by: username_0 on 2024-08-11)

The response matrix column in my RMF fits file is in "PE" format. I want to change my matrix as 2D matrix. Is there any solution to this?

**Tags:** astrophysics, spectra, fits

> **Comments:**
> **username_1**: I’m voting to close this question because it appears to be about resolving a mathematics problem rather than relating directly to astronomy. It might be suited to Mathematics.SE but is off-topic on Astronomy.SE.  
> **username_2**: I think it's likely on-topic but could do with the some additional details in the question from the OP. Brief googling turns a link to the Chandra X-ray tools as it's first [hit for RMF](https://cxc.cfa.harvard.edu/ciao/ahelp/mkrmf.html)  
> **username_3**: @username_1 [fits](https://en.wikipedia.org/wiki/FITS) is a real staple of astronomy - it's how a lot of astronomers get their astronomy done. Note the [tag:fits] tag! We usually leave software questions relate to specific astronomical packages OPEN as on-topic so that answers can be posted and future readers can benefit. No need to block answers here, but like username_2 mentions, the OP might get a better/faster answer if they add some more details. **voting to leave open**  
> **username_1**: @username_3 If it's merely a difficulty performing a matrix transform, it should be closed. But you've identified the key requirement: "future readers can benefit". If the OP's issue is one that others might also encounter with fits files & have come here hoping for a solution, then it deserves to stay open. The great thing about the SE model is that I've merely flagged a potential reason for closure, but it's the *Astron.SE community* that makes the final decision. And I value transparency in reasons for closure or keeping open. :-)  

---

## 1 answers

### Answer by username_0 on 2024-08-22. Score: 1 | Accepted answer

I have managed to extract the response matrix as 2D array. This works perfectly in my case. I filled the empty positions in matrix column with zeros and extracted the matrix out for me. PE format contains the array with variable length. Here is my approach to the solution.

```
import numpy as np
from astropy.io import fits
from astropy.table import Table
from astropy.table import QTable

# Read RMF
        try:
            RSPdata = Table.read(RSPfile, 'MATRIX')  # FITS extension 'MATRIX'
        except:
            RSPdata = Table.read(RSPfile, 'SPECRESP MATRIX')  # Backup FITS extension 'SPECRESP MATRIX'

        MAT_column = RSPdata['MATRIX']  # Response matrix column in FITS file
        max_length = max(len(row) for row in MAT_column)
        padded_MAT_column = np.array([np.pad(row, (0, max_length - len(row)), 'constant') for row in MAT_column])  # Padding each row to the maximum length

        matrix = np.ascontiguousarray(padded_MAT_column.T, dtype=np.double)

```


---

