Skip to content

Changes to integer column values with bzero set in opened fits tables are not written back to file #6887

Closed

Description

@kgabor
# Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
import numpy as np
import astropy
from astropy.io import fits as pf
print (astropy.__version__ , np.__version__)
2.0.2 1.13.3
c1=pf.Column(name='c1',array=np.array([1],dtype='>i2'),format='1I',bscale = 1,bzero = 32768)
S=pf.HDUList([pf.PrimaryHDU(),pf.BinTableHDU.from_columns([c1])])
print("S=",S[1].data)
# Change value in memory
S[1].data['c1'][0]=2
print("S=",S[1].data)
print(S[1].columns)
S.writeto("a.fits")
S.close()
S= [(1,)]
S= [(2,)]
ColDefs(
    name = 'c1'; format = '1I'; bscale = 1; bzero = 32768
)
X=pf.open("a.fits")
print("a.fits=",X[1].data)
print(X[1].columns)

# Change value in memory
X[1].data['c1'][0]=10
print("X=",X[1].data)

# Write back to file
X.writeto("b.fits")
X.close()

#Now check the file
print("b.fits=",pf.open("b.fits")[1].data)
a.fits= [(     2,)]
ColDefs(
    name = 'c1'; format = '1I'; bscale = 1; bzero = 32768
)
X= [(    10,)]
b.fits= [(     2,)]

So if we read in a fits file with bzero set in one column that column can be changed in memory but this is not written back to file by HDUList.writeto(). In case of multiple columns, string and float column changes are written out properly. Without the bzero argument, changes are written out properly.

Activity

  1. saimn commented on Dec 6, 2017

    @saimn
    Contributor

    I think I get it, the column is converted but not marked as such, so when writing to a file it is not scaled back. I will finalize a fix later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions