def get_ogle_parameters(config, log): '''Function to download the parameters of lensing events from the OGLE survey. OGLE make these available via anonymous FTP from ftp.astrouw.edu.pl in the form of two files. ogle/ogle4/ews/last.changed contains a yyyymmdd.daydecimal timestamp of the time of last update ogle/ogle4/ews/<year>/lenses.par contains a list of all known lenses with the following columns: Event Field StarNo RA(J2000) Dec(J2000) Tmax(HJD) Tmax(UT) tau umin Amax Dmag fbl I_bl I0 This function returns the parameters of all the lenses as a dictionary, plus a datetime object of the last changed date. ''' log.info('Syncing data from OGLE') ogle_data = survey_classes.SurveyData() years = [ '2014', '2015', '2016' ] # Fetch the parameter files from OGLE via anonymous FTP ftp = ftplib.FTP( config['ogle_ftp_server'] ) ftp.login() ftp_file_path = path.join( 'ogle', 'ogle4', 'ews' ) ts_file_path = path.join( config['ogle_data_local_location'], config['ogle_time_stamp_file'] ) ftp.cwd(ftp_file_path) ftp.retrbinary('RETR last.changed', open( ts_file_path, 'w').write ) ts = Time.now() for year in years: ftp_file_path = path.join( str(year) ) ftp.cwd(ftp_file_path) par_file_path = path.join( config['ogle_data_local_location'], \ config['ogle_lenses_file']+'.'+str(year) ) ftp.retrbinary('RETR lenses.par', open( par_file_path, 'w').write ) ftp.cwd('../') ftp.quit() ogle_data = survey_data_utilities.read_ogle_param_files( config ) log.info('--> Last updated at: ' + \ ogle_data.last_changed.strftime("%Y-%m-%dT%H:%M:%S")) log.info('--> Downloaded index of ' + str(len(ogle_data.lenses)) + \ ' events') update_file_path = path.join( config['ogle_data_local_location'], \ config['ogle_updated_file'] ) ogle_data.last_updated = \ survey_data_utilities.write_update_file( update_file_path ) log.info('-> Completed sync of data from OGLE') return ogle_data