<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Getting the data
Please look at the information in the get_data.ipynb notebook. You have to end up with swift.dkrz.de folder located somwere in your system. All data used in this examples are located in this folder.
Step1:  First, as usuall load the mesh
Step2:  Load data for one year
Step3:  Select one month
Step4:  Decide start and end points of the transect and plot the map of your future transect. Use %matplotlib notebook if you whant to be able to zoom to the map. NOTE! you have to have cartopy installed to make the plotting work.
Step5:  We just use closest points for selection, so on the map blues dots show generated transect, while red points are  model points that will be used for "interpolation" (we will just use nearest neighbor aproach). 
Lets. now plot the transect from monthly data that we have extracted previously. There are plenty of parameters that you can control. Function plot_transect return instance of an image, so you can further modify it (font sizes and so on).
Step6:  If instead of kilometers you would like to have lons or lats, below is the code that will help you to do so 
Step7:  Let's use it
Step8:  Several transects at once
Let's get data for some other montsh, say April, July and October
Step9:  Put all of them in to list
Step10:  Now you can have several transects in a loop. Make sure you have changed number of rows (nrows), number of columns (ncols), figsize and other parameters at the top of the script 
<ASSISTANT_TASK:>
Python Code:
import sys
sys.path.append("../")
import pyfesom as pf
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import LinearSegmentedColormap
import numpy as np
# %matplotlib notebook
%matplotlib inline
from matplotlib import cm
from netCDF4 import Dataset, MFDataset
basedir = '/mnt/lustre01/work/ab0995/a270088/DATA/swift.dkrz.de/'
Explanation: Getting the data
Please look at the information in the get_data.ipynb notebook. You have to end up with swift.dkrz.de folder located somwere in your system. All data used in this examples are located in this folder.
End of explanation
meshpath  = basedir+'/COREII/'
mesh = pf.load_mesh(meshpath, usepickle=True)
Explanation: First, as usuall load the mesh:
End of explanation
fl = Dataset(basedir+'/COREII_data/fesom.1951.oce.mean.nc')
fl.variables['temp'].shape
Explanation: Load data for one year:
End of explanation
data = fl.variables['temp'][0,:]
Explanation: Select one month
End of explanation
lon_start = -15
lat_start = -70
lon_end   = -15
lat_end   = -20
pf.plot_transect_map(lon_start, lat_start, lon_end, lat_end, 
                       mesh, npoints=30, view = 'w', stock_img=False)
Explanation: Decide start and end points of the transect and plot the map of your future transect. Use %matplotlib notebook if you whant to be able to zoom to the map. NOTE! you have to have cartopy installed to make the plotting work.
End of explanation
npoints = 80
fig, ax = plt.subplots(1,1, figsize=(15,7))
image = pf.plot_transect(data, mesh, 
                         lon_start,
                         lat_start,
                         lon_end,
                         lat_end,
                         npoints=npoints,
                         levels = np.round(np.linspace(-2, 13, 42),2),
                         cmap=cm.Spectral_r,
                         maxdepth =6000,
                         title = 'Southern Ocean Transect',
                         ncols=1,
                         figsize=(5,10),
                        ax = ax
                        )
cb = fig.colorbar(image, orientation='horizontal', ax=ax, pad=0.13)
cb.set_label('deg C')
Explanation: We just use closest points for selection, so on the map blues dots show generated transect, while red points are  model points that will be used for "interpolation" (we will just use nearest neighbor aproach). 
Lets. now plot the transect from monthly data that we have extracted previously. There are plenty of parameters that you can control. Function plot_transect return instance of an image, so you can further modify it (font sizes and so on).
End of explanation
npoints = 80
lonlat = pf.transect_get_lonlat(lon_start, lat_start, lon_end, lat_end, npoints=npoints)
labeles = [str(abs(int(x)))+"$^{\circ}$S" for x in lonlat[7::8][:,1]]
labeles
Explanation: If instead of kilometers you would like to have lons or lats, below is the code that will help you to do so :) Pay attention to combination of npoints, lonlat[7::8] (were in this case 7 is a starting point and 8 is a step). The 1 in lonlat[7::8][:,1] is latitudes, to switch to longitudes change it to 0. This crazy thing $^{\circ}$S adds $^{\circ}$S, change to N, E or W, depending on what you would like to show. I know now it look ubly, in the future will try to make it more automatic. On the other hand you have control on what exactly you are ploting :)
End of explanation
npoints = 80
lonlat = pf.transect_get_lonlat(lon_start, lat_start, lon_end, lat_end, npoints=npoints)
labeles = [str(abs(int(x)))+"$^{\circ}$S" for x in lonlat[7::8][:,1]]
dist   = pf.transect_get_distance(lonlat) # get's distances between starting point and present point
fig, ax = plt.subplots(1,1, figsize=(15,7))
image = pf.plot_transect(data, mesh, 
                         lon_start,
                         lat_start,
                         lon_end,
                         lat_end,
                         npoints=npoints,
                         levels = np.round(np.linspace(-2, 13, 42),2),
                         cmap=cm.Spectral_r,
                         maxdepth =6000,
                         title = 'Southern Ocean Transect',
                         ncols=1,
                         figsize=(5,10),
                        ax = ax
                        )
cb = fig.colorbar(image, orientation='horizontal', ax=ax, pad=0.13)
cb.set_label('deg C')
ax.xaxis.set_ticks(dist[7::8])
ax.set_xticklabels(labeles, size=20);
Explanation: Let's use it:
End of explanation
data1 = fl.variables['temp'][3,:]
data2 = fl.variables['temp'][6,:]
data3 = fl.variables['temp'][9,:]
Explanation: Several transects at once
Let's get data for some other montsh, say April, July and October:
End of explanation
data_all = [data, data1, data2, data3]
Explanation: Put all of them in to list:
End of explanation
nrows = 2
ncols = 2
figsize = (15,10)
label = '$^{\circ}$C'
vmin = -2
vmax = 15
cmap = cm.Spectral_r
npoints = 100
cmap.set_bad(color = 'k', alpha = 1.)
lonlat = pf.transect_get_lonlat(lon_start, lat_start, lon_end, lat_end, npoints=npoints)
dist   = pf.transect_get_distance(lonlat)
labeles = [str(abs(int(x)))+"$^{\circ}$S" for x in lonlat[9::10][:,1]]
months = ['JAN', 'APR', 'JUL', 'NOV']
fig, ax = plt.subplots(nrows,ncols, figsize=figsize)
ax = ax.flatten()
# for i, sim in enumerate(data):
for i, sim in enumerate(data_all):   
    image = pf.plot_transect(sim, mesh, lon_start,
                      lat_start,
                      lon_end,
                      lat_end,
                      npoints=npoints,
                      levels = np.round(np.linspace(-3, 7, 41),2),
                      cmap=cmap,
                      maxdepth =6000,
                      label = '$^{\circ}$C',
                      title = months.pop(0),
                      ncols=3,
                      ax=ax[i])
    cb = fig.colorbar(image, orientation='horizontal', ax=ax[i], pad=0.16)
    cb.set_label(label)
    ax[i].xaxis.set_ticks(dist[9::10])
# ax.xaxis.set_ticks(list(range(lonlat.shape[0]))[9::10])
    ax[i].set_xticklabels(labeles, size=10)
    ax[i].set_xlabel(' ')
    ax[i].xaxis.grid(True)
Explanation: Now you can have several transects in a loop. Make sure you have changed number of rows (nrows), number of columns (ncols), figsize and other parameters at the top of the script :)
End of explanation
<END_TASK>