<jupyter_start><jupyter_text>Time series plots of interannual variability of surface temperature, salinity, DIN, Chl-a, upper mixed layer depth using monthly output for the period 1995-2005.<jupyter_code>#import modules 
#allows plots to appear beneath cell
%matplotlib notebook 
import numpy as np
import numpy.ma as ma
from matplotlib import *
import netCDF4 as nc4
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from matplotlib import gridspec
import matplotlib.colors as colors
from matplotlib import colors, ticker, cm
import matplotlib.patches as mpatches
import cartopy as cart
from mpl_toolkits.basemap import Basemap
import xarray as xrr
from numpy.ma import masked_where
import calendar
import datetime
from matplotlib import dates as mdates
import pandas as pd<jupyter_output><empty_output><jupyter_text>To download the data, we should split it in two parts of ten years each,to avoid problems with the header notations from the last years<jupyter_code>#sst
m_list = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
sst1=np.zeros((120,180,216))
va=0
for i in range(1995,2013): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/means/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'T.nc','r',format='NETCDF4')
        sst_=fyd.variables['sst'][0,1373:1493,3865:4045]
        sst1[:,:,va]=sst_
        va=va+1

sst2=np.zeros((120,180,36))
va=0
for i in range(2013,2016): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/means/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'T.nc','r',format='NETCDF4')
        sst2_=fyd.variables['tos'][0,1373:1493,3865:4045]
        sst2[:,:,va]=sst2_
        va=va+1        
              
        
sst1[np.abs(sst1) > 3000.] = np.nan 
sst1[sst1 == 0.] = np.nan
sst2[np.abs(sst2) > 3000.] = np.nan 
sst2[sst2 == 0.] = np.nan

sst=np.concatenate((sst1,sst2),axis=2)
#Salinity and Surface Layer Depth
m_list = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
sss1=np.zeros((120,180,216))
va=0
for i in range(1995,2013): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/means/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'T.nc','r',format='NETCDF4')
        sss_=fyd.variables['sss'][0,1373:1493,3865:4045]
        sss1[:,:,va]=sss_
        va=va+1

sss2=np.zeros((120,180,36))
va=0
for i in range(2013,2016): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/means/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'T.nc','r',format='NETCDF4')
        sss2_=fyd.variables['sos'][0,1373:1493,3865:4045]
        sss2[:,:,va]=sss2_
        va=va+1        
              
        
sss1[np.abs(sss1) > 3000.] = np.nan 
sss1[sss1 == 0.] = np.nan
sss2[np.abs(sss2) > 3000.] = np.nan 
sss2[sss2 == 0.] = np.nan

sss=np.concatenate((sss1,sss2),axis=2)

####
mld=np.zeros((120,180,252))
va=0
for i in range(1995,2016): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/means/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'T.nc','r',format='NETCDF4')
        mld_=fyd.variables['mldkz5'][0,1373:1493,3865:4045]
        mld[:,:,va]=mld_
        va=va+1

mld[np.abs(mld) > 3000.] = np.nan 
mld[mld == 0.] = np.nan

#DIN
#There is no files in medusa from August,2013 and
#from January, 2014...we should divide the extraction..
din1=np.zeros((120,180,216))
va=0

for i in range(1995,2013): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'P.nc','r',format='NETCDF4')
        din1_=fyd.variables['DIN'][0,0,1373:1493,3865:4045]
        din1[:,:,va]=din1_
        va=va+1
        
din2=np.zeros((120,180,12))
va=0  
m08_list = ['01', '02', '03', '04', '05', '06', '07', '09', '10', '11', '12']
for m in m08_list:
    fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2013/ORCA0083-N06_2013m'+str(m)+'P.nc','r',format='NETCDF4')
    din2_=fyd.variables['DIN'][0,0,1373:1493,3865:4045]
    din2[:,:,va]=din2_
    va=va+1 
    

din3=np.zeros((120,180,12))
va=0
m01_list = ['02', '03', '04', '05', '06', '07', '09', '10', '11', '12']
for m in m01_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2014/ORCA0083-N06_2014m'+str(m)+'P.nc','r',format='NETCDF4')
        din3_=fyd.variables['DIN'][0,0,1373:1493,3865:4045]
        din3[:,:,va]=din3_
        va=va+1        

din4=np.zeros((120,180,12))
va=0
for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2015/ORCA0083-N06_2015m'+str(m)+'P.nc','r',format='NETCDF4')
        din4_=fyd.variables['DIN'][0,0,1373:1493,3865:4045]
        din4[:,:,va]=din4_
        va=va+1          
        
        
        
din1[np.abs(din1) > 3000.] = np.nan 
din1[din1 == 0.] = np.nan 
din2[np.abs(din2) > 3000.] = np.nan 
din2[din2 == 0.] = np.nan
din3[np.abs(din3) > 3000.] = np.nan 
din3[din3 == 0.] = np.nan  
din4[np.abs(din4) > 3000.] = np.nan 
din4[din4 == 0.] = np.nan      
 
din = np.concatenate((din1,din2,din3,din4),axis=2)    
  
#Chl-a
#Remember: there is no files in medusa from August,2013 and
#from January, 2014...we should divide the extraction..
chlND1=np.zeros((120,180,216))
chlD1=np.zeros((120,180,216))
va=0

for i in range(1995,2013): 
    for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/'+str(i)+'/ORCA0083-N06_'+str(i)+'m'+str(m)+'P.nc','r',format='NETCDF4')
        chlND1_=fyd.variables['CHN'][0,0,1373:1493,3865:4045]
        chlND1[:,:,va]=chlND1_
        chlD1_=fyd.variables['CHD'][0,0,1373:1493,3865:4045]
        chlD1[:,:,va]=chlD1_
        va=va+1

        
chlND2=np.zeros((120,180,12))
chlD2=np.zeros((120,180,12))
va=0  
m08_list = ['01', '02', '03', '04', '05', '06', '07', '09', '10', '11', '12']
for m in m08_list:
    fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2013/ORCA0083-N06_2013m'+str(m)+'P.nc','r',format='NETCDF4')
    chlND2_=fyd.variables['CHN'][0,0,1373:1493,3865:4045]
    chlND2[:,:,va]=chlND2_
    chlD2_=fyd.variables['CHD'][0,0,1373:1493,3865:4045]
    chlD2[:,:,va]=chlD2_
    va=va+1 
    
 
chlND3=np.zeros((120,180,12))
chlD3=np.zeros((120,180,12))
va=0
m01_list = ['02', '03', '04', '05', '06', '07', '09', '10', '11', '12']
for m in m01_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2014/ORCA0083-N06_2014m'+str(m)+'P.nc','r',format='NETCDF4')
        chlND3_=fyd.variables['CHN'][0,0,1373:1493,3865:4045]
        chlND3[:,:,va]=chlND3_
        chlD3_=fyd.variables['CHD'][0,0,1373:1493,3865:4045]
        chlD3[:,:,va]=chlD3_
        va=va+1        

chlND4=np.zeros((120,180,12))
chlD4=np.zeros((120,180,12))
va=0
for m in m_list:
        fyd=nc4.Dataset('/group_workspaces/jasmin2/nemo/vol1/ORCA0083-N006/medusa/2015/ORCA0083-N06_2015m'+str(m)+'P.nc','r',format='NETCDF4')
        chlND4_=fyd.variables['CHN'][0,0,1373:1493,3865:4045]
        chlND4[:,:,va]=chlND4_
        chlD4_=fyd.variables['CHD'][0,0,1373:1493,3865:4045]
        chlD4[:,:,va]=chlD4_
        va=va+1          
        

chl_1=chlND1+chlD1 
chl_2=chlND2+chlD2 
chl_3=chlND3+chlD3 
chl_4=chlND4+chlD4 

chl_a = np.concatenate((chl_1,chl_2,chl_3,chl_4),axis=2)

chl_a[np.abs(chl_a) > 3000.] = np.nan 
chl_a[chl_a == 0.] = np.nan 
    
#Means 
sst_m=np.nanmean(sst,axis=(0,1))
sss_m=np.nanmean(sss,axis=(0,1))
din_m=np.nanmean(din,axis=(0,1))
chl_a_m=np.nanmean(chl_a,axis=(0,1))
mld_m=np.nanmean(mld,axis=(0,1))
#timee = pd.date_range('1995-01','2016-01',freq='M')
#timee_l=list(timee)

#a = pd.Period('1995-01')
#b = pd.Period('2016-01
#myarray = np.asarray(timee_l)
#myarray
#years = mdates.YearLocator()
#timee.year
#axdates=range(10)
#k=24
#for i in range(10):
        #axdates[i]=timee_l[i] + pd.DateOffset(months=k)
        #timee_l[i+1]=timee_l[i] + pd.DateOffset(months=k)
        #i=i+1
#We generated one list for the x-axis ticks. 
axdates=range(11)
k=24
for i in range(11):
    if (i==0):
        axdates[i]=timee_l[i]
    else:    
        axdates[i]=timee_l[i-1] + pd.DateOffset(months=k)
        timee_l[i]=timee_l[i-1] + pd.DateOffset(months=k)
        i=i+1
#...and we generate this one for the even years, to put ticks in the
#future plots as well, but without tick titles (here only is the
#creation of the list).
axdates_p=range(11)
j=12
for i in range(11):
    if (i==0):
        axdates_p[i] = axdates[0] + pd.DateOffset(months=j)
    else:    
        axdates_p[i]=axdates[i] + pd.DateOffset(months=j)
        #timee_l[i]=timee_l[i-1] + pd.DateOffset(months=k)
        i=i+1
#SST

fig, ax = plt.subplots(1,1,figsize=(8,5))
ax = plt.axes()

ax.plot_date(timee,sst_m,xdate=True,linestyle='-',markersize=2,color='r')
plt.title('Time Series - SST (monthly data), 1995-2015',fontsize=10)
plt.ylim((24.5,31))
plt.xlabel('time',fontsize=9)
plt.ylabel('T$^\circ$C',fontsize=10)

plt.xticks(axdates)
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=366))
plt.gcf().autofmt_xdate()
####
#Salinity

fig, ax = plt.subplots(1,1,figsize=(8,5))
ax = plt.axes()
ax.plot_date(timee,sss_m,xdate=True,linestyle='-',markersize=2,color='r')
plt.title('Time Series - SSS (monthly data), 1995-2015',fontsize=10)
plt.ylim((34.75,35.75))
plt.xlabel('time',fontsize=9)
plt.ylabel('g/kg',fontsize=10)

plt.xticks(axdates)
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=366))
plt.gcf().autofmt_xdate()
#DIN
fig, ax = plt.subplots(1,1,figsize=(8,5))
ax = plt.axes()
ax.plot_date(timee,din_m,xdate=True,linestyle='-',markersize=2,color='r')

plt.title('Time Series - DIN (monthly data), 1995-2015',fontsize=10)
plt.ylim((0.028,0.72))
plt.xlabel('time',fontsize=9)
plt.ylabel('mmol N/m$^3$',fontsize=10)

plt.xticks(axdates)
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=366))
plt.gcf().autofmt_xdate()
#Chl-a
fig, ax = plt.subplots(1,1,figsize=(7,5))
ax = plt.axes()

ax.plot_date(timee,chl_a_m,xdate=True,linestyle='-',markersize=2,color='r')
plt.title('Time Series - Chl-a (monthly data), 1995-2015',fontsize=10)
plt.ylim((0.035,0.67))
plt.xlabel('time',fontsize=9)
plt.ylabel('mg/m$^3$',fontsize=10)
plt.xticks(axdates)
#ax.xaxis.set_major_locator(ticker.LinearLocator(10)) 
#ax.xaxis.set_minor_locator(ticker.LinearLocator(numticks=21))
#ax.xaxis.set_major_formatter(dates.DateFormatter('\n%Y-%m-%d'))
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=366))

#plt.gcf().autofmt_xdate()
#Mixed layer

fig, ax = plt.subplots(1,1,figsize=(8,5))
ax = plt.axes()

ax.plot_date(timee,mld_m,xdate=True,linestyle='-',markersize=2,color='r')
plt.title('Time Series - mixed layer (monthly data), 1995-2015',fontsize=10)
plt.ylim((15,75))
plt.xlabel('time',fontsize=9)
plt.ylabel('depth(m)',fontsize=10)
plt.xticks(axdates)
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=366))

plt.gcf().autofmt_xdate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2020257322748426, 'fraction_numerical': 0.12263892690938955, 'mean_word_length': 4.507537688442211, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '641103', 'license': 'MIT', 'n_tokens_mistral': 5819, 'n_tokens_neox': 5095, 'n_words': 680, 'path': 'q_7.ipynb', 'repo_name': 'Pardavila/Ocean_Analysis', 'size': '10959'}