コード例 #1
0
ファイル: RSLcreator.py プロジェクト: iamaSam/RAOBget
    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()
コード例 #2
0
ファイル: raobdata.py プロジェクト: iamaSam/RAOBget
    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")
コード例 #3
0
ファイル: gifskewt.py プロジェクト: iamaSam/RAOBget
    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])
コード例 #4
0
ファイル: RSLcreator.py プロジェクト: iamaSam/RAOBget
class RSLCreator(QMainWindow):
    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 createMenuBar(self):
        """ Create the menu bar and add options and dropdowns """
        # A Menu bar will show menus at the top of the QMainWindow
        menubar = self.menuBar()

        # Mac OS treats menubars differently. To get a similar outcome, we can
        # add the following line: menubar.setNativeMenuBar(False).
        menubar.setNativeMenuBar(False)

        # Add a menu option to access config files
        fileMenu = menubar.addMenu("File")

        # In order for tooltips of actions to display, need to
        # setToolTipsVisible to True (is False by default)
        fileMenu.setToolTipsVisible(True)

        # Add a submenu option to load a master station list
        loadStationListFile = QAction("Load master station list", self)
        loadStationListFile.setToolTip('Load file containing list of RAOB ' +
                                       'station locations, etc to select ' +
                                       'from to create RSL file.')
        loadStationListFile.triggered.connect(self.loadStationListFile)
        fileMenu.addAction(loadStationListFile)

        # Add a submenu option to load an existing RSL file for modification
        loadRSLFile = QAction("Load RSL file", self)
        loadRSLFile.setToolTip('Load an existing RSL file to be ' + 'modified')
        loadRSLFile.triggered.connect(self.loadRSLFile)
        fileMenu.addAction(loadRSLFile)

        # Add a menu/submenu? option to quit
        quitButton = QAction('Quit', self)
        quitButton.setShortcut('Ctrl+Q')
        quitButton.setToolTip('Exit application')
        quitButton.triggered.connect(self.close)
        menubar.addAction(quitButton)

    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 loadRSLFile(self):
        """
        Open a dialog to let the user select an RSL file to be modified
        """
        rootdir = os.path.join(os.getcwd(), "config")
        filefilter = "RSL files (*.rsl, *.RSL)"

        self.request.set_rsl(self.initDialog(rootdir, filefilter))
        if self.request.get_rsl() != "":
            self.rsl = RSL()
            self.rslList = self.rsl.read_rsl(
                os.path.join(rootdir, self.request.get_rsl()))

            # Populate the RSL window with the contents of the file
            self.win.rslbox.clear()
            for stn in self.rslList:
                print(stn)
                self.win.rslbox.addItem(stn)

    def close_win(self):
        self.close()
        self.request.set_rsl(self.win.get_rsl_filename())
        logging.info("RAOB station list set to " + self.request.get_rsl())

    def get_rsl_filename(self):
        return (self.win.get_rsl_filename())

    def initDialog(self, rootdir, filefilter):
        """
        Instantiate the file dialog used to select the source station list
        """
        # When use native dialogs, get an error that Class
        # FIFinderSyncExtensionHost is implemented twice. Googling seems to
        # indicate this is an incompatability with the latest Mac OS's, so for
        # now disable Native Dialog
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog

        # getOpenFileName returns the complete path to the selected file, and a
        # string containing the filter used. Ignore the filter return.
        # If user selects cancel, returns None.
        filename, _ = QFileDialog.getOpenFileName(self,
                                                  "Select a master " +
                                                  "RAOB station list file",
                                                  rootdir,
                                                  filefilter,
                                                  options=options)

        if filename == "":
            # When user hits cancel, QFileDIalog return an empty string
            return (filename)
        else:
            # QFileDialog returns the complete path to the file. We want to
            # only save the relative path in the request, starting with config
            # so remove the value of getrootdir() from the filename
            return (os.path.relpath(filename, start=rootdir))
コード例 #5
0
ファイル: test_stationlist.py プロジェクト: iamaSam/RAOBget
class TestRAOBstation_list(unittest.TestCase):

    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 get_stns(self):

        assert(os.path.isfile(self.station_list_file))

        self.stationList = RAOBstation_list()
        self.stationList.read(self.station_list_file)

    def test_by_index(self):
        # Test first station list
        self.station_list_file = self.stnlist1
        self.get_stns()

        station = self.stationList.get_by_stnm('01003')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn1['01003'])

        station = self.stationList.get_by_stnm('01015')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn1['01015'])

    def test_by_index2(self):
        # Test second station list
        self.station_list_file = self.stnlist2
        self.get_stns()

        station = self.stationList.get_by_stnm('72476')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn2['72476'])

    def test_by_id(self):
        # Test first station list
        self.station_list_file = self.stnlist1
        self.get_stns()

        station = self.stationList.get_by_id('BJC')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn1['BJC'])

        station = self.stationList.get_by_id('GJT')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn1['GJT'])

    def test_by_id2(self):
        # Test second station list
        self.station_list_file = self.stnlist2
        self.get_stns()

        station = self.stationList.get_by_id('GJT')
        self.assertEqual(len(station), 1)
        self.assertDictEqual(station[0], self.stn2['GJT'])
コード例 #6
0
ファイル: test_stationlist.py プロジェクト: iamaSam/RAOBget
    def get_stns(self):

        assert(os.path.isfile(self.station_list_file))

        self.stationList = RAOBstation_list()
        self.stationList.read(self.station_list_file)
コード例 #7
0
ファイル: raobdata.py プロジェクト: iamaSam/RAOBget
class RAOBdata():
    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 set_key(self, key, value):
        self.request[key] = value

    def get_keys(self):
        return (self.request.keys())

    def set_region(self, region):
        self.request['region'] = region

    def get_region(self):
        return (self.request['region'])

    def set_type(self, raobtype):
        self.request['raobtype'] = raobtype

    def get_type(self):
        return (self.request['raobtype'])

    def set_year(self, year):
        self.request['year'] = year

    def get_year(self):
        return (self.request['year'])

    def set_month(self, month):
        self.request['month'] = month

    def get_month(self):
        return (self.request['month'])

    def set_begin(self, bday, bhr):
        self.request['begin'] = bday + bhr

    def get_begin(self):
        return (self.request['begin'])

    def set_end(self, eday, ehr):
        self.request['end'] = eday + ehr

    def get_end(self):
        return (self.request['end'])

    def set_test(self, test):
        self.request['test'] = test

    def get_test(self):
        return (self.request['test'])

    def set_mtp(self, mtp):
        self.request['mtp'] = mtp

    def get_mtp(self):
        return (self.request['mtp'])

    def set_mtp_dir(self, mtpdir):
        self.request['mtpdir'] = mtpdir

    def get_mtp_dir(self):
        return (self.request['mtpdir'])

    def set_catalog(self, catalog):
        self.request['catalog'] = catalog

    def get_catalog(self):
        return (self.request['catalog'])

    def set_now(self, now):
        self.request['now'] = now

    def get_now(self):
        return (self.request['now'])

    def set_stnm(self, stnm):
        self.request['stnm'] = stnm
        # This code tests if the station requested is valid by comparing it to
        # the stations in the master list received from UWyo. If that list gets
        # out of date with the UWyo website, comment out the next 5 lines to
        # turn off validation.
        if stnm != "" and not self.stationList.get_by_stnm(stnm) and \
           not self.stationList.get_by_id(stnm):
            return (False)
        else:
            return (True)

    def get_stnm(self):
        return (self.request['stnm'])

    def set_rsl(self, rsl):
        self.request['rsl'] = rsl

    def get_rsl(self):
        return (self.request['rsl'])

    def set_freq(self, freq):
        self.request['freq'] = freq

    def get_freq(self):
        return (self.request['freq'])

    def set_config(self, config):
        self.request['config'] = config

    def get_config(self):
        return (self.request['config'])

    def set_stnlist_file(self, station_list_file):
        self.request['station_list_file'] = station_list_file

    def get_stnlist_file(self):
        return (self.request['station_list_file'])

    def set_prov(self, args):  # Set provenance of RAOB to retrieve
        """
        Set request from all the metadata specificed on the command line.
        Calls individual set_ methods for each argument.
        Doesn't set stnm because that is set in raobget.get to either a
        single station, or looping over stns from rsl file.
        """
        self.set_region(args.region)
        self.set_type(args.raobtype)
        self.set_stnm(args.stnm)
        self.set_rsl(args.rsl)
        self.set_year(args.year)
        self.set_month(args.month)
        self.set_begin(args.bday, args.bhr)
        self.set_end(args.eday, args.ehr)
        self.set_freq(args.freq)
        self.set_test(args.test)
        self.set_mtp(args.mtp)
        self.set_mtp_dir(args.mtpdir)
        self.set_catalog(args.catalog)
        if args.catalog is True and args.config == '':
            print("ERROR: --config option required if --catalog is set")
            exit(1)
        self.set_config(args.config)
        self.set_stnlist_file(args.station_list_file)
        self.set_now(args.now)

        return (True)

    def get_request(self):
        """ Return request metadata dictionary """

        return (self.request)

    def get_dict(self):
        """ Return request dictionary contents """
        return (dict(self.request))

    def set_time_now(self):
        """ Set request time to most recent 12 hour (UTC) RAOB unless freq is
        set higher. """
        if self.request['freq'] == "":
            print("ERROR: freq must be set before can set times to now")
            return (False)
        time = datetime.utcnow()
        self.set_year(str(time.year))
        self.set_month('{:02d}'.format(time.month))
        for hr in range(0, 24, int(self.request['freq'])):
            if time.hour > hr and time.hour <= hr + int(self.request['freq']):
                hour = hr

        self.set_begin('{:02d}'.format(time.day), '{:02d}'.format(hour))
        self.set_end('{:02d}'.format(time.day), '{:02d}'.format(hour))