<jupyter_start><jupyter_text>To do list<NAME> **General goals:**1. Read data in python- [x] From a Folder- [ ] From the cloud2. Make plots1. What features in those plots**Progress track list:** - [x] download global dataset- [x] Read data (one and sevarl)- [x] Plot (SST, SSH, Salinity)- [x] Save plots- [x] Set a range in bar graph- [x] Plot vectors- [x] plot more than one variable in a single figure - [x] Select a region automatically or specify a region- [x] Create for loop- [x] Subplot (oceanography type related plot)- [x] Make video out of plots or visualize the trajectories- [x] Fix SST scale - [x] Write the date on the figures as text (title) - [ ] Read data from the cloud<jupyter_code>import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import cartopy.crs as ccrs                   #import projections
import cartopy
import gsw
import cftime
%matplotlib inline  
#%matplotlib qt5 
plt.rcParams['figure.figsize'] = (5,4)
plt.rcParams['figure.dpi'] = 200
plt.rcParams['savefig.dpi'] = 400
plt.close('all')
#file = '/Users/lfp/Documents/GitHub/satellite_python_2022V2/Data/dt_global_allsat_phy_l4_20190909_20210726.nc'
#file = '../Data/dt_global_allsat_phy_l4_20190909_20210726.nc'
#directory = '../Data1/*.nc'
#file = '../Data/SLA/20190701-IFR-L3C_GHRSST-SSTsubskin-ODYSSEA-GLOB_010_adjusted-v2.0-fv1.0.nc'
#file = '../Data/dataset-duacs-nrt(7:10:219).nc'
#file = '../Data/dt_global_allsat_phy_l4_20190909_20210726.nc'
#file = '../Data/Data/SLA/20210706-IFR-L3C_GHRSST-SSTsubskin-ODYSSEA-GLOB_010_adjusted-v2.0-fv1.0.nc'
#file = '../Data//20190708-IFR-L3C_GHRSST-SSTsubskin-ODYSSEA-GLOB_010_adjusted-v2.0-fv1.0.nc'

#directory = '../Data1/*.nc'
#file = '/Users/lfp/Desktop/try/20190629120000-REMSS-L4_GHRSST-SSTfnd-MW_OI-GLOB-v02.0-fv05.0.nc'
file = '/Users/lfp/Desktop/try/RSS_AMSR2_ocean_L3_weekly_2019-01-05_v08.2.nc'

ds = xr.open_dataset(file)
#ds = xr.open_mfdataset(directory)
#ds = ds.sel(lon=slice(80,100),lat=slice(5,25))
sst = ds.SST
# figure saving
__figdir__ = '../plots/' + 'BoB 7-22-2019'
savefig_args = {'bbox_inches':'tight', 'pad_inches':0.2}
plotfiletype='png'
# define savefig if we want to use if savefig 
savefig = 1
ax = plt.axes(projection = ccrs.PlateCarree(central_longitude=200))  # Orthographic
ax.set_title('SST 7/08/2019 ', fontsize=10, fontweight='bold')

plt.set_cmap(cmap=plt.get_cmap('nipy_spectral'))
plt.set_cmap(cmap=plt.get_cmap('turbo'))
    
gl = ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha=0.5, linestyle='--')
gl.top_labels = False
gl.ylabels_right = False

levels = 10 #related to dataframe

cs = ax.contourf(ds.lon,ds.lat,np.squeeze(sst), levels, extend='both', transform=ccrs.PlateCarree())

#cb = plt.colorbar(cs,ax=ax,shrink=.8,pad=.05)
cb = plt.colorbar(cs,fraction = 0.022, extend='both')
cb.set_label('SST (C)',fontsize = 8)
ax.coastlines()
#Plot coast
ax.add_feature(cartopy.feature.LAND, zorder=3, facecolor=[.6,.6,.6], edgecolor='black')

if savefig:

    plt.savefig(__figdir__+'_SST'+'.'+plotfiletype,**savefig_args)
# figure saving
__figdir__ = '../plots/' + 'BoB 7-22-2019'
savefig_args = {'bbox_inches':'tight', 'pad_inches':0.2}
plotfiletype='png'
# define savefig if we want to use if savefig 
savefig = 1
sla=ds
timeindex = 1
ax1 = plt.axes(projection = ccrs.PlateCarree(central_longitude=200))  # Orthographic
ax1.set_title('BoB SLA')
plt.set_cmap(cmap=plt.get_cmap('nipy_spectral'))
plt.set_cmap(cmap=plt.get_cmap('turbo'))
gl = ax1.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha=0.5, linestyle='--')
gl.top_labels = False
gl.ylabels_right = False
levels = 10
cs = ax1.contourf(ds.lon,ds.lat,np.squeeze(sla[timeindex ,:,:]), levels, extend='both', transform=ccrs.PlateCarree())
#cs = ax.pcolormesh(ds.longitude,ds.latitude,np.squeeze(ds.sla), vmin=levels[0], vmax=levels[-1], transform=ccrs.PlateCarree())
#cb = plt.colorbar(cs,ax=ax,shrink=.8,pad=.05)



cb.set_label('SLA [m]',fontsize = 10)
ax1.coastlines()
ax1.add_feature(cartopy.feature.LAND, zorder=3, facecolor=[.6,.6,.6], edgecolor='black')

if savefig:

    plt.savefig(__figdir__+'_SLA'+plotfiletype,**savefig_args)

timeindex = 0
ax0 = plt.axes(projection = ccrs.PlateCarree(central_longitude=200))
ax0.set_title('BoB SLA 7/10/19')

gl = ax0.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha=0.5, linestyle='--')
gl.top_labels = False
gl.ylabels_right = False
levels = 10

cs = ax0.contourf(ds.longitude,ds.latitude,np.squeeze(sla[timeindex ,:,:]), levels, extend='both', transform=ccrs.PlateCarree())
cb = plt.colorbar(cs,fraction = 0.022, extend='both')
cb.set_label('SLA [m]',fontsize = 10)
ax0.coastlines()
ax0.add_feature(cartopy.feature.LAND, zorder=3, facecolor=[.6,.6,.6], edgecolor='black')

plt.subplots()
#fig.tight_layout(pad=50.0)
#----------------------------------------------------------------------------------------------
timeindex = 1
ax1 = plt.axes(projection = ccrs.PlateCarree(central_longitude=200))
ax1.set_title('BoB SLA 7/22/19')

plt.set_cmap(cmap=plt.get_cmap('turbo'))
gl = ax1.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha=0.5, linestyle='--')
gl.top_labels = False
gl.ylabels_right = False
levels = 10

cs = ax1.contourf(ds.longitude,ds.latitude,np.squeeze(sla[timeindex ,:,:]), levels, extend='both', transform=ccrs.PlateCarree())
cb = plt.colorbar(cs,fraction = 0.022, extend='both')
cb.set_label('SLA [m]',fontsize = 10)
ax1.coastlines()
ax1.add_feature(cartopy.feature.LAND, zorder=3, facecolor=[.6,.6,.6], edgecolor='black')

def plot_variables(longitude,latitude,sla):
    
    cs = ax.contourf(longitude,latitude,np.squeeze(sla), levels, extend='both', transform=ccrs.PlateCarree())
    
    ax.set_title('BoB SLA')
    

    gl = ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False, alpha=0.5, linestyle='--')
    gl.top_labels = False
    gl.ylabels_right = False
    levels = 10
    cs = ax.contourf(longitude,latitude,np.squeeze(sla), levels, extend='both', transform=ccrs.PlateCarree())
    
    
    
    cb.set_label('SLA [m]',fontsize = 10)
    ax.coastlines()
    ax.add_feature(cartopy.feature.LAND, zorder=3, facecolor=[.6,.6,.6], edgecolor='black')

    return ax,gl,cs,cb 
    
    
    
fig,axes = plt.subplots(1,2, subplot_kw = {'projection' : ccrs.PlateCarree(central_longitude=200)}, figsize = (6,8))
                       
                       
plot_variables(ds.longitude,ds.latitude,sla,axes[1,1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1793018606796863, 'fraction_numerical': 0.0490542826387821, 'mean_word_length': 4.720316622691293, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '352269', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2846, 'n_tokens_neox': 2594, 'n_words': 440, 'path': 'notebooks/STT_plots_Practice.ipynb', 'repo_name': 'jtomfarrar/satellite_python_2022', 'size': '6511'}