Lectura de datos via ftp, manipulación NetCDF y Graficos

Integrantes:

  • Ines Leyba
  • Milagros Alvarez Imaz
  • Leandro Díaz
In [154]:
#Abrimos el txt con la informacion de los usuarios de las cosas
usuario = open('usuario', 'r')
#El ftp de donde quiero descargar
FTPusuario='AVISO'

while True:
    line = usuario.readline()
    if line == '':
        break
    
    if FTPusuario in line:
        split = line.split(';') #Separamos los elementos por los ;

usuario.close() #Cerramos el archivo de usuarios
     
#Tomamos de la segunda columna que tiene el nombre del usuario
user=str(split[1])
#Tomamos de la tercera columna que tiene la contraseña
pw=str(split[2])
In [139]:
from ftplib import FTP

ftp = FTP('ftp.aviso.altimetry.fr') #ftp de donde quiero los datos
ftp.login(user, pw)  # 'usuario', 'contraseña'
Out[139]:
'230 User cima_leyba logged in'
In [140]:
anio=input('Año entre 1993 a 2015 = ') #elegimos el año que queremos bajar 
Año entre 1993 a 2015 = 2014
In [141]:
ftp.cwd('/global/delayed-time/grids/msla/all-sat-merged/h/'+ anio) # Poner el directorio donde estan los datos
 
Out[141]:
'250 CWD command successful'
In [142]:
# Generamos una lista con todos los archivos que estan en el directorio.
ListaDatos=[]
ListaDatos = ftp.nlst()  
ListaDatos 
Out[142]:
['dt_global_allsat_msla_h_20141114_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140305_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141127_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141124_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140228_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141122_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141224_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141202_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140425_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141023_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140729_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140717_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141101_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140527_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140509_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140902_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141012_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141113_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141107_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140607_20141124.nc.gz',
 'dt_global_allsat_msla_h_20141029_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140730_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140220_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141104_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140815_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141121_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141213_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140212_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140512_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141129_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140511_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140326_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140422_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140613_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140526_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141118_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140331_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141215_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140814_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140103_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140825_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141015_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140417_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140922_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140915_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140313_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140314_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140823_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140131_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140707_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140206_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140113_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140309_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141117_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140416_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140718_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141004_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141013_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140629_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140224_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141028_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140912_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140719_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140123_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141225_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141205_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141217_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140715_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140114_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140919_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140712_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140216_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140510_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140808_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140311_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140926_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140824_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140312_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140321_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140414_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140115_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141203_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140928_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140802_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140910_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140303_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140608_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140125_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141110_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140627_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140127_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141006_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141214_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140602_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140411_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140905_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140725_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140112_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140610_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140901_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140419_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140918_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140821_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141002_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140731_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141016_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140406_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140427_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140413_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140215_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140620_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141014_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140504_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141211_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141020_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140301_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141116_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141126_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140214_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141022_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140327_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140603_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140907_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140506_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140706_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140930_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140830_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140128_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141025_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141027_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140807_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140307_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140831_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140605_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140405_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140109_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140412_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140904_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140207_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140702_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141106_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141227_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140601_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140703_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141001_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140801_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140818_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140404_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140320_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140120_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141229_20150914.nc.gz',
 'dt_global_allsat_msla_h_20140711_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140724_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140505_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140806_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140202_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140426_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141231_20150914.nc.gz',
 'dt_global_allsat_msla_h_20141201_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140325_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140822_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140924_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140530_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140522_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140917_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140328_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141007_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141218_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141212_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140914_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140306_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140927_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140423_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140219_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141112_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140119_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140418_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140315_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140209_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140921_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140726_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140630_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141018_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140705_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140906_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141209_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140616_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140618_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140812_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141008_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140721_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141030_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140117_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140221_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140121_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141119_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140519_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140218_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140401_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140330_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140429_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141128_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140622_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140625_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140709_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140829_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140226_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140609_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140701_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141021_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140531_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141123_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141230_20150914.nc.gz',
 'dt_global_allsat_msla_h_20140606_20141124.nc.gz',
 'dt_global_allsat_msla_h_20141109_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141108_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140126_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140129_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140408_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140614_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141210_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140615_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140911_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140323_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140804_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141220_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140503_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140105_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140623_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140502_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140514_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140213_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140110_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140409_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141111_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140819_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141226_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140204_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140903_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140521_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140513_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140713_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140508_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140913_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141009_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140106_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140318_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140805_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140528_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140316_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140728_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140308_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141216_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140923_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140403_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140225_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140813_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141130_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140517_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140916_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141010_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140817_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140124_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140617_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140420_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140518_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140428_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140203_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140410_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141120_20150513.nc.gz',
 'dt_global_allsat_msla_h_20141003_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140524_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140516_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141102_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140108_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140810_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140621_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140319_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141026_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140211_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140925_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141019_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140628_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140710_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140828_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140322_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141207_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140415_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141115_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140520_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140722_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141228_20150914.nc.gz',
 'dt_global_allsat_msla_h_20140111_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140104_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141206_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140507_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140523_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140525_20141010.nc.gz',
 'dt_global_allsat_msla_h_20141011_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140324_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140716_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140827_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140714_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141017_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141204_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140317_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140820_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140208_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140826_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140624_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140310_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140424_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140604_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140816_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141221_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140223_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140101_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140102_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140407_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140304_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140515_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140122_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140329_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140619_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141031_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140529_20141010.nc.gz',
 'dt_global_allsat_msla_h_20140704_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140201_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140402_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141125_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140210_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140611_20141124.nc.gz',
 'dt_global_allsat_msla_h_20140811_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141219_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140501_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140809_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141222_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140430_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141005_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140118_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140217_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141208_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140803_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140723_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140116_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140626_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140727_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140227_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140920_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141103_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140130_20140829.nc.gz',
 'dt_global_allsat_msla_h_20141105_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140909_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140612_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141223_20150513.nc.gz',
 'dt_global_allsat_msla_h_20140708_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140222_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140929_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140908_20150209.nc.gz',
 'dt_global_allsat_msla_h_20141024_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140720_20150209.nc.gz',
 'dt_global_allsat_msla_h_20140205_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140107_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140421_20140829.nc.gz',
 'dt_global_allsat_msla_h_20140302_20140829.nc.gz']
In [143]:
# Bajamos una lista de datos especificos

ListaDatosSelec=[]

for i in ListaDatos:
    if i.endswith('01_20150209.nc.gz'): # Aca decimos que datos queremos seleccionar
        
        localfile = open(i, 'wb') #Localfile es el nombre del archivo en la maquina local, puede ser el mismo nombre que filename o no.
        ftp.retrbinary('RETR ' + i, localfile.write)    # descarga el filename, lo descarga en localfile, velocidad de descarga           
        
        ListaDatosSelec.append(i)
        localfile.close() # Importante cerrar archivos, comentar problema de no cerrarlo
        
print(ListaDatosSelec)

ftp.quit()
['dt_global_allsat_msla_h_20140901_20150209.nc.gz', 'dt_global_allsat_msla_h_20141001_20150209.nc.gz', 'dt_global_allsat_msla_h_20140801_20150209.nc.gz', 'dt_global_allsat_msla_h_20140701_20150209.nc.gz']
Out[143]:
'221 Goodbye.'
In [146]:
import os

ListaUncompress_file = []

for compressed_file in ListaDatosSelec:
    print(compressed_file)
    
    uncompressed_file = os.path.splitext(compressed_file)[0]  # Te separa hasta el ultimo "."
    print(uncompressed_file)
   
    ListaUncompress_file.append(uncompressed_file) #Generamos una lsita con todos los nombres sin ".gz"
        
    inF = gzip.open(compressed_file, 'rb') # abre el archivo de entrada en modo lectura binario

    outF = open(uncompressed_file, 'wb')   # crea el archivo de salida en modo escritura binario
    
    # try --> Prueba las funciones, si llega a haber un error, continua. 
    try:
        outF.write( inF.read() ) #  Escribe el archivo de salida
    # except --> Uno puede printiear el error que uno quiere o por ejemplo generar una lista con todos los archivos que presentaron un problema    
    except:
        print('error --> no se puede descomprimir este archivo')

    inF.close()
    outF.close()
    
    print('descomprimí archivo')
dt_global_allsat_msla_h_20140901_20150209.nc.gz
dt_global_allsat_msla_h_20140901_20150209.nc
descomprimí archivo
dt_global_allsat_msla_h_20141001_20150209.nc.gz
dt_global_allsat_msla_h_20141001_20150209.nc
descomprimí archivo
dt_global_allsat_msla_h_20140801_20150209.nc.gz
dt_global_allsat_msla_h_20140801_20150209.nc
descomprimí archivo
dt_global_allsat_msla_h_20140701_20150209.nc.gz
dt_global_allsat_msla_h_20140701_20150209.nc
descomprimí archivo
In [151]:
# Abrir Netcdf 

from netCDF4 import Dataset 
import numpy as np 

#dataset = Dataset(out_nc, mode='r') #Ver tipo de netcdf 
dataset = Dataset('dt_global_allsat_msla_h_20140801_20150209.nc', mode='r') #Ver tipo de netcdf 

print(dataset.file_format) 
#Dimensiones 
dataset.dimensions.keys() 
#Variables del netcdf 
dataset.variables.keys() 
NETCDF3_CLASSIC
Out[151]:
odict_keys(['time', 'lat', 'lat_bnds', 'lon', 'lon_bnds', 'crs', 'nv', 'sla', 'err'])
In [152]:
#Ver informacion de la variable
dataset.variables['sla']
Out[152]:
<class 'netCDF4._netCDF4.Variable'>
int32 sla(time, lat, lon)
    _FillValue: -2147483647
    coordinates: lon lat
    grid_mapping: crs
    long_name: Sea Level Anomalies
    scale_factor: 0.0001
    standard_name: sea_surface_height_above_sea_level
    units: m
unlimited dimensions: 
current shape = (1, 720, 1440)
filling off
In [153]:
#Ver informacion de la variable
dataset.variables['time']
Out[153]:
<class 'netCDF4._netCDF4.Variable'>
float32 time(time)
    axis: T
    calendar: gregorian
    long_name: Time
    standard_name: time
    units: days since 1950-01-01 00:00:00
unlimited dimensions: 
current shape = (1,)
filling off
In [124]:
# EXtraemos las variables

lons = dataset.variables['lon'][:]
lats = dataset.variables['lat'][:]
sla = dataset.variables['sla'][:]
time = dataset.variables['time'][:]

dataset.close() # Cierra netcdf
In [126]:
# Pasar a fecha calendario
import datetime
day = time[0]

date = datetime.datetime(1950, 1, 1) + datetime.timedelta(float(day)) #This assumes that the year is 2007

#Pasamos al formato que queremos (buscar documentación strftime)
fecha=date.strftime("%d-%B-%Y")
print(fecha)

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt


#Con esto muestra el gráfico dentro de esta pantalla y no aparte
%matplotlib inline

# create Basemap instance for Robinson projection.
m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]))
# compute map projection coordinates for lat/lon grid.
x, y = m(*np.meshgrid(lons,lats))
# make filled contour plot.
#clevs = [-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5] # defino los intervalos en la barra de colores 
clevs = [-0.5,-0.3,-0.1,0,0.1,0.3,0.5] # defino los valores 

cs = m.contourf(x,y,sla[0,:,:],clevs,cmap=plt.cm.jet)
#cs = m.contourf(x,y,sla[0,:,:],30,cmap=plt.cm.jet)
m.drawcoastlines() # draw coastlines
m.drawmapboundary() # draw a line around the map region
m.drawparallels(np.arange(-90.,120.,30.),labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(0.,420.,60.),labels=[0,0,0,1]) # draw meridians
plt.title('SLA ' + fecha) # add a title
cbar = m.colorbar(cs, location='bottom', pad="10%") #Agregamos la barra de colores
cbar.set_label('m')



plt.show()
01-September-2014
/home/ines/anaconda3/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py:3644: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  xx = x[x.shape[0]/2,:]
In [1]:
#Este css es trabajo de @LorenaABarba y su grupo
from IPython.core.display import HTML
css_file = '../../css/personal.css'
HTML(open(css_file, "r").read())
Out[1]: