new_modeling_toolkit.core.temporal package

Submodules

new_modeling_toolkit.core.temporal.new_temporal module

new_modeling_toolkit.core.temporal.timeseries module

class BooleanTimeseries

Bases: Timeseries

Fields:
  • DST ()

  • data ()

  • data_dir ()

  • freq_ ()

  • name ()

  • timezone ()

  • type ()

  • weather_year ()

model_post_init(_ModelMetaclass__context: Any) โ†’ None

We need to both initialize private attributes and call the user-defined model_post_init method.

class FractionalTimeseries

Bases: Timeseries

Fields:
  • DST ()

  • data ()

  • data_dir ()

  • freq_ ()

  • name ()

  • timezone ()

  • type ()

  • weather_year ()

model_post_init(_ModelMetaclass__context: Any) โ†’ None

We need to both initialize private attributes and call the user-defined model_post_init method.

class NoDateTimeseries

Bases: CustomModel

Fields:
field data: Series [Required]
field data_dir: Path | None = None
field type: TimeseriesType | None = None
model_post_init(__context: Any) โ†’ None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since thatโ€™s what pydantic-core passes when calling it.

Parameters:
  • self โ€“ The BaseModel instance.

  • __context โ€“ The context.

class NumericTimeseries

Bases: Timeseries

Fields:
  • DST ()

  • data ()

  • data_dir ()

  • freq_ ()

  • name ()

  • timezone ()

  • type ()

  • weather_year ()

model_post_init(_ModelMetaclass__context: Any) โ†’ None

We need to both initialize private attributes and call the user-defined model_post_init method.

class Timeseries

Bases: CustomModel

Fields:
field DST: bool | None = None
field data: Series [Required]
field data_dir: Path | None = None
field freq_: str | None = None
field timezone: str | None = None
field type: TimeseriesType | None = None
field weather_year: bool = False
add_index(year, interval, remove_leap_day=False)

Add datetime index to dataframe

add_leap_day(year, interval)
Parameters:

interval โ€“ Interval of timeseries in minutes. Ex: 60

Only valid when original timeseries do not contain leap day.

classmethod default_factory(value: float = 0)

Migrate all the other defaults to this one.

dict(**kwargs)

Need to exclude _data_dict attributes to avoid recursion error when saving to JSON.

classmethod from_annual_series(name: str, data: Series, **kwargs)

Try to convert a pd.Series with year (e.g., 2020) indices into a Timeseries (with DateTimeIndex).

classmethod from_csv(name: str, filepath: str | Path, **kwargs)

Lightweight wrapper around pandas.read_csv() method

classmethod from_dir(directory, filetype='csv') โ†’ Dict[str, Timeseries]

Reads all files in specified directory to Timeseries objects and returns dictionary of Timeseries objects

Parameters:
  • directory (str or pathlib.Path object) โ€“ directory containing files to be read to timeseries objects

  • filetype (str) โ€“ either โ€˜csvโ€™ or โ€˜jsonโ€™; specifies type of file being read to Timeseries objects

Returns:

dictionary containing Timeseries objects with Timeseries names as keys

Return type:

ts_dict (dict)

classmethod infinity()
model_post_init(__context: Any) โ†’ None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since thatโ€™s what pydantic-core passes when calling it.

Parameters:
  • self โ€“ The BaseModel instance.

  • __context โ€“ The context.

classmethod one()
remove_leap_day(year, interval)
Parameters:

interval โ€“ Interval of timeseries in minutes. Ex: 60

Only valid when original timeseries do contain leap day.

repeat_ts(repeat_year_dict)

Replicate the timeseries for certain times.

Parameters:
  • repeat_year_dict โ€“ a dictionary between weather/load year and data year.

  • e.g. โ€“ one year of raw DR data};

  • profiles (for Hydro) โ€“ one year of raw DR data};

  • year (the dictionary can be {extended load) โ€“ one year of raw DR data};

  • e.g. โ€“ shuffled hydro year}

  • profiles โ€“ shuffled hydro year}

  • year โ€“ shuffled hydro year}

static resample_down(df, frequency, method)

Resample timeseries by reducing the timestamps.

Parameters:
  • frequency โ€“ New frequency of timestamps. Ex: โ€˜Hโ€™ for hourly

  • method โ€“ Method for combining data into less frequent timestamps. - โ€˜sumโ€™ to add all existing values that fall into new timestamp range - โ€˜meanโ€™ to average all existing values that fall into new timestamp range - โ€˜firstโ€™ to take the first existing value within the new timestamp range

resample_month_hour_to_hourly(correct_index: DatetimeIndex)
resample_month_or_season_hour_to_hourly(correct_index: DatetimeIndex)

This is a method called by resample_ts_attributes in the Component Class which resamples monthly, month-hour, or season-hour data to the correct frequency and start and end date for a specific attribute.

resample_season_hour_to_hourly(correct_index: DatetimeIndex)
resample_simple_extend_years(weather_years: tuple[int, int])

Copies a year of data for the range of weather years. For leap years, wraps the first day of the year around for last day of leap year

Parameters:

weather_years โ€“ tuple of beginning and end of weather year range

Returns:

static resample_up(df, method)

Resample timeseries by increasing the timestamps.

Parameters:
  • frequency โ€“ New freqency of timestamps. Ex: โ€˜Hโ€™ for hourly

  • method โ€“ Method for upsampling data into more frequent timestamps. - โ€˜interpolateโ€™ to interpolate between existing values - โ€˜ffillโ€™ to forward fill value until next timestamp - โ€˜bfillโ€™ to back fill value until previous timestamp

serialize_pd_series()

This is needed for loading system from json. Without this, the default is to shrink timeseries with repeated values to a single timestamp, which does not translate correctly when resampling the timeseries attributes again because depending on the `up_methodโ€™ it might try

to interpolate for example instead of forward fill

slice_by_timepoint(temporal_settings, model_year, period, hour)

Given model_year, period, and hour, find the correct value for this time series at those times. The ts_type determines the behavior of the tp slicing. For renewable profiles, we use only the period and hour to slice the correct value. For load components, we find the correct load through load profiles that are scaled to a future year, which is not incorporated into this function right now. For all others, we directly query the corresponding datetime.

Parameters:
  • system โ€“ System object that contains the power system component and linkages

  • model_year โ€“ The year we are trying to model. Doesnโ€™t make an impact for renewable profiles

  • period โ€“ The index of the representative period weโ€™re looking for

  • hour โ€“ The hour within the representative period

Returns: Value of the current TS at the queried (model year, period, hour)

slice_by_year(year)
to_json()

Save Timeseries object to specified path.

validate_data()

Validate data passed to timeseries object

validate_timezone()

Validate timezone passed to timeseries object

classmethod zero()
property data_dict

Accessing data as a dictionary is faster than using .iloc/.loc.

Should only use this once, because this will only crease the _as_dict hidden field once. For this to be more robust, need a way to update _as_dict every time data field gets updated

https://github.com/e3-/new-modeling-toolkit/issues/597

property days_in_year: Series

Returns the number of days in each year of a timeseries

property freq
property processed_dir
class TimeseriesType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

MODELED_YEAR = 'Modeled Year'
MONTHLY = 'Monthly'
MONTH_HOUR = 'Month-Hour'
SEASON_HOUR = 'Season-Hour'
WEATHER_YEAR = 'Weather Year'

Module contents