90 likes | 289 Views
MyOcean Ferrybox with Python. Requirements. Python 2.7 netCDF4 Ipython Numpy Scipy Matplotlib Basemap All can be found in Python( x,y ) for Windows. Imports. import datetime import netCDF4 import numpy as np import matplotlib.pyplot as plt. Read netCDF.
E N D
MyOcean Ferrybox with Python Pierre Jaccard
Requirements • Python 2.7 • netCDF4 • Ipython • Numpy • Scipy • Matplotlib • Basemap • All can be found in Python(x,y) for Windows Pierre Jaccard
Imports import datetime import netCDF4 import numpy as np import matplotlib.pyplot as plt Pierre Jaccard
Read netCDF 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
Calculate Time t = nc.variables['TIME'] t0 = datetime.datetime(1950, 1, 1) dt = np.array(map(lambda x: datetime.timedelta(days=x), t)) t1 = t0 + dt Pierre Jaccard
Plot Temperature I T = nc.variables['TEMP'][:] plt.figure() plt.plot(t1, T, 'b-') plt.grid(True) plt.show() Pierre Jaccard
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
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
FTP import ftplib host = 'vftp1.ifremer.fr' path = '/INSITU_GLO_NRT_OBSERVATIONS_013_030/' ftp = ftplib.FTP(host) ftp.login(user, passwd) ftp.cwd(path) fd = open(local, 'wb') self.ftp.retrbinary("RETR " + remote, fd.write) fd.close() ftp.close() Pierre Jaccard