Skip to content

Commit

Permalink
removed enforcement of plot limits from multiple routines
Browse files Browse the repository at this point in the history
I was getting annoyed at frequent violation of the min / max plot limits when it is not really a fatal issue. At the same time the "min", "max" features are still useful. So now Cline.get_value has another keyword parameter, "enforce", which is by default True, but can be turned off. Have done so for multiple routines, inc. rtplot, nrtplot, reduce
  • Loading branch information
trmrsh committed Jun 9, 2021
1 parent 4ddc1ab commit 48be2fc
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 82 deletions.
94 changes: 44 additions & 50 deletions hipercam/cline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(npoint and output will be prompted for)
or
or
command device=/ps npoint=20<cr>
Expand Down Expand Up @@ -481,16 +481,11 @@ def get_default(self, param, noval=None):
return defval

def get_value(
self,
param,
prompt,
defval,
minval=None,
maxval=None,
lvals=None,
fixlen=True,
multipleof=None,
ignore=None,
self, param, prompt, defval,
minval=None, maxval=None,
lvals=None, fixlen=True,
multipleof=None, ignore=None,
enforce=True
):
"""Gets the value of a parameter, either from the command arguments, or by
retrieving default values or by prompting the user as required. This
Expand All @@ -500,45 +495,53 @@ def get_value(
Parameters:
param : string
param : str
parameter name.
prompt : string
prompt : str
the prompt string associated with the parameter
defval : various
defval : various
default value if no other source can be found (e.g. at start).
This also defines the data type of the parameter (see below for
possibilities)
minval : same as defval's type
the minimum value of the parameter to allow.
minval : same as defval's type
the minimum value of the parameter to allow. This is also the
value that will be used if the user type "min". See also "enforce".
maxval : same as defval's type
the maximum value of the parameter to allow.
maxval : same as defval's type
the maximum value of the parameter to allow. This is also the
value that will be used if the user type "max". See also "enforce".
lvals : list
lvals : list
list of possible values (exact matching used)
fixlen : bool
fixlen : bool
for lists or tuples, this insists that the user input has the
same length
multipleof : int
specifies a number that the final value must be a multiple of
(integers only)
ignore : string
ignore : str
for Fname inputs, this is a value that will cause the checks on
existence of files to be skipped.
enforce : bool
controls whether "min" and "max" are used to prevent user input
outside the range. In some case one really does not want input
outside of min and max, whereas in others, it would not matter
and "min" and "max" are mainly as guidance.
Data types: at the moment, only certain data types are recognised by
this routine. These are the standard numerical types, 'int', 'long',
'float', the logical type 'bool' which can be set with any of (case
insensitively) 'true', 'yes', 'y', '1' (all True), or 'false', 'no',
'n', '0' (all False), strings, and hipercam.cline.Fname objects to
represent filenames with specific extensions, and lists. In the case
of tuples, it is the default value 'defval' which sets the type.
'float', the logical type 'bool' (which can be set with any of, case
insensitively, 'true', 'yes', 'y', '1' (all True), or 'false', 'no',
'n', '0' (all False)), strings, tuples, lists, and hipercam.cline.Fname
objects to represent filenames with specific extensions. In the case
of tuples and lists, it is the default value 'defval' which sets the type.
"""

Expand Down Expand Up @@ -603,33 +606,25 @@ def get_value(
self._usedef = True
elif reply == "?":
print()
qualifier = "must" if enforce else "should normally"
if minval is not None and maxval is not None:
print(
(
'Parameter = "{:s}" must lie from' " {!s} to {!s}"
).format(param, minval, maxval)
f'Parameter = "{param}" {qualifier} lie from {minval} to {maxval}'
)
elif minval is not None:
print(
(
'Parameter = "{:s}" must be' " greater than {!s}"
).format(param, minval)
f'Parameter = "{param}" {qualifier} be greater than {minval}'
)
elif maxval is not None:
print(
('Parameter = "{:s}" must be ' "less than {!s}").format(
param, maxval
)
f'Parameter = "{param}" {qualifier} be less than {maxval}'
)
else:
print(
(
'Parameter = "{:s}" has no '
"restriction on its value"
).format(param)
f'Parameter = "{param}" has no restriction on its value'
)

print('"{:s}" has data type = {!s}'.format(param, type(defval)))
print(f'"{param}" has data type = {type(defval)}')
if lvals is not None:
print("Only the following values are allowed:")
print(lvals)
Expand Down Expand Up @@ -701,12 +696,12 @@ def get_value(
if minval is not None:
value = minval
else:
raise ClineError("{:s} has no minimum value".format(param))
raise ClineError(f"{param} has no minimum value")
elif value == "max":
if maxval is not None:
value = maxval
else:
raise ClineError("{:s} has no maximum value".format(param))
raise ClineError(f"{param} has no maximum value")

value = int(value)

Expand All @@ -719,12 +714,12 @@ def get_value(
if minval is not None:
value = minval
else:
raise ClineError("{:s} has no minimum value".format(param))
raise ClineError(f"{param} has no minimum value")
elif value == "max":
if maxval is not None:
value = maxval
else:
raise ClineError("{:s} has no maximum value".format(param))
raise ClineError(f"{param} has no maximum value")

value = float(value)

Expand All @@ -740,18 +735,17 @@ def get_value(
value = tuple(value)
else:
raise ClineError(
"did not recognize the data type of the default supplied for parameter {:s} = {!s}".format(
param, type(defval)
)
"did not recognize the data type of the default"
" supplied for parameter {param} = {type(defval)}"
)

except ValueError as err:
raise ClineError("{!s}".format(err))
raise ClineError(str(err))

# ensure value is within range
if minval != None and value < minval:
if minval != None and value < minval and enforce:
raise ClineError(param + " = " + str(value) + " < " + str(minval))
elif maxval != None and value > maxval:
elif maxval != None and value > maxval and enforce:
raise ClineError(param + " = " + str(value) + " > " + str(maxval))

# and that it is an OK value
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/ftargets.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ def ftargets(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

################################################################
#
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/hplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ def hplot(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)
width = cl.get_value("width", "plot width (inches)", 0.0)
height = cl.get_value("height", "plot height (inches)", 0.0)

Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/makemovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ def makemovie(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)
dpi = cl.get_value("dpi", "dots per inch", 200)
if rlog is not None:
style = cl.get_value(
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/nrtplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,10 @@ def nrtplot(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

# many parameters for profile fits, although most are not
# plotted by default
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/psf_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ def psf_reduce(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

else:
xlo, xhi, ylo, yhi = None, None, None, None
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ def reduce(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

else:
ccds, nx, msub, iset = None, None, None, None
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/rtplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ def rtplot(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

# profile fitting if just one CCD chosen
if len(ccds) == 1:
Expand Down
8 changes: 4 additions & 4 deletions hipercam/scripts/setaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ def setaper(args=None):
ymin = min(ymin, float(-nypad))
ymax = max(ymax, float(nytot + nypad + 1))

xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax)
xlo = cl.get_value("xlo", "left-hand X value", xmin, xmin, xmax, enforce=False)
xhi = cl.get_value("xhi", "right-hand X value", xmax, xmin, xmax, enforce=False)
ylo = cl.get_value("ylo", "lower Y value", ymin, ymin, ymax, enforce=False)
yhi = cl.get_value("yhi", "upper Y value", ymax, ymin, ymax, enforce=False)

# number of panels in X
if len(ccds) > 1:
Expand Down

0 comments on commit 48be2fc

Please sign in to comment.