pyyeti.cla.rptpct1¶
- pyyeti.cla.rptpct1(mxmn1, mxmn2, filename, *, title='PERCENT DIFFERENCE REPORT', names=('Self', 'Reference'), desc=None, filterval=None, labels=None, units=None, ignorepv=None, uf_reds=None, use_range=True, numform=None, prtbad=None, prtbadh=None, prtbadl=None, flagbad=None, flagbadh=None, flagbadl=None, dohistogram=True, histogram_inc=1.0, domagpct=True, magpct_options=None, doabsmax=False, shortabsmax=False, roundvals=-1, rowhdr='Row', deschdr='Description', maxhdr='Maximum', minhdr='Minimum', absmhdr='Abs-Max', perpage=-1, tight_layout_args=None, show_figures=False, align_by_label=True)[source]¶
Write a percent difference report between 2 sets of max/min data
- Parameters:
mxmn1 (2d array_like or SimpleNamespace) – The max/min data to compare to the mxmn2 set. If 2-column array_like, its columns are: [max, min]. If SimpleNamespace, it must be as defined in
DR_Resultsand have these members:.ext = [max, min] .drminfo = SimpleNamespace which has (at least): .desc = one line description of category .filterval = the filter value; (see `filterval` description below) .labels = a list of descriptions; one per row .ignorepv = these rows will get 'n/a' for % diff .units = string with units .uf_reds = uncertainty factorsNote that the inputs desc, labels, etc, override the values above.
mxmn2 (2d array_like or SimpleNamespace) – The reference set of max/min data. Format is the same as mxmn1.
Note
If both mxmn1 and mxmn2 are SimpleNamespaces and have the
.drminfo.labelsattribute, this routine will, by default, use the labels to align the data sets for comparison. To prevent this, set the align_by_label parameter to False.filename (string or file_like or 1 or None) – Either a name of a file, or is a file_like object as returned by
open()orio.StringIO. Input as integer 1 to write to stdout. Can also be the name of a directory or None; in these cases, a GUI is opened for file selection.title (string; must be named; optional) – Title for the report
names (list/tuple; must be named; optional) – Two (short) strings identifying the two sets of data
desc (string or None; must be named; optional) – A one line description of the table. Overrides mxmn1.drminfo.desc. If neither are input, ‘No description provided’ is used.
filterval (scalar, 1d array_like or None; must be named; optional) – Numbers with absolute value <= than filterval will get a ‘n/a’ % diff. If vector, length must match number of rows in mxmn1 and mxmn2 data. Overrides mxmn1.drminfo.filterval. If neither are input, filterval is set to 1.e-6.
labels (list or None; must be named; optional) – A list of strings briefly describing each row. Overrides mxmn1.drminfo.labels. If neither are input,
['Row 1','Row 2',...]is used.units (string or None; must be named; optional) – Specifies the units. Overrides mxmn1.drminfo.units. If neither are input, ‘Not specified’ is used.
ignorepv (1d array or None; must be named; optional) – 0-offset index vector specifying which rows of mxmn1 to ignore (they get the ‘n/a’ % diff). Overrides mxmn1.drminfo.ignorepv. If neither are input, no rows are ignored (though filterval is still used).
Note
ignorepv applies before any alignment by labels is done (when align_by_label is True, which is the default).
uf_reds (1d array or None; must be named; optional) – Uncertainty factors: [rigid, elastic, dynamic, static]. Overrides mxmn1.drminfo.uf_reds. If neither is input, ‘Not specified’ is used.
use_range (bool; must be named, optional) – If True, the denominator of the % diff calc for both the max & min for each row is the absolute maximum of the reference max & min for that row. If False, the denominator is the applicable reference max or min. A quick example shows why
use_range=Truemight be useful:If [max1, min1] = [12345, -10] and [max2, min2] = [12300, 50] Then: % diff = [0.37%, 0.49%] if use_range is True % diff = [0.37%, 120.00%] if use_range is False
Note that the sign of the % diff is defined such that a positive % diff means an exceedance: where
max1 > max2ormin1 < min2.use_range is ignored if doabsmax is True.
numform (string or None; must be named; optional) – Format of the max & min numbers. If None, it is set internally to be 13 chars wide and depends on the range of numbers to print:
if range is “small”, numform=’{:13.xf}’ where “x” ranges from 0 to 7
if range is “large”, numform=’{:13.6e}’
prtbad (scalar or None; must be named; optional) – Only print rows where
abs(%diff) > prtbad. For example, to print rows off by more than 5%, useprtbad=5. prtbad takes precedence over prtbadh and prtbadl.prtbadh (scalar or None; must be named; optional) – Only print rows where
%diff > prtbadh. Handy for showing just the exceedances. prtbadh takes precedence over prtbadl.prtbadl (scalar or None; must be named; optional) – Only print rows where
%diff < prtbadl. Handy for showing where reference rows are higher.flagbad (scalar or None; must be named; optional) – Flag % diffs where
abs(%diff) > flagbad. Works similar to prtbad. The flag is an asterisk (*).flagbadh (scalar or None; must be named; optional) – Flag % diffs where
%diff > flagbadh. Works similar to prtbadh. Handy for flagging exceedances. flagbadh takes precedence over flagbadl.flagbadl (scalar or None; must be named; optional) – Flag % diffs where
%diff < flagbadl. Works similar to prtbadl.dohistogram (bool; must be named; optional) – If True, plot the histograms. Plots will be written to “filename.histogram.png”.
histogram_inc (scalar; must be named; optional) – The histogram increment; defaults to 1.0 (for 1%).
domagpct (bool; must be named; optional) – If True, plot the percent differences versus magnitude via
magpct(). Plots will be written to “filename.magpct.png”. Filtering for the “magpct” plot is controlled by themagpct_options['filterval']andmagpct_options['symlogy']options. By default, all percent differences are shown, but the larger values (according to the filterval filter) are emphasized by using a mixed linear/log y-axis. The percent differences for the ignorepv rows are not plotted.magpct_options (None or dict; must be named; optional) –
If None, it is internally reset to:
magpct_options = {'filterval': 'same'}
Use this parameter to provide any options to
magpct()but note that the filterval option formagpct()is treated specially. Here, in addition to any of the values thatmagpct()accepts, it can also be set to the string “same” as in the default case shown above. If set to “same”,magpct_options['filterval']gets internally reset to the final value of filterval so that the comparison table, the histogram, and the magpct plot all use the same filter value. For backward compatibility, the string “filterval” is accepted as well and works like “same”.Note
The call to
magpct()is after applying ignorepv and doing any data aligning by labels.doabsmax (bool; must be named; optional) – If True, compare only absolute maximums.
shortabsmax (bool; must be named; optional) – If True, set
doabsmax=Trueand do not print the max1 and min1 columns.roundvals (integer; must be named; optional) – Round max & min numbers at specified decimal. If negative, no rounding.
rowhdr (string; must be named; optional) – Header for row number column
deschdr (string; must be named; optional) – Header for description column
maxhdr (string; must be named; optional) – Header for the column 1 data
minhdr (string; must be named; optional) – Header for the column 2 data
absmhdr (string; must be named; optional) – Header for abs-max column
perpage (integer; must be named; optional) – The number of lines to write perpage. If < 1, there is no limit (one page).
tight_layout_args (dict or None; must be named; optional) – Arguments for
matplotlib.pyplot.tight_layout(). If None, defaults to{'pad': 3.0}.show_figures (bool; must be named; optional) – If True, plot figures will be displayed on the screen for interactive viewing. Warning: there may be many figures.
align_by_label (bool; must be named; optional) – If True, use labels to align the two sets of data for comparison. See note above under the mxmn2 option.
- Returns:
pdiff_info (dict) – Dictionary with ‘amx’ (abs-max), ‘mx’ (max), and ‘mn’ keys:
<class 'dict'>[n=3] 'amx': <class 'dict'>[n=5] 'hsto' : float64 ndarray 33 elems: (11, 3) 'mag' : [n=2]: (float64 ndarray: (100,), ... 'pct' : float64 ndarray 100 elems: (100,) 'prtpv': bool ndarray 100 elems: (100,) 'spct' : [n=100]: [' -2.46', ' -1.50', ... 'mn' : <class 'dict'>[n=5] 'hsto' : float64 ndarray 33 elems: (11, 3) 'mag' : [n=2]: (float64 ndarray: (100,), ... 'pct' : float64 ndarray 100 elems: (100,) 'prtpv': bool ndarray 100 elems: (100,) 'spct' : [n=100]: [' 1.55', ' 1.53', ... 'mx' : <class 'dict'>[n=5] 'hsto' : float64 ndarray 27 elems: (9, 3) 'mag' : [n=2]: (float64 ndarray: (100,), ... 'pct' : float64 ndarray 100 elems: (100,) 'prtpv': bool ndarray 100 elems: (100,) 'spct' : [n=100]: [' -2.46', ' -1.50', ...Where:
'hsto' : output of :func:`histogram`: [center, count, %] 'mag' : inputs to :func:`magpct` 'pct' : percent differences 'prtpv' : rows to print partition vector 'spct' : string version of 'pct'
Examples
>>> import numpy as np >>> from pyyeti import cla >>> ext1 = [[120.0, -8.0], ... [8.0, -120.0]] >>> ext2 = [[115.0, -5.0], ... [10.0, -125.0]]
Run
rptpct1()multiple times to get a more complete picture of all the output (the table is very wide). Also, the plots will be turned off for this example.First, the header:
>>> opts = {'domagpct': False, 'dohistogram': False} >>> dct = cla.rptpct1(ext1, ext2, 1, **opts) PERCENT DIFFERENCE REPORT Description: No description provided Uncertainty: Not specified Units: Not specified Filter: 1e-06 Notes: % Diff = +/- abs(Self-Reference)/max(abs(Reference... Sign set such that positive % differences indicate... Date: ... ...
Then, the max/min/absmax percent difference table in 3 calls:
>>> dct = cla.rptpct1(ext1, ext2, 1, **opts) PERCENT DIFFERENCE REPORT ... Self Reference ... Row Description Maximum Maximum % Diff ... ------- ----------- ------------- ------------- ------- ... 1 Row 1 120.00000 115.00000 4.35 ... 2 Row 2 8.00000 10.00000 -1.60 ... ... >>> dct = cla.rptpct1(ext1, ext2, 1, **opts) PERCENT DIFFERENCE REPORT ... ... Self Reference ... Row Description ... Minimum Minimum % Diff ... ------- ----------- ...------------- ------------- ------- ... 1 Row 1 ... -8.00000 -5.00000 2.61 ... 2 Row 2 ... -120.00000 -125.00000 -4.00 ... ... >>> dct = cla.rptpct1(ext1, ext2, 1, **opts) PERCENT DIFFERENCE REPORT ... ... Self Reference Row Description ... Abs-Max Abs-Max % Diff ------- ----------- ...------------- ------------- ------- 1 Row 1 ... 120.00000 115.00000 4.35 2 Row 2 ... 120.00000 125.00000 -4.00 ...
Finally, the histogram summaries:
>>> dct = cla.rptpct1(ext1, ext2, 1, **opts) PERCENT DIFFERENCE REPORT ... No description provided - Maximum Comparison Histogram % Diff Count Percent -------- -------- ------- -2.00 1 50.00 4.00 1 50.00 0.0% of values are within 1% 50.0% of values are within 2% 100.0% of values are within 5% % Diff Statistics: [Min, Max, Mean, StdDev] = [-1.60, 4.35,... No description provided - Minimum Comparison Histogram % Diff Count Percent -------- -------- ------- -4.00 1 50.00 3.00 1 50.00 0.0% of values are within 1% 100.0% of values are within 5% % Diff Statistics: [Min, Max, Mean, StdDev] = [-4.00, 2.61,... No description provided - Abs-Max Comparison Histogram % Diff Count Percent -------- -------- ------- -4.00 1 50.00 4.00 1 50.00 0.0% of values are within 1% 100.0% of values are within 5% % Diff Statistics: [Min, Max, Mean, StdDev] = [-4.00, 4.35,...