def __init__(self, request, log=""): """ Set the initial GUI window size here and initialize the UI """ super().__init__() self.title = 'RSL Creator' self.left = 200 self.top = 100 self.width = 1000 self.height = 500 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.request = request self.log = log # Configure the menu bar self.createMenuBar() # Read in the contents of the source list of stations. # Get the filename from the request station_list_file so it will # be the default unless user changes it via menu option 'load master # station list' self.stationList = RAOBstation_list() self.station_list = \ self.stationList.read(getrootdir() + "/" + self.request.get_stnlist_file()) # Create the GUI that will allow selecting stations from the source # list to be included in the RSL file. self.win = RSLWidget(self.station_list) self.setCentralWidget(self.win) self.win.signal.connect(self.close_win) self.win.show()
def getImage(self, gifimage=getrootdir() + '/src/gui/message.gif'): """ Return the image associated with the latest downloaded RAOB data. Defaults to usage message on initialization. """ self.pixmap = \ QPixmap(gifimage) return (self.pixmap)
def setUp(self): self.stnlist1 = getrootdir() + "/config/station-query.html" # stations from station-query.html self.stn1 = { '01003': { 'id': ' ', 'number': '01003', 'description': 'HORNSUND RIVER ', 'state': '--', 'country': 'NO', 'lat': ' 7700', 'lon': ' 1550', 'elev': ' 12'}, '01015': { 'id': ' ', 'number': '01015', 'description': 'HEKKINGEN (LGT-H) ', 'state': '--', 'country': 'NO', 'lat': ' 6960', 'lon': ' 1783', 'elev': ' 14'}, 'BJC': { 'id': 'BJC ', 'number': '99999', 'description': 'BROOMFIELD/JEFFCO ', 'state': 'CO', 'country': 'US', 'lat': ' 3992', 'lon': '-10512', 'elev': ' 1724'}, 'GJT': { 'id': 'GJT ', 'number': '72476', 'description': 'GRAND JUNCTION ', 'state': 'CO', 'country': 'US', 'lat': ' 3912', 'lon': '-10853', 'elev': ' 1475'}, } self.stnlist2 = getrootdir() + "/config/snstns.tbl" # stations from snstns.tbl self.stn2 = { 'GJT': { 'id': 'GJT ', 'number': '72476', 'description': 'GRAND_JUNCTION/WALKER ', 'state': 'CO', 'country': 'US', 'lat': ' 3911', 'lon': '-10853', 'elev': ' 1475'}, '72476': { 'id': 'GJT ', 'number': '72476', 'description': 'GRAND_JUNCTION/WALKER ', 'state': 'CO', 'country': 'US', 'lat': ' 3911', 'lon': '-10853', 'elev': ' 1475'}, }
def test_rsl(self): ctrlstnlist = [ '89611', 'ASLH', 'DNR', 'GJT', 'LKN', 'NCRG', 'NFFN', 'NKX', 'NSTU', 'NWWN', 'NZNV', 'NZPP', 'NZRN', 'NZWP', 'NZHK', 'NZLD', 'OAK', 'PHLI', 'PHTO', 'PKMJ', 'PTKK', 'PTPN', 'REV', 'SLC', 'VBG', 'VEF', 'YBBN', 'YBRK', 'YBTL', 'YMHB', 'YMMG', 'YMMQ', 'YMML', 'YSNF', 'YSWM' ] self.option.rsl = getrootdir() + "/config/sample.RSL" self.assertTrue(self.raob.test_rsl(self.option.rsl)) rsl = RSL() stnlist = rsl.read_rsl(self.option.rsl) self.assertListEqual(stnlist, ctrlstnlist)
def loadStationListFile(self): """ Open a dialog to let the user select the source list of stations to choose from when creating their RSL file. """ rootdir = getrootdir() + "/config" filefilter = "station list files (*.tbl, *.TBL)" self.request.set_stnlist_file(self.initDialog(rootdir, filefilter)) if self.request.get_stnlist_file() != "": self.station_list = \ self.stationList.read(os.path.join( rootdir, self.request.get_stnlist_file())) self.win.textbox.clear() self.win.display_station(self.station_list)
def test_TEXT_LIST(self): # Remove files if we downloaded them before if os.path.isfile("7267220190528122812.txt"): os.remove('7267220190528122812.txt') outfile = self.get_data() # Compare retrieved text file to control file ctrlfile = getrootdir() + "/test/data/7267220190528122812.ctrl" with open(ctrlfile) as ctrl, open(outfile) as out: self.assertTrue([row1 for row1 in ctrl] == [row for row in out], "files " + ctrlfile + " and " + outfile + " differ ") ctrl.close() out.close()
class options(): region = 'North America' raobtype = 'TEXT:LIST' year = "2019" month = "05" bday = "28" bhr = "12" eday = "28" ehr = "12" stnm = "72672" rsl = "" test = False mtp = False mtpdir = "../mtp" catalog = False now = False config = getrootdir() + "/" + "test/data/config_cp.yml" freq = "12" station_list_file = "config/snstns.tbl"
def test_mtp(self): # Remove files if we downloaded them before if os.path.isfile("726722019052812.txt"): os.remove('726722019052812.txt') self.option.mtp = True self.raob.request.set_prov(self.option) outfile = self.get_data() # Compare files with HTML stripped ctrlfile = getrootdir() + "/test/data/726722019052812.ctrl.mtp" mtpfile = outfile with open(ctrlfile) as ctrl, open(mtpfile) as out: self.assertTrue([row1 for row1 in ctrl] == [row for row in out], "files " + ctrlfile + " and " + mtpfile + " differ ") ctrl.close() out.close()
def get_station_info(self, request): """ Read in the station metadata for the given station id/number """ station_list_file = getrootdir() + "/" + request.get_stnlist_file() stationList = RAOBstation_list(self.log) stationList.read(station_list_file) if request.get_stnm().isdigit(): station = stationList.get_by_stnm(request.get_stnm()) else: station = stationList.get_by_id(request.get_stnm()) # Should only get back one, unique station. If not, warn user if (len(station) != 1): printmsg( self.log, "WARNING: Found more than one station " + "matching request['stnm']") for i in range(len(station)): printmsg(self.log, str(station[i])) printmsg(self.log, "Returning first station found") return (station[0])
def __init__(self): """ Initialize a RAOBrequest dictionary to hold request metadata """ RAOBrequest = { # Default station used in testing. Will be overwritten # with requested station in normal usage. 'region': '', # Region identifier 'raobtype': '', # Retreived data/imagery type indentifier 'year': "", # Year to retrieve data for 'month': "", # Month to retrieve data for 'begin': "", # Begin day/hour (ddhh) to retrieve data for 'end': "", # End day/hour (ddhh) to retrieve data for 'stnm': "", # Station number to retrieve data for 'freq': "12", # Freq to look for RAOBs. Default is every 12 hrs 'rsl': "", # Name of file containing list of stations to # retrieve data for 'config': "", # Name of config file 'test': False, # Run in test/dev mode 'mtp': False, # MTP-specific processing 'mtpdir': "", # Dir to write RAOBs for MTP use 'catalog': False, # catalog-specific processing 'now': False, # Set requested date/time to current time, # i.e. retrieve current RAOB. 'ftp': False, # Ftp data to catalog site, or cp to local dir? 'ftp_server': "", # If ftp is True, need ftp_server and ftp_dir 'ftp_dir': "", 'cp_dir': "", # If ftp is False, need dir to cp files to 'station_list_file': "", # List of RAOB station locations, # description, etc. Used to assign metadata to # retrieved RAOB. Give path relative to RAOBget # dir. } self.request = RAOBrequest # dictionary to hold all URL components # Load a station list so we can validate stnm requests self.stationList = RAOBstation_list() self.stationList.read(getrootdir() + "/config/snstns.tbl")
def test_GIF_SKEWT(self): # Remove files if we downloaded them before if os.path.isfile("7267220190528122812.html"): os.remove('7267220190528122812.html') if os.path.isfile("upperair.SkewT2019052812.RIW_Riverton.gif"): os.remove('upperair.SkewT2019052812.RIW_Riverton.gif') outfile = self.get_skewt() # Compare retrieved html file to control file ctrlfile = getrootdir() + "/test/data/7267220190528122812.html.ctrl" with open(ctrlfile) as ctrl, open(outfile) as out: self.assertTrue([row1 for row1 in ctrl] == [row for row in out], "files " + ctrlfile + " and " + outfile + " differ ") ctrl.close() out.close() # Remove HTML file self.gifskewt.cleanup()
def test_rsl_missing(self): self.option.rsl = getrootdir() + "/config/missing.RSL" self.assertFalse(self.raob.test_rsl(self.option.rsl))
def retrieve(self, app, request, log=""): """ Retrieves the requested data from the U Wyoming archive Parameters: request: A dictionary containing the metadata for the request. Returns: outfile: The name of the retrieved file. """ # SKEWT's are downloaded in two steps. # The first request generates the skewt on the website and downloads an # HTML wrapper with a reference to the gif image that is still on the # website. The second request downloads the gif image. # Create first request URL from request metadata url = self.get_url(request) if app is not None: # Force the GUI to redraw so log app.processEvents() # messages, etc are displayed # Create output filename from request metadata self.set_outfile_html(request) # If in test mode, copy file from data dir to simulate download... if request.get_test() is True: shutil.copyfile( getrootdir() + '/test/data/7267220190528122812.html.ctrl', '7267220190528122812.html') status = False # ...else download data else: status = self.rwget.get_data(url, self.get_outfile_html()) if app is not None: # Force the GUI to redraw so log app.processEvents() # messages, etc are displayed # If site returned good html file and thus generated gif if status: # Download the gif image directly url = self.get_gif_url(request) # Create output filename from request metadata self.set_outfile_gif(request) outfile = self.get_outfile_gif() if app is not None: # Force the GUI to redraw so log app.processEvents() # messages, etc are displayed # Download gif image gifstatus = self.rwget.get_data(url, outfile) if app is not None: # Force the GUI to redraw so log app.processEvents() # messages, etc are displayed else: gifstatus = None if request.get_test() is True: shutil.copyfile( getrootdir() + '/test/data/' + 'upperair.SkewT.201905280000.Riverton_WY.gif' + '.ctrl', 'upperair.SkewT.201905280000.Riverton_WY.gif') outfile = "upperair.SkewT.201905280000.Riverton_WY.gif" # If running in catalog mode, ftp files to catalog dir if request.get_catalog() is True and gifstatus: ftpstatus = userlib.catalog.to_ftp(outfile, request, self.log) printmsg(self.log, ftpstatus) if app is not None: # Force the GUI to redraw so log app.processEvents() # messages, etc are displayed return (gifstatus, outfile)