climind.web package

Submodules

climind.web.dashboard module

class climind.web.dashboard.Card(card_metadata: dict)

Bases: WebComponent

A 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]

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)

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)

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)

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

process_datasets()

Run the processing specified in the card metadata on each of the data sets.

Return type

None

class climind.web.dashboard.Dashboard(metadata: dict, archive: DataArchive)

Bases: object

Create a dashboard from a set of dashboard metadata

Parameters
  • metadata (dict) – Dictionary containing the dashboard metadata

  • archive (DataArchive) – Data archive that will be used to populate the dashboard

build(build_dir: Path, focus_year: int = 2021)

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

static from_json(json_file: Path, archive_dir: Path)

Create a Dashboard from a json file and directory containing dataset metadata

Parameters
  • json_file (Path) – Path to the json file

  • archive_dir (Path) – Path of the directory which contains the dataset metadata

Return type

Dashboard

class climind.web.dashboard.Page(metadata: dict)

Bases: object

A 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]] = [])

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)

Bases: WebComponent

process_datasets()

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)

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.

render(year: int = 2021)

Render out the text of the paragraph specified in the paragraph metadata.

Parameters

year (int) – Year which is the focus of the paragraph.

Return type

None

class climind.web.dashboard.WebComponent(component_metadata: dict)

Bases: object

process_datasets()

Apply the processing steps specified in the ‘processing’ section of the metadata file to all the data sets.

Return type

None

select_and_read_data(data_dir: Path, archive: DataArchive)

Using the specified data archive, 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: Union[TimeSeriesAnnual, TimeSeriesMonthly], processing_steps: list) Union[TimeSeriesAnnual, TimeSeriesMonthly]

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 (TimeSeriesAnnual or TimeSeriesMonthly) – 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]

climind.web.extract_from_word module

climind.web.extract_from_word.GetParagraphText(paragraph)
climind.web.extract_from_word.clean_awkward_characters(in_text: str) str

Clean a string of odd characters or otherwise inelegant combinations that cause problems for jinja and/or html.

Parameters

in_text (str) – String to be cleaned

Returns

Cleaned string

Return type

str

climind.web.extract_from_word.split_document(document_name)