citylearn.utilities module

class citylearn.utilities.FileHandler[source]

Bases: object

static join_url(*args: str) str[source]
static read_json(filepath: str, **kwargs) dict[source]

Return JSON document as dictionary.

Parameters:
  • filepath (str)

  • document. (pathname of JSON)

  • **kwargs (dict) – Other infrequently used keyword arguments to be parsed to simplejson.load.

Returns:

JSON document converted to dictionary.

Return type:

dict

static read_pickle(filepath: str, **kwargs) Any[source]

Return pickle file as some Python class object.

Parameters:
  • filepath (str)

  • file. (pathname of pickle)

  • **kwargs (dict) – Other infrequently used keyword arguments to be parsed to pickle.load.

Returns:

Pickle file as a Python object.

Return type:

Any

static read_yaml(filepath: str) dict[source]

Return YAML document as dictionary.

Parameters:
  • filepath (str)

  • document. (pathname of YAML)

Returns:

YAML document converted to dictionary.

Return type:

dict

static write_json(filepath: str, dictionary: dict, **kwargs)[source]

Write dictionary to JSON file.

Parameters:
  • filepath (str) – pathname of JSON document.

  • dictionary (dict) – dictionary to convert to JSON.

  • **kwargs (dict) – Other infrequently used keyword arguments to be parsed to simplejson.dump.

static write_pickle(filepath: str, data: Any, **kwargs)[source]

Write Python object to pickle file.

Parameters:
  • filepath (str) – pathname of pickle document.

  • data (dict) – object to convert to pickle.

  • **kwargs (dict) – Other infrequently used keyword arguments to be parsed to pickle.dump.

static write_yaml(filepath: str, dictionary: dict, **kwargs)[source]

Write dictionary to YAML file.

Parameters:
  • filepath (str) – pathname of YAML document.

  • dictionary (dict) – dictionary to convert to YAML.

  • **kwargs (dict) – Other infrequently used keyword arguments to be parsed to yaml.safe_dump.

class citylearn.utilities.NoiseUtils[source]

Bases: object

static generate_gaussian_noise(input_data: ndarray | Iterable[float], noise_std: float) ndarray[source]

Generates Gaussian noise matching input shape.

Parameters:
  • input_data (Union[np.ndarray, Iterable[float]]) – Time series to add noise to.

  • noise_std (float) – Noise standard deviation (ignored if <= 0)

Returns:

noise – Zero-mean noise array with same shape as input

Return type:

np.ndarray

static generate_scaled_noise(input_data: ndarray | Iterable[float], noise_std: float, scale: float = 1.0) ndarray[source]

Generates pre-scaled noise (e.g., for percentage values).