PISM, A Parallel Ice Sheet Model  stable v1.2 committed by Constantine Khrulev on 2020-02-11 20:24:05 -0900
Public Member Functions | Private Member Functions | Private Attributes | List of all members
pism::Timeseries Class Reference

A general class for reading and accessing time-series. More...

#include <Timeseries.hh>

Public Member Functions

 Timeseries (const IceGrid &g, const std::string &name, const std::string &dimension_name)
 Timeseries (MPI_Comm com, units::System::Ptr units_system, const std::string &name, const std::string &dimension_name)
void read (const File &nc, const Time &time_manager, const Logger &log)
 Read timeseries data from a NetCDF file filename. More...
void write (const File &nc) const
 Write timeseries data to a NetCDF file filename. More...
double operator() (double time) const
 Get a value of timeseries at time t. More...
double operator[] (unsigned int j) const
 Get a value of timeseries by index. More...
double average (double t, double dt, unsigned int N) const
 Compute an average of a time-series over interval (t,t+dt) using trapezoidal rule with N sub-intervals. More...
void append (double value, double a, double b)
 Append a pair (t,v) to the timeseries. More...
void reset ()
 Clear storage. More...
TimeseriesMetadatavariable ()
TimeseriesMetadatadimension ()
TimeBoundsMetadatabounds ()
const TimeseriesMetadatavariable () const
const TimeseriesMetadatadimension () const
const TimeBoundsMetadatabounds () const
const std::vector< double > & times () const
const std::vector< double > & time_bounds () const
const std::vector< double > & values () const
void scale (double scaling_factor)
std::string name () const
bool get_use_bounds () const
void set_use_bounds (bool flag)

Private Member Functions

void set_bounds_units ()
 Ensure that time bounds have the same units as the dimension. More...
void private_constructor (MPI_Comm com, const std::string &dimension_name)
void report_range (const Logger &log)
 Report the range of a time-series stored in values. More...

Private Attributes

MPI_Comm m_com
bool m_use_bounds
TimeseriesMetadata m_dimension
TimeseriesMetadata m_variable
TimeBoundsMetadata m_bounds
std::vector< doublem_time
std::vector< doublem_values
std::vector< doublem_time_bounds

Detailed Description

A general class for reading and accessing time-series.

Scalar time-series

This class provides random access to time-series values. It is used to implement forcing with scalar time-dependent parameters (such as paleo-climate forcing).

Note that every processor stores the whole time-series and calling append() repeatedly will use a lot of memory.

Please use DiagnosticTimeseries to output long time-series.

An example

The following snippet from PAForcing::init() illustrates creating a Timeseries object and reading data from a file.

delta_T = new Timeseries(grid.com, grid.rank, "delta_T", "time");
ierr = delta_T->set_string("units", "Kelvin", ""); CHKERRQ(ierr);
ierr = delta_T->set_dimension_units("years", ""); CHKERRQ(ierr);
ierr = delta_T->set_attr("long_name", "near-surface air temperature offsets");
ierr = delta_T->read(dT_file); CHKERRQ(ierr);


double offset = (*delta_T)(time);

to get the value corresponding to the time "time", in this case in years. The value returned will be computed using linear interpolation.

It is also possible to get an n-th value from a time-series: just use square brackets:

double offset = (*delta_T)[10];

Definition at line 74 of file Timeseries.hh.

The documentation for this class was generated from the following files:
Timeseries(const IceGrid &g, const std::string &name, const std::string &dimension_name)
Definition: Timeseries.cc:35