sustaingym.envs.evcharging.utils
#
Implements utility methods for interacting with ACN-data and GMMs.
- When run on its own, this script downloads the default data found in
sustaingym/data/evcharging/acn_data.
Module Contents#
Functions#
|
Converts string '%Y-%m-%d' to datetime localized in LA Time. |
|
Returns charging network from string. |
|
Retrieves charging sessions using ACNData. |
|
Returns a pandas DataFrame of charging events from ACN-Data. |
|
Returns a pandas DataFrame of charging events. |
|
Returns folder name for a trained GMM. |
|
Saves GMM (presumably trained) and other information to directory. |
|
Load pickled GMM and other data from folder. |
|
Round array values when decimal is above threshold. |
|
Downloads default data from ACNData. |
Attributes#
- sustaingym.envs.evcharging.utils.DEFAULT_DATE_RANGES = (('2019-05-01', '2019-08-31'), ('2019-09-01', '2019-12-31'), ('2020-02-01', '2020-05-31'),...[source]#
- sustaingym.envs.evcharging.utils.to_la_dt(s: str) datetime.datetime [source]#
Converts string ‘%Y-%m-%d’ to datetime localized in LA Time.
- Parameters:
s (str) –
- Return type:
datetime.datetime
- sustaingym.envs.evcharging.utils.site_str_to_site(site: SiteStr) acnportal.acnsim.ChargingNetwork [source]#
Returns charging network from string.
- Parameters:
site (SiteStr) –
- Return type:
acnportal.acnsim.ChargingNetwork
- sustaingym.envs.evcharging.utils.get_sessions(start_date: datetime.datetime, end_date: datetime.datetime, site: SiteStr = 'caltech') collections.abc.Iterator[dict[str, Any]] [source]#
Retrieves charging sessions using ACNData.
- Parameters:
start_date (datetime.datetime) – beginning time of interval. Only year, month, and day are considered. The datetime is expected to be localized in LA time, the timezone of the charging garages.
end_date (datetime.datetime) – ending time of interval, exclusive. See
start_date
.site (SiteStr) – ‘caltech’ or ‘jpl’
- Returns:
sessions – iterator of sessions with a connection time starting on
start_date
and ending the day beforeend_date
- Return type:
collections.abc.Iterator[dict[str, Any]]
Example:
fall2020_sessions = get_sessions( datetime(2020, 9, 1), datetime(2020, 12, 1))
- sustaingym.envs.evcharging.utils.fetch_real_events(start_date: datetime.datetime, end_date: datetime.datetime, site: SiteStr) pandas.DataFrame [source]#
Returns a pandas DataFrame of charging events from ACN-Data.
See
get_sessions()
for arguments.- Returns:
events – DataFrame containing charging info
arrival datetime64[ns, America/Los_Angeles] departure datetime64[ns, America/Los_Angeles] requested_energy (kWh) float64 delivered_energy (kWh) float64 station_id str session_id str estimated_departure datetime64[ns, America/Los_Angeles] claimed bool
- Parameters:
start_date (datetime.datetime) –
end_date (datetime.datetime) –
site (SiteStr) –
- Return type:
pandas.DataFrame
- sustaingym.envs.evcharging.utils.get_real_events(start_date: datetime.datetime, end_date: datetime.datetime, site: SiteStr) pandas.DataFrame [source]#
Returns a pandas DataFrame of charging events.
Either loads data from package or retrieves from ACN-Data.
See
fetch_real_events()
for arguments and return value, except function is now inclusive ofend_date
.- Parameters:
start_date (datetime.datetime) –
end_date (datetime.datetime) –
site (SiteStr) –
- Return type:
pandas.DataFrame
- sustaingym.envs.evcharging.utils.get_model_name(begin: datetime.datetime, end: datetime.datetime, n_components: int) str [source]#
Returns folder name for a trained GMM.
- Parameters:
begin (datetime.datetime) –
end (datetime.datetime) –
n_components (int) –
- Return type:
str
- sustaingym.envs.evcharging.utils.save_gmm_model(site: SiteStr, gmm: sklearn.mixture.GaussianMixture, cnt: numpy.ndarray, sid: numpy.ndarray, begin: datetime.datetime, end: datetime.datetime, n_components: int) None [source]#
Saves GMM (presumably trained) and other information to directory.
- Parameters:
site (SiteStr) – either ‘caltech’ or ‘jpl’
gmm (sklearn.mixture.GaussianMixture) – trained Gaussian Mixture Model
cnt (numpy.ndarray) – a 1-D np.ndarray session counts per day during date period, expected to have the same length as the number of days, inclusive, in the date period
sid (numpy.ndarray) – a 1-D np.ndarray stations’ usage counts for entire date period, expected to have the same length as the number of stations in the network
begin (datetime.datetime) – beginning of training period, for folder name
end (datetime.datetime) – ending of training period, for folder name
n_components (int) – number of GMM components
- Return type:
None
- sustaingym.envs.evcharging.utils.load_gmm_model(site: SiteStr, begin: datetime.datetime, end: datetime.datetime, n_components: int) dict[str, numpy.ndarray | sklearn.mixture.GaussianMixture] [source]#
Load pickled GMM and other data from folder.
If searching for a custom model, searches relative to the current working directory in
GMMS_DIR
. If searching for a default model, searches inside the data folder.- Parameters:
site (SiteStr) – either ‘caltech’ or ‘jpl’
begin (datetime.datetime) – start date of date range GMM is trained in
end (datetime.datetime) – end date of date range GMM is trained in
n_components (int) – number of GMM components
- Returns:
data – dict containing the following key-value pairs:
‘gmm’: mixture.GaussianMixture, trained gmm, date range and components are specified on folder
‘count’: np.ndarray, session counts per day
‘station_usage’: np.ndarray, stations’ usage counts for date range
- Return type:
dict[str, numpy.ndarray | sklearn.mixture.GaussianMixture]
- sustaingym.envs.evcharging.utils.round(arr: numpy.ndarray, thresh: float = 0.7) numpy.ndarray [source]#
Round array values when decimal is above threshold.
Same as np.round if thresh = 0.5
- Parameters:
arr (numpy.ndarray) – input array
thresh (float) – decimal between 0 and 1
- Returns:
rounded array
- Return type:
numpy.ndarray