Skip to content

Commit

Permalink
added suport for list resource to get_ccd_pars
Browse files Browse the repository at this point in the history
as well as a file name or a file list
  • Loading branch information
Tom Marsh committed May 29, 2021
1 parent 5833f12 commit 6c83d64
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
37 changes: 18 additions & 19 deletions hipercam/cline.py
Expand Up @@ -78,7 +78,6 @@

# next two lines allow tab completion of file names
import readline

readline.parse_and_bind("tab: complete")

from .core import HipercamError, HipercamWarning
Expand Down Expand Up @@ -764,8 +763,8 @@ def get_value(
if multipleof != None and value % multipleof != 0:
raise ClineError(str(value) + " is not a multiple of " + str(multipleof))

# update appropriate set of defaults. In the case of Fnames, strip the
# extension
# update appropriate set of defaults. In the case of Fnames,
# strip the extension
if self._rpars[param]["g_or_l"] == Cline.GLOBAL:
if isinstance(defval, Fname):
self._gpars[param] = defval.noext(value)
Expand Down Expand Up @@ -842,7 +841,8 @@ def __new__(cls, root, ext="", ftype=OLD, exist=True):
"""

if ftype != Fname.OLD and ftype != Fname.NEW and ftype != Fname.NOCLOBBER:
if ftype != Fname.OLD and ftype != Fname.NEW and \
ftype != Fname.NOCLOBBER:
raise ClineError("ftype must be either OLD, NEW or NOCLOBBER")

# store root with no extension
Expand All @@ -854,9 +854,9 @@ def __new__(cls, root, ext="", ftype=OLD, exist=True):
return fname

def __init__(self, root, ext="", ftype=OLD, exist=True):
"""Initialiser. In the following text items in capitals such as 'OLD' are
static variables so that one should use hipercam.cline.Fname.OLD or
equivalent to refer to them.
"""Initialiser. In the following text items in capitals such as 'OLD'
are static variables so that one should use
hipercam.cline.Fname.OLD or equivalent to refer to them.
Arguments::
Expand All @@ -868,14 +868,14 @@ def __init__(self, root, ext="", ftype=OLD, exist=True):
extension, e.g. '.dat'
ftype : (int)
If exist=True and ftype=OLD, the file :must: exist. If exist=False, the file may or may
not exist already.
If exist=True and ftype=OLD, the file :must: exist. If
exist=False, the file may or may not exist already.
exist : (bool)
If True, the file must exist.
ext, ftype and exist are stored as identically-named attributes. 'root'
is stored as the base string.
ext, ftype and exist are stored as identically-named
attributes. 'root' is stored as the base string.
"""

Expand All @@ -884,16 +884,16 @@ def __init__(self, root, ext="", ftype=OLD, exist=True):
self.exist = exist

def __call__(self, fname):
"""Given a potential file name, this first ensures that it has the correct
extension, and then tests for its existence if need be, depending upon
the values of `ftype` and `exist` defined at instantiation.
"""Given a potential file name, this first ensures that it has the
correct extension, and then tests for its existence if need
be, depending upon the values of `ftype` and `exist` defined
at instantiation.
Arguments::
fname : (string)
file name. The extension associated with the :class:`Fname` will
be added if necessary.
fname : str
file name. The extension associated with the
:class:`Fname` will be added if necessary.
Returns the file name to use. Raises a ClineError exception if there
are problems.
Expand Down Expand Up @@ -926,7 +926,6 @@ def __getnewargs__(self):
"""
return (str(self), self.ext, self.ftype, self.exist)


class ClineError(HipercamError):
"""For throwing exceptions from hipercam.cline"""

Expand Down
35 changes: 22 additions & 13 deletions hipercam/spooler.py
Expand Up @@ -423,11 +423,11 @@ def get_ccd_pars(source, resource):
Parameters:
source : string
source : str
Data source. See 'data_source' for details.
resource : string
File name. Either a run number or a file list. Again, see
resource : str
Either a run number, a file list or a list of names. Again, see
'data_source' for details.
Returns with a list of tuples with the information outlined above. In the
Expand All @@ -454,22 +454,31 @@ def get_ccd_pars(source, resource):
return OrderedDict((("1", (1056, 1072, 0, 0)),))

else:
raise ValueError("instrument = {:s} not supported".format(rhead.instrument))
raise ValueError(
"instrument = {:s} not supported".format(rhead.instrument)
)

elif source.startswith("h"):
if source.endswith("f"):
# file list: we access the first file of the list to read the key
# and dimension info on the assumption that it is the same, for
# all files.
with open(resource) as flp:
for fname in flp:
if not fname.startswith("#") and not fname.isspace():
break
else:
raise ValueError(
"failed to find any file names in {:s}".format(resource)
)
return ccd.get_ccd_info(utils.add_extension(fname.strip(), core.HCAM))
try:
with open(resource) as flp:
for fname in flp:
if not fname.startswith("#") and not fname.isspace():
break
else:
raise ValueError(
f"failed to find any file names in {resource}"
)
except:
# assume resource is a list and read the first one
fname = resource[0]

return ccd.get_ccd_info(
utils.add_extension(fname.strip(), core.HCAM)
)

else:
# HiPERCAM raw data file: fixed data
Expand Down

0 comments on commit 6c83d64

Please sign in to comment.