コード例 #1
0
 def test_get_fields3(self):
     # Only Obs is common between the two files
     inputs = [
         verif.input.Text("verif/tests/files/%s" % file)
         for file in ["file1.txt", "file1_no_fcst.txt"]
     ]
     data = verif.data.Data(inputs)
     self.assertFalse(verif.field.Fcst() in data.get_fields())
     self.assertTrue(verif.field.Obs() in data.get_fields())
コード例 #2
0
ファイル: driver.py プロジェクト: tommz9/verif
def run(argv):
   ############
   # Defaults #
   ############
   ifiles = list()
   ofile = None
   metric = None
   locations = None
   locations_x = None
   lat_range = None
   lon_range = None
   elev_range = None
   obs_range = None
   thresholds = None
   quantiles = None
   clim_file = None
   clim_type = "subtract"
   leg = None
   ylabel = None
   xlabel = None
   clabel = None
   title = None
   dates = None
   tods = None
   times = None
   leadtimes = None
   axis = None
   aspect = None
   figsize = None
   dpi = 100
   no_margin = False
   bin_type = None
   simple = None
   marker_size = None
   line_width = None
   line_colors = None
   line_styles = None
   tick_font_size = None
   lab_font_size = None
   leg_font_size = None
   title_font_size = None
   leg_loc = None
   plot_type = "plot"
   grid = True
   xrot = None
   yrot = None
   bottom_padding = None
   top_padding = None
   right_padding = None
   left_padding = None
   Pad = None
   show_perfect = None
   aggregator_name = None
   do_hist = False
   do_sort = False
   do_acc = False
   proj = None
   xlim = None
   ylim = None
   clim = None
   annotate = False
   xticks = None
   xticklabels = None
   yticks = None
   yticklabels = None
   version = None
   list_thresholds = False
   list_quantiles = False
   list_locations = False
   list_times = False
   list_dates = False
   map_type = None
   xlog = False
   ylog = False
   cmap = None
   obs_field = verif.field.Obs()
   fcst_field = verif.field.Fcst()

   # Parse config files
   i = 1
   extra = []
   while(i < len(argv)):
      arg = argv[i]
      if arg == "--config":
         if i == len(argv) - 1:
            verif.util.error("Missing filename after --config")
         i = i + 1
         filename = argv[i]
         try:
            fid = open(filename, 'r')
            for line in fid:
               extra += line.split()
         except:
            if not os.path.isfile(filename):
               verif.util.error("Could not read %s" % filename)
      i = i + 1

   argv = argv + extra

   # Read command line arguments
   i = 1
   while(i < len(argv)):
      arg = argv[i]
      if arg[0] == '-':
         # Process option
         if arg == "-nomargin":
            no_margin = True
         elif arg == "--version":
            version = True
         elif arg == "--list-thresholds":
            list_thresholds = True
         elif arg == "--list-quantiles":
            list_quantiles = True
         elif arg == "--list-locations":
            list_locations = True
         elif arg == "--list-times":
            list_times = True
         elif arg == "--list-dates":
            list_dates = True
         elif arg == "-sp":
            show_perfect = True
         elif arg == "-hist":
            do_hist = True
         elif arg == "-acc":
            do_acc = True
         elif arg == "-sort":
            do_sort = True
         elif arg == "-simple":
            simple = True
         elif arg == "-xlog":
            xlog = True
         elif arg == "-ylog":
            ylog = True
         elif arg == "-a":
            annotate = True
         elif arg == "-nogrid":
            grid = False
         else:
            if len(argv) <= i + 1:
               verif.util.error("Missing value after %s" % argv[i])
            arg_next = argv[i + 1]
            if arg == "-f":
               ofile = arg_next
            elif arg == "-l":
               locations = verif.util.parse_numbers(arg_next)
            elif arg == "-lx":
               locations_x = verif.util.parse_numbers(arg_next)
            elif arg == "-latrange":
               lat_range = verif.util.parse_numbers(arg_next)
            elif arg == "-lonrange":
               lon_range = verif.util.parse_numbers(arg_next)
            elif arg == "-elevrange":
               elev_range = verif.util.parse_numbers(arg_next)
            elif arg == "-obsrange":
               obs_range = verif.util.parse_numbers(arg_next)
            elif arg == "-x":
               axisname = arg_next
               axis = verif.axis.get(axisname)
            elif arg == "-o":
               leadtimes = verif.util.parse_numbers(arg_next)
            elif arg == "-leg":
               leg = str(arg_next)
            elif arg == "-ylabel":
               ylabel = str(arg_next)
            elif arg == "-xlabel":
               xlabel = str(arg_next)
            elif arg == "-clabel":
               clabel = str(arg_next)
            elif arg == "-title":
               title = str(arg_next)
            elif arg == "-b":
               bin_type = arg_next
            elif arg == "-type":
               plot_type = arg_next
            elif arg == "-fs":
               figsize = arg_next
            elif arg == "-dpi":
               dpi = int(arg_next)
            elif arg == "-d":
               dates = verif.util.parse_numbers(arg_next, True)
            elif arg == "-tod":
               tods = [int(tod) for tod in verif.util.parse_numbers(arg_next)]
            elif arg == "-t":
               times = verif.util.parse_numbers(arg_next)
            elif arg == "-c":
               clim_file = verif.input.get_input(arg_next)
               clim_type = "subtract"
            elif arg == "-C":
               clim_file = verif.input.get_input(arg_next)
               clim_type = "divide"
            elif arg == "-xlim":
               xlim = verif.util.parse_numbers(arg_next)
            elif arg == "-ylim":
               ylim = verif.util.parse_numbers(arg_next)
            elif arg == "-clim":
               clim = verif.util.parse_numbers(arg_next)
            elif arg == "-xticks":
               xticks = verif.util.parse_numbers(arg_next)
            elif arg == "-xticklabels":
               xticklabels = (arg_next).split(',')
            elif arg == "-yticks":
               yticks = verif.util.parse_numbers(arg_next)
            elif arg == "-yticklabels":
               yticklabels = (arg_next).split(',')
            elif arg == "-agg":
               aggregator_name = arg_next
            elif arg == "-aspect":
               aspect = float(arg_next)
            elif arg == "-r":
               thresholds = np.array(verif.util.parse_numbers(arg_next))
            elif arg == "-q":
               quantiles = np.array(verif.util.parse_numbers(arg_next))
               if np.min(quantiles) < 0 or np.max(quantiles) > 1:
                  verif.util.error("Quantiles must be between 0 and 1 inclusive")
            elif arg == "-ms":
               marker_size = float(arg_next)
            elif arg == "-lw":
               line_width = float(arg_next)
            elif arg == "-lc":
               line_colors = arg_next
            elif arg == "-ls":
               line_styles = arg_next
            elif arg == "-tickfs":
               tick_font_size = float(arg_next)
            elif arg == "-labfs":
               lab_font_size = float(arg_next)
            elif arg == "-legfs":
               leg_font_size = float(arg_next)
            elif arg == "-legloc":
               leg_loc = arg_next.replace('_', ' ')
            elif arg == "-xrot":
               xrot = float(arg_next)
            elif arg == "-yrot":
               yrot = float(arg_next)
            elif arg == "-bottom":
               bottom_padding = float(arg_next)
            elif arg == "-top":
               top_padding = float(arg_next)
            elif arg == "-right":
               right_padding = float(arg_next)
            elif arg == "-left":
               left_padding = float(arg_next)
            elif arg == "-pad":
               Pad = arg_next
            elif arg == "-titlefs":
               title_font_size = float(arg_next)
            elif arg == "-cmap":
               cmap = arg_next
            elif arg == "-maptype":
               map_type = arg_next
            elif arg == "-proj":
               proj = arg_next
            elif arg == "-obs":
               obs_field = verif.field.get(arg_next)
            elif arg == "-fcst":
               fcst_field = verif.field.get(arg_next)
            elif arg == "-m":
               metric = arg_next
            elif arg == "--config":
               pass
            else:
               verif.util.error("Flag '" + argv[i] + "' not recognized")
            i = i + 1
      else:
         ifiles.append(argv[i])
      i = i + 1

   if version:
      print("Version: " + verif.version.__version__)
      return

   # Deal with legend entries
   if leg is not None:
      leg = leg.split(',')
      for i in range(0, len(leg)):
         leg[i] = leg[i].replace('_', ' ')

   if lat_range is not None and len(lat_range) != 2:
      verif.util.error("-latrange <values> must have exactly 2 values")

   if lon_range is not None and len(lon_range) != 2:
      verif.util.error("-lonrange <values> must have exactly 2 values")

   if elev_range is not None and len(elev_range) != 2:
      verif.util.error("-elevrange <values> must have exactly 2 values")

   if obs_range is not None and len(obs_range) != 2:
      verif.util.error("-obsrange <values> must have exactly 2 values")

   if len(ifiles) > 0:
      inputs = [verif.input.get_input(filename) for filename in ifiles]
      data = verif.data.Data(inputs, clim=clim_file, clim_type=clim_type,
            times=times, dates=dates, tods=tods, leadtimes=leadtimes, locations=locations,
            locations_x=locations_x,
            lat_range=lat_range, lon_range=lon_range, elev_range=elev_range,
            obs_range=obs_range, legend=leg, obs_field=obs_field, fcst_field=fcst_field)
   else:
      data = None

   if list_thresholds or list_quantiles or list_locations or list_times or list_dates:
      if len(ifiles) == 0:
         verif.util.error("Files are required in order to list thresholds, quantiles, or times")
      if list_thresholds:
         print("Thresholds:", end=' ')
         for threshold in data.thresholds:
            print("%g" % threshold, end=' ')
         print("")
      if list_quantiles:
         print("Quantiles:", end=' ')
         for quantile in data.quantiles:
            print("%g" % quantile, end=' ')
         print("")
      if list_locations:
         print("    id     lat     lon    elev")
         for location in data.locations:
            print("%6d %7.2f %7.2f %7.1f" % (location.id, location.lat,
                  location.lon, location.elev))
         print("")
      if list_times:
         for time in data.times:
            print("%d" % time)
         print("")
      if list_dates:
         for time in data.times:
            date = verif.util.unixtime_to_date(time)
            diff = time % 86400
            hour = diff / 3600
            minute = (diff % 3600)/60
            second = diff % 60
            print("%d %02d:%02d:%02d" % (date, hour, minute, second))
         print("")
      return
   elif len(ifiles) == 0 and metric is not None:
      m = verif.metric.get(metric)
      if m is not None:
         print(m.help())
      else:
         m = verif.output.get(metric)
         if m is not None:
            print(m.help())
      return
   elif len(argv) == 1 or len(ifiles) == 0 or metric is None:
      print(show_description(data))
      return

   if figsize is not None:
      figsize = figsize.split(',')
      if len(figsize) != 2:
         print("-fs figsize must be in the form: width,height")
         sys.exit(1)

   m = None

   # Handle special plots
   if metric == "pithist":
      pl = verif.output.PitHist()
   elif metric == "obsfcst":
      pl = verif.output.ObsFcst()
   elif metric == "timeseries":
      pl = verif.output.TimeSeries()
   elif metric == "meteo":
      pl = verif.output.Meteo()
   elif metric == "qq":
      pl = verif.output.QQ()
   elif metric == "autocorr":
      pl = verif.output.Auto("corr")
   elif metric == "autocov":
      pl = verif.output.Auto("cov")
   elif metric == "fss":
      pl = verif.output.Fss()
   elif metric == "cond":
      pl = verif.output.Cond()
   elif metric == "against":
      pl = verif.output.Against()
   elif metric == "scatter":
      pl = verif.output.Scatter()
   elif metric == "change":
      pl = verif.output.Change()
   elif metric == "spreadskill":
      pl = verif.output.SpreadSkill()
   elif metric == "taylor":
      pl = verif.output.Taylor()
   elif metric == "error":
      pl = verif.output.Error()
   elif metric == "freq":
      pl = verif.output.Freq()
   elif metric == "roc":
      pl = verif.output.Roc()
   elif metric == "droc":
      pl = verif.output.DRoc()
   elif metric == "droc0":
      pl = verif.output.DRoc0()
   elif metric == "drocnorm":
      pl = verif.output.DRocNorm()
   elif metric == "reliability":
      pl = verif.output.Reliability()
   elif metric == "discrimination":
      pl = verif.output.Discrimination()
   elif metric == "performance":
      pl = verif.output.Performance()
   elif metric == "invreliability":
      pl = verif.output.InvReliability()
   elif metric == "igncontrib":
      pl = verif.output.IgnContrib()
   elif metric == "economicvalue":
      pl = verif.output.EconomicValue()
   elif metric == "marginal":
      pl = verif.output.Marginal()
   else:
      # Standard plots
      # Attempt at automating
      m = verif.metric.get(metric)
      if m is None:
         m = verif.metric.FromField(verif.field.Other(metric))

      if aggregator_name is not None:
         if not m.supports_aggregator:
            verif.util.warning("-m %s does not support -agg" % metric)
         m.aggregator = verif.aggregator.get(aggregator_name)

      # Output type
      if plot_type in ["plot", "text", "csv", "map", "maprank", "rank", "impact", "mapimpact"]:
         if do_sort:
            field = verif.field.get(metric)
            pl = verif.output.Sort(field)
         elif do_hist:
            field = verif.field.get(metric)
            pl = verif.output.Hist(field)
         else:
            pl = verif.output.Standard(m)
      else:
         verif.util.error("Type not understood")

   # Rest dimension of '-x' is not allowed
   if axis is not None and not pl.supports_x:
      verif.util.warning("'-m %s'" % metric + " does not support '-x'. Ignoring it.")
      axis = None

   # Reset dimension if 'threshold' is not allowed
   if axis == verif.axis.Threshold() and ((not pl.supports_threshold) or (m is not None and not m.supports_threshold)):
      verif.util.warning("'-m %s'" % metric + " does not support '-x threshold'. Ignoring it.")
      thresholds = None
      axis = None
   # Reset dimension if 'obs' or 'fcst' is not allowed
   if axis in [verif.axis.Obs(), verif.axis.Fcst()] and ((not pl.supports_field) or (m is not None and not m.supports_field)):
      verif.util.warning("'-m %s'" % metric + " does not support '-x %s'. Ignoring it." % axis.name().lower())
      thresholds = None
      axis = None

   # Create thresholds if needed
   if thresholds is None:
      type = None
      if plot_type == "impact":
         type = "deterministic"
      elif pl.require_threshold_type == "deterministic":
         type = "deterministic"
      elif pl.require_threshold_type == "threshold":
         type = "threshold"
      elif pl.require_threshold_type == "quantile":
         type = "quantile"
      elif m is not None:
         if m.require_threshold_type == "deterministic":
            type = "deterministic"
         elif m.require_threshold_type == "threshold":
            type = "threshold"
         elif m.require_threshold_type == "quantile":
            type = "quantile"
         elif m.require_threshold_type is not None:
            verif.util.error("Internal error for metric %s: Cannot understand required threshold type '%s'" % (m.name(), m.require_threshold_type))
      elif pl.require_threshold_type is not None:
         verif.util.error("Internal error for output %s: Cannot understand required threshold type '%s'" % (pl.name(), pl.require_threshold_type))

      if type is not None:
         if type == "deterministic":
            smin = np.inf
            smax = -np.inf
            if verif.field.Obs() in data.get_fields():
               obs = data.get_scores(verif.field.Obs(), 0)
               smin = min(np.nanmin(obs), smin)
               smax = max(np.nanmax(obs), smax)
            if verif.field.Fcst() in data.get_fields():
               fcst = data.get_scores(verif.field.Fcst(), 0)
               smin = min(np.nanmin(fcst), smin)
               smax = max(np.nanmax(fcst), smax)
            num_default_thresholds = 20
            thresholds = np.linspace(smin, smax, num_default_thresholds)
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         elif type == "threshold":
            thresholds = data.thresholds
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         elif type == "quantile":
            thresholds = data.quantiles
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         if len(thresholds) == 0:
            verif.util.error("No thresholds available")

   # Set plot parameters
   if simple is not None:
      pl.simple = simple
   if marker_size is not None:
      pl.ms = marker_size
   if line_width is not None:
      pl.lw = line_width
   if line_colors is not None:
      pl.line_colors = line_colors
   if line_styles is not None:
      pl.line_styles = line_styles
   if lab_font_size is not None:
      pl.labfs = lab_font_size
   if leg_font_size is not None:
      pl.legfs = leg_font_size
   if title_font_size is not None:
      pl.title_font_size = title_font_size
   if leg_loc is not None:
      pl.leg_loc = leg_loc
   if tick_font_size is not None:
      pl.tick_font_size = tick_font_size
   if xrot is not None:
      pl.xrot = xrot
   if yrot is not None:
      pl.yrot = yrot
   if bottom_padding is not None:
      pl.bottom = bottom_padding
   if top_padding is not None:
      pl.top = top_padding
   if right_padding is not None:
      pl.right = right_padding
   if left_padding is not None:
      pl.left = left_padding
   if Pad is not None:
      pl.pad = None
   if bin_type is not None:
      pl.bin_type = bin_type
   if show_perfect is not None:
      pl.show_perfect = show_perfect
   if proj is not None:
      pl.proj = proj
   if xlim is not None:
      pl.xlim = xlim
   if ylim is not None:
      pl.ylim = ylim
   if clim is not None:
      pl.clim = clim
   if xticks is not None:
      pl.xticks = xticks
   if xticklabels is not None:
      pl.xticklabels = xticklabels
   if yticks is not None:
      pl.yticks = yticks
   if yticklabels is not None:
      pl.yticklabels = yticklabels
   if xlog is not None:
      pl.xlog = xlog
   if ylog is not None:
      pl.ylog = ylog
   if annotate is not None:
      pl.annotate = annotate
   pl.grid = grid
   if cmap is not None:
      pl.cmap = cmap
   if map_type is not None:
      pl.map_type = map_type
   pl.filename = ofile
   if thresholds is not None:
      pl.thresholds = thresholds
   if quantiles is not None:
      pl.quantiles = quantiles
   pl.figsize = figsize
   pl.dpi = dpi
   if axis is not None:
      pl.axis = axis
   if aggregator_name is not None:
      pl.aggregator = verif.aggregator.get(aggregator_name)
   if aspect is not None:
      pl.aspect = aspect
   pl.show_margin = not no_margin
   if ylabel is not None:
      pl.ylabel = ylabel
   if xlabel is not None:
      pl.xlabel = xlabel
   if clabel is not None:
      pl.clabel = clabel
   if title is not None:
      pl.title = title
   if do_acc:
      if pl.supports_acc:
         pl.show_acc = do_acc
      else:
         verif.util.warning("%s does not support -acc" % metric)

   if plot_type == "text":
      pl.text(data)
   elif plot_type == "csv":
      pl.csv(data)
   elif plot_type == "map":
      pl.map(data)
   elif plot_type == "maprank":
      pl.show_rank = True
      pl.map(data)
   elif plot_type == "rank":
      pl.show_rank = True
      pl.plot_rank(data)
   elif plot_type == "impact":
      pl.plot_impact(data)
   elif plot_type == "mapimpact":
      pl.plot_mapimpact(data)
   else:
      pl.plot(data)
コード例 #3
0
 def test_get_fields2(self):
     inputs = [verif.input.Text("verif/tests/files/file1_no_fcst.txt")]
     data = verif.data.Data(inputs)
     self.assertFalse(verif.field.Fcst() in data.get_fields())
     self.assertTrue(verif.field.Obs() in data.get_fields())
コード例 #4
0
ファイル: driver.py プロジェクト: moghimis/verif
def run(argv):
   ############
   # Defaults #
   ############
   ifiles = list()
   ofile = None
   metric = None
   locations = None
   locations_x = None
   lat_range = None
   lon_range = None
   elev_range = None
   thresholds = None
   quantiles = None
   clim_file = None
   clim_type = "subtract"
   leg = None
   ylabel = None
   xlabel = None
   title = None
   times = None
   leadtimes = None
   axis = None
   aspect = None
   figsize = None
   dpi = 100
   no_margin = False
   bin_type = None
   simple = None
   marker_size = None
   line_width = None
   line_colors = None
   line_styles = None
   tick_font_size = None
   lab_font_size = None
   leg_font_size = None
   title_font_size = None
   leg_loc = None
   plot_type = "plot"
   grid = True
   xrot = None
   yrot = None
   bottom_padding = None
   top_padding = None
   right_padding = None
   left_padding = None
   Pad = None
   show_perfect = None
   aggregator_name = None
   do_hist = False
   do_sort = False
   do_acc = False
   xlim = None
   ylim = None
   clim = None
   xticks = None
   xticklabels = None
   yticks = None
   yticklabels = None
   version = None
   list_thresholds = False
   list_quantiles = False
   list_locations = False
   list_times = False
   map_type = None
   xlog = False
   ylog = False
   cmap = None
   obs_field = verif.field.Obs()
   fcst_field = verif.field.Fcst()

   # Read command line arguments
   i = 1
   while(i < len(argv)):
      arg = argv[i]
      if(arg[0] == '-'):
         # Process option
         if(arg == "-nomargin"):
            no_margin = True
         elif(arg == "--version"):
            version = True
         elif(arg == "--list-thresholds"):
            list_thresholds = True
         elif(arg == "--list-quantiles"):
            list_quantiles = True
         elif(arg == "--list-locations"):
            list_locations = True
         elif(arg == "--list-times"):
            list_times = True
         elif(arg == "-sp"):
            show_perfect = True
         elif(arg == "-hist"):
            do_hist = True
         elif(arg == "-acc"):
            do_acc = True
         elif(arg == "-sort"):
            do_sort = True
         elif(arg == "-simple"):
            simple = True
         elif(arg == "-xlog"):
            xlog = True
         elif(arg == "-ylog"):
            ylog = True
         elif(arg == "-nogrid"):
            grid = False
         else:
            if len(argv) <= i + 1:
               verif.util.error("Missing value after %s" % argv[i])
            arg_next = argv[i + 1]
            if(arg == "-f"):
               ofile = arg_next
            elif(arg == "-l"):
               locations = verif.util.parse_numbers(arg_next)
            elif(arg == "-lx"):
               locations_x = verif.util.parse_numbers(arg_next)
            elif(arg == "-latrange"):
               lat_range = verif.util.parse_numbers(arg_next)
            elif(arg == "-lonrange"):
               lon_range = verif.util.parse_numbers(arg_next)
            elif(arg == "-elevrange"):
               elev_range = verif.util.parse_numbers(arg_next)
            elif(arg == "-x"):
               axisname = arg_next
               axis = verif.axis.get(axisname)
            elif(arg == "-o"):
               leadtimes = verif.util.parse_numbers(arg_next)
            elif(arg == "-leg"):
               leg = unicode(arg_next, 'utf8')
            elif(arg == "-ylabel"):
               ylabel = unicode(arg_next, 'utf8')
            elif(arg == "-xlabel"):
               xlabel = unicode(arg_next, 'utf8')
            elif(arg == "-title"):
               title = unicode(arg_next, 'utf8')
            elif(arg == "-b"):
               bin_type = arg_next
            elif(arg == "-type"):
               plot_type = arg_next
            elif(arg == "-fs"):
               figsize = arg_next
            elif(arg == "-dpi"):
               dpi = int(arg_next)
            elif(arg == "-d"):
               dates = verif.util.parse_numbers(arg_next, True)
               times = [verif.util.date_to_unixtime(date) for date in dates]
            elif(arg == "-t"):
               times = verif.util.parse_numbers(arg_next, True)
            elif(arg == "-c"):
               clim_file = verif.input.get_input(arg_next)
               clim_type = "subtract"
            elif(arg == "-C"):
               clim_file = verif.input.get_input(arg_next)
               clim_type = "divide"
            elif(arg == "-xlim"):
               xlim = verif.util.parse_numbers(arg_next)
            elif(arg == "-ylim"):
               ylim = verif.util.parse_numbers(arg_next)
            elif(arg == "-clim"):
               clim = verif.util.parse_numbers(arg_next)
            elif(arg == "-xticks"):
               xticks = verif.util.parse_numbers(arg_next)
            elif(arg == "-xticklabels"):
               xticklabels = (arg_next).split(',')
            elif(arg == "-yticks"):
               yticks = verif.util.parse_numbers(arg_next)
            elif(arg == "-yticklabels"):
               yticklabels = (arg_next).split(',')
            elif(arg == "-agg"):
               aggregator_name = arg_next
            elif(arg == "-aspect"):
               aspect = float(arg_next)
            elif(arg == "-r"):
               thresholds = np.array(verif.util.parse_numbers(arg_next))
            elif(arg == "-q"):
               quantiles = np.array(verif.util.parse_numbers(arg_next))
               if np.min(quantiles) < 0 or np.max(quantiles) > 1:
                  verif.util.error("Quantiles must be between 0 and 1 inclusive")
            elif(arg == "-ms"):
               marker_size = float(arg_next)
            elif(arg == "-lw"):
               line_width = float(arg_next)
            elif(arg == "-lc"):
               line_colors = arg_next
            elif(arg == "-ls"):
               line_styles = arg_next
            elif(arg == "-tickfs"):
               tick_font_size = float(arg_next)
            elif(arg == "-labfs"):
               lab_font_size = float(arg_next)
            elif(arg == "-legfs"):
               leg_font_size = float(arg_next)
            elif(arg == "-legloc"):
               leg_loc = arg_next.replace('_', ' ')
            elif(arg == "-xrot"):
               xrot = float(arg_next)
            elif(arg == "-yrot"):
               yrot = float(arg_next)
            elif(arg == "-bottom"):
               bottom_padding = float(arg_next)
            elif(arg == "-top"):
               top_padding = float(arg_next)
            elif(arg == "-right"):
               right_padding = float(arg_next)
            elif(arg == "-left"):
               left_padding = float(arg_next)
            elif(arg == "-pad"):
               Pad = arg_next
            elif(arg == "-titlefs"):
               title_font_size = float(arg_next)
            elif(arg == "-cmap"):
               cmap = arg_next
            elif(arg == "-maptype"):
               map_type = arg_next
            elif(arg == "-obs"):
               obs_field = verif.field.get(arg_next)
            elif(arg == "-fcst"):
               fcst_field = verif.field.get(arg_next)
            elif(arg == "-m"):
               metric = arg_next
            else:
               verif.util.error("Flag '" + argv[i] + "' not recognized")
            i = i + 1
      else:
         ifiles.append(argv[i])
      i = i + 1

   if(version):
      print "Version: " + verif.version.__version__
      return

   # Deal with legend entries
   if(leg is not None):
      leg = leg.split(',')
      for i in range(0, len(leg)):
         leg[i] = leg[i].replace('_', ' ')

   if(lat_range is not None and len(lat_range) != 2):
      verif.util.error("-lat_range <values> must have exactly 2 values")

   if(lon_range is not None and len(lon_range) != 2):
      verif.util.error("-lon_range <values> must have exactly 2 values")

   if(elev_range is not None and len(elev_range) != 2):
      verif.util.error("-elev_range <values> must have exactly 2 values")

   if(len(ifiles) > 0):
      inputs = [verif.input.get_input(filename) for filename in ifiles]
      data = verif.data.Data(inputs, clim=clim_file, clim_type=clim_type,
            times=times, leadtimes=leadtimes, locations=locations,
            locations_x=locations_x,
            lat_range=lat_range, lon_range=lon_range, elev_range=elev_range,
            legend=leg, obs_field=obs_field, fcst_field=fcst_field)
   else:
      data = None

   if(list_thresholds or list_quantiles or list_locations or list_times):
      if(len(ifiles) == 0):
         verif.util.error("Files are required in order to list thresholds, quantiles, or times")
      if(list_thresholds):
         print "Thresholds:",
         for threshold in data.thresholds:
            print "%g" % threshold,
         print ""
      if(list_quantiles):
         print "Quantiles:",
         for quantile in data.quantiles:
            print "%g" % quantile,
         print ""
      if(list_locations):
         print "    id     lat     lon    elev"
         for location in data.locations:
            print "%6d %7.2f %7.2f %7.1f" % (location.id, location.lat,
                  location.lon, location.elev)
         print ""
      if(list_times):
         for time in data.times:
            print "%d" % time
         print ""
      return
   elif(len(ifiles) == 0 and metric is not None):
      m = verif.metric.get(metric)
      if(m is not None):
         print m.help()
      else:
         m = verif.output.get(metric)
         if(m is not None):
            print m.help()
      return
   elif(len(argv) == 1 or len(ifiles) == 0 or metric is None):
      print show_description(data)
      return

   if(figsize is not None):
      figsize = figsize.split(',')
      if(len(figsize) != 2):
         print "-fs figsize must be in the form: width,height"
         sys.exit(1)

   m = None

   # Handle special plots
   if(metric == "pithist"):
      pl = verif.output.PitHist()
   elif(metric == "obsfcst"):
      pl = verif.output.ObsFcst()
   elif(metric == "timeseries"):
      pl = verif.output.TimeSeries()
   elif(metric == "meteo"):
      pl = verif.output.Meteo()
   elif(metric == "qq"):
      pl = verif.output.QQ()
   elif(metric == "cond"):
      pl = verif.output.Cond()
   elif(metric == "against"):
      pl = verif.output.Against()
   elif(metric == "impact"):
      pl = verif.output.Impact()
   elif(metric == "scatter"):
      pl = verif.output.Scatter()
   elif(metric == "change"):
      pl = verif.output.Change()
   elif(metric == "spreadskill"):
      pl = verif.output.SpreadSkill()
   elif(metric == "taylor"):
      pl = verif.output.Taylor()
   elif(metric == "error"):
      pl = verif.output.Error()
   elif(metric == "freq"):
      pl = verif.output.Freq()
   elif(metric == "roc"):
      pl = verif.output.Roc()
   elif(metric == "droc"):
      pl = verif.output.DRoc()
   elif(metric == "droc0"):
      pl = verif.output.DRoc0()
   elif(metric == "drocnorm"):
      pl = verif.output.DRocNorm()
   elif(metric == "reliability"):
      pl = verif.output.Reliability()
   elif(metric == "discrimination"):
      pl = verif.output.Discrimination()
   elif(metric == "performance"):
      pl = verif.output.Performance()
   elif(metric == "invreliability"):
      pl = verif.output.InvReliability()
   elif(metric == "igncontrib"):
      pl = verif.output.IgnContrib()
   elif(metric == "economicvalue"):
      pl = verif.output.EconomicValue()
   elif(metric == "marginal"):
      pl = verif.output.Marginal()
   else:
      # Standard plots
      # Attempt at automating
      m = verif.metric.get(metric)
      if(m is None):
         verif.util.error("Unknown plot: %s" % metric)

      if aggregator_name is not None:
         if not m.supports_aggregator:
            verif.util.warning("-m %s does not support -agg" % metric)
         m.aggregator = verif.aggregator.get(aggregator_name)

      # Output type
      if(plot_type in ["plot", "text", "csv", "map", "maprank"]):
         if do_sort:
            field = verif.field.get(metric)
            pl = verif.output.Sort(field)
         elif do_hist:
            field = verif.field.get(metric)
            pl = verif.output.Hist(field)
         else:
            pl = verif.output.Standard(m)
      else:
         verif.util.error("Type not understood")

   # Rest dimension of '-x' is not allowed
   if(axis is not None and not pl.supports_x):
      verif.util.warning(metric + " does not support -x. Ignoring it.")
      axis = None

   # Reset dimension if 'threshold' is not allowed
   if(axis == verif.axis.Threshold() and
         ((not pl.supports_threshold) or (m is not None and not m.supports_threshold))):
      verif.util.warning(metric + " does not support '-x threshold'. Ignoring it.")
      thresholds = None
      axis = None

   # Create thresholds if needed
   if thresholds is None:
      type = None
      if pl.require_threshold_type == "deterministic":
         type = "deterministic"
      elif pl.require_threshold_type == "threshold":
         type = "threshold"
      elif pl.require_threshold_type == "quantile":
         type = "quantile"
      elif m is not None:
         if m.require_threshold_type == "deterministic":
            type = "deterministic"
         elif m.require_threshold_type == "threshold":
            type = "threshold"
         elif m.require_threshold_type == "quantile":
            type = "quantile"
         elif m.require_threshold_type is not None:
            verif.util.error("Internal error for metric %s: Cannot understand required threshold type '%s'" % (m.name(), m.require_threshold_type))
      elif pl.require_threshold_type is not None:
         verif.util.error("Internal error for output %s: Cannot understand required threshold type '%s'" % (pl.name(), pl.require_threshold_type))

      if type is not None:
         if type == "deterministic":
            smin = np.inf
            smax = -np.inf
            if verif.field.Obs() in data.get_fields():
               obs = data.get_scores(verif.field.Obs(), 0)
               smin = min(np.nanmin(obs), smin)
               smax = max(np.nanmax(obs), smax)
            if verif.field.Fcst() in data.get_fields():
               fcst = data.get_scores(verif.field.Fcst(), 0)
               smin = min(np.nanmin(fcst), smin)
               smax = max(np.nanmax(fcst), smax)
            thresholds = np.linspace(smin, smax, 10)
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         elif type == "threshold":
            thresholds = data.thresholds
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         elif type == "quantile":
            thresholds = data.quantiles
            verif.util.warning("Missing '-r <thresholds>'. Automatically setting thresholds.")
         if len(thresholds) == 0:
            verif.util.error("No thresholds available")

   # Set plot parameters
   if(simple is not None):
      pl.simple = simple
   if(marker_size is not None):
      pl.ms = marker_size
   if(line_width is not None):
      pl.lw = line_width
   if(line_colors is not None):
      pl.line_colors = line_colors
   if(line_styles is not None):
      pl.line_styles = line_styles
   if(lab_font_size is not None):
      pl.labfs = lab_font_size
   if(leg_font_size is not None):
      pl.legfs = leg_font_size
   if(title_font_size is not None):
      pl.title_font_size = title_font_size
   if(leg_loc is not None):
      pl.leg_loc = leg_loc
   if(tick_font_size is not None):
      pl.tick_font_size = tick_font_size
   if(xrot is not None):
      pl.xrot = xrot
   if(yrot is not None):
      pl.yrot = yrot
   if(bottom_padding is not None):
      pl.bottom = bottom_padding
   if(top_padding is not None):
      pl.top = top_padding
   if(right_padding is not None):
      pl.right = right_padding
   if(left_padding is not None):
      pl.left = left_padding
   if(Pad is not None):
      pl.pad = None
   if(bin_type is not None):
      pl.bin_type = bin_type
   if(show_perfect is not None):
      pl.show_perfect = show_perfect
   if(xlim is not None):
      pl.xlim = xlim
   if(ylim is not None):
      pl.ylim = ylim
   if(clim is not None):
      pl.clim = clim
   if(xticks is not None):
      pl.xticks = xticks
   if(xticklabels is not None):
      pl.xticklabels = xticklabels
   if(yticks is not None):
      pl.yticks = yticks
   if(yticklabels is not None):
      pl.yticklabels = yticklabels
   if(xlog is not None):
      pl.xlog = xlog
   if(ylog is not None):
      pl.ylog = ylog
   pl.grid = grid
   if(cmap is not None):
      pl.cmap = cmap
   if(map_type is not None):
      pl.map_type = map_type
   pl.filename = ofile
   if thresholds is not None:
      pl.thresholds = thresholds
   if quantiles is not None:
      pl.quantiles = quantiles
   pl.figsize = figsize
   pl.dpi = dpi
   if axis is not None:
      pl.axis = axis
   if aggregator_name is not None:
      pl.aggregator = verif.aggregator.get(aggregator_name)
   if aspect is not None:
      pl.aspect = aspect
   pl.show_margin = not no_margin
   if ylabel is not None:
      pl.ylabel = ylabel
   if xlabel is not None:
      pl.xlabel = xlabel
   if title is not None:
      pl.title = title
   if do_acc:
      if pl.supports_acc:
         pl.show_acc = do_acc
      else:
         verif.util.warning("%s does not support -acc" % metric)

   if(plot_type == "text"):
      pl.text(data)
   elif(plot_type == "csv"):
      pl.csv(data)
   elif(plot_type == "map"):
      pl.map(data)
   elif(plot_type == "maprank"):
      pl.show_rank = True
      pl.map(data)
   else:
      pl.plot(data)