Skip to content

Commit

Permalink
Merge pull request #123 from shanosborne/fix-writing-xlsx
Browse files Browse the repository at this point in the history
Fix bug when writing xlsx
  • Loading branch information
shanosborne authored Nov 14, 2019
2 parents 9bd5209 + fe51118 commit e4c8f5b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pysiaf/iando/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ def write_jwst_siaf(aperture_collection, filename=None, basepath=None, label=Non
----------
aperture_collection : ApertureCollection
dictionary of apertures
filename
basepath
label
filename : str
The file name and path if you do not wish to use the default naming
basepath : str
If you wish to use the default naming, basepath allows you to set the path where the file will be saved
label : str
Append default file name ("INSTR_SIAF") with this string
file_format : str list
one of ['xml', 'xlsx', 'csv', and formats supported by astropy Table.write]
verbose
Returns
-------
filenames : list
list of the filenames written out
TODO
----
Expand Down Expand Up @@ -204,7 +209,7 @@ def write_jwst_siaf(aperture_collection, filename=None, basepath=None, label=Non
# adjust column width
for column_cells in ws1.columns:
length = max(len(cell.value or '') for cell in column_cells[1:])
ws1.column_dimensions[column_cells[0].column].width = length * 1.5
ws1.column_dimensions[column_cells[0].column_letter].width = length * 1.5
siaf_workbook.save(filename=out_filename)
if verbose:
print('Wrote Siaf to xlsx file {}'.format(out_filename))
Expand Down
64 changes: 64 additions & 0 deletions pysiaf/tests/test_iando.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python
"""Tests for the pysiaf iando/ write.py and read.py functions.
Authors
-------
Shannon Osborne
"""
import os

import pytest

from ..aperture import JwstAperture
from ..siaf import ApertureCollection
from ..iando.write import write_jwst_siaf


def test_write_jwst_siaf_xml(tmpdir):
"""Basic test to check that JWST SIAF XML file is written out"""

aperture = JwstAperture()
aperture.AperName = 'MIRIM_FULL_OSS'
aperture.InstrName = 'MIRI'
aperture.VIdlParity = 1
aperture.DetSciYAngle = 0
aperture.DetSciParity = 1
aperture_dict = {
'MIRIM_FULL_OSS': aperture
}
aperture_collection = ApertureCollection(aperture_dict)
filename = os.path.join(tmpdir, 'test_miri.xml')

write_jwst_siaf(aperture_collection, filename=filename,
file_format='xml', verbose=False)

assert os.path.isfile(filename)

# Remove temporary directory
tmpdir.remove()


def test_write_jwst_siaf_xlsx(tmpdir):
"""Basic test to check that JWST SIAF XLSX file is written out"""

aperture = JwstAperture()
aperture.AperName = 'MIRIM_FULL_OSS'
aperture.InstrName = 'MIRI'
aperture.VIdlParity = 1
aperture.DetSciYAngle = 0
aperture.DetSciParity = 1
aperture_dict = {
'MIRIM_FULL_OSS': aperture
}
aperture_collection = ApertureCollection(aperture_dict)
filename = os.path.join(tmpdir, 'test_miri.xlsx')

write_jwst_siaf(aperture_collection, filename=filename,
file_format='xlsx', verbose=False)

assert os.path.isfile(filename)

# Remove temporary directory
tmpdir.remove()

0 comments on commit e4c8f5b

Please sign in to comment.