Skip to content

Commit

Permalink
replace six.print_() by print() available since Python2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste authored and tammojan committed May 1, 2024
1 parent e6e7060 commit 9ce7e82
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 82 deletions.
4 changes: 3 additions & 1 deletion casacore/fitting/fitting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

from ._fitting import fitting
import numpy as NUM
import six
Expand Down Expand Up @@ -231,7 +233,7 @@ def addconstraint(self, x, y=0, fnct=None, fid=0):
functional("hyper", len(x)).todict()
self._fitids[fid]["constraint"][i]["x"] = [float(v) for v in x]
self._fitids[fid]["constraint"][i]["y"] = float(y)
six.print_(self._fitids[fid]["constraint"])
print(self._fitids[fid]["constraint"])

def fitpoly(self, n, x, y, sd=None, wt=1.0, fid=0):
if self.set(n=n + 1, fid=fid):
Expand Down
4 changes: 2 additions & 2 deletions casacore/images/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#
# $Id$

import six
from __future__ import print_function


class coordinatesystem(object):
Expand Down Expand Up @@ -66,7 +66,7 @@ def dict(self):
return self._csys

def summary(self):
six.print_(str(self))
print(str(self))

def _get_coordinatenames(self):
"""Create ordered list of coordinate names
Expand Down
18 changes: 9 additions & 9 deletions casacore/images/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
# 520 Edgemont Road
# Charlottesville, VA 22903-2475 USA

from __future__ import print_function

from six import string_types, integer_types
from ._images import Image
import numpy
import numpy.ma as nma
from casacore.images.coordinates import coordinatesystem
import six


class image(Image):
Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(self, imagename, axis=0, maskname="", images=(), values=None,
[(image, '', imgs)],
locals=cu.getlocals(3))
except:
six.print_("Probably could not import casacore.util")
print("Probably could not import casacore.util")
pass
Image.__init__(self, imagename, maskname, imgs)
else:
Expand Down Expand Up @@ -592,21 +592,21 @@ def view(self, tempname='/tmp/tempimage'):
# Test if casaviewer can be found.
# On OS-X 'which' always returns 0, so use test on top of it.
if os.system('test -x `which casaviewer` > /dev/null 2>&1') == 0:
six.print_("Starting casaviewer in the background ...")
print("Starting casaviewer in the background ...")
self.unlock()
if self.ispersistent():
os.system('casaviewer ' + self.name() + ' &')
elif len(tempname) > 0:
six.print_(" making a persistent copy in " + tempname)
six.print_(" which should be deleted after the viewer has ended")
print(" making a persistent copy in " + tempname)
print(" which should be deleted after the viewer has ended")
self.saveas(tempname)
os.system('casaviewer ' + tempname + ' &')
else:
six.print_("Cannot view because the image is in memory only.")
six.print_("You can browse a persistent copy of the image like:")
six.print_(" t.view('/tmp/tempimage')")
print("Cannot view because the image is in memory only.")
print("You can browse a persistent copy of the image like:")
print(" t.view('/tmp/tempimage')")
else:
six.print_("casaviewer cannot be found")
print("casaviewer cannot be found")

def _adaptAxes(self, axes):
# If axes is a single integer value, turn it into a list.
Expand Down
2 changes: 2 additions & 0 deletions casacore/measures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import casacore.quanta as dq
import os

from six import string_types

if 'MEASURESDATA' in os.environ.keys():
if 'AIPSPATH' not in os.environ.keys():
os.environ['AIPSPATH'] = '%s dummy dummy' % os.environ['MEASURESDATA']
Expand Down
25 changes: 13 additions & 12 deletions casacore/tables/msutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
# 520 Edgemont Road
# Charlottesville, VA 22903-2475 USA
#
from __future__ import print_function

from six import string_types
import numpy as np
import six
from casacore.tables.table import (table, taql,
_required_ms_desc,
_complete_ms_desc)
Expand Down Expand Up @@ -94,23 +95,23 @@ def addImagingColumns(msname, ack=True):
'SPEC': {'DEFAULTTILESHAPE': [4, 32, 128]}}
# Add the columns(if not existing). Use the description of the DATA column.
if 'MODEL_DATA' in cnames:
six.print_("Column MODEL_DATA not added; it already exists")
print("Column MODEL_DATA not added; it already exists")
else:
dminfo['NAME'] = 'modeldata'
cdesc['comment'] = 'The model data column'
t.addcols(maketabdesc(makecoldesc('MODEL_DATA', cdesc)), dminfo)
if ack:
six.print_("added column MODEL_DATA")
print("added column MODEL_DATA")
if 'CORRECTED_DATA' in cnames:
six.print_("Column CORRECTED_DATA not added; it already exists")
print("Column CORRECTED_DATA not added; it already exists")
else:
dminfo['NAME'] = 'correcteddata'
cdesc['comment'] = 'The corrected data column'
t.addcols(maketabdesc(makecoldesc('CORRECTED_DATA', cdesc)), dminfo)
if ack:
six.print_("'added column CORRECTED_DATA")
print("'added column CORRECTED_DATA")
if 'IMAGING_WEIGHT' in cnames:
six.print_("Column IMAGING_WEIGHT not added; it already exists")
print("Column IMAGING_WEIGHT not added; it already exists")
else:
# Add IMAGING_WEIGHT which is 1-dim and has type float.
# It needs a shape, otherwise the CASA imager complains.
Expand All @@ -128,7 +129,7 @@ def addImagingColumns(msname, ack=True):
dminfo['NAME'] = 'imagingweight'
t.addcols(maketabdesc(cd), dminfo)
if ack:
six.print_("added column IMAGING_WEIGHT")
print("added column IMAGING_WEIGHT")
# Add or overwrite keyword CHANNEL_SELECTION.
if 'CHANNEL_SELECTION' in t.colkeywordnames('MODEL_DATA'):
t.removecolkeyword('MODEL_DATA', 'CHANNEL_SELECTION')
Expand All @@ -139,7 +140,7 @@ def addImagingColumns(msname, ack=True):
chans = [[0, nch] for nch in nchans]
t.putcolkeyword('MODEL_DATA', 'CHANNEL_SELECTION', np.int32(chans))
if ack:
six.print_("defined keyword CHANNEL_SELECTION in column MODEL_DATA")
print("defined keyword CHANNEL_SELECTION in column MODEL_DATA")
# Flush the table to make sure it is written.
t.flush()

Expand Down Expand Up @@ -408,7 +409,7 @@ def msregularize(msname, newname):
ant2 = tsub.getcol('ANTENNA2')
t2 = taql('select from $t1 where !any(ANTENNA1 == $ant1 &&' +
' ANTENNA2 == $ant2)')
six.print_(nmissing, t1.nrows(), tsub.nrows(), t2.nrows())
print(nmissing, t1.nrows(), tsub.nrows(), t2.nrows())
if t2.nrows() != nmissing:
raise ValueError("A time/band chunk behaves strangely")
# If nothing added yet, create a new table.
Expand Down Expand Up @@ -438,8 +439,8 @@ def msregularize(msname, newname):
else:
tcombs = t.query(offset=0)
tcombs.rename(newname)
six.print_(newname, 'has been created; it references the original MS')
print(newname, 'has been created; it references the original MS')
if nadded > 0:
six.print_(' and', newname + '_adds', 'containing', nadded, 'new rows')
print(' and', newname + '_adds', 'containing', nadded, 'new rows')
else:
six.print_(' no rows needed to be added')
print(' no rows needed to be added')
104 changes: 53 additions & 51 deletions casacore/tables/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"""

from __future__ import print_function

from six import string_types
from ._tables import (Table,
_default_ms,
Expand Down Expand Up @@ -352,11 +354,11 @@ def __init__(self, tablename, tabledesc=False, nrow=0, readonly=True,
Table.__init__(self, tabname, lockopt, endian,
memtype, nrow, tabledesc, dminfo)
if ack:
six.print_('Successful creation of',
lockopt['option'] + '-locked table',
tabname + ':',
self.ncols(), 'columns,',
self.nrows(), 'rows')
print('Successful creation of',
lockopt['option'] + '-locked table',
tabname + ':',
self.ncols(), 'columns,',
self.nrows(), 'rows')
else:
# Deal with existing tables.
if not tabname:
Expand All @@ -372,28 +374,28 @@ def __init__(self, tablename, tabledesc=False, nrow=0, readonly=True,
if isinstance(tabname, string_types):
Table.__init__(self, tabname, lockopt, opt)
if ack:
six.print_('Successful', typstr, 'open of',
lockopt['option'] + '-locked table',
tabname + ':',
self.ncols(), 'columns,',
self.nrows(), 'rows')
print('Successful', typstr, 'open of',
lockopt['option'] + '-locked table',
tabname + ':',
self.ncols(), 'columns,',
self.nrows(), 'rows')
elif isinstance(tabname[0], string_types):
# Concatenate and open named tables.
Table.__init__(self, tabname, concatsubtables,
lockopt, opt)
if ack:
six.print_('Successful', typstr, 'open of',
lockopt['option'] +
'-locked concatenated tables',
tabname, ':', self.ncols(), 'columns,',
self.nrows(), 'rows')
print('Successful', typstr, 'open of',
lockopt['option'] +
'-locked concatenated tables',
tabname, ':', self.ncols(), 'columns,',
self.nrows(), 'rows')
else:
# Concatenate already open tables.
Table.__init__(self, tabname, concatsubtables, 0, 0, 0)
if ack:
six.print_('Successful virtual concatenation of',
len(tabname), 'tables:', self.ncols(),
'columns,', self.nrows(), 'rows')
print('Successful virtual concatenation of',
len(tabname), 'tables:', self.ncols(),
'columns,', self.nrows(), 'rows')
# Create a row object for this table.
self._makerow()

Expand Down Expand Up @@ -622,7 +624,7 @@ def toascii(self, asciifile, headerfile='', columnnames=(), sep=' ',
msg = self._toascii(asciifile, headerfile, columnnames, sep,
precision, usebrackets)
if len(msg) > 0:
six.print_(msg)
print(msg)

def rename(self, newtablename):
"""Rename the table.
Expand Down Expand Up @@ -1618,23 +1620,23 @@ def summary(self, recurse=False):
tables referenced by table keywords.
"""
six.print_('Table summary:', self.name())
six.print_('Shape:', self.ncols(), 'columns by', self.nrows(), 'rows')
six.print_('Info:', self.info())
print('Table summary:', self.name())
print('Shape:', self.ncols(), 'columns by', self.nrows(), 'rows')
print('Info:', self.info())
tkeys = self.getkeywords()
if (len(tkeys) > 0):
six.print_('Table keywords:', tkeys)
print('Table keywords:', tkeys)
columns = self.colnames()
if (len(columns) > 0):
six.print_('Columns:', columns)
print('Columns:', columns)
for column in columns:
ckeys = self.getcolkeywords(column)
if (len(ckeys) > 0):
six.print_(column, 'keywords:', ckeys)
print(column, 'keywords:', ckeys)
if (recurse):
for key, value in tkeys.items():
tabname = _remove_prefix(value)
six.print_('Summarizing subtable:', tabname)
print('Summarizing subtable:', tabname)
lt = table(tabname)
if (not lt.summary(recurse)):
break
Expand Down Expand Up @@ -1829,36 +1831,36 @@ def browse(self, wait=True, tempname="/tmp/seltable"):
waitstr1 = " &"
waitstr2 = "background ..."
if self.iswritable():
six.print_("Flushing data and starting casabrowser in the " +
waitstr2)
print("Flushing data and starting casabrowser in the " +
waitstr2)
else:
six.print_("Starting casabrowser in the " + waitstr2)
print("Starting casabrowser in the " + waitstr2)
self.flush()
self.unlock()
if os.system('test -e ' + self.name() + '/table.dat') == 0:
os.system('casabrowser ' + self.name() + waitstr1)
elif len(tempname) > 0:
six.print_(" making a persistent copy in table " + tempname)
print(" making a persistent copy in table " + tempname)
self.copy(tempname)
os.system('casabrowser ' + tempname + waitstr1)
if wait:
from casacore.tables import tabledelete
six.print_(" finished browsing")
print(" finished browsing")
tabledelete(tempname)

else:
six.print_(" after browsing use tabledelete('" + tempname +
"') to delete the copy")
print(" after browsing use tabledelete('" + tempname +
"') to delete the copy")
else:
six.print_("Cannot browse because the table is in memory only")
six.print_("You can browse a (shallow) persistent copy " +
"of the table like: ")
six.print_(" t.browse(True, '/tmp/tab1')")
print("Cannot browse because the table is in memory only")
print("You can browse a (shallow) persistent copy " +
"of the table like: ")
print(" t.browse(True, '/tmp/tab1')")
else:
try:
import wxPython
except ImportError:
six.print_('casabrowser nor wxPython can be found')
print('casabrowser nor wxPython can be found')
return
from wxPython.wx import wxPySimpleApp
import sys
Expand Down Expand Up @@ -1915,34 +1917,34 @@ def view(self, wait=True, tempname="/tmp/seltable"):
waitstr1 = " &"
waitstr2 = "background ..."
if self.iswritable():
six.print_("Flushing data and starting casaviewer " +
"in the " + waitstr2)
print("Flushing data and starting casaviewer " +
"in the " + waitstr2)
else:
six.print_("Starting casaviewer in the " + waitstr2)
print("Starting casaviewer in the " + waitstr2)
self.flush()
self.unlock()
if os.system('test -e ' + self.name() + '/table.dat') == 0:
os.system('casaviewer ' + self.name() + waitstr1)
viewed = True
elif len(tempname) > 0:
six.print_(" making a persistent copy in table " +
tempname)
print(" making a persistent copy in table " +
tempname)
self.copy(tempname)
os.system('casaviewer ' + tempname + waitstr1)
viewed = True
if wait:
from casacore.tables import tabledelete
six.print_(" finished viewing")
print(" finished viewing")
tabledelete(tempname)
else:
six.print_(" after viewing use tabledelete('" +
tempname + "') to delete the copy")
print(" after viewing use tabledelete('" +
tempname + "') to delete the copy")
else:
six.print_("Cannot browse because the table is " +
"in memory only.")
six.print_("You can browse a (shallow) persistent " +
"copy of the table like:")
six.print_(" t.view(True, '/tmp/tab1')")
print("Cannot browse because the table is " +
"in memory only.")
print("You can browse a (shallow) persistent " +
"copy of the table like:")
print(" t.view(True, '/tmp/tab1')")
# Could not view the table, so browse it.
if not viewed:
self.browse(wait, tempname)
Expand Down
Loading

0 comments on commit 9ce7e82

Please sign in to comment.