<p>I have recently learned (after some struggle similar to yours) that astropy is <em>not</em> the easiest way to deal with a fits file. Way better to use <a href="https://curvit.readthedocs.io/en/latest/" rel="nofollow noreferrer">curvit</a>. Have a look at the functions <code>makecurve</code> and <code>curve</code>. They are able to locate a light source in your file and to compute the intensity vs time. They will save a plot image and a data file on you PC with three columns: time, counts per second and uncertainty. As easy as that.</p>
<p>Edit:
Actually I have tried it only with an UV data file. I'm not sure it will work in your case, that contains many frequencies. I hope this still helps</p>

CC BY-SA 4.0
2021-09-05T06:03:16.003Z
2021-09-05T06:08:58.730Z
2021-09-05T06:08:58.730Z
Prallax
<p>If your original file has a bunch of columns and you only want to keep two of them, you could try</p>
<pre><code>from astropy.table import Table

data = Table.read('path/to/file.fits')

column_names = ['time', 'intensity'] 
# or whatever the names of the columns you want to keep are

data = data[column_names]
data.write('path/to/new_file.fits')
</code></pre>

CC BY-SA 4.0
2020-07-28T13:58:08.573Z
2020-08-04T14:20:40.557Z
2020-08-04T14:20:40.557Z
usernumber
<p>I have a .fits file (<a href="https://drive.google.com/file/d/11yNbFzfDfspIM4fbY6_FRwIMMTMcQ4DZ/view?usp=sharing" rel="nofollow noreferrer">this one</a>, in fact) containing the data of a fast radio burst, FRB110523. Is it possible to, from  that, make a simpler file containing the intensity (integrated over all bands) as a function of time for each band? Just two columns, time and intensity, like <a href="https://drive.google.com/file/d/17t28InvFH_fH3YYWELGhGeOEnu8CL5ub/view?usp=sharing" rel="nofollow noreferrer">this one</a> I have from FRB010125.</p>
<p>Hopefully, the following results are helpful:</p>
<p>Code:</p>
<pre><code>import astropy.io.fits as fits
tmp = fits.open('data.fits')
tmp.info()
</code></pre>
<p>Output:</p>
<pre><code>Filename: data.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      57   ()      
  1  SUBINT        1 BinTableHDU     74   27R x 17C   [1D, 1D, 1D, 1D, 1D, 1D, 1D, 1E, 1E, 1E, 1E, 1E, 4096E, 4096E, 16384E, 16384E, 33554432B]
</code></pre>
<p>Code:</p>
<pre><code>from astropy.table import Table
data = Table.read('data.fits')
print(data)
</code></pre>
<p>Output:</p>
<pre><code>TSUBINT       OFFS_SUB      LST_SUB  RA_SUB  DEC_SUB      GLON_SUB            GLAT_SUB      FD_ANG POS_ANG PAR_ANG  TEL_AZ  TEL_ZEN  DAT_FREQ [4096]  DAT_WTS [4096] DAT_OFFS [16384] DAT_SCL [16384] DATA [2048,4,4096,1]
s             s             s      deg      deg          deg                 deg          deg     deg     deg     deg      deg          MHz                                                                 Jy         
-------- ------------------ ------- -------- ------- ------------------ ------------------- ------ ------- ------- -------- ------- ----------------- -------------- ---------------- --------------- --------------------
2.097152           1.048576  6518.0 327.2472 -1.3192 55.600326870430095 -39.263556172524744    0.0     0.0     0.0 249.0642 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           3.145728  6521.0 327.1672 -1.2243  55.64203005836015  -39.14372906977867    0.0     0.0     0.0 249.2044 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 5.2428799999999995  6522.0 327.0924 -1.1347  55.68180605375925   -39.0311783908062    0.0     0.0     0.0 249.3366 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           7.340032  6525.0 326.9798 -0.9996  55.74166711593311 -38.861593872821025    0.0     0.0     0.0 249.5357 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           9.437184  6528.0 326.9426 -0.9546  55.76176432626036 -38.805350174949325    0.0     0.0     0.0 249.6018 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          11.534336  6529.0 326.8672 -0.8638  55.80196796363764  -38.69157302203851    0.0     0.0     0.0 249.7353 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 13.631488000000001  6531.0 326.7918 -0.7728  55.84224945207001  -38.57766553711451    0.0     0.0     0.0 249.8692 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           15.72864  6533.0 326.7171 -0.6827  55.88196971628508   -38.4648317324958    0.0     0.0     0.0 250.0017 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          17.825792  6536.0 326.6047 -0.5464  55.94225637778036  -38.29460678198602    0.0     0.0     0.0 250.2017 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          19.922944  6538.0 326.5292 -0.4549   55.9825332995631  -38.18027720348178    0.0     0.0     0.0 250.3358 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          22.020096  6539.0 326.4548 -0.3642   56.0226521529888   -38.0672927256878    0.0     0.0     0.0 250.4686 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          24.117248  6542.0   326.38  -0.273  56.06287305979266  -37.95367911615346    0.0     0.0     0.0 250.6021 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152            26.2144  6543.0 326.3051 -0.1814 56.103310047019306  -37.83973940242644    0.0     0.0     0.0  250.736 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          28.311552  6546.0 326.2303 -0.0899 56.143590738030696  -37.72592478738406    0.0     0.0     0.0 250.8697 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          30.408704  6549.0  326.193 -0.0441  56.16380884342669  -37.66906526333595    0.0     0.0     0.0 250.9365 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 32.505855999999994  6550.0 326.0826  0.0915  56.22351209883429 -37.500728982061325    0.0     0.0     0.0 251.1344 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 34.603007999999996  6553.0 326.0098  0.1813  56.26312846654171  -37.38948795169926    0.0     0.0     0.0 251.2653 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           36.70016  6554.0 325.8958  0.3218  56.32480734729754  -37.21533604990489    0.0     0.0     0.0 251.4697 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          38.797312  6557.0 325.8217  0.4134  56.36502945145312  -37.10196242447719    0.0     0.0     0.0  251.603 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  40.89446399999999  6559.0 325.7482  0.5044  56.40495384812726  -36.98941257131456    0.0     0.0     0.0 251.7355 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  42.99161599999999  6560.0 325.6747  0.5958  56.44517069708175 -36.876619441740374    0.0     0.0     0.0 251.8681 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 45.088767999999995  6563.0 325.6003  0.6883  56.48574246851606 -36.762443953910875    0.0     0.0     0.0 252.0023 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 47.185919999999996  6564.0 325.5267    0.78  56.52596036385265  -36.64937170603004    0.0     0.0     0.0 252.1354 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          49.283072  6567.0 325.4897  0.8261 56.546136169449326 -36.592523443988895    0.0     0.0     0.0 252.2022 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          51.380224  6570.0 325.4159  0.9183   56.5865457279752  -36.47898131739231    0.0     0.0     0.0 252.3358 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  53.47737599999999  6571.0 325.3425  1.0104  56.62702782811415  -36.36581174438072    0.0     0.0     0.0 252.4689 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 55.574527999999994  6574.0 325.1995  1.1905  56.70624702848769  -36.14491218248362    0.0     0.0     0.0 252.7292 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
</code></pre>

CC BY-SA 4.0
2020-08-11T01:11:32.123Z
The link is fixed – sorry about that
Lucca
CC BY-SA 4.0
2020-07-28T12:17:27.487Z
I cannot access that fits file. You can try astropy.io.fits...

from astropy.io import fits

tmp = fits.open('filename.fits')

From that, it will depend on what you have in the file. I think you probably already have a table in one of the extension. You can simply access data in each extension by tmp[extension_number].data. Use tmp.info() to check information about extensions.
Kornpob Bhirombhakdi
CC BY-SA 4.0
2020-07-28T13:09:42.873Z
Hello! You need to make the google drive sharing link public, so everyone can see it (we cannot see it currently)
jng224
<radio-astronomy><data-analysis><fast-radio-bursts>
How to read light curve from .fits?
Lucca
# How to read light curve from .fits?

(Asked by: username_0 on 2020-07-28)

I have a .fits file ([this one](https://drive.google.com/file/d/11yNbFzfDfspIM4fbY6_FRwIMMTMcQ4DZ/view?usp=sharing), in fact) containing the data of a fast radio burst, FRB110523. Is it possible to, from that, make a simpler file containing the intensity (integrated over all bands) as a function of time for each band? Just two columns, time and intensity, like [this one](https://drive.google.com/file/d/17t28InvFH_fH3YYWELGhGeOEnu8CL5ub/view?usp=sharing) I have from FRB010125.

Hopefully, the following results are helpful:

Code:

```
import astropy.io.fits as fits
tmp = fits.open('data.fits')
tmp.info()

```

Output:

```
Filename: data.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      57   ()      
  1  SUBINT        1 BinTableHDU     74   27R x 17C   [1D, 1D, 1D, 1D, 1D, 1D, 1D, 1E, 1E, 1E, 1E, 1E, 4096E, 4096E, 16384E, 16384E, 33554432B]

```

Code:

```
from astropy.table import Table
data = Table.read('data.fits')
print(data)

```

Output:

```
TSUBINT       OFFS_SUB      LST_SUB  RA_SUB  DEC_SUB      GLON_SUB            GLAT_SUB      FD_ANG POS_ANG PAR_ANG  TEL_AZ  TEL_ZEN  DAT_FREQ [4096]  DAT_WTS [4096] DAT_OFFS [16384] DAT_SCL [16384] DATA [2048,4,4096,1]
s             s             s      deg      deg          deg                 deg          deg     deg     deg     deg      deg          MHz                                                                 Jy         
-------- ------------------ ------- -------- ------- ------------------ ------------------- ------ ------- ------- -------- ------- ----------------- -------------- ---------------- --------------- --------------------
2.097152           1.048576  6518.0 327.2472 -1.3192 55.600326870430095 -39.263556172524744    0.0     0.0     0.0 249.0642 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           3.145728  6521.0 327.1672 -1.2243  55.64203005836015  -39.14372906977867    0.0     0.0     0.0 249.2044 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 5.2428799999999995  6522.0 327.0924 -1.1347  55.68180605375925   -39.0311783908062    0.0     0.0     0.0 249.3366 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           7.340032  6525.0 326.9798 -0.9996  55.74166711593311 -38.861593872821025    0.0     0.0     0.0 249.5357 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           9.437184  6528.0 326.9426 -0.9546  55.76176432626036 -38.805350174949325    0.0     0.0     0.0 249.6018 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          11.534336  6529.0 326.8672 -0.8638  55.80196796363764  -38.69157302203851    0.0     0.0     0.0 249.7353 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 13.631488000000001  6531.0 326.7918 -0.7728  55.84224945207001  -38.57766553711451    0.0     0.0     0.0 249.8692 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           15.72864  6533.0 326.7171 -0.6827  55.88196971628508   -38.4648317324958    0.0     0.0     0.0 250.0017 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          17.825792  6536.0 326.6047 -0.5464  55.94225637778036  -38.29460678198602    0.0     0.0     0.0 250.2017 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          19.922944  6538.0 326.5292 -0.4549   55.9825332995631  -38.18027720348178    0.0     0.0     0.0 250.3358 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          22.020096  6539.0 326.4548 -0.3642   56.0226521529888   -38.0672927256878    0.0     0.0     0.0 250.4686 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          24.117248  6542.0   326.38  -0.273  56.06287305979266  -37.95367911615346    0.0     0.0     0.0 250.6021 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152            26.2144  6543.0 326.3051 -0.1814 56.103310047019306  -37.83973940242644    0.0     0.0     0.0  250.736 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          28.311552  6546.0 326.2303 -0.0899 56.143590738030696  -37.72592478738406    0.0     0.0     0.0 250.8697 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          30.408704  6549.0  326.193 -0.0441  56.16380884342669  -37.66906526333595    0.0     0.0     0.0 250.9365 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 32.505855999999994  6550.0 326.0826  0.0915  56.22351209883429 -37.500728982061325    0.0     0.0     0.0 251.1344 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 34.603007999999996  6553.0 326.0098  0.1813  56.26312846654171  -37.38948795169926    0.0     0.0     0.0 251.2653 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152           36.70016  6554.0 325.8958  0.3218  56.32480734729754  -37.21533604990489    0.0     0.0     0.0 251.4697 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          38.797312  6557.0 325.8217  0.4134  56.36502945145312  -37.10196242447719    0.0     0.0     0.0  251.603 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  40.89446399999999  6559.0 325.7482  0.5044  56.40495384812726  -36.98941257131456    0.0     0.0     0.0 251.7355 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  42.99161599999999  6560.0 325.6747  0.5958  56.44517069708175 -36.876619441740374    0.0     0.0     0.0 251.8681 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 45.088767999999995  6563.0 325.6003  0.6883  56.48574246851606 -36.762443953910875    0.0     0.0     0.0 252.0023 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 47.185919999999996  6564.0 325.5267    0.78  56.52596036385265  -36.64937170603004    0.0     0.0     0.0 252.1354 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          49.283072  6567.0 325.4897  0.8261 56.546136169449326 -36.592523443988895    0.0     0.0     0.0 252.2022 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152          51.380224  6570.0 325.4159  0.9183   56.5865457279752  -36.47898131739231    0.0     0.0     0.0 252.3358 67.6145 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152  53.47737599999999  6571.0 325.3425  1.0104  56.62702782811415  -36.36581174438072    0.0     0.0     0.0 252.4689 67.6144 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0
2.097152 55.574527999999994  6574.0 325.1995  1.1905  56.70624702848769  -36.14491218248362    0.0     0.0     0.0 252.7292 67.6143 900.0 .. 700.0488     0.0 .. 1.0       0.0 .. 0.5      1.0 .. 1.0               0 .. 0

```

**Tags:** radio-astronomy, data-analysis, fast-radio-bursts

> **Comments:**
> **username_1**: I cannot access that fits file. You can try astropy.io.fits...  from astropy.io import fits  tmp = fits.open('filename.fits')  From that, it will depend on what you have in the file. I think you probably already have a table in one of the extension. You can simply access data in each extension by tmp[extension_number].data. Use tmp.info() to check information about extensions.  
> **username_2**: Hello! You need to make the google drive sharing link public, so everyone can see it (we cannot see it currently)  
> **username_0**: The link is fixed – sorry about that  

---

## 2 answers

### Answer by username_3 on 2021-09-05. Score: 1

I have recently learned (after some struggle similar to yours) that astropy is *not* the easiest way to deal with a fits file. Way better to use [curvit](https://curvit.readthedocs.io/en/latest/). Have a look at the functions `makecurve` and `curve`. They are able to locate a light source in your file and to compute the intensity vs time. They will save a plot image and a data file on you PC with three columns: time, counts per second and uncertainty. As easy as that.

Edit:
Actually I have tried it only with an UV data file. I'm not sure it will work in your case, that contains many frequencies. I hope this still helps


---

### Answer by username_4 on 2020-07-28. Score: 1

If your original file has a bunch of columns and you only want to keep two of them, you could try

```
from astropy.table import Table

data = Table.read('path/to/file.fits')

column_names = ['time', 'intensity'] 
# or whatever the names of the columns you want to keep are

data = data[column_names]
data.write('path/to/new_file.fits')

```


---

