### Document

```MyOcean Ferrybox with Python
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
1
Requirements
•
•
•
•
•
•
•
•
Python 2.7
netCDF4
Ipython
Numpy
Scipy
Matplotlib
Basemap
All can be found in Python(x,y) for
Windows
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
2
Imports
import
import
import
import
datetime
netCDF4
numpy as np
matplotlib.pyplot as plt
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
3
ncf = '../Data/GO_LATEST_TS_FB_ColorFantasy_20130607.nc'
nc = netCDF4.Dataset(ncf, 'r')
nc.variables.keys()
t = nc.variables['TIME']
T = nc.variables['TEMP'][:]
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
4
Calculate Time
t
t0
dt
t1
=
=
=
=
nc.variables['TIME']
datetime.datetime(1950, 1, 1)
np.array(map(lambda x: datetime.timedelta(days=x), t))
t0 + dt
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
5
Plot Temperature I
T
= nc.variables['TEMP'][:]
plt.figure()
plt.plot(t1, T, 'b-')
plt.grid(True)
plt.show()
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
6
Quality Flags
qcT = nc.variables['TEMP_QC'][:,0]
qct = nc.variables['TIME_QC'][:]
qcp = nc.variables['POSITION_QC'][:]
qcm = (qcT > 0) & (qcT < 3) & (qct > 0) & (qct < 3) & (qcp > 0) & (qcp < 3)
np.any(qcm)
np.all(qcm)
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
7
Plot Temperature II
plt.figure()
plt.hold(True)
plt.plot(t1[qcm], T[qcm], 'g.')
plt.plot(t1[~qcm], T[~qcm], 'r.')
plt.grid(True)
plt.show()
Pierre Jaccard
10.06.2013 - MyOcean
Tutorial, NERSC, Bergen
8
FTP
import ftplib
host = 'vftp1.ifremer.fr'
path = '/INSITU_GLO_NRT_OBSERVATIONS_013_030/'
ftp = ftplib.FTP(host)