def create_viewer(root_dir, parameters, ext): """Based of the parameters, find the files with extension ext and create the viewer in root_dir.""" viewer = OutputViewer(path=root_dir, index_name='ACME Diagnostics') add_pages_and_top_row(viewer, parameters) for parameter in parameters: for set_num in parameter.sets: viewer.set_page("Set-{}".format(set_num)) try: viewer.set_group(parameter.case_id) except RuntimeError: viewer.add_group(parameter.case_id) # Add all of the files with extension ext from the case_id/ folder' pth = get_output_dir(set_num, parameter) files = glob.glob( pth + '/*.' + ext ) # ex: files[0] = myresults/set5/set5_SST_HadISST/HadISST_CL-SST-SON-global.png for ext_fnm in files: fnm = ext_fnm.replace('.' + ext, '') fnm = fnm.split('/')[-1] # ex: HadISST_CL-SST-SON-global keywords = fnm.split('-') # 2d vars, format is [ref_name, var, season, region] # 3d vars, format is [ref_name, var, plev, season, region] # ref_name and/or var can be something_like_this, so we always use negative indices ref_name = keywords[0] region = keywords[-1] season = keywords[-2] if keywords[-3].isdigit( ): # for when we have a 3d variable, ex: keywords[-3] = 880 plev = keywords[-3] var = keywords[-4] else: plev = None var = keywords[-3] if plev is None: # 2d variable #row_name = '%s %s %s' % (ref_name, var, region) row_name = '%s %s' % (var, region) else: # 3d variable #row_name = '%s %s %s %s' % (ref_name, var, plev + ' mb ', region) row_name = '%s %s %s' % (var, plev + ' mb ', region) try: viewer.set_row(row_name) except RuntimeError: # row of row_name wasn't in the viewer, so add it viewer.add_row(row_name) viewer.add_col(var) # the description if parameter.case_id not in ROW_INFO[set_num]: ROW_INFO[set_num][parameter.case_id] = {} if row_name not in ROW_INFO[set_num][parameter.case_id]: ROW_INFO[set_num][parameter.case_id][row_name] = {} # format fnm to support relative paths ROW_INFO[set_num][ parameter.case_id][row_name][season] = os.path.join( 'set{}'.format(set_num), parameter.case_id, fnm) # add all of the files in from the case_id/ folder in ANN, DJF, MAM, JJA, SON order for set_num in ROW_INFO: viewer.set_page("Set-{}".format(set_num)) for group in ROW_INFO[set_num]: viewer.set_group(group) for row_name in ROW_INFO[set_num][group]: viewer.set_row(row_name) for col_season in viewer.page.columns[ 1:]: # [1:] is to ignore 'Description' col if col_season in ROW_INFO[set_num][group][row_name]: fnm = ROW_INFO[set_num][group][row_name][col_season] nc_files = [ fnm + nc_ext for nc_ext in ['_test.nc', '_ref.nc', '_diff.nc'] ] formatted_files = [{ 'url': f, 'title': f } for f in nc_files] viewer.add_col(fnm + '.' + ext, is_file=True, title=col_season, other_files=formatted_files) else: # insert a blank value # is_file must be True, otherwise OutputViewer indexes incorrectly viewer.add_col('-----', is_file=True) viewer.generate_viewer(prompt_user=False)
def create_viewer(root_dir, parameters): """ Given a set of parameters for the streamflow set, create a single webpage. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. display_name = "Streamflow" set_name = "streamflow" # The title of the columns on the webpage. # Appears in the second and third columns of the bolded rows. cols = ["Description", "Plot"] viewer.add_page(display_name, short_name=set_name, columns=cols) for plot_type in ["seasonality_map", "annual_map", "annual_scatter"]: if plot_type == "seasonality_map": group_name = "Seasonality Map" elif plot_type == "annual_map": group_name = "Mean Annual Streamflow Map" elif plot_type == "annual_scatter": group_name = "Mean Annual Streamflow Scatter Plot" else: raise Exception("Invalid plot_type={}".format(plot_type)) # Appears in the first column of the bolded rows. viewer.add_group(group_name) for param in parameters: # We need to make sure we have relative paths, and not absolute ones. # This is why we don't use get_output_dir() as in the plotting script # to get the file name. ext = param.output_format[0] # TODO: will param.variables ever be longer than one variable? # If so, we'll need to create unique image_relative_paths for var in param.variables: param.var_id = "{}-{}".format(var, plot_type) if plot_type == "seasonality_map": param.viewer_descr[var] = param.main_title_seasonality_map output_file = param.output_file_seasonality_map elif plot_type == "annual_map": param.viewer_descr[var] = param.main_title_annual_map output_file = param.output_file_annual_map elif plot_type == "annual_scatter": param.viewer_descr[var] = param.main_title_annual_scatter output_file = param.output_file_annual_scatter else: raise Exception("Invalid plot_type={}".format(plot_type)) # param.output_file_{seasonality, annual_map, annual_scatter} is defined in # acme_diags/parameter/streamflow_parameter.py. # relative_path must use param.case_id and output_file # to match the file_path determined in # acme_diags/plot/cartopy/streamflow_plot.py. # Otherwise, the plot will not be properly linked from the viewer. relative_path = os.path.join("..", set_name, param.case_id, output_file) image_relative_path = "{}.{}".format(relative_path, ext) if param.print_statements: print( "image_relative_path: {}".format(image_relative_path)) # Appears in the first column of the non-bolded rows. # To match the output_dir determined by get_output_dir in acme_diags/plot/cartopy/streamflow_plot.py, # the row name should be param.case_id. # Otherwise, the plot image and the plot HTML file will have URLs with different final directory names. # (The viewer will still display everything properly though). viewer.add_row("{}-{}".format(param.case_id, plot_type)) # Adding the description for this var to the current row. # Appears in the second column of the non-bolded rows. viewer.add_col(param.viewer_descr[var]) # Link to an html version of the plot png file. # Appears in the third column of the non-bolded rows. meta = create_metadata(param) viewer.add_col( image_relative_path, is_file=True, title="Plot", other_files=[], meta=meta, ) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for the enso_diags set, create a single webpage. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. display_name = "ENSO Diagnostics" set_name = "enso_diags" # The title of the colums on the webpage. # Appears in the second and third columns of the bolded rows. cols = ["Description", "Plot"] viewer.add_page(display_name, short_name=set_name, columns=cols) param_dict = {} # type: Dict[str, List[str]] for param in parameters: key = param.plot_type if key not in param_dict.keys(): param_dict[key] = [] param_dict[key].append(param) for plot_type in param_dict.keys(): # Appears in the first column of the bolded rows. viewer.add_group(plot_type.capitalize()) # Only iterate through parameters with this plot type. valid_parameters = param_dict[plot_type] for param in valid_parameters: # We need to make sure we have relative paths, and not absolute ones. # This is why we don't use get_output_dir() as in the plotting script # to get the file name. ext = param.output_format[0] # param.output_file is defined in e3sm_diags/driver/enso_diags_driver.py # This must be use param.case_id and param.output_file # to match the file_path determined in # e3sm_diags/plot/cartopy/enso_diags_plot.py. # Otherwise, the plot will not be properly linked from the viewer. relative_path = os.path.join("..", set_name, param.case_id, param.output_file) image_relative_path = "{}.{}".format(relative_path, ext) if param.print_statements: print("image_relative_path: {}".format(image_relative_path)) formatted_files = [] if param.save_netcdf: nc_files = [ relative_path + nc_ext for nc_ext in ["_test.nc", "_ref.nc", "_diff.nc"] ] formatted_files = [{"url": f, "title": f} for f in nc_files] # TODO: will param.variables ever be longer than one variable? # If so, we'll need to create unique image_relative_paths for var in param.variables: # Appears in the first column of the non-bolded rows. # This should use param.case_id to match the output_dir determined by # get_output_dir in e3sm_diags/plot/cartopy/enso_diags_plot.py. # Otherwise, the plot image and the plot HTML file will have URLs # differing in the final directory name. viewer.add_row(param.case_id) # Adding the description for this var to the current row. # This was obtained and stored in the driver for this plotset. # Appears in the second column of the non-bolded rows. viewer.add_col(param.viewer_descr[var]) # Link to an html version of the plot png file. # Appears in the third column of the non-bolded rows. viewer.add_col( image_relative_path, is_file=True, title="Plot", other_files=formatted_files, meta=create_metadata(param), ) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for a the diff_diags set, create a single webpage. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) display_name = "Annual Cycle Zonal Mean Contour Plots" set_name = "annual_cycle_zonal_mean" cols = ["Description", "Plot"] viewer.add_page(display_name, short_name=set_name, columns=cols) viewer.add_group("Variable") for param in parameters: for var in param.variables: viewer.add_row("{} {}".format(var, param.ref_name)) # Adding the description for this var to the current row. # This was obtained and stored in the driver for this plotset. viewer.add_col(param.viewer_descr[var]) file_name = "{}-{}-{}.png".format(param.ref_name, var, "Annual-Cycle") # We need to make sure we have relative paths, and not absolute ones. # This is why we don't use get_output_dir() as in the plotting script # to get the file name. file_name = os.path.join("..", set_name, param.case_id, file_name) viewer.add_col(file_name, is_file=True, title="Plot", meta=create_metadata(param)) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for the qbo set, create a single webpage. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. display_name = 'Quasi-biennial Oscillation' set_name = 'qbo' # The title of the colums on the webpage. # Appears in the second and third columns of the bolded rows. cols = ['Description', 'Plot'] viewer.add_page(display_name, short_name=set_name, columns=cols) # Appears in the first column of the bolded rows. viewer.add_group('Variable') for param in parameters: # We need to make sure we have relative paths, and not absolute ones. # This is why we don't use get_output_dir() as in the plotting script # to get the file name. ext = param.output_format[0] # param.output_file is defined in acme_diags/driver/qbo_driver.py # This must be use param.case_id and param.output_file # to match the file_path determined in # acme_diags/plot/cartopy/qbo_plot.py. # Otherwise, the plot will not be properly linked from the viewer. relative_path = os.path.join('..', set_name, param.case_id, param.output_file) image_relative_path = '{}.{}'.format(relative_path, ext) if param.print_statements: print('image_relative_path: {}'.format(image_relative_path)) formatted_files = [] if param.save_netcdf: nc_files = [] variables = ['qbo', 'level'] for variable_name in variables: for label in ['test', 'ref']: file_name = '{}_{}_{}.nc'.format(param.output_file, variable_name, label) nc_files.append(relative_path + file_name) formatted_files = [{'url': f, 'title': f} for f in nc_files] # TODO: will param.variables ever be longer than one variable? # If so, we'll need to create unique image_relative_paths for var in param.variables: # Appears in the first column of the non-bolded rows. # This should use param.case_id to match the output_dir determined by # get_output_dir in acme_diags/plot/cartopy/qbo_plot.py. # Otherwise, the plot image and the plot HTML file will have URLs # differing in the final directory name. viewer.add_row(param.case_id) # Adding the description for this var to the current row. # This was obtained and stored in the driver for this plotset. # Appears in the second column of the non-bolded rows. viewer.add_col(param.viewer_descr[var]) # Link to an html version of the plot png file. # Appears in the third column of the non-bolded rows. viewer.add_col(image_relative_path, is_file=True, title='Plot', other_files=formatted_files, meta=create_metadata(param)) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for a certain set of diagnostics, create a single page. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. display_name = "Area Mean Time Series" set_name = "area_mean_time_series" cols = ["Description", "Plot"] viewer.add_page(display_name, short_name=set_name, columns=cols) viewer.add_group("Variable") for param in parameters: for var in param.variables: viewer.add_row(var) # Adding the description for this var to the current row. # This was obtained and stored in the driver for this plotset. viewer.add_col(param.viewer_descr[var]) ext = param.output_format[0] file_name = os.path.join("..", set_name, param.case_id, "{}.{}".format(var, ext)) viewer.add_col( file_name, is_file=True, title="Plot", meta=create_metadata(param), ) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for a certain set of diagnostics, create a single page. Return the title and url for this page. """ # Information for each row in the viewer. # The order is: # { # case_id: { # row_name: { # season: filename # } # } # } ROW_INFO = collections.OrderedDict() # A similar dict, but for creating the lat-lon tables. LAT_LON_TABLE_INFO = collections.OrderedDict() # Since we're only having one set for each # create_viewer() call, this works. set_name = parameters[0].sets[0] viewer = OutputViewer(path=root_dir) cols = ['Description'] + seasons_used(parameters) viewer.add_page(SET_TO_NAME[set_name], short_name=set_name, columns=cols) for parameter in parameters: results_dir = parameter.results_dir # Filenames are like one in the two formats: # ref_name-variable-season-region # ref_name-variable-plev'mb'-season-region ref_name = getattr(parameter, 'ref_name', '') for var in parameter.variables: for season in parameter.seasons: for region in parameter.regions: # Since some parameters have plevs, there might be # more than one row_name, filename pair. # Hence, this is why we have a list. row_name_and_filename = [] if parameter.plevs == []: # 2d variables. if parameter.run_type == 'model_vs_model': row_name = '{} {}'.format(var, region) else: row_name = '{} {} {}'.format(var, region, ref_name) fnm = '{}-{}-{}-{}'.format(ref_name, var, season, region) row_name_and_filename.append((row_name, fnm)) else: # 3d variables. for plev in parameter.plevs: if parameter.run_type == 'model_vs_model': row_name = '{}-{} {}'.format( var, str(int(plev)) + 'mb', region) else: row_name = '{}-{} {} {}'.format( var, str(int(plev)) + 'mb', region, ref_name) fnm = '{}-{}-{}-{}-{}'.format( ref_name, var, int(plev), season, region) row_name_and_filename.append((row_name, fnm)) if set_name == 'lat_lon': metrics_path = os.path.join(results_dir, '{}'.format(set_name), parameter.case_id, fnm) if os.path.exists(metrics_path + '.json'): _add_to_lat_lon_metrics_table(LAT_LON_TABLE_INFO, metrics_path, season, row_name) else: print(('JSON does not exist: {}'.format(metrics_path + '.json'))) continue for row_name, fnm in row_name_and_filename: if set_name not in ROW_INFO: ROW_INFO[set_name] = collections.OrderedDict() if parameter.case_id not in ROW_INFO[set_name]: ROW_INFO[set_name][parameter.case_id] = collections.OrderedDict( ) if row_name not in ROW_INFO[set_name][parameter.case_id]: ROW_INFO[set_name][parameter.case_id][row_name] = collections.OrderedDict( ) ROW_INFO[set_name][parameter.case_id][row_name]['descr'] = _get_description( var, parameter) # Each season has a image_path and metadata linked to it, thus we use a dict. ROW_INFO[set_name][parameter.case_id][row_name][season] = {} # Format the filename to support relative paths. ROW_INFO[set_name][parameter.case_id][row_name][season]['image_path'] = os.path.join( '..', '{}'.format(set_name), parameter.case_id, fnm) ROW_INFO[set_name][parameter.case_id][row_name][season]['metadata'] = create_metadata(parameter) save_netcdf = parameters[0].save_netcdf ext = parameters[0].output_format[0] _add_information_to_viewer(viewer, ROW_INFO, set_name, save_netcdf, ext) viewer.set_page(SET_TO_NAME[set_name]) # Return the name and the url of the current page of the viewer. name, url = SET_TO_NAME[set_name], viewer.generate_page() # Edit the final URL to add in the header. utils.add_header(root_dir, os.path.join(root_dir, url), parameters) utils.h1_to_h3(os.path.join(root_dir, url)) if set_name == 'lat_lon': table_tuple = lat_lon_viewer.generate_lat_lon_metrics_table( LAT_LON_TABLE_INFO, SEASONS, viewer, root_dir, parameters) taylor_diag_tuple = lat_lon_viewer.generate_lat_lon_taylor_diag( LAT_LON_TABLE_INFO, SEASONS, viewer, root_dir, parameters) return [(name, url), table_tuple, taylor_diag_tuple] return (name, url)
def create_viewer(root_dir, parameters): """ Given a set of parameter for a certain set of diagnostics, create a single page. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. set_name = "tc_analysis" display_name = "Diagnostics for Tropical Cyclones" # The title of the colums on the webpage. # Appears in the second and third columns of the bolded rows. cols = ["Description", "Plot"] viewer.add_page(display_name, short_name=set_name, columns=cols) relative_path = os.path.join("..", set_name) ext = parameters[0].output_format[0] viewer.add_group("Bar/Line plots") viewer.add_row("TC Frequency") output_file = "tc-frequency.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Frequency of TCs by ocean basins") viewer.add_col(image_relative_path, is_file=True, title="Plot") viewer.add_row("TC Intensity") output_file = "tc-intensity.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Intensity of TCs by ocean basins") viewer.add_col(image_relative_path, is_file=True, title="Plot") viewer.add_row("TC Seasonality") output_file = "tc-frequency-annual-cycle.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Annual cycle of TC frequency by ocean basins") viewer.add_col(image_relative_path, is_file=True, title="Plot") viewer.add_row("ACE Distribution") output_file = "ace-distribution.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Distribution of Accumulated Cyclone Energy (ACE)") viewer.add_col(image_relative_path, is_file=True, title="Plot") viewer.add_group("Maps") viewer.add_row("Cyclone Density Map") output_file = "cyclone-density-map.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Density map of Tropical Cyclones") viewer.add_col(image_relative_path, is_file=True, title="Plot") viewer.add_row("AEW Density Map") output_file = "aew-density-map.{}".format(ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col("Density map of African Easterly Wave") viewer.add_col(image_relative_path, is_file=True, title="Plot") url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters, ext): """Based of the parameters, find the files with extension ext and create the viewer in root_dir.""" viewer = OutputViewer(path=root_dir, index_name='E3SM Diagnostics') _add_pages_and_top_row(viewer, parameters) for parameter in parameters: results_dir = parameter.results_dir for set_num in parameter.sets: set_num = get_set_name(set_num) # Filenames are like: # ref_name-variable-season-region # or # ref_name-variable-plev'mb'-season-region ref_name = parameter.ref_name for var in parameter.variables: for season in parameter.seasons: for region in parameter.regions: # because some parameters have plevs, there might be # more than one row_name, fnm pair row_name_and_fnm = [] if parameter.plevs == []: # 2d variables if parameter.run_type == 'model_vs_model': row_name = '{} {}'.format(var, region) else: row_name = '{} {} {}'.format( var, region, ref_name) fnm = '{}-{}-{}-{}'.format(ref_name, var, season, region) row_name_and_fnm.append((row_name, fnm)) else: # 3d variables for plev in parameter.plevs: if parameter.run_type == 'model_vs_model': row_name = '{}-{} {}'.format( var, str(int(plev)) + 'mb', region) else: row_name = '{}-{} {} {}'.format( var, str(int(plev)) + 'mb', region, ref_name) fnm = '{}-{}-{}-{}-{}'.format( ref_name, var, int(plev), season, region) row_name_and_fnm.append((row_name, fnm)) if set_num in ['lat_lon', '5']: metrics_path = os.path.join( results_dir, '{}'.format(set_num), parameter.case_id, fnm) if os.path.exists(metrics_path + '.json'): _add_to_lat_lon_metrics_table( metrics_path, season, row_name) else: print(('JSON does not exist: {}'.format( metrics_path + '.json'))) continue for row_name, fnm in row_name_and_fnm: if parameter.case_id not in ROW_INFO[set_num]: ROW_INFO[set_num][ parameter. case_id] = collections.OrderedDict() if row_name not in ROW_INFO[set_num][ parameter.case_id]: ROW_INFO[set_num][parameter.case_id][ row_name] = collections.OrderedDict() ROW_INFO[set_num][parameter.case_id][row_name][ 'descr'] = _get_description( var, parameter) # each season has a image_path and metadata linked to it, thus we use a dict ROW_INFO[set_num][ parameter.case_id][row_name][season] = {} # format fnm to support relative paths ROW_INFO[set_num][parameter.case_id][row_name][ season]['image_path'] = os.path.join( '..', '{}'.format(set_num), parameter.case_id, fnm) # If ran in a container, create_metadata() will modify *_data_path and results_dir to their original value. ROW_INFO[set_num][parameter.case_id][row_name][ season]['metadata'] = create_metadata( parameter) # add all of the files in from the case_id/ folder in ANN, DJF, MAM, JJA, # SON order for set_num in ROW_INFO: viewer.set_page("{}".format(_better_page_name(set_num))) for group in ROW_INFO[set_num]: try: viewer.set_group(group) except RuntimeError: viewer.add_group(group) for row_name in ROW_INFO[set_num][group]: try: viewer.set_row(row_name) except RuntimeError: # row of row_name wasn't in the viewer, so add it viewer.add_row(row_name) # the description, currently the var viewer.add_col(ROW_INFO[set_num][group][row_name]['descr']) # [1:] is to ignore 'Description' col for col_season in viewer.page.columns[1:]: if col_season not in ROW_INFO[set_num][group][row_name]: viewer.add_col('-----', is_file=True, title='-----') else: metadata = ROW_INFO[set_num][group][row_name][ col_season]['metadata'] fnm = ROW_INFO[set_num][group][row_name][col_season][ 'image_path'] formatted_files = [] if parameters[0].save_netcdf: nc_files = [ fnm + nc_ext for nc_ext in ['_test.nc', '_ref.nc', '_diff.nc'] ] formatted_files = [{ 'url': f, 'title': f } for f in nc_files] viewer.add_col(fnm + '.' + ext, is_file=True, title=col_season, other_files=formatted_files, meta=metadata) generate_lat_lon_metrics_table(viewer, root_dir, parameters) generate_lat_lon_taylor_diag(viewer, root_dir, parameters) viewer.generate_viewer(prompt_user=False) _extras(root_dir, parameters)
def create_viewer(root_dir, parameters): """ Given a set of parameter for a certain set of diagnostics, create a single page. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) # The name that's displayed on the viewer. set_name = "arm_diags" display_name = "Diagnostics at ARM stations" # The title of the colums on the webpage. # Appears in the second and third columns of the bolded rows. cols = ["Description", "Plot", "", "", "", ""] viewer.add_page(display_name, short_name=set_name, columns=cols) param_dict = {} # type: ignore relative_path = os.path.join("..", set_name) for param in parameters: key = param.diags_set if key not in param_dict.keys(): param_dict[key] = [] param_dict[key].append(param) for diags_set in param_dict.keys(): valid_parameters = param_dict[diags_set] if diags_set == "annual_cycle": viewer.add_group("Annual Cycle") for param in valid_parameters: ext = param.output_format[0] viewer.add_row("{} at {} ({})".format( param.variables[0], region_name[param.regions[0]], param.regions[0], )) viewer.add_col("Annual cycles of " + param.var_name) image_relative_path = os.path.join( relative_path, "{}.{}".format(param.output_file, ext)) viewer.add_col(image_relative_path, is_file=True, title="Plot") if diags_set == "diurnal_cycle": viewer.add_group("Diurnal Cycle") for param in valid_parameters: ext = param.output_format[0] viewer.add_row("PRECT at SGP") viewer.add_col("Diurnal cycle of precipitation") for season in ["DJF", "MAM", "JJA", "SON"]: output_file = "{}-PRECT-{}-sgp-diurnal-cycle.{}".format( param.ref_name, season, ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col(image_relative_path, is_file=True, title=season) if diags_set == "convection_onset": viewer.add_group("Convection Onset Statistics") for param in valid_parameters: ext = param.output_format[0] viewer.add_row("{} ({})".format(region_name[param.regions[0]], param.regions[0])) viewer.add_col("Convection Onset Statistics") region = param.regions[0] output_file = "{}-convection-onset-{}.{}".format( param.ref_name, region, ext) image_relative_path = os.path.join(relative_path, output_file) viewer.add_col(image_relative_path, is_file=True, title="Plot") if diags_set == "diurnal_cycle_zt": viewer.add_group("Monthly Diurnal Cycle of Cloud") for param in valid_parameters: ext = param.output_format[0] viewer.add_row("{} ({})".format(region_name[param.regions[0]], param.regions[0])) region = param.regions[0] viewer.add_col("Monthly Diurnal Cycle of Cloud") output_file1 = "{}-CLOUD-ANNUALCYCLE-{}-{}.{}".format( param.ref_name, region, "test", ext) output_file2 = "{}-CLOUD-ANNUALCYCLE-{}-{}.{}".format( param.ref_name, region, "ref", ext) image_relative_path = os.path.join(relative_path, output_file1) viewer.add_col(image_relative_path, is_file=True, title="Test") image_relative_path = os.path.join(relative_path, output_file2) viewer.add_col(image_relative_path, is_file=True, title="Reference") url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters): """ Given a set of parameters for a certain set of diagnostics, create a single page. Return the title and url for this page. """ viewer = OutputViewer(path=root_dir) set_name = parameters[0].sets[0] # The name that's displayed on the viewer. if set_name == 'zonal_mean_2d': display_name = 'Pressure-Latitude zonal mean contour plots' elif set_name == 'meridional_mean_2d': display_name = 'Pressure-Longitude meridional mean contour plots' cols = ['Description'] + seasons_used(parameters) viewer.add_page(display_name, short_name=set_name, columns=cols) # Sort the parameters so that the viewer is created in the correct order. # Using SEASONS.index(), we make sure we get the parameters in # ['ANN', 'DJF', ..., 'SON'] order instead of alphabetical. parameters.sort( key=lambda x: (x.case_id, x.variables[0], SEASONS.index(x.seasons[0]))) for param in parameters: ref_name = getattr(param, 'ref_name', '') for var in param.variables: for season in param.seasons: for region in param.regions: try: viewer.set_group(param.case_id) except RuntimeError: viewer.add_group(param.case_id) if param.run_type == 'model_vs_model': row_name = '{} {}'.format(var, region) else: row_name = '{} {} {}'.format(var, region, ref_name) try: viewer.set_row(row_name) except RuntimeError: # A row of row_name wasn't in the viewer, so add it. viewer.add_row(row_name) # Adding the description for the row. viewer.add_col(param.viewer_descr[var]) ext = param.output_format[0] fnm = '{}-{}-{}-{}'.format(ref_name, var, season, region) file_name = os.path.join('..', set_name, param.case_id, '{}.{}'.format(fnm, ext)) viewer.add_col(file_name, is_file=True, title=season, meta=create_metadata(param)) url = viewer.generate_page() add_header(root_dir, os.path.join(root_dir, url), parameters) h1_to_h3(os.path.join(root_dir, url)) return display_name, url
def create_viewer(root_dir, parameters, ext): """Based of the parameters, find the files with extension ext and create the viewer in root_dir.""" viewer = OutputViewer(path=root_dir, index_name='ACME Diagnostics') _add_pages_and_top_row(viewer, parameters) for parameter in parameters: for set_num in parameter.sets: set_num = get_set_name(set_num) # Add all of the files with extension ext from the case_id/ folder' pth = get_output_dir(set_num, parameter) # ex: myresults/lat_lon # Filenames are like: # ref_name-variable-season-region # or # ref_name-variable-plev'mb'-season-region ref_name = parameter.ref_name for var in parameter.variables: for season in parameter.seasons: for region in parameter.regions: row_name_and_fnm = [ ] # because some parameters have plevs, there might be more than one row_name, fnm pair if parameter.plevs == []: # 2d variables row_name = '{} {}'.format(var, region) fnm = '{}-{}-{}-{}'.format(ref_name, var, season, region) row_name_and_fnm.append((row_name, fnm)) else: # 3d variables for plev in parameter.plevs: row_name = '{} {} {}'.format( var, str(int(plev)) + ' mb', region) fnm = '{}-{}-{}-{}-{}'.format( ref_name, var, int(plev), season, region) row_name_and_fnm.append((row_name, fnm)) for row_name, fnm in row_name_and_fnm: if parameter.case_id not in ROW_INFO[set_num]: ROW_INFO[set_num][ parameter. case_id] = collections.OrderedDict() if row_name not in ROW_INFO[set_num][ parameter.case_id]: ROW_INFO[set_num][parameter.case_id][ row_name] = collections.OrderedDict() ROW_INFO[set_num][parameter.case_id][row_name][ 'descr'] = _get_description( var, parameter) # format fnm to support relative paths ROW_INFO[set_num][parameter.case_id][row_name][ season] = os.path.join('..', '{}'.format(set_num), parameter.case_id, fnm) # add all of the files in from the case_id/ folder in ANN, DJF, MAM, JJA, SON order for set_num in ROW_INFO: viewer.set_page("{}".format(_better_page_name(set_num))) for group in ROW_INFO[set_num]: try: viewer.set_group(group) except RuntimeError: viewer.add_group(group) for row_name in ROW_INFO[set_num][group]: try: viewer.set_row(row_name) except RuntimeError: # row of row_name wasn't in the viewer, so add it viewer.add_row(row_name) viewer.add_col( ROW_INFO[set_num][group][row_name] ['descr']) # the description, currently the var for col_season in viewer.page.columns[ 1:]: # [1:] is to ignore 'Description' col fnm = ROW_INFO[set_num][group][row_name][col_season] formatted_files = [] if parameters[0].save_netcdf: nc_files = [ fnm + nc_ext for nc_ext in ['_test.nc', '_ref.nc', '_diff.nc'] ] formatted_files = [{ 'url': f, 'title': f } for f in nc_files] viewer.add_col(fnm + '.' + ext, is_file=True, title=col_season, other_files=formatted_files) viewer.generate_viewer(prompt_user=False) _extras(root_dir, parameters)