예제 #1
0
    def skewApp(self, filename=None):
        """
        Create the SPC style SkewT window, complete with insets
        and magical funtimes.
        :return:
        """

        failure = False

        exc = ""

        ## if the profile is an archived file, load the file from
        ## the hard disk
        if filename is not None:
            model = "Archive"
            prof_collection, stn_id = self.loadArchive(filename)
            disp_name = stn_id

            run = prof_collection.getCurrentDate()
        else:
        ## otherwise, download with the data thread
            prof_idx = self.prof_idx
            disp_name = self.disp_name
            run = self.run
            model = self.model

            if self.data_sources[model].getForecastHours() == [ 0 ]:
                prof_idx = [ 0 ]

            ret = loadData(self.data_sources[model], self.loc, run, prof_idx)

            if isinstance(ret[0], Exception):
                exc = ret[0]
                failure = True
            else:
                prof_collection = ret[0]

        if not failure:
            prof_collection.setMeta('model', model)
            prof_collection.setMeta('run', run)
            prof_collection.setMeta('loc', disp_name)

            if not prof_collection.getMeta('observed'):
                # If it's not an observed profile, then generate profile objects in background.
                prof_collection.setAsync(Picker.async)

            if self.skew is None:
                # If the SPCWindow isn't shown, set it up.
                self.skew = SPCWindow(parent=self.parent(), cfg=self.config)
                self.skew.closed.connect(self.skewAppClosed)
                self.skew.show()

            self.focusSkewApp()
            self.skew.addProfileCollection(prof_collection)
        else:
            raise exc
예제 #2
0
    def skewApp(self, filename=None, ntry=0):
        logging.debug("Calling full_gui.skewApp")
        """
        Create the SPC style SkewT window, complete with insets
        and magical funtimes.
        :return:
        """

        logging.debug("Calling full_gui.skewApp")

        failure = False

        exc = ""

        # if the profile is an archived file, load the file from
        # the hard disk
        if filename is not None:
            logging.info("Trying to load file from local disk...")

            model = "Archive"
            prof_collection, stn_id = self.loadArchive(filename)
            logging.info(
                "Successfully loaded the profile collection for this file...")
            disp_name = stn_id
            observed = True
            fhours = None

            # Determine if the dataset passed was from a model or is observed
            if len(prof_collection._dates) > 1:
                prof_idx = self.prof_idx
                fhours = [
                    "F%03d" % fh for idx, fh in enumerate(self.data_sources[
                        self.model].getForecastHours()) if idx in prof_idx
                ]
                observed = False
            else:
                fhours = None
                observed = True

            run = prof_collection.getCurrentDate()

        else:
            # otherwise, download with the data thread
            logging.info("Loading a real-time data stream...")
            prof_idx = self.prof_idx
            disp_name = self.disp_name
            run = self.run
            model = self.model
            observed = self.data_sources[model].isObserved()

            if self.data_sources[model].getForecastHours() == [0]:
                prof_idx = [0]

            logging.info("Program is going to load the data...")
            ret = loadData(self.data_sources[model],
                           self.loc,
                           run,
                           prof_idx,
                           ntry=ntry)

            # failure variable makes sure the data actually exists online.
            if isinstance(ret[0], Exception):
                exc = ret[0]
                failure = True
                logging.info(
                    "There was a problem with loadData() in obtaining the data from the Internet."
                )
            else:
                logging.info("Data was found and successfully decoded!")
                prof_collection = ret[0]

            fhours = [
                "F%03d" % fh for idx, fh in enumerate(self.data_sources[
                    self.model].getForecastHours()) if idx in prof_idx
            ]

        # If the observed or model profile (not Archive) successfully loaded)
        if not failure:
            prof_collection.setMeta('model', model)
            prof_collection.setMeta('run', run)
            prof_collection.setMeta('loc', disp_name)
            prof_collection.setMeta('fhour', fhours)
            prof_collection.setMeta('observed', observed)

            if not prof_collection.getMeta('observed'):
                # If it's not an observed profile, then generate profile objects in background.
                prof_collection.setAsync(Picker.async_obj)

            if self.skew is None:
                logging.debug("Constructing SPCWindow")
                # If the SPCWindow isn't shown, set it up.
                self.skew = SPCWindow(parent=self.parent(), cfg=self.config)
                self.parent().config_changed.connect(
                    self.skew.centralWidget().updateConfig)
                self.skew.closed.connect(self.skewAppClosed)
                self.skew.show()

            logging.debug("Focusing on the SkewApp")
            self.focusSkewApp()
            logging.debug("Adding the profile collection to SPCWindow")
            self.skew.addProfileCollection(prof_collection,
                                           check_integrity=self.strictQC)
        else:
            print("There was an exception:", exc)

            raise exc
예제 #3
0
    def skewApp(self, filename=None):
        """
        Create the SPC style SkewT window, complete with insets
        and magical funtimes.
        :return:
        """

        profs = []
        dates = []
        failure = False

        exc = ""

        ## if the profile is an archived file, load the file from
        ## the hard disk
        if filename is not None:
            model = "Observed"
            prof_collection, stn_id = self.loadArchive(filename)
            disp_name = stn_id
            prof_idx = range(len(dates))

            run = prof_collection.getCurrentDate()
            fhours = None
            observed = True
        else:
            ## otherwise, download with the data thread
            prof_idx = self.prof_idx
            disp_name = self.disp_name
            run = self.run
            model = self.model
            observed = self.data_sources[model].isObserved()

            if self.data_sources[model].getForecastHours() == [0]:
                prof_idx = [0]

            ret = loadData(self.data_sources[model], self.loc, run, prof_idx)

            if isinstance(ret[0], Exception):
                exc = ret[0]
                failure = True
            else:
                prof_collection = ret[0]

            fhours = [
                "F%03d" % fh for idx, fh in enumerate(self.data_sources[
                    self.model].getForecastHours()) if idx in prof_idx
            ]

        if not failure:
            prof_collection.setMeta('model', model)
            prof_collection.setMeta('run', run)
            prof_collection.setMeta('loc', disp_name)
            prof_collection.setMeta('fhour', fhours)
            prof_collection.setMeta('observed', observed)

            if not observed:
                # If it's not an observed profile, then generate profile objects in background.
                prof_collection.setAsync(Picker. async)

            if self.skew is None:
                # If the SPCWindow isn't shown, set it up.
                self.skew = SPCWindow(parent=self.parent(), cfg=self.config)
                self.skew.closed.connect(self.skewAppClosed)
                self.skew.show()

            self.focusSkewApp()
            self.skew.addProfileCollection(prof_collection)

            # We're done here, write the pid so we can be killed off:
            pidFile = open(pidFilename, "w")
            pidFile.write(str(os.getpid()))
            pidFile.close
예제 #4
0
  def gen_sounding(self, *args):
    '''
    Method for generating the SPC-like sounding using the
    SPCWindow class of SHARPpy.
    '''
    self.log.info( 'Generating Skew-T diagram' );                               # Log some information
    sndDataPNG      = settings.skewT_fmt.format( self.date_str );               # Set the name for the skewT file using the settings.skew_T_fmt string
    self.sndDataPNG = os.path.join( self.dst_dirFull, sndDataPNG );             # Set the sndDataPNG attribute using the dst_dirFull attribute and sndDataFile variable

    save_msg = "Check that the image looks okay.\n " + \
      "If ok, click save, else click cancel";                                   # Confirmation message for the save dialog for Skew-T; will update if cannot save Skew-T due to issue in SHARPpy
    sharppy_bug = False;                                                        # Flag for if sharppy bug encountered
    try:                                                                        # Try to...
      decoder = SPCDecoder( self.sndDataFile );                                 # Decode the sounding file using the SPCDecoder
      profile = decoder.getProfiles();                                          # Get the profiles from the file
      stn_id  = decoder.getStnId();                                             # Get the station id from the file
    except:                                                                     # On exception
      criticalMessage( 
        "There was an error loading the sounding data\n\n"
      ).exec_();                                                                # Initialize and display critical error dialog
      return;                                                                   # Return from method
    model     = "Archive";                                                      # Set model to 'Archive'; not sure why but was in the SHARPpy full_gui.py 
    disp_name = stn_id;                                                         # Set the display name to the station ID from the sounding data file
    run       = profile.getCurrentDate();                                       # Set the run to the current date from the sounding data
    profile.setMeta('model', model);                                            # Set the model in the sounding data
    profile.setMeta('loc',   disp_name);                                        # Set the display name in the sounding data
    profile.setMeta('run',   run);                                              # Set the run in the sounding data
    
    if not profile.getMeta('observed'):                                         # If it's not an observed profile
      profile.setAsync( AsyncThreads(2, debug) );                               # Generate profile objects in background. Not sure why works but in SHARPpy full_gui.py
    
    self.log.debug('Generating SHARPpy window')
    if self.skew is None:                                                       # If there is no skew window setup; there should never be...
      self.skew = SPCWindow(cfg=self.config);                                   # Initialize a new SPCWindow object
      self.skew.closed.connect(self.__skewAppClosed);                           # Connect the closed method to the __skewAppClosed private method
      self.skew.addProfileCollection(profile);                                  # Add the profile data to the SPCWindow object
      try:
        self.skew.show();                                                         # Show the window
      except:
        sharppy_bug = True;
        self.log.warning("SHARPpy didn't like that sounding very much!")
        save_msg = "Congradulations!\n\n"   + \
          "You just found a bug in SHARPpy.\n" + \
          "There is nothing we can about this. No Skew-T can be created.\n" + \
          "Just click 'Save' and continue with the uploading";
    dial = saveMessage( save_msg );                                             # Set up save message pop-up
    dial.exec_();                                                               # Display the save message pop-up
    if dial.check():                                                            # If clicked save
      if not sharppy_bug:                                                       # If the SHARPpy bug did NOT occur
        self.ftpInfo['ucar']['files'].append( self.sndDataPNG );                # Append the SHARPpy image file name to the ftpInfo['ucar']['files'] list
        self.log.info('Saving the Skew-T to: {}'.format( self.sndDataPNG ) );   # Log some information
        pixmap = QPixmap.grabWidget( self.skew );                               # Grab the image from the skew T window
        pixmap.save( self.sndDataPNG, 'PNG', 100);                              # Save the image
        self.config.set('paths', 'save_img', os.path.dirname(self.sndDataPNG)); # Add image path to the config object

      self.log.debug( 'Files to upload to UCAR: {}'.format( 
        ', '.join(self.ftpInfo['ucar']['files']) ) )
      self.genSucces.show();                                                    # Show green light next to the 'Generate Sounding' button to indicate that step is complete
      self.uploadButton.setEnabled( True );                                     # Enable the upload button
    else:                                                                       # Else
      self.log.critical('Skew-T save aborted! Not allowed to upload!');         # Log an error
    try:
      self.skew.close();                                                        # Close the skew T window
    except:
      pass;