Skip to content

Commit

Permalink
Make purpose of fix_file clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
loostrum committed Apr 16, 2020
1 parent d1075c6 commit 6113ece
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ Processing scripts for Apertif Radio Transient System data
`pip install arts_tools`

## Fixing archival FITS files
FITS files retrieved from the Apertif Long-Term Archive (ALTA) from before 2020/04/08 can be made readable with `arts_fix_fits file.fits`. These fixes are applied:
FITS files retrieved from the Apertif Long-Term Archive (ALTA) from before 2020/04/08 can be made readable with
`arts_fix_fits_from_before_20200408 file.fits`. These fixes are applied:
1. The NAXIS2 value in the header is changed from zero to the correct value
2. The data size is expressed in bytes instead of bits
2. The frequency and time axes of the data are swapped
3. The frequency order of the data and weights, scales, offsets, and frequencies columns is flipped
3. The frequency and time axes of the data are swapped
4. The frequency order of the data and weights, scales, offsets, and frequencies columns is flipped

By default, the script appends `_fixed` to the filename. Run `arts_fix_fits -h` for more options.
By default, the script appends `_fixed` to the filename. Run `arts_fix_fits_from_before_20200408 -h` for more options.

#### Note for Science Verification Campaign data
Data from the SVC has a correct NAXIS2 value in some cases. However, the other fixes do need to be applied.
This can be forced by running `arts_fix_fits_from_before_20200408 --force file.fits`.

## Reading parametersets
The FITS headers contain an encoded observation parameterset. To print the parameterset, use `arts_read_parameterset file.fits`. It can also be loaded in python as a dictionary with:
The FITS headers contain an encoded observation parameterset. To print the parameterset, use
`arts_read_parameterset file.fits`. It can also be loaded in python as a dictionary with:
```python
from arts_tools.fits.reader import read_parameterset
parset = read_parameterset('/path/to/file.fits')
```
Note that all values are read as strings.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def fix_header(header, naxis2, force=False):
logging.debug("New header line: {}".format(new_line))

# bit to bytes fix
# assume the old value is unique enough to appear anywhere else in the header
# assume the old value is unique enough to not appear anywhere else in the header
old_value = '{}X'.format(NSAMP * NCHAN)
# new value has one space to make length the same as old value
# new value has a space at the end to make length the same as old value
new_value = '{}B '.format(int((NCHAN * NSAMP) / 8))
logging.debug("Replacing {} by {} in header".format(old_value, new_value))
header_fixed = header_fixed.replace(old_value, new_value)
Expand Down Expand Up @@ -224,7 +224,14 @@ def write_file(fname, *args):

def main():
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
description="Repair ARTS 1-bit FITS files")
description="Repair ARTS 1-bit FITS files. "
"These fixes are applied:\n"
"1. The NAXIS2 value in the header is changed from zero to the correct value\n"
"2. The data size is expressed in bytes instead of bits\n"
"3. The frequency and time axes of the data are swapped\n"
"4. The frequency order of the data and weights, scales, offsets, "
"and frequencies columns is flipped"
)
parser.add_argument('--output', help="Output file "
"(Default: input.fits -> input_fixed.fits)")
parser.add_argument('--force', action='store_true', help="Apply fix even if FITS file seems good")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
packages=find_packages(),
install_requires=['numpy>=1.17',
'astropy'],
entry_points={'console_scripts': ['arts_fix_fits=arts_tools.fits.fix_file:main']},
entry_points={'console_scripts': ['arts_fix_fits_from_before_20200408=arts_tools.fits.fix_file_from_before_20200408:main']},
scripts=scripts,
classifiers=['License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
Expand Down

0 comments on commit 6113ece

Please sign in to comment.