Exemplo n.º 1
0
class WeatherStation():
    # These are all the data fields pulled for each station, add/remove from this list to get less or more data
    DATA_LABELS = ['time', 'lat', 'lon', 'elev', 'winAngle', 'winSpeed', 'visibility', 'degreesC', 'seaLvlPress']
    DATA_WORKER = DataWorker(LOC_FOLS['templates']+TEMP_FILES['station-data-temp'])

    def __init__(self, metadata, interest_year):
        self.metaDataDictionary = {}
        self.interest_year = interest_year
        self.sim_time = datetime.datetime.now()           # Default time for simulation is the most recent time, now
        for i, data in enumerate(metadata):
            self.metaDataDictionary.update({META_WORKER.labels[i] : data})
        self.data = []
    
    # Updates data as well as the sim_time of the object
    def update(self, new_time):
        logging.info(TAG+'Updating weather station...')
        prev_line = []
        prev_line_delta = sys.maxsize
        time_index = WeatherStation.DATA_WORKER.labels.index('time')
        self.sim_time = new_time
        desired_time = get_isd_time(self.sim_time)
        with gzip.open(LOC_FOLS['current-data']+self.get_file_name(), 'rt') as gzFile:
            for line in gzFile.readlines():
                parsed_line = WeatherStation.DATA_WORKER.parse_line(line)
                time = parsed_line[time_index]
                time_delta = abs(int(time) - desired_time)
                if time_delta < prev_line_delta:
                    prev_line = line
                    prev_line_delta = time_delta
                elif time_delta < 1000:
                    break
                else:
                    logging.info(TAG+'line not in chronological order encountered')
        self.data = WeatherStation.DATA_WORKER.get_vals_lined(prev_line, WeatherStation.DATA_LABELS)
        print(self.data)

    # Update the time by a certain datetime increment (increment is a timedelta object)
    def time_step(self, increment):
        self.update(self.sim_time + increment)
        logging.info(TAG+'Updating the station time to '+str(self.sim_time))

    def pull_gz(self):
        path = self.get_ftp_path()
        if not os.path.exists(LOC_FOLS['current-data']+self.get_file_name()):
            with open(LOC_FOLS['current-data']+self.get_file_name(), 'wb') as writer:
                with FTP(FTP_URL) as ftp:
                    ftp.login(user = '******', passwd=FTP_EMAIL)
                    ftp.retrbinary('RETR '+path, writer.write, 8*1024)
                    logging.info(TAG+'pulling ' + path)
        else:
            logging.info(TAG+path+' already pulled')

    def get_file_name(self):
        return self.metaDataDictionary['usaf'] + '-' + self.metaDataDictionary['wban'] + '-' + str(self.interest_year) + '.gz'

    def get_ftp_path(self):
        return FTP_GEN_PATH + str(self.interest_year) + '/' + self.get_file_name()

    def __str__(self):
        return str(self.metaDataDictionary)
Exemplo n.º 2
0
 def make_map(self):
     coordinate_list = META_WORKER.get_vals(self.data_file, ['lat', 'lon'])
 
     for i, point in enumerate(coordinate_list):
         for j, val in enumerate(point):
             coordinate_list[i][j] = DataWorker.str_to_flt(val)
     map = folium.Map(location=[40.12, -88.22], zoom_start=4)
     for point in coordinate_list:
         folium.Marker(point).add_to(map)
     return map
Exemplo n.º 3
0
def metadata_pull():
    logging.info(TAG+'Checking for metadata')
    data_pulled = False
    with FTP(FTP_URL) as ftp:
        ftp.login(user = '******', passwd=FTP_EMAIL)
        for fileKey in META_FILES.keys():
            if not os.path.exists(LOC_FOLS['metadata']+META_FILES[fileKey]):
                data_pulled = True
                logging.info(TAG+'Attempting pull of '+META_FILES[fileKey]+' from FTP server')
                with open(LOC_FOLS['metadata']+META_FILES[fileKey], 'wb') as writer:
                    try:
                        ftp.retrbinary('RETR '+META_FTP_PATHS[fileKey], writer.write)
                        logging.info(TAG+'\tPull successful')
                    except:
                        data_pulled = False
                        logging.info(TAG+'\tMetadata file '+META_FILES[fileKey]+' was not found on the FTP server')
        for i in range (INTEREST_RANGE[0], INTEREST_RANGE[1]):
            if not os.path.exists(LOC_FOLS['metadata']+str(i)+'.txt'):
                data_pulled = True
                logging.info(TAG+'Downloading metadata for ' + str(i))
                file_list = ftp.nlst(FTP_GEN_PATH+str(i)+'/')
                DataWorker.save_lines(LOC_FOLS['metadata']+str(i)+'.txt', file_list, [20, len(file_list)])
    return data_pulled
Exemplo n.º 4
0
    def __init__(self, left_bot_cor, right_top_cor, time):
        self.__radar_stations = [
        ]  # All the radar stations, generated from metadata
        self.__sim_time = time  # Current time for the simulation

        worker = DataWorker(LOC_FOLS['meta'] + 'nexrad-stations-template.txt')
        worker.quicksort_lg(LOC_FOLS['meta'] + 'nexrad-stations.txt',
                            LOC_FOLS['meta'] + 'nexrad-stations-sorted.txt',
                            'longitude')
        worker.replace(LOC_FOLS['meta'] + 'nexrad-stations.txt',
                       LOC_FOLS['meta'] + 'nexrad-stations-sorted.txt')
        meta_data = worker.get_vals(
            LOC_FOLS['meta'] + 'nexrad-stations.txt',
            ['icao', 'state', 'elevation', 'latitude', 'longitude'])
        for station_list in meta_data:
            self.__radar_stations.append(
                RadarStation(station_list[0], station_list[1], station_list[2],
                             station_list[3], station_list[4]))
        self.update_area(left_bot_cor, right_top_cor)
Exemplo n.º 5
0
    def __init__(self, sim_time):
        self.sim_time = sim_time
        self.__radar_stations = []
        self.__http_errors = 0
        self.__img_path = None
        self.__wld_path = None

        worker = DataWorker(LOC_FOLS['meta']+'nexrad-stations-template.txt')
        worker.quicksort_lg(LOC_FOLS['meta']+'nexrad-stations.txt',
                            LOC_FOLS['meta']+'nexrad-stations-sorted.txt',
                            'longitude')
        worker.replace(LOC_FOLS['meta']+'nexrad-stations.txt',
                       LOC_FOLS['meta']+'nexrad-stations-sorted.txt')
        meta_data = worker.get_vals(LOC_FOLS['meta']+'nexrad-stations.txt', 
                                    ['icao', 'state', 'elevation', 'latitude', 'longitude'])
        for station_list in meta_data:
            self.__radar_stations.append(RadarStation(station_list[0], station_list[1],
                                                      station_list[2], station_list[3],
                                                      station_list[4]))
Exemplo n.º 6
0
import nexradaws, config, pytz, pyart, tempfile, logging
import matplotlib.pyplot as plt
from NEXRADWorker import NEXRADStationManager
from txtparsing import DataWorker
from datetime import datetime, timezone

templocation = tempfile.mkdtemp()

# Initializing variables and local folder environment
config.init_environment()
LOC_FOLS = config.LOC_FOLS
BING_KEY = config.BING_MAPS_API_KEY

TAG = 'tester - '

worker = DataWorker(LOC_FOLS['meta'] + 'nexrad-stations-template.txt')

time = datetime(2016, 3, 23, 12, 34, tzinfo=timezone.utc)
manager = NEXRADStationManager([40.149284, -104.755224],
                               [41.951239, -102.351951], time)
#list = manager.bin_search_longitude(-108.755224, -102.351951)
NEXRADStationManager.cl_wd()
manager.pull_new_data()

manager.print_scan_data()
manager.combine_scans_into_overlay()
logging.info(TAG + 'Done executing.')

## Example code from the nexradaws examples page
#print('************************************************')
#print('Going on to a sample download and display of radar plots')
Exemplo n.º 7
0
def getsort_us_data():
    worker = DataWorker(LOC_FOLS['templates']+TEMP_FILES['station-list-temp'])

    logging.info(TAG+'Reading pulled ISD metadata')
    DataWorker.read_save(22, 29700, LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG)
    DataWorker.replace(LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG)

    logging.info(TAG+'Filtering metadata for US stations')
    worker.read_filter(LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG, ['lat', 24.53105, 49.04069], filter2=['lon', -124.48491, -66.56499])
    DataWorker.replace(LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG)

    logging.info(TAG+'Quicksorting metadata w/latitude')
    worker.quicksort_lg(LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG, 'lat')
    DataWorker.replace(LOC_FOLS['metadata']+META_FILES['station-list'], LOC_FOLS['metadata']+FIL_TAG)
Exemplo n.º 8
0
	'metadata' : 'data/metadata/',
	'templates' : 'data/templates/',
	'current-data' : 'data/current-data/'
}
TEMP_FILES = {
    'station-list-temp' : 'isd-history-template.txt',
    'station-data-temp' : 'station-data-template.txt'
}
META_FILES = {
    'station-list' : 'isd-history.txt',
    'rectangle-list' : 'current-rectangle.txt'
}
META_FTP_PATHS = {
    'station-list' : '/pub/data/noaa/isd-history.txt'
}
META_WORKER =  DataWorker(LOC_FOLS['templates']+TEMP_FILES['station-list-temp'])

# Class in order to represent a viewing window in the GUI
class StationWindow():
    def __init__(self, gps_bot_left, gps_top_right, interest_year):
        self.data_file = LOC_FOLS['metadata']+META_FILES['rectangle-list']
        self.interest_year = interest_year
        self.update_area(gps_bot_left, gps_top_right)

    def update_area(self, gps_bot_left, gps_top_right):
        META_WORKER.read_filter(LOC_FOLS['metadata']+META_FILES['station-list'], 
                                LOC_FOLS['metadata']+META_FILES['rectangle-list'], 
                                ['lat', gps_bot_left[0], gps_top_right[0]], 
                                filter2=['lon', gps_bot_left[1], gps_top_right[1]])

        self.station_list = []