atomica.excel.TimeDependentValuesEntry

class atomica.excel.TimeDependentValuesEntry(name, tvec=None, ts=None, allowed_units=None, comment=None, pop_type=None, default_all=False, code_name=None)[source]

Bases: object

Table for time-dependent data entry

This class is Databooks and Program books to enter potentially time-varying data. Conceptually, it maps a set of TimeSeries object to a single name and table in the spreadsheet. For example, a Characteristic might contain a TimeSeries for each population, and the resulting TimeDependentValuesEntry (TDVE) table would have a name matching the population, and TimeSeries for each population.

The TDVE class optionally allows the specification of units, assumptions, and uncertainty, which each map to properties on the underlying TimeSeries objects. It also contains a time vector corresponding to the time values that appear or will appear in the spreadsheet.

Note that the units are stored within the TimeSeries objects, which means that they can are able to differ across rows.

Parameters:
  • name – The name for the quantity printed in Excel (usually a display name rather than a code name)

  • tvec (array) – Time axis (e.g. np.arange(2000,2019)) - all TimeSeries time values must exactly match one of the values here

  • ts (dict) – Optionally specify a dict of TimeSeries objects populating the rows. Could be populated after.

  • allowed_units (list) – A list/iterable containing allowed units for this quantity to populate the dropdown choices. Leave as None for no restriction

  • comment (str) – Optionally specify descriptive text that will be added as a comment to the name cell

  • pop_type (str) – A population type to associate with this table

  • default_all (bool) – Record whether the framework specifies that this TDVE should default to having an ‘All’ row instead of population-specific rows (the user can manually modify further)

  • code_name (str) – Optionally specify a code name for the quantity, which will be used to name the cell containing the (display) name

Attributes

has_data

Check whether all time series have data entered

ts_attributes

Dictionary containing extra attributes to write along with each TimeSeries object.

assumption_heading

Heading to use for assumption column

write_units

Write a column for units (if None, units will be written if any of the TimeSeries have units)

write_uncertainty

Write a column for uncertainty (if None, uncertainty will be written if any of the TimeSeries have uncertainty)

write_assumption

Write a column for assumption/constant (if None, assumption will be written if any of the TimeSeries have an assumption)

Methods

from_rows

Create new instance from Excel rows

write

Write to cells in a worksheet

assumption_heading

Heading to use for assumption column

classmethod from_rows(rows)[source]

Create new instance from Excel rows

Given a set of openpyxl rows, instantiate a TimeDependentValuesEntry object That is, the parent object e.g. ProjectData is responsible for finding where the TDVE table is, and reading all of the rows associated with it (skipping #ignored rows) and then passing those rows, unparsed, to this function

Headings for ‘units’, ‘uncertainty’, and ‘assumption’/’constant’ are optional and will be read in if they are present in the spreadsheet.

Parameters:

rows (list) – A list of rows

Returns:

A new TimeDependentValuesEntry instance

property has_data: bool

Check whether all time series have data entered

Returns:

True if all of the TimeSeries objects stored in the TDVE have data

ts_attributes

Dictionary containing extra attributes to write along with each TimeSeries object.

write(worksheet, start_row, formats, references=None, widths=None, workbook=None)[source]

Write to cells in a worksheet

Note that the year columns are drawn from the tvec attribute. To suppress the year columns (e.g. for the user to enter only an assumption) then set tvec to an empty array/list.

Parameters:
  • worksheet – An xlsxwriter worksheet instance

  • start_row – The first row in which to write values

  • formats – Format dict for the opened workbook - typically the return value of standard_formats() when the workbook was opened

  • references (dict) – References dict containing cell references for strings in the current workbook

  • widths (dict) – dict storing column widths

  • workbook (Workbook) – Optionally provide the workbook containing the worksheet (needed to write named cells)

Return type:

int

Returns:

The row index for the next available row for writing in the spreadsheet

write_assumption

Write a column for assumption/constant (if None, assumption will be written if any of the TimeSeries have an assumption)

write_uncertainty

Write a column for uncertainty (if None, uncertainty will be written if any of the TimeSeries have uncertainty)

write_units

Write a column for units (if None, units will be written if any of the TimeSeries have units)