Skip to content

Commit

Permalink
Fixed compatibility of test suite with most recent versions of casatools
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Apr 17, 2024
1 parent d275d32 commit fbe11b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion casa_formats_io/casa_low_level_io/casa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def getdminfo(filename, endian='>'):

if isinstance(dm, StandardStMan):

dminfo['COLUMNS'] = np.array(sorted(col.name for col in colset.columns), '<U16')
dminfo['COLUMNS'] = np.array(sorted(col.name for col in colset.columns), 'U')
dminfo['NAME'] = dm.name
dminfo['SEQNR'] = 0
dminfo['TYPE'] = 'StandardStMan'
Expand Down
8 changes: 2 additions & 6 deletions casa_formats_io/casa_low_level_io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def read_iposition(f):
'float': ('float', read_float32, np.float32),
'double': ('double', read_float64, np.float64),
'dcomplex': ('void', read_complex128, np.complex128),
'string': ('String', read_string, '<U16'),
'string': ('String', read_string, 'U'),
'int': ('Int', read_int32, int),
'uint': ('uInt', read_int32, int)
}
Expand All @@ -172,7 +172,7 @@ def read_iposition(f):
TO_DTYPE['int'] = 'i4'
TO_DTYPE['uint'] = 'u4'
TO_DTYPE['short'] = 'i2'
TO_DTYPE['string'] = '<U16'
TO_DTYPE['string'] = 'U'
TO_DTYPE['bool'] = 'bool'
TO_DTYPE['record'] = 'O'

Expand All @@ -192,10 +192,6 @@ def read_as_numpy_array(f, value_type, nelem, shape=None, length_modifier=0):
if value_type == 'string':
array = np.array([read_string(f, length_modifier=length_modifier)
for i in range(nelem)])
if nelem > 0:
# HACK: only needed for getdesc comparisons
if max([len(s) for s in array]) < 16:
array = array.astype('<U16')
elif value_type == 'bool':
length = int(np.ceil(nelem / 8)) * 8
array = np.unpackbits(np.frombuffer(f.read(length), dtype='uint8'),
Expand Down
12 changes: 6 additions & 6 deletions casa_formats_io/casa_low_level_io/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ def read(cls, f):
elif rectype == 'table':
self.values[name] = 'Table: ' + os.path.abspath(os.path.join(f.original_filename, read_string(f)))
elif rectype == 'arrayint':
self.values[name] = read_array(f, 'int')
self.values[name] = read_array(f, 'int').astype('<i4')
elif rectype == 'arrayuint':
self.values[name] = read_array(f, 'uint')
self.values[name] = read_array(f, 'uint').astype('<u4')
elif rectype == 'arrayfloat':
self.values[name] = read_array(f, 'float')
self.values[name] = read_array(f, 'float').astype('<f4')
elif rectype == 'arraydouble':
self.values[name] = read_array(f, 'double')
self.values[name] = read_array(f, 'double').astype('<f8')
elif rectype == 'arraycomplex':
self.values[name] = read_array(f, 'complex')
self.values[name] = read_array(f, 'complex').astype('<c8')
elif rectype == 'arraydcomplex':
self.values[name] = read_array(f, 'dcomplex')
self.values[name] = read_array(f, 'dcomplex').astype('<c16')
elif rectype == 'arraystr':
self.values[name] = read_array(f, 'string')
elif rectype == 'record':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_getdminfo(tmp_path, shape):
# the Numpy arrays inside). Older versions of casatools represent some of
# the vectors as int32 instead of native int but our implementation uses
# native int so strip any mention of int32 from reference output
assert pformat(actual) == pformat(reference).replace(', dtype=int32', '')
assert pformat(actual) == pformat(reference).replace(', dtype=int32', '').replace('U3', 'U16')


def test_getdminfo_large():
Expand Down Expand Up @@ -83,7 +83,6 @@ def filename(request):
return request.getfixturevalue(request.param)


@pytest.mark.openfiles_ignore
@pytest.mark.skipif('not CASATOOLS_INSTALLED')
def test_generic_table_read(tmp_path):

Expand Down Expand Up @@ -122,7 +121,7 @@ def test_generic_table_read(tmp_path):
keywords['scalars']['s_' + name] = t[name][0]
keywords['arrays']['a_' + name] = t[name]

tb.open(filename_casa)
tb.open(filename_casa, nomodify=False)
tb.putkeywords(keywords)
tb.flush()
tb.close()
Expand All @@ -138,10 +137,7 @@ def test_generic_table_read(tmp_path):

actual_getdminfo = getdminfo(filename_casa, endian='<')

# FIXME: For some reason IndexLength is zero in the CASA output
actual_getdminfo['*1']['SPEC']['IndexLength'] = 0

assert pformat(actual_getdminfo) == pformat(reference_getdminfo)
assert pformat(actual_getdminfo).replace('<U16', '<U8') == pformat(reference_getdminfo)

tnew = Table.read(filename_casa)

Expand All @@ -155,7 +151,7 @@ def test_getdesc_floatarray():

desc = getdesc(os.path.join(DATA, 'floatarray.image'))
trc = desc['_keywords_']['masks']['mask0']['box']['trc']
assert trc.dtype == np.dtype('>f4')
assert trc.dtype == np.dtype('<f4')
assert_equal(trc, [512, 512, 1, 100])


Expand Down Expand Up @@ -246,7 +242,6 @@ def test_ms_tables(tablename):
tb.close()


@pytest.mark.openfiles_ignore
@pytest.mark.skipif('not CASATOOLS_INSTALLED')
def test_vector_columns(tmp_path):

Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ docs =
casa =
# Note that it looks like there is a casatools bug in 6.4.3.8
# https://github.com/radio-astro-tools/casa-formats-io/issues/39
casatools>=6.2.0.124,<6.4.3.8
casatools>=6.2.0.12

[options.package_data]
casa_formats_io.tests = data/*, data/*/*, data/*/*/*, data/*/*/*/*
Expand All @@ -38,8 +38,6 @@ casa_formats_io.casa_low_level_io.tests = data/*, data/*/*, data/*/*/*, data/*/*
minversion = 3.0
norecursedirs = build docs/_build
doctest_plus = enabled
filterwarnings =
error::ResourceWarning

[coverage:run]
omit =
Expand Down

0 comments on commit fbe11b1

Please sign in to comment.