Commits

Neal Schweighart authored 359c0ea8bfa
first attempt at switching to using ftplib for getting tec data

casatasks/src/private/tec_maps.py

Modified
149 149 ##
150 150 ##
151 151 ## =============================================================================
152 152 ## =============================================================================
153 153
154 154
155 155 import glob, pylab, os, datetime
156 156 import numpy as np
157 157 from matplotlib import rc
158 158 import matplotlib.pyplot as plt
159 +import ftplib
159 160
160 161 from casatasks.private.casa_transition import is_CASA6
161 162 if is_CASA6:
162 163 from casatools import table, quanta, coordsys, image, measures
163 164
164 165 tb = table()
165 166 qa = quanta()
166 167 cs = coordsys()
167 168 ia = image()
168 169 me = measures()
301 302
302 303 ## Set up the days for which we need to go get TEC files
303 304 day_list = []
304 305 next_day = begin_day
305 306 for iter in range(call_num):
306 307 day_list.append(next_day)
307 308 next_day = qa.time(str(t_min[0]+86400.*(iter+1))+'s',form='ymd')[0][:10]
308 309
309 310 print('IGS files required for: '+str(day_list))
310 311
312 + # plot name declared here to avoid potential reference before assignment error
313 + plot_name = ''
311 314 ## Runs the IGS methods
312 315 if tec_server == 'IGS':
313 316 ymd_date_num = 0
314 317 #array = []
315 318 lo=0
316 319 hi=0
317 320 for ymd_date in day_list:
318 321 points_long,points_lat,ref_long,ref_lat,incr_long,incr_lat,incr_time,num_maps,tec_array,tec_type = get_IGS_TEC(ymd_date)
319 322
320 323 ## Fill a new array with all the full set of TEC/DTEC values for all days in the observation set.
487 490 ## unavailable, it will try to retrieve the JPL Rapid Product (JPRG),
488 491 ## released ~ 1 day after data is collected. While the 'uncompress' command
489 492 ## is not necessary, it is the most straightforward on Linux.
490 493 ##
491 494 ## =========================================================================
492 495
493 496 #CDDIS = 'ftp://cddis.gsfc.nasa.gov/gnss/products/ionex/' # pre-2020Nov01 version
494 497 CDDIS = 'ftp://gdc.cddis.eosdis.nasa.gov/gps/products/ionex/' # new, more secure ftp-ssl server (2020Nov01)
495 498 file_location = CDDIS+str(year)+'/'+str(dayofyear)+'/'
496 499 curlcmd='curl -u anonymous:casa-feedback@nrao.edu --ftp-ssl-reqd '
500 + #ftps login and navigation
501 + try:
502 + ftps = ftplib.FTP_TLS(host = 'gdc.cddis.eosdis.nasa.gov/gps/products/ionex') # ftp-ssl version
503 + ftps.login(user='anonymous', passwd='casa-feedback@nrao.edu')
504 + ftps.prot_p()
505 + ftps.cwd(file_location)
506 + except ftplib.all_errors as e:
507 + print('Failed to connect with error: ', e)
497 508
498 509 ## The name of the IONEX file you require.
499 510 igs_file='igsg'+str(dayofyear)+'0.'+str(year)[2:4]+'i' if ( gpsweek<2238) else 'IGS0OPSFIN_'+str(year)+str(dayofyear)+'0000_01D_02H_GIM.INX'
500 511 get_file=igs_file + ('.Z' if gpsweek<2238 else '.gz')
501 512
502 513 print('\nFor '+ymd_date+', the required IGS file is called: '+igs_file)
503 514
504 515 if len(glob.glob(igs_file))<1: # file does not yet exist locally
505 516 print('Attempting retrieval of IGS Final product file: '+str(get_file))
506 517 get_path = file_location+get_file
507 518 if test_IONEX_connection(get_path):
508 - os.system(curlcmd+get_path+' > '+workDir+get_file)
509 - os.system('gunzip '+get_file)
519 + #os.system(curlcmd+get_path+' > '+workDir+get_file)
520 + #os.system('gunzip '+get_file)
521 + #ftps version
522 + ftps.retrbinary("RETR " + get_file, open(get_file, 'wb').write)
510 523 else:
511 524 # IGS final product file does not exist; try rapid product file
512 525 igs_file='igrg'+str(dayofyear)+'0.'+str(year)[2:4]+'i' if ( gpsweek<2238) else 'IGS0OPSRAP_'+str(year)+str(dayofyear)+'0000_01D_02H_GIM.INX'
513 526 get_file=igs_file + ('.Z' if gpsweek<2238 else '.gz')
514 527
515 528 if len(glob.glob(igs_file))<1: # file does not yet exist
516 529 print('Attempting retrieval of IGS Rapid product file: '+str(get_file))
517 530 get_path = file_location+get_file
518 531 if test_IONEX_connection(get_path):
519 - os.system(curlcmd+get_path+' > '+workDir+get_file)
520 - os.system('gunzip '+get_file)
532 + #os.system(curlcmd+get_path+' > '+workDir+get_file)
533 + #os.system('gunzip '+get_file)
534 + #ftps version
535 + ftps.retrbinary("RETR " + get_file, open(get_file, 'wb').write)
521 536 else:
522 537 #igs_file = igs_file.replace('igr','jpr')
523 538 igs_file= 'jprg'+str(dayofyear)+'0.'+str(year)[2:4]+'i' if (gpsweek<2274.5) else 'JPL0OPSRAP_'+str(year)+str(dayofyear)+'0000_01D_02H_GIM.INX'
524 539 get_file=igs_file + ('.Z' if gpsweek<2274.5 else '.gz')
525 540
526 541 if len(glob.glob(igs_file))<1: # file does not yet exist
527 542 print('Attempting retrieval of JPL Rapid product file: '+str(igs_file))
528 543 get_path = file_location+get_file
529 544 if test_IONEX_connection(get_path):
530 - os.system(curlcmd+get_path+' > '+workDir+get_file)
531 - os.system('gunzip '+get_file)
545 + #os.system(curlcmd+get_path+' > '+workDir+get_file)
546 + #os.system('gunzip '+get_file)
547 + #ftps version
548 + ftps.retrbinary("RETR " + get_file, open(get_file, 'wb').write)
532 549 else:
533 550 print('\nNo data products available. You may try to manually'+\
534 551 ' download the products at:\n'+\
535 552 'ftp://gdc.cddis.eosdis.nasa.gov/gps/products/ionex\n')
536 553 return 0,0,0,0,0,0,0,0,[0],''
537 554 else:
538 555 print('JPL Rapid product file: '+igs_file+' already available in current working directory.')
539 556 else:
540 557 print('IGS Rapid product file: '+igs_file+' already available in current working directory.')
541 558 else:

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut