From dfb03e147cdf247c59a79f9913519de59d88bb0f Mon Sep 17 00:00:00 2001 From: Mike Fienen Date: Sat, 19 Sep 2020 08:45:46 -0500 Subject: [PATCH 1/4] fix(pp_utils): account for MF6-style pass-through cells in ibound --- pyemu/utils/pp_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyemu/utils/pp_utils.py b/pyemu/utils/pp_utils.py index e45440928..183e77dbc 100644 --- a/pyemu/utils/pp_utils.py +++ b/pyemu/utils/pp_utils.py @@ -150,7 +150,7 @@ def setup_pilotpoints_grid(ml=None, sr=None, ibound=None, prefix_dict=None, for i in range(start,ib.shape[0]-start,every_n_cell): for j in range(start,ib.shape[1]-start,every_n_cell): # skip if this is an inactive cell - if ib[i,j] == 0: + if ib[i,j] <= 0: # this will account for MF6 style ibound as well continue # get the attributes we need From 3ef284c51a85ae2cb96736e934282c3cdfefbcc3 Mon Sep 17 00:00:00 2001 From: Mike Fienen Date: Thu, 1 Oct 2020 15:15:36 -0500 Subject: [PATCH 2/4] bugfix(plot_utils.py): fix include_zero kwarg behavior --- pyemu/plot/plot_utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyemu/plot/plot_utils.py b/pyemu/plot/plot_utils.py index 579667ba9..ff26644cf 100644 --- a/pyemu/plot/plot_utils.py +++ b/pyemu/plot/plot_utils.py @@ -578,7 +578,13 @@ def res_phi_pie(pst, logger=None, **kwargs): logger (`pyemu.Logger`): a logger. If None, a generic one is created kwargs (`dict`): a dict of plotting options. Accepts 'include_zero' as a flag to include phi groups with only zero-weight obs (not - sure why anyone would do this, but whatevs). Any additional + sure why anyone would do this, but whatevs). + + Also accepts 'label_comps': list of components for the labels. Any combination + of ['name', 'phi_comp', 'phi_percent']. Labels will use those three components + in the order of the 'label_comps' list. + + Any additional args are passed to `matplotlib`. Returns: @@ -613,7 +619,7 @@ def res_phi_pie(pst, logger=None, **kwargs): phi_comps = pst.phi_components norm_phi_comps = pst.phi_components_normalized keys = list(phi_comps.keys()) - if "include_zero" not in kwargs or kwargs["include_zero"] is True: + if "include_zero" not in kwargs or kwargs["include_zero"] is False: phi_comps = {k: phi_comps[k] for k in keys if phi_comps[k] > 0.0} keys = list(phi_comps.keys()) norm_phi_comps = {k: norm_phi_comps[k] for k in keys} From 19e4e52f2c6955812aeb1392c055f5f28571c789 Mon Sep 17 00:00:00 2001 From: Mike Fienen Date: Thu, 1 Oct 2020 16:53:03 -0500 Subject: [PATCH 3/4] feat(plot_utils.py) added kwarg (label_comps) to control label content on phi_pie plots --- pyemu/plot/plot_utils.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pyemu/plot/plot_utils.py b/pyemu/plot/plot_utils.py index ff26644cf..e3aff2977 100644 --- a/pyemu/plot/plot_utils.py +++ b/pyemu/plot/plot_utils.py @@ -580,8 +580,8 @@ def res_phi_pie(pst, logger=None, **kwargs): as a flag to include phi groups with only zero-weight obs (not sure why anyone would do this, but whatevs). - Also accepts 'label_comps': list of components for the labels. Any combination - of ['name', 'phi_comp', 'phi_percent']. Labels will use those three components + Also accepts 'label_comps': list of components for the labels. Options are + ['name', 'phi_comp', 'phi_percent']. Labels will use those three components in the order of the 'label_comps' list. Any additional @@ -595,6 +595,8 @@ def res_phi_pie(pst, logger=None, **kwargs): import pyemu pst = pyemu.Pst("my.pst") pyemu.plot_utils.res_phi_pie(pst,figsize=(12,4)) + pyemu.plot_utils.res_phi_pie(pst,label_comps = ['name','phi_percent'], figsize=(12,4)) + """ if logger is None: @@ -628,10 +630,26 @@ def res_phi_pie(pst, logger=None, **kwargs): else: fig = plt.figure(figsize=figsize) ax = plt.subplot(1, 1, 1, aspect="equal") - labels = [ - "{0}\n{1:4G}\n({2:3.1f}%)".format(k, phi_comps[k], 100.0 * (phi_comps[k] / phi)) - for k in keys - ] + + if "label_comps" not in kwargs: + labels = [ + "{0}\n{1:4G}\n({2:3.1f}%)".format(k, phi_comps[k], 100.0 * (phi_comps[k] / phi)) + for k in keys + ] + else: + # make sure the components for the labels are in a list + if not isinstance (kwargs['label_comps'], list): + fmtchoices = list([kwargs['label_comps']]) + else: + fmtchoices = kwargs['label_comps'] + # assemble all possible label components + labfmts = {'name':['{}\n',keys], 'phi_comp':['{:4G}\n',[phi_comps[k] for k in keys]], + 'phi_percent':['({:3.1f}%)',[100.0 * (phi_comps[k] / phi) for k in keys]]} + # make the string format + labfmtstr = ''.join([labfmts[k][0] for k in fmtchoices]) + # pull it together + labels = [labfmtstr.format(*k) for k in zip(*[labfmts[j][1] for j in fmtchoices])] + ax.pie([float(norm_phi_comps[k]) for k in keys], labels=labels) logger.log("plot res_phi_pie") if "filename" in kwargs: From afe62dab82f41166e543942a186a48f7c8e9554f Mon Sep 17 00:00:00 2001 From: Mike Fienen Date: Thu, 1 Oct 2020 17:41:44 -0500 Subject: [PATCH 4/4] bugfix(plot_utils.py) allow any order of label_comps --- pyemu/plot/plot_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyemu/plot/plot_utils.py b/pyemu/plot/plot_utils.py index e3aff2977..1f50bd8f6 100644 --- a/pyemu/plot/plot_utils.py +++ b/pyemu/plot/plot_utils.py @@ -645,6 +645,8 @@ def res_phi_pie(pst, logger=None, **kwargs): # assemble all possible label components labfmts = {'name':['{}\n',keys], 'phi_comp':['{:4G}\n',[phi_comps[k] for k in keys]], 'phi_percent':['({:3.1f}%)',[100.0 * (phi_comps[k] / phi) for k in keys]]} + if fmtchoices[0] is 'phi_percent': + labfmts['phi_percent'][0] = '{}\n'.format(labfmts['phi_percent'][0]) # make the string format labfmtstr = ''.join([labfmts[k][0] for k in fmtchoices]) # pull it together