question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fits.append() does not support documented fits.open() kwargs

See original GitHub issue

According to the append() documentation, it supports the kwargs that are supported in the open() function: http://docs.astropy.org/en/stable/io/fits/api/files.html#astropy.io.fits.append

However, I tried to use the scale_back kwarg value, but got this error:

TypeError: writeto() got an unexpected keyword argument 'scale_back'

To reproduce:

import tempfile
import numpy as np
from astropy.io import fits


def github_issue():
    _, file_path = tempfile.mkstemp(prefix='test_file_', suffix='.fits')

    with open(file_path, 'ab+') as append_test_file_handle:
      fits.append(filename=append_test_file_handle, data=np.empty((4,4)), overwrite=False, output_verify='silentfix', checksum=False, scale_back=True)

github_issue()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
saimncommented, Feb 25, 2019

Looking at this with fresh eyes, I think that there are several things to do, because the inner function that is used is not always the same:

  • if the file does not exist, writeto is used, and kwargs are passed here. The only option that can be used here is output_verify. We can keep it like this and document this properly.

  • if the file exists, and filename is a string, fits.open is used. Here we need to pass kwargs.

  • if the file exists, and filename is a file object, there is no additional argument to pass. We could maybe check that kwargs is empty and raise a warning if it is not empty ?

1reaction
at88mphcommented, Feb 21, 2019

Hello. My test case above still fails with version 3.1 (hash: 743055cada122d6da8704ad28452806690679ef5). This issue is not holding me up anymore as I’ve worked around it for now, but the bug persists.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

File Handling and Convenience Functions — Astropy v5.1.1
Factory function to open a FITS file and return an HDUList object. ... Open mode, 'readonly', 'update', 'append', 'denywrite', or 'ostream'. Default is...
Read more >
FITS append/update is broken in Python 3.x #7854 - GitHub
When appending to a FITS file using the astropy.io.fits.append() method, there is an error in Python 3.x.
Read more >
File Handling and Convenience Functions - Read the Docs
Factory function to open a FITS file and return an HDUList object. ... If the file was opened in update or append mode,...
Read more >
File Handling and Convenience Functions — Astropy v1.0.4
Factory function to open a FITS file and return an HDUList object. ... If the file was opened in update or append mode,...
Read more >
15_PyFITS - | notebook.community
Originally you used PyFITS to work with FITS files in Python, this was a wrapper around ... Also differs from list.append() in that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found