Frontal Areas¶

Author: Kai Yang

Manuscript: Global trends in ocean fronts: impacts on air-sea CO2 flux and chlorophyll concentrations

Creation date: 2024-Aug-25

Latest update: 2025-Jun-03

This Jupyter notebook produces Fig. 2 of the manuscript.

In [1]:
# Import libraries
import xarray as xr
import cartopy.crs as ccrs
import pylab as plt
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.font_manager as font_manager
import geopandas as gpd
/Users/kyang7/anaconda3/lib/python3.11/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).
  from pandas.core import (
In [2]:
from utils import area,ccrs_land,add_patches
In [3]:
F_bw1 = xr.open_dataset('../datasets/mask/overlap_cumulative_masks.nc',chunks={'lat':10,'lon':10})
F_bw2 = xr.open_dataset('../datasets/mask/overlap_cumulative_masks_intensify.nc',chunks={'lat':10,'lon':10})
F_bw3 = xr.open_dataset('../datasets/mask/overlap_cumulative_masks_decline.nc',chunks={'lat':10,'lon':10})
F_bw4 = xr.open_dataset('../datasets/mask/overlap_cumulative_masks_remain.nc',chunks={'lat':10,'lon':10})
In [4]:
Key_Frontal_Areas1 = F_bw1.overlapMask
Key_Frontal_Areas2 = F_bw1.cumulativeMask

Intensify_Area1 = F_bw2.overlapMask
Intensify_Area2 = F_bw2.cumulativeMask

Decline_Area1 = F_bw3.overlapMask
Decline_Area2 = F_bw3.cumulativeMask

Remaining_Area = F_bw4.remMask
In [5]:
# Define colormap for key frontal areas 
cmap = mpl.colormaps["BuPu"]

newcolors = cmap(np.linspace(0, 1, 300))
newcolors[150:] = mpl.colors.to_rgb('#F6944B') + (1,)
# newcolors[150:] = mpl.colors.to_rgb('k') + (1,)



newcolors[:150] = np.array([1,1,1,0])

newcmap0 = mpl.colors.ListedColormap(newcolors)
In [6]:
# Define colormap for intensifying frontal areas 
cmap = mpl.colormaps["YlGnBu"]

newcolors = cmap(np.linspace(0, 1, 300))
newcolors[150:] = mpl.colors.to_rgb('#EC3232') + (1,)
newcolors[:150] = np.array([1,1,1,0])

newcmap1 = mpl.colors.ListedColormap(newcolors)
In [7]:
# Define colormap for declining frontal areas 
cmap = mpl.colormaps["YlGnBu"]

newcolors = cmap(np.linspace(0, 1, 300))
newcolors[150:] = mpl.colors.to_rgb('#0787C3') + (1,)
newcolors[:150] = np.array([1,1,1,0])

newcmap2 = mpl.colors.ListedColormap(newcolors)
In [8]:
# Define colormap for remaining frontal areas 
cmap = mpl.colormaps["YlGnBu"]

newcolors = cmap(np.linspace(0, 1, 300))
newcolors[150:] = mpl.colors.to_rgb('gainsboro') + (1,)
newcolors[:150] = np.array([1,1,1,0])

newcmap3 = mpl.colors.ListedColormap(newcolors)
In [9]:
fig = plt.figure(figsize=(10, 10),dpi=600)
#################################################################################################################################################
#################################################################################################################################################
#################################################################################################################################################
# Panel a
ax1 = fig.add_subplot(2, 1, 1, projection = ccrs.Robinson(central_longitude=180))

# map areas
im1 = Key_Frontal_Areas2.plot(ax=ax1, transform = ccrs.PlateCarree(), add_colorbar=False, 
                           cmap = newcmap0,
                           rasterized=True,vmin = 0, vmax = 1) 
im1 = Remaining_Area.plot(ax=ax1, transform = ccrs.PlateCarree(), add_colorbar=False, 
                           cmap = newcmap3,
                           rasterized=True,vmin = 0, vmax = 1) 

plt.plot([0, 360], [60.01, 60.01],
         color='black', linewidth=1, linestyle='--', markersize=3,
         # Be explicit about which transform you want:
         transform = ccrs.PlateCarree())
plt.plot([0, 360], [-60.1, -60.1],
         color='black', linewidth=1, linestyle='--', markersize=3,
         # Be explicit about which transform you want:
         transform = ccrs.PlateCarree())

# keyF.plot(transform=ccrs.PlateCarree(),edgecolor='k', facecolor="None", linewidth=1, linestyle = "-", alpha=1, ax = ax1)


# map settings
ax1.set_extent([0.1,359.99,-85, 85], crs=ccrs.PlateCarree())
ax1.add_feature(ccrs_land)
add_patches(ax1)
ax1.set_title("a  Key frontal areas & remaining areas",fontsize=15, fontweight = "bold",loc = 'left', fontname = 'Arial')
gl = ax1.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
                  linewidth=0.5, color='gray', alpha=0.0, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xlabel_style = {'size': 12, 'color': 'k','name':'Arial'}
gl.ylabel_style = {'size': 12, 'color': 'k','name':'Arial'}

ax1.text(-0.07, 0.55, 'Latitude', va='bottom', ha='center',
        rotation='vertical', rotation_mode='anchor',fontweight = 'bold',
        transform=ax1.transAxes, fontname = 'Arial', fontsize = 12)
ax1.text(0.5, -0.12, 'Longitude', va='bottom', ha='center',
        rotation='horizontal', rotation_mode='anchor', fontweight = 'bold',
        transform=ax1.transAxes, fontname = 'Arial', fontsize = 12)

# legend
colors1 = ['#F6944B', 'lightgrey']
patch = [mpatches.Patch(color=c, label='manual patch') for c in colors1]   
labels = ['Key', 'Remaining']
font = font_manager.FontProperties(family='Arial',size = 11)
plt.legend(patch, labels,loc='lower center', ncols=2, frameon=True,prop=font)
#################################################################################################################################################
#################################################################################################################################################
#################################################################################################################################################
# Panel a
ax2 = fig.add_subplot(2, 1, 2, projection = ccrs.Robinson(central_longitude=180))

# map areas
im1 = Intensify_Area1.plot(ax=ax2, transform = ccrs.PlateCarree(), add_colorbar=False, 
                           cmap = newcmap1,
                           rasterized=True,vmin = 0, vmax = 1) 
im1 = Decline_Area1.plot(ax=ax2, transform = ccrs.PlateCarree(), add_colorbar=False, 
                           cmap = newcmap2,
                           rasterized=True,vmin = 0, vmax = 1) 

plt.plot([0, 360], [60.01, 60.01],
         color='black', linewidth=1, linestyle='--', markersize=3,
         # Be explicit about which transform you want:
         transform = ccrs.PlateCarree())
plt.plot([0, 360], [-60.1, -60.1],
         color='black', linewidth=1, linestyle='--', markersize=3,
         # Be explicit about which transform you want:
         transform = ccrs.PlateCarree())

# map settings
ax2.set_extent([0.1,359.99,-85, 85], crs=ccrs.PlateCarree())
ax2.add_feature(ccrs_land)
add_patches(ax2)
ax2.set_title("b  Intensifying & declining frontal areas",fontsize=15, fontweight = "bold",loc = 'left', fontname = 'Arial')
gl = ax2.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
                  linewidth=0.5, color='gray', alpha=0.0, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xlabel_style = {'size': 12, 'color': 'k','name':'Arial'}
gl.ylabel_style = {'size': 12, 'color': 'k','name':'Arial'}

ax2.text(-0.07, 0.55, 'Latitude', va='bottom', ha='center',
        rotation='vertical', rotation_mode='anchor',fontweight = 'bold',
        transform=ax2.transAxes, fontname = 'Arial', fontsize = 12)
ax2.text(0.5, -0.12, 'Longitude', va='bottom', ha='center',
        rotation='horizontal', rotation_mode='anchor', fontweight = 'bold',
        transform=ax2.transAxes, fontname = 'Arial', fontsize = 12)

# legend
colors1 = ['#ec3232', '#0787c3']
patch = [mpatches.Patch(color=c, label='manual patch') for c in colors1]   
labels = ['Intensifying', 'Declining']
font = font_manager.FontProperties(family='Arial',size = 11)
plt.legend(patch, labels,loc='lower center', ncols=2, frameon=True,prop=font)
#################################################################################################################################################
plt.savefig('../JPEG/Fig2_frontal_areas_weighted.jpeg',dpi=600,bbox_inches='tight')
plt.show()
/Users/kyang7/anaconda3/lib/python3.11/site-packages/cartopy/mpl/gridliner.py:451: UserWarning: The .xlabels_top attribute is deprecated. Please use .top_labels to toggle visibility instead.
  warnings.warn('The .xlabels_top attribute is deprecated. Please '
/Users/kyang7/anaconda3/lib/python3.11/site-packages/cartopy/mpl/gridliner.py:487: UserWarning: The .ylabels_right attribute is deprecated. Please use .right_labels to toggle visibility instead.
  warnings.warn('The .ylabels_right attribute is deprecated. Please '
/Users/kyang7/anaconda3/lib/python3.11/site-packages/cartopy/mpl/gridliner.py:451: UserWarning: The .xlabels_top attribute is deprecated. Please use .top_labels to toggle visibility instead.
  warnings.warn('The .xlabels_top attribute is deprecated. Please '
/Users/kyang7/anaconda3/lib/python3.11/site-packages/cartopy/mpl/gridliner.py:487: UserWarning: The .ylabels_right attribute is deprecated. Please use .right_labels to toggle visibility instead.
  warnings.warn('The .ylabels_right attribute is deprecated. Please '

Figure 2. Identified frontal areas based on MODIS satellite data (2003–2023). Panel a: Key frontal areas (orange) and remaining areas (light grey); Panel b: Intensifying frontal areas (red) and declining frontal areas (blue). Key frontal areas do not necessarily overlap with intensifying or declining areas. Remaining areas (light grey) are areas that are not key, intensifying or declining areas.

In [ ]: