Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map configurability #437

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions pyleoclim/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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', {})
Expand All @@ -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])
Expand Down
28 changes: 19 additions & 9 deletions pyleoclim/core/multiplegeoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 15 additions & 13 deletions pyleoclim/utils/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'.

Expand Down Expand Up @@ -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:
Expand Down