def _parseFunctionConstituents(self, function, parse_consts=True, data_scheme=None): """ _parseFunctionConstituents() [protected] Purpose: Take a function string and parse out the variables and constants that the function needs for computations. If the data_scheme variable is given, convert the list to a file-based variable names. Parameters: function [ type=str ] String containing the function. parse_consts [ type=bool ] [ optional ] Boolean value specifying whether or not to parse out the constants in the file name. Default is True. data_scheme [ type=dict ] [ optional ] A dictionary containing the mapping of internal variables names to the variable names in the data file. Returns: A list of internal constant names and/or a list of internal variable names or file variable names, depending on whether or not parse_consts was set and data_scheme was given. """ # Put the variable list into a regexp-like format nc_variable_list = "(?:^|(?<=[\\W]))(?:" + "|".join(self._var_map.keys()) + ")(?:(?=[\\W])|$)" # Find all NetCDF variables in the function, removing duplicates var_list = uniquify(re.findall(nc_variable_list, function)) if parse_consts: hp_const_list = "|".join([ const for const in dir(derived) if const[0] != "_" ]) # Find all the constants in the function, removing duplicates const_list = uniquify(re.findall(hp_const_list, function)) if data_scheme is not None: var_list = [ data_scheme[self._var_map[v]] for v in var_list ] if parse_consts: return var_list, const_list else: return var_list
def _finalizeProduct(self, plot_time, is_forecast, plot_names=[]): """ _finalizeProduct() [protected] Purpose: Add final things to the product, such as the title, valid time, and border, and then save. Parameters: forecast_hour [type=int] Forecast hour for model products (pass in None for an observed product). Returns: [nothing] """ plot_names = uniquify(plot_names) # Modify the last plot name for joining for the title string if len(plot_names) > 1: plot_names[-1] = "and " + plot_names[-1] # Create the forecast hour string according to whether or not we're passed a forecast hour. plot_time_delta = plot_time - self._valid_time hour = Units.convert(plot_time_delta.microseconds, 'us', 'hr') + Units.convert(plot_time_delta.seconds, 's', 'hr') + Units.convert(plot_time_delta.days, 'dy', 'hr') file_name = self._image_file_name % { 'plot_time':hour } if is_forecast: fh_string = " (F%03d)" % hour else: fh_string = "" if self._vertical_level in ['surface', 'sfc', "None"]: vert_level_str = "" else: vert_level_str = " %s" % self._vertical_level # Create the valid time string and assemble the title string valid_time_string = plot_time.strftime(self._product_time_format) title_string = "%s%s %s Valid: %s%s" % (self._product_title, vert_level_str, ", ".join(plot_names), valid_time_string, fh_string) # Put the title on the image pylab.title(title_string, weight="bold", size="x-small", bbox=dict(facecolor="#ffffff", alpha=0.7),x=0.5,y=0.95) # Save the figure try: pylab.savefig(file_name) except IOError: fatalError("Couldn't save image to %s" % file_name) print "Saved product '%s', valid at %s%s, to file %s" % (self._product_title, valid_time_string, fh_string, file_name) pylab.close() return