From a09cc2ea3c06c037e4a2d6f2cd8a78a573e4f727 Mon Sep 17 00:00:00 2001 From: khider <11758571+khider@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:38:07 -0700 Subject: [PATCH 1/4] Fix problems with graphics --- pyleoclim/core/ensemblegeoseries.py | 4 ++-- pyleoclim/core/ensembleseries.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pyleoclim/core/ensemblegeoseries.py b/pyleoclim/core/ensemblegeoseries.py index e73c178d..a7b262b0 100644 --- a/pyleoclim/core/ensemblegeoseries.py +++ b/pyleoclim/core/ensemblegeoseries.py @@ -614,8 +614,8 @@ def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=No plt_kwargs.update({'ax': ax['ts']}) # use the defaults if color/markers not specified - if self.archiveType is not None: - archiveType = lipdutils.LipdToOntology(self.archiveType) + if self.series_list[0].archiveType is not None: + archiveType = lipdutils.LipdToOntology(self.series_list[0].archiveType) if archiveType not in lipdutils.PLOT_DEFAULT.keys(): archiveType = 'Other' else: diff --git a/pyleoclim/core/ensembleseries.py b/pyleoclim/core/ensembleseries.py index 5058faef..6617c16b 100644 --- a/pyleoclim/core/ensembleseries.py +++ b/pyleoclim/core/ensembleseries.py @@ -13,6 +13,7 @@ from ..core.multipleseries import MultipleSeries import warnings +warnings.filterwarnings("ignore") import seaborn as sns import matplotlib.pyplot as plt @@ -666,7 +667,7 @@ def correlation(self, target=None, timespan=None, alpha=0.05, method = 'ttest', return corr_ens def plot_traces(self, figsize=[10, 4], xlabel=None, ylabel=None, title=None, num_traces=10, seed=None, - xlim=None, ylim=None, linestyle='-', savefig_settings=None, ax=None, plot_legend=True, + xlim=None, ylim=None, linestyle='-', savefig_settings=None, ax=None, legend=True, color=sns.xkcd_rgb['pale red'], lw=0.5, alpha=0.3, lgd_kwargs=None): '''Plot EnsembleSeries as a subset of traces. @@ -804,8 +805,8 @@ def plot_traces(self, figsize=[10, 4], xlabel=None, ylabel=None, title=None, num for idx in random_draw_idx: self.series_list[idx].plot(xlabel=xlabel, ylabel=ylabel, zorder=99, linewidth=lw, - xlim=xlim, ylim=ylim, ax=ax, color=color, alpha=alpha,linestyle='-') - ax.plot(np.nan, np.nan, color=color, label=f'example members (n={num_traces})',linestyle='-') + xlim=xlim, ylim=ylim, ax=ax, color=color, alpha=alpha,linestyle='-', label='_ignore') + l1, = ax.plot(np.nan, np.nan, color=color, label=f'example members (n={num_traces})',linestyle='-') if title is not None: ax.set_title(title) @@ -813,10 +814,14 @@ def plot_traces(self, figsize=[10, 4], xlabel=None, ylabel=None, title=None, num if self.label is not None: ax.set_title(self.label) - if plot_legend: + if legend==True: lgd_args = {'frameon': False} lgd_args.update(lgd_kwargs) ax.legend(**lgd_args) + elif legend==False: + ax.legend().remove() + else: + raise ValueError('legend should be set to either True or False') if 'fig' in locals(): if 'path' in savefig_settings: From d5495582272603cce763944823896d6e55d16cde Mon Sep 17 00:00:00 2001 From: Alexander James Date: Fri, 19 Jul 2024 15:38:10 -0700 Subject: [PATCH 2/4] update archiveType logic in ensgeoseries --- pyleoclim/core/ensemblegeoseries.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pyleoclim/core/ensemblegeoseries.py b/pyleoclim/core/ensemblegeoseries.py index a7b262b0..3717b0aa 100644 --- a/pyleoclim/core/ensemblegeoseries.py +++ b/pyleoclim/core/ensemblegeoseries.py @@ -13,6 +13,8 @@ import warnings +from collections import Counter + import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec @@ -86,6 +88,19 @@ def __init__(self, series_list,label=None,lat=None,lon=None,elevation=None,archi super().__init__(series_list,label) + # Assign archiveType if it isn't passed and it is present in all series in series_list + if archiveType is None: + if not all([isinstance(ts, GeoSeries) for ts in series_list]): + pass + else: + archiveList = [str(ts.archiveType) for ts in series_list] + #Check that they're all the same + if all([a == archiveList[0] for a in archiveList]): + archiveType = archiveList[0] + #If they aren't, pick the most common one + else: + archiveType = Counter(archiveList).most_common(1)[0][0] + if lat is None: # check that all components are GeoSeries if not all([isinstance(ts, GeoSeries) for ts in series_list]): @@ -614,13 +629,13 @@ def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=No plt_kwargs.update({'ax': ax['ts']}) # use the defaults if color/markers not specified - if self.series_list[0].archiveType is not None: - archiveType = lipdutils.LipdToOntology(self.series_list[0].archiveType) + if self.archiveType is not None: + archiveType = lipdutils.LipdToOntology(self.archiveType) if archiveType not in lipdutils.PLOT_DEFAULT.keys(): + print(archiveType) archiveType = 'Other' else: archiveType = 'Other' - # if 'marker' not in plt_kwargs.keys(): # plt_kwargs.update({'marker': lipdutils.PLOT_DEFAULT[archiveType][1]}) if 'curve_clr' not in plt_kwargs.keys(): From cbc087a223a4617a4ad20227d21144ff41c61766 Mon Sep 17 00:00:00 2001 From: Alexander James Date: Fri, 19 Jul 2024 15:45:46 -0700 Subject: [PATCH 3/4] remove errant print statement --- pyleoclim/core/ensemblegeoseries.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyleoclim/core/ensemblegeoseries.py b/pyleoclim/core/ensemblegeoseries.py index 3717b0aa..e26a873f 100644 --- a/pyleoclim/core/ensemblegeoseries.py +++ b/pyleoclim/core/ensemblegeoseries.py @@ -632,7 +632,6 @@ def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=No if self.archiveType is not None: archiveType = lipdutils.LipdToOntology(self.archiveType) if archiveType not in lipdutils.PLOT_DEFAULT.keys(): - print(archiveType) archiveType = 'Other' else: archiveType = 'Other' From 73e8d8888fa9ec7c68a3d330a68c1f65f21d69be Mon Sep 17 00:00:00 2001 From: Alexander James Date: Fri, 19 Jul 2024 15:48:34 -0700 Subject: [PATCH 4/4] include archiveType logic in dashboard function --- pyleoclim/core/ensemblegeoseries.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyleoclim/core/ensemblegeoseries.py b/pyleoclim/core/ensemblegeoseries.py index e26a873f..33d27191 100644 --- a/pyleoclim/core/ensemblegeoseries.py +++ b/pyleoclim/core/ensemblegeoseries.py @@ -634,7 +634,16 @@ def dashboard(self, figsize=[11, 8], gs=None, plt_kwargs=None, histplt_kwargs=No if archiveType not in lipdutils.PLOT_DEFAULT.keys(): archiveType = 'Other' else: - archiveType = 'Other' + if not all([isinstance(ts, GeoSeries) for ts in self.series_list]): + archiveType = 'Other' + else: + archiveList = [str(ts.archiveType) for ts in self.series_list] + #Check that they're all the same + if all([a == archiveList[0] for a in archiveList]): + archiveType = archiveList[0] + #If they aren't, pick the most common one + else: + archiveType = Counter(archiveList).most_common(1)[0][0] # if 'marker' not in plt_kwargs.keys(): # plt_kwargs.update({'marker': lipdutils.PLOT_DEFAULT[archiveType][1]}) if 'curve_clr' not in plt_kwargs.keys():