From 459d1b26c815a3a3740e35ec21a4b97d009864f9 Mon Sep 17 00:00:00 2001 From: jlanders Date: Mon, 12 Jun 2023 11:00:43 -0700 Subject: [PATCH 1/2] added configurability to map features can now pass dictionaries to arguments like borders to specify linewidth or alpha values --- pyleoclim/utils/mapping.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pyleoclim/utils/mapping.py b/pyleoclim/utils/mapping.py index 419d09bf..ca1075a7 100644 --- a/pyleoclim/utils/mapping.py +++ b/pyleoclim/utils/mapping.py @@ -553,7 +553,7 @@ def make_df(geo_ms, hue=None, marker=None, size=None, cols=None, d=None): def scatter_map(geos, hue='archiveType', size=None, marker='archiveType', edgecolor='k', proj_default=True, projection='auto', crit_dist=5000, - background=True, borders=False, rivers=False, lakes=False, ocean=True, land=True, + background=True, borders=False, coastline=True, rivers=False, lakes=False, ocean=True, land=True, figsize=None, scatter_kwargs=None, gridspec_kwargs=None, extent='global', lgd_kwargs=None, legend=True, colorbar=True, cmap=None, fig=None, gs_slot=None, **kwargs): @@ -1174,22 +1174,24 @@ def plot_scatter(df=None, x=None, y=None, hue_var=None, size_var=None, marker_va ax_d['leg'] = fig.add_subplot(gs[-1]) # draw the coastlines - ax_d['map'].add_feature(cfeature.COASTLINE, linewidths=(.5,)) + # ax_d['map'].add_feature(cfeature.COASTLINE, linewidths=(.5,)) # Background if background is True: ax_d['map'].stock_img() # Other extra information - if borders is True: - ax_d['map'].add_feature(cfeature.BORDERS, alpha=.5, linewidths=(.5,)) - if lakes is True: - ax_d['map'].add_feature(cfeature.LAKES, alpha=0.25) - if rivers is True: - ax_d['map'].add_feature(cfeature.RIVERS) - if ocean is True: - ax_d['map'].add_feature(cfeature.OCEAN, alpha=.25) - if land is True: - ax_d['map'].add_feature(cfeature.LAND, alpha=.5) + feature_d = {'borders':borders, 'lakes':lakes, 'rivers':rivers, 'land':land, 'ocean':ocean, 'coastline':coastline} + feature_d = {key:(value if type(value)==dict else {}) for key, value in feature_d.items() if value !=False } + feature_spec_defaults = {'borders':dict(alpha=.5, linewidths=(.5,)), 'lakes':dict(alpha=0.25), + 'rivers': {}, 'land':dict(alpha=0.5), 'ocean':dict(alpha=0.25), 'coastline':dict(linewidths=(.5,))} + for key in feature_d.keys(): + feature_spec_defaults[key].update(feature_d[key]) + + feature_types = {'borders':cfeature.BORDERS, 'coastline':cfeature.COASTLINE, 'lakes':cfeature.LAKES, + 'rivers':cfeature.RIVERS, 'land':cfeature.LAND, 'ocean':cfeature.OCEAN} + for feature in feature_d.keys(): + ax_d['map'].add_feature(feature_types[feature], **feature_spec_defaults[feature]) + if extent == 'global': ax_d['map'].set_global() elif isinstance(extent, list) and len(extent)==4: From 82f92013cd26feb5bae286e37ebd5e628d64c4fd Mon Sep 17 00:00:00 2001 From: jlanders Date: Mon, 12 Jun 2023 11:48:21 -0700 Subject: [PATCH 2/2] add coastline configurability --- pyleoclim/core/geoseries.py | 45 ++++++++++++++++++++++------- pyleoclim/core/multiplegeoseries.py | 28 ++++++++++++------ pyleoclim/utils/mapping.py | 2 +- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/pyleoclim/core/geoseries.py b/pyleoclim/core/geoseries.py index ad50192d..6d7012b4 100644 --- a/pyleoclim/core/geoseries.py +++ b/pyleoclim/core/geoseries.py @@ -208,7 +208,7 @@ def from_json(cls, path): return cls(**b) def map(self, projection='Orthographic', proj_default=True, - background=True, borders=False, rivers=False, lakes=False, ocean=True, + background=True, borders=False, coastline=True, rivers=False, lakes=False, ocean=True, land=True, fig=None, gridspec_slot=None, figsize=None, marker='archiveType', hue='archiveType', size=None, edgecolor='w', markersize=None, scatter_kwargs=None, cmap=None, colorbar=False, gridspec_kwargs=None, @@ -225,17 +225,39 @@ def map(self, projection='Orthographic', proj_default=True, proj_default : bool; {True, False}, optional Whether to use the Pyleoclim defaults for each projection type. The default is True. - background : bool; {True, False}, optional - Whether to use a background. The default is True. + background : bool, optional + If True, uses a shaded relief background (only one available in Cartopy) + Default is on (True). - borders : bool; {True, False}, optional - Draw borders. The default is False. + borders : bool or dict, optional + Draws the countries border. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. + Defaults is off (False). - rivers : bool; {True, False}, optional - Draw rivers. The default is False. + coastline : bool or dict, optional + Draws the coastline. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. + Defaults is on (True). - lakes : bool; {True, False}, optional - Draw lakes. The default is False. + land : bool or dict, optional + Colors land masses. + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. + Default is off (True). Overriden if background=True. + + ocean : bool or dict, optional + Colors oceans. + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. + Default is on (True). Overriden if background=True. + + rivers : bool or dict, optional + Draws major rivers. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. + Default is off (False). + + lakes : bool or dict, optional + Draws major lakes. + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. + Default is off (False). figsize : list or tuple, optional The size of the figure. The default is None. @@ -293,7 +315,7 @@ def map(self, projection='Orthographic', proj_default=True, proj_default=proj_default, background=background, borders=borders, rivers=rivers, lakes=lakes, ocean=ocean, - land=land, + land=land, coastline=coastline, figsize=figsize, scatter_kwargs=scatter_kwargs, gridspec_kwargs=gridspec_kwargs, lgd_kwargs=lgd_kwargs, legend=legend, colorbar=colorbar, cmap=cmap, edgecolor=edgecolor, @@ -532,6 +554,7 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect ocean = map_kwargs.pop('ocean', False) rivers = map_kwargs.pop('rivers', False) borders = map_kwargs.pop('borders', True) + coastline = map_kwargs.pop('coastline', True) background = map_kwargs.pop('background', True) gridspec_kwargs = map_kwargs.pop('gridspec_kwargs', {}) @@ -553,7 +576,7 @@ def dashboard(self, figsize=[11, 8], plt_kwargs=None, histplt_kwargs=None, spect gridspec_kwargs['width_ratios'] = [.5,16, 1] _, ax['map'] =mapping.scatter_map(self, hue=hue, size=size, marker=marker, projection=projection, proj_default=proj_default, - background=background, borders=borders, rivers=rivers, lakes=lakes, ocean=ocean, land=land, + background=background, borders=borders, coastline=coastline, rivers=rivers, lakes=lakes, ocean=ocean, land=land, figsize=None, scatter_kwargs=scatter_kwargs,gridspec_kwargs = gridspec_kwargs, lgd_kwargs=lgd_kwargs, legend=legend, cmap=cmap, colorbar=colorbar, fig=fig, gs_slot=gs[-1, 0:-4]) diff --git a/pyleoclim/core/multiplegeoseries.py b/pyleoclim/core/multiplegeoseries.py index 14bfd6d7..dfbcc80a 100644 --- a/pyleoclim/core/multiplegeoseries.py +++ b/pyleoclim/core/multiplegeoseries.py @@ -85,7 +85,7 @@ def __init__(self, series_list, time_unit=None, label=None): def map(self, marker='archiveType', hue='archiveType', size=None, cmap=None, edgecolor='k', projection='auto', proj_default=True, crit_dist=5000,colorbar=True, - background=True, borders=True, rivers=False, lakes=False, land=True,ocean=True, + background=True, borders=False, coastline=True,rivers=False, lakes=False, land=True,ocean=True, figsize=None, fig=None, scatter_kwargs=None, gridspec_kwargs=None, legend=True, gridspec_slot=None, lgd_kwargs=None, savefig_settings=None, **kwargs): ''' @@ -134,24 +134,34 @@ def map(self, marker='archiveType', hue='archiveType', size=None, cmap=None, If True, uses a shaded relief background (only one available in Cartopy) Default is on (True). - borders : bool, optional + borders : bool or dict, optional Draws the countries border. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. Defaults is off (False). - land : bool, optional + coastline : bool or dict, optional + Draws the coastline. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. + Defaults is on (True). + + land : bool or dict, optional Colors land masses. - Default is off (False). + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. + Default is off (True). Overriden if background=True. - ocean : bool, optional + ocean : bool or dict, optional Colors oceans. - Default is off (False). + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. + Default is on (True). Overriden if background=True. - rivers : bool, optional + rivers : bool or dict, optional Draws major rivers. + If a dictionary of formatting arguments is supplied (e.g. linewidth, alpha), will draw according to specifications. Default is off (False). - lakes : bool, optional + lakes : bool or dict, optional Draws major lakes. + If a dictionary of formatting arguments is supplied (e.g. color, alpha), will draw according to specifications. Default is off (False). figsize : list or tuple, optional @@ -268,7 +278,7 @@ def map(self, marker='archiveType', hue='archiveType', size=None, cmap=None, proj_default=proj_default, crit_dist=crit_dist, background=background, borders=borders, rivers=rivers, lakes=lakes, - ocean=ocean, + ocean=ocean, coastline=coastline, land=land, gridspec_kwargs=gridspec_kwargs, figsize=figsize, scatter_kwargs=scatter_kwargs, lgd_kwargs=lgd_kwargs, legend=legend, colorbar=colorbar, diff --git a/pyleoclim/utils/mapping.py b/pyleoclim/utils/mapping.py index ca1075a7..aefe86e2 100644 --- a/pyleoclim/utils/mapping.py +++ b/pyleoclim/utils/mapping.py @@ -573,7 +573,7 @@ def scatter_map(geos, hue='archiveType', size=None, marker='archiveType', edgeco Grouping variable that will produce points with different sizes. Expects to be numeric. Any data without a value for the size variable will be filtered out. The default is None. - marker : TYPE, optional + marker : string, optional Grouping variable that will produce points with different markers. Can have a numeric dtype but will always be treated as categorical. The default is 'archiveType'.