Skip to content

Commit 08221a3

Browse files
authored
Merge pull request #1827 from danforthcenter/params-verbosity
Params verbosity
2 parents 94cacbc + c042cff commit 08221a3

6 files changed

Lines changed: 45 additions & 34 deletions

File tree

docs/Points.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Using [Jupyter Notebooks](jupyter.md) it is possible to interactively click to collect coordinates from an image, which can be used in various downstream applications. Left click on the image to collect a point. Right click removes the
44
closest collected point.
55

6-
**plantcv.Points**(*img, figsize=(12, 6)*)
6+
**plantcv.Point**(*img, figsize=(12, 6)*)
77

88
**returns** interactive image class
99

@@ -25,8 +25,8 @@ closest collected point.
2525
```python
2626
from plantcv import plantcv as pcv
2727

28-
# Create an instance of the Points class
29-
marker = pcv.Points(img=img, figsize=(12,6))
28+
# Create an instance of the Point class
29+
marker = pcv.Point(img=img, figsize=(12,6))
3030

3131
# Click on the plotted image to collect coordinates
3232

docs/params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ the morphology sub-package. Default = 2.
5050

5151
**saved_color_scale**: Using the `color_palette` function will save the color scale here for reuse in downstream functions. Set to `None` to remove. Default = `None`.
5252

53-
**verbose**: Set the status of verboseness. When in "verbose" mode, the deprecation warning will always be printed once triggered. Default: `True`. Users can turn off deprecation warnings by setting `verbose=False`.
53+
**verbose**: Set the status of verboseness as an integer between 0 and 2. When in the most verbose mode (2), the deprecation warning will always be printed once triggered. Default: `1`. Users can turn off messages by setting `verbose=0` or opt for more messages/debug images with `verbose=2`.
5454

5555
**unit**: Set the units of the size outputs. Users can scale size measurements by updating the `unit`, `px_height` and `px_width` Default: `pixels`
5656

plantcv/plantcv/_debug.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@
44
from plantcv.plantcv import plot_image
55

66

7-
def _debug(visual, filename=None, **kwargs):
8-
"""
9-
Save or display a visual for debugging.
7+
def _debug(visual, filename=None, verbosity_level=0, **kwargs):
8+
"""Save or display a visual for debugging.
109
11-
Inputs:
12-
visual - An image or plot to display for debugging
13-
filename - An optional filename to save the visual to (default: None)
14-
kwargs - key-value arguments to xarray.plot method
10+
Parameters
11+
----------
12+
visual : numpy.ndarray
13+
An image or plot to display for debugging
14+
filename : str, optional
15+
An optional filename to save the visual to (default: None)
16+
verbosity_level : int, optional
17+
Threshold for params.verbose to make debug image.
18+
Defaults to 0, which essentially ignores params.verbose
19+
**kwargs : dict
20+
Key-value arguments to xarray.plot method
1521
16-
:param visual: numpy.ndarray
17-
:param filename: str
18-
:param kwargs: dict
22+
Returns
23+
-------
24+
None
1925
"""
20-
# Auto-increment the device counter
21-
params.device += 1
26+
# if verbose from params is at least to the verbosity level, make debug images
27+
if params.verbose >= verbosity_level:
28+
# Auto-increment the device counter
29+
params.device += 1
2230

23-
if params.debug == "print":
24-
# If debug is print, save the image to a file
25-
print_image(img=visual, filename=filename, **kwargs)
26-
elif params.debug == "plot":
27-
# If debug is plot, print to the plotting device
28-
plot_image(img=visual, **kwargs)
31+
if params.debug == "print":
32+
# If debug is print, save the image to a file
33+
print_image(img=visual, filename=filename, **kwargs)
34+
elif params.debug == "plot":
35+
# If debug is plot, print to the plotting device
36+
plot_image(img=visual, **kwargs)

plantcv/plantcv/_globals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Params:
1414
def __init__(self, device=0, debug=None, debug_outdir=".", line_thickness=5,
1515
line_color=(255, 0, 255), dpi=100, text_size=0.55,
1616
text_thickness=2, marker_size=60, color_scale="gist_rainbow", color_sequence="sequential",
17-
sample_label="default", saved_color_scale=None, verbose=True, unit="pixels", px_height=1, px_width=1):
17+
sample_label="default", saved_color_scale=None, verbose=1, unit="pixels", px_height=1, px_width=1):
1818
"""Initialize parameters.
1919
2020
Parameters
@@ -45,8 +45,8 @@ def __init__(self, device=0, debug=None, debug_outdir=".", line_thickness=5,
4545
Sample name prefix. Used in analyze functions. Default is "default".
4646
saved_color_scale : list, optional
4747
Saved color scale that will be applied next time color_palette is called. Default is None.
48-
verbose : bool
49-
Whether or not in verbose mode. Default is True.
48+
verbose : int
49+
0:2 representing verbosity level. 0 is least verbose, 2 is most verbose. Default is 1.
5050
unit : str
5151
Units of size trait outputs. Default is "pixels".
5252
px_height : float

plantcv/plantcv/deprecation_warning.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77

88
def deprecation_warning(warning):
9-
"""Print out deprecation warning
9+
"""Print out deprecation warning.
1010
11-
Inputs:
12-
warning = warning message text
13-
14-
:param warning: str
11+
Parameters
12+
----------
13+
warning : str
14+
The warning message text.
1515
"""
16-
v = version("plantcv")
17-
warning_msg = f"DeprecationWarning: {warning} Current PlantCV version: {v}"
18-
if params.verbose is True:
16+
if params.verbose == 2:
17+
v = version("plantcv")
18+
warning_msg = f"DeprecationWarning: {warning} Current PlantCV version: {v}"
19+
1920
print(warning_msg, file=sys.stderr)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from plantcv.plantcv import deprecation_warning
1+
from plantcv.plantcv._globals import params
2+
from plantcv.plantcv.deprecation_warning import deprecation_warning
23

34

45
def test_deprecation_warning():
56
"""Test for PlantCV."""
67
# Verify that the fatal_error function raises a RuntimeError
8+
params.verbose = 2
79
deprecation_warning("This is just a test, and it's just a warning")
810
assert True

0 commit comments

Comments
 (0)