climind.web package
Submodules
climind.web.dashboard module
- class climind.web.dashboard.Card(card_metadata: dict)[source]
Bases:
WebComponentA card is a single panel in a dashboard web page. The Card class manages the metadata associated with the card, and generates the files that are associated with it. These include the figure (in multiple formats) and the data files (in a zip archive)
- Parameters:
card_metadata (dict) – dictionary containing the metadata for the card
- make_csv_files(formatted_data_dir: Path) List[Path][source]
Make a csv file in the standard format for each data set in the Card and return a list of all their names of the csv files.
- Parameters:
formatted_data_dir (Path) – Path of the directory to which the csv files will be written
- Returns:
List containing a Path for each csv file written
- Return type:
List[Path]
- make_zip_file(formatted_data_dir: Path)[source]
Create a formatted data file for each data set and zip these into a zip file. Adds a metadata element ‘csv_name’ with the names of the zip file once it is created.
- Parameters:
formatted_data_dir (Path) – Path of the directory to which the zip file and data files should be written
- Return type:
None
- plot(figure_dir)[source]
Plot the figure specified in the card metadata, output to the figure_dir directory
- Parameters:
figure_dir (Path) – Path of the directory to which the figure should be written
- Return type:
None
- process_card(data_dir: Path, figure_dir: Path, formatted_data_dir: Path, archive: DataArchive)[source]
Process the datasets, plot them and write out the data based on the metadata in the Card
- Parameters:
data_dir (Path) – Path of the directory in which the data are found.
figure_dir (Path) – Path of the directory to which the figures will be written.
formatted_data_dir (Path) – Path of the directory to which the formatted data will be written.
archive (DataArchive) – DataArchive object containing the descriptive metadata.
- Return type:
None
- class climind.web.dashboard.Dashboard(metadata: dict, archive: DataArchive)[source]
Bases:
objectCreate a dashboard from a set of dashboard metadata
- Parameters:
metadata (dict) – Dictionary containing the dashboard metadata
archive (DataArchive) – Metadata archive that will be used to populate the dashboard
- build(build_dir: Path, focus_year: int = 2021)[source]
Build all the pages in the dashboard. This will create the html, the images, the formatted data in a chosen directory
- Parameters:
build_dir (Path) – Path of the directory to build the web pages in
focus_year (int) – Year to focus on. Usually, this will be the latest year
- Return type:
None
- class climind.web.dashboard.Page(metadata: dict)[source]
Bases:
objectA Page from a dashboard. A page contains multiple Cards, which are used to render a jinja2 template.
- Parameters:
metadata (dict) – Dictionary containing the page metadata
- build(build_dir: Path, data_dir: Path, archive: DataArchive, focus_year: int = 2021, menu_items: List[List[str]] = [])[source]
Build the Page, processing all the Card and Paragraph objects, then populating the template to generate a webpage, figures and formatted data.
- Parameters:
build_dir (Path) – Path of the directory to which the html, figures and data will be written
data_dir (Path) – Path of the directory where the data are to be found.
archive (DataArchive) – DataArchive containing the metadata for the datasets
focus_year (int) – Year to focus on. Usually, this will be the latest year
menu_items (List[List[str]]) – List of items to display in the menu. Each item is a two element list, with the name of the webpage as the first element (which gets a .html extension) and the title of the page as the second elements. The title is used to generate the menu items so should be human readable.
- Return type:
None
- class climind.web.dashboard.Paragraph(paragraph_metadata: dict)[source]
Bases:
WebComponent- process_datasets()[source]
Run the processing specified in the paragraph metadata on each of the data sets.
- Return type:
None
- process_paragraph(data_dir: Path, archive: DataArchive, focus_year: int = 2021) None[source]
Process and ultimately render the Paragraph object
- Parameters:
data_dir (Path) – Path of the directory containing the data
archive (DataArchive) – DataArchive object with the metadata describing all the datasets
focus_year (int) – Year which the paragraph will focus on, usually the most recent year, though it needn’t be.
- Return type:
None
- class climind.web.dashboard.WebComponent(component_metadata: dict)[source]
Bases:
object- process_datasets()[source]
Apply the processing steps specified in the ‘processing’ section of the metadata file to all the data sets.
- Return type:
None
- Raises:
RuntimeError – If any of the processing steps fails to run
- select_and_read_data(data_dir: Path, archive: DataArchive)[source]
Using the specified DataArchive, select the appropriate subset of data as specified in the Card metadata and read in the data sets from the data_dir directory.
- Parameters:
data_dir (Path) – Path of the directory in which the data are to be found
archive (DataArchive) – Archive of data used to select and populate the data sets
- Return type:
None
- climind.web.dashboard.process_single_dataset(ds: TimeSeriesAnnual | TimeSeriesMonthly | TimeSeriesIrregular, processing_steps: List[dict]) TimeSeriesAnnual | TimeSeriesMonthly | TimeSeriesIrregular[source]
Process the input data set using the methods and arguments provided in a list of processing steps. Each processing step is a dictionary containing a ‘method’ and an ‘arguments’ entry.
- Parameters:
ds (Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]) – Data set to be processed
processing_steps (List) – List of steps. Each step must be a dictionary containing a ‘method’ entry that corresponds to the name of a method in the timeseries class and a ‘arguments’ entry which contains a list of arguments for that method
- Return type:
Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]