Research area: MODIS¶

Author: Kai Yang

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

Creation date: 2024-May-18

Latest update: 2025-Jun-03

This Jupyter notebook produces Supplementary Fig. 1 of the manuscript.

In [2]:
# Import libraries
import xarray as xr
# import cmocean as cm
import cartopy.crs as ccrs
import geopandas as gpd
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import ticker
import matplotlib.ticker as mticker
import pylab as plt
import numpy as np
# Inline plotting
%matplotlib inline
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
/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 [3]:
from utils import area,ccrs_land,add_patches
In [4]:
data_set = xr.open_dataset('../datasets/maps/MODIS_9km_quality_analysis.nc',chunks={'lat':10,'lon':10})
sst_qua = data_set.qua/252*100
In [8]:
# read mask data
dataset = xr.open_dataset('../datasets/mask/MODIS_ESA_mask.nc',chunks={'lat':10,'lon':10})
MODIS_mask = dataset.MODIS_mask

MODIS_mask[1:600,:] = np.nan
MODIS_mask[3000:3600,:] = np.nan
In [9]:
fig = plt.figure(figsize=(30, 15),dpi=600)

plt.rcParams['figure.figsize'] = [30, 15]

axs1 = fig.add_subplot(2, 1, 1, projection = ccrs.Robinson(central_longitude=180))

im1 = sst_qua.plot(ax=axs1, transform = ccrs.PlateCarree(), add_colorbar=False, 
                 cmap = 'Wistia', rasterized=True,vmin = 0, vmax = 100) 

mask = sst_qua > 80  # or use your own mask here

# Create a masked array with 1 where you want to hatch
masked = xr.where(mask, 1, np.nan)

# Overlay hatched contour where mask is True
hatch_contour = axs1.contourf(
    sst_qua['lon'],
    sst_qua['lat'],
    masked,
    levels=[0.5, 1.5],           # values of masked area (1 where hatched)
    hatches=['////'],
    colors='none',
    transform=ccrs.PlateCarree(),
    zorder=15
)

# axs1.set_facecolor('black')

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



# map settings
axs1.set_extent([0.1,359.99,-85, 85], crs=ccrs.PlateCarree())
axs1.add_feature(ccrs_land)
add_patches(axs1)
# axs1.set_title("Temporal coverage of Aqua-MODIS Sea Surface Temperature",fontsize = 25, fontweight = "bold",loc = 'left',fontname = 'Arial')
gl = axs1.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': 18, 'color': 'k','name': 'Arial'}
gl.ylabel_style = {'size': 18, 'color': 'k','name': 'Arial'}

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

# colorbar
cbar_ax = fig.add_axes([0.7, 0.55, 0.01, 0.3])
cbar=fig.colorbar(im1, cax=cbar_ax,orientation='vertical',extend='neither')
cbar.set_label('Temporal coverage (%)', fontsize = 20,fontname = 'Arial')
cbar.ax.tick_params(labelsize=20)
for l in cbar.ax.yaxis.get_ticklabels():
    l.set_family("Arial")

plt.savefig('../JPEG/temporal_coverage_MODIS.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 '

Supplementary Figure A1 Temporal coverage of highest-quality (quality level = 0; clear data with high confidence) Aqua-MODIS monthly sea surface temperature (SST) data from 2003 to 2023. Hatched areas indicate regions with more than 80% temporal coverage. Only data in the hatched region between 60°N and 60°S, were used in this analysis.

:)

In [ ]:
 
In [1]:
# Import libraries
import xarray as xr
import numpy as np
import cartopy.crs as ccrs
import matplotlib.pyplot as plt 
import matplotlib as mpl
import cmocean as cm
import geopandas as gpd

import matplotlib.patches as mpatches
import matplotlib.font_manager as font_manager
In [2]:
# Import plot utilities
from plot_utils_v2 import (ccrs_land, add_patches)
In [3]:
# Define a half-half colormap
cmap = mpl.colormaps["YlGnBu"]

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

newcmap = mpl.colors.ListedColormap(newcolors)
In [4]:
# read mask data
dataset = xr.open_dataset('../datasets/masks/MODIS_ESA_mask.nc',chunks={'lat':10,'lon':10})
MODIS_mask = dataset.MODIS_mask
ESA_mask = dataset.ESA_mask

MODIS_mask[1:600,:] = np.nan
MODIS_mask[3000:3600,:] = np.nan
In [5]:
ESA_mask[601:2999,:] = np.nan
In [6]:
fig = plt.figure(figsize=(10, 10),dpi=600)
ax1 = fig.add_subplot(2, 1, 1, projection = ccrs.Robinson(central_longitude=180))
ax1.set_extent([0.1,359.99,-85, 85], crs=ccrs.PlateCarree())
##################################################################################
# map areas
im1 = ESA_mask.plot(ax = ax1,transform = ccrs.PlateCarree(),add_colorbar=False, 
                  cmap = newcmap, rasterized = True, vmin = 0, vmax = 100) 

MODIS_mask.plot(ax = ax1,transform = ccrs.PlateCarree(),add_colorbar=False,
              cmap = newcmap, rasterized=True, vmin=-100, vmax=0)

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())
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
ax1.add_feature(ccrs_land)
add_patches(ax1)
ax1.set_title("Research area",fontsize=15, fontweight = "bold",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.xlabels_bottom = True
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.15, 'Longitude', va='bottom', ha='center',
        rotation='horizontal', rotation_mode='anchor', fontweight = 'bold',
        transform=ax1.transAxes, fontname = 'Arial', fontsize = 12)

# legend
colors1 = ['#5867af', '#ed6f6e']
patch = [mpatches.Patch(color=c, label='manual patch') for c in colors1]   
labels = ['MODIS', 'ESA']
font = font_manager.FontProperties(family='Arial',size = 10)
plt.legend(patch, labels,loc='lower center', ncols=2, frameon=True,prop=font)
##################################################################################
plt.savefig('../JPEG/FigS1_MODIS_ESA_mask_v1.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:463: UserWarning: The .xlabels_bottom attribute is deprecated. Please use .bottom_labels to toggle visibility instead.
  warnings.warn('The .xlabels_bottom 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 '

Supplementary Figure 1 Map of the SST datasets used for the analysis: pre-processed MODIS SST data (blue) cover most regions, and pre-processed ESA SST data (red) for high-latitude areas and other regions.

:)

In [8]:
fig = plt.figure(figsize=(10, 10),dpi=600)
ax1 = fig.add_subplot(2, 1, 1, projection = ccrs.Robinson(central_longitude=180))
ax1.set_extent([0.1,359.99,-85, 85], crs=ccrs.PlateCarree())
##################################################################################
# map areas
im1 = ESA_mask.plot(ax = ax1,transform = ccrs.PlateCarree(),add_colorbar=False, 
                  cmap = newcmap, rasterized = True, vmin = 0, vmax = 100) 

# MODIS_mask.plot(ax = ax1,transform = ccrs.PlateCarree(),add_colorbar=False,
#               cmap = newcmap, rasterized=True, vmin=-100, vmax=0)

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())
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
ax1.add_feature(ccrs_land)
add_patches(ax1)
ax1.set_title("Research area",fontsize=15, fontweight = "bold",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.xlabels_bottom = True
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.15, 'Longitude', va='bottom', ha='center',
        rotation='horizontal', rotation_mode='anchor', fontweight = 'bold',
        transform=ax1.transAxes, fontname = 'Arial', fontsize = 12)

# legend
colors1 = ['#ed6f6e']
patch = [mpatches.Patch(color=c, label='manual patch') for c in colors1]   
labels = ['ESA']
font = font_manager.FontProperties(family='Arial',size = 10)
plt.legend(patch, labels,loc='lower center', ncols=2, frameon=True,prop=font)
##################################################################################
plt.savefig('../JPEG/FigS1_MODIS_ESA_mask_polar.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:463: UserWarning: The .xlabels_bottom attribute is deprecated. Please use .bottom_labels to toggle visibility instead.
  warnings.warn('The .xlabels_bottom 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 '
In [ ]: