CityLearn 2.4.0__tar.gz → 2.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/PKG-INFO +1 -1
  2. {CityLearn-2.4.0 → CityLearn-2.4.2}/PKG-INFO +1 -1
  3. CityLearn-2.4.2/citylearn/__init__.py +1 -0
  4. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/__main__.py +5 -5
  5. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/building.py +0 -4
  6. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/citylearn.py +5 -3
  7. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/data.py +14 -16
  8. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/neighborhood.py +3 -3
  9. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/occupant.py +3 -3
  10. CityLearn-2.4.2/citylearn/utilities.py +175 -0
  11. CityLearn-2.4.0/citylearn/__init__.py +0 -1
  12. CityLearn-2.4.0/citylearn/utilities.py +0 -137
  13. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/SOURCES.txt +0 -0
  14. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/dependency_links.txt +0 -0
  15. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/entry_points.txt +0 -0
  16. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/requires.txt +0 -0
  17. {CityLearn-2.4.0 → CityLearn-2.4.2}/CityLearn.egg-info/top_level.txt +0 -0
  18. {CityLearn-2.4.0 → CityLearn-2.4.2}/LICENSE +0 -0
  19. {CityLearn-2.4.0 → CityLearn-2.4.2}/MANIFEST.in +0 -0
  20. {CityLearn-2.4.0 → CityLearn-2.4.2}/README.md +0 -0
  21. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/__init__.py +0 -0
  22. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/base.py +0 -0
  23. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/marlisa.py +0 -0
  24. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/q_learning.py +0 -0
  25. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/rbc.py +0 -0
  26. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/rlc.py +0 -0
  27. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/agents/sac.py +0 -0
  28. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-0-charge-0.png +0 -0
  29. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-0-charge-1.png +0 -0
  30. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-0-charge-2.png +0 -0
  31. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-0-charge-3.png +0 -0
  32. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-1-charge-0.png +0 -0
  33. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-1-charge-1.png +0 -0
  34. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-1-charge-2.png +0 -0
  35. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/building-1-charge-3.png +0 -0
  36. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/glow.png +0 -0
  37. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/assets/grid.png +0 -0
  38. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/base.py +0 -0
  39. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/cost_function.py +0 -0
  40. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/dynamics.py +0 -0
  41. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/electric_vehicle.py +0 -0
  42. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/electric_vehicle_charger.py +0 -0
  43. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/__init__.py +0 -0
  44. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/clustering.py +0 -0
  45. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/lstm_model/__init__.py +0 -0
  46. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/lstm_model/model.py +0 -0
  47. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/lstm_model/model_generation.py +0 -0
  48. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/lstm_model/model_generation_wrapper.py +0 -0
  49. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/lstm_model/preprocessing.py +0 -0
  50. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/end_use_load_profiles/simulate.py +0 -0
  51. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/energy_model.py +0 -0
  52. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/create_zone_metadata.sql +0 -0
  53. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/select_citylearn_energy_simulation.sql +0 -0
  54. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/select_citylearn_weather.sql +0 -0
  55. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/select_ideal_loads.sql +0 -0
  56. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/select_lstm_training_data.sql +0 -0
  57. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/queries/select_zone_conditioning_metadata.sql +0 -0
  58. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/misc/settings.yaml +0 -0
  59. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/power_outage.py +0 -0
  60. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/preprocessing.py +0 -0
  61. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/reward_function.py +0 -0
  62. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/rl.py +0 -0
  63. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/__init__.py +0 -0
  64. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_battery.py +0 -0
  65. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_electric_vehicle.py +0 -0
  66. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_electric_vehicle_charger.py +0 -0
  67. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_pv.py +0 -0
  68. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_washing_machine.py +0 -0
  69. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/tests/test_weather.py +0 -0
  70. {CityLearn-2.4.0 → CityLearn-2.4.2}/citylearn/wrappers.py +0 -0
  71. {CityLearn-2.4.0 → CityLearn-2.4.2}/setup.cfg +0 -0
  72. {CityLearn-2.4.0 → CityLearn-2.4.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CityLearn
3
- Version: 2.4.0
3
+ Version: 2.4.2
4
4
  Summary: An open source Farama Foundation Gymnasium environment for benchmarking distributed energy resource control algorithms to provide energy flexibility in a district of buildings.
5
5
  Home-page: https://github.com/intelligent-environments-lab/CityLearn
6
6
  Author: Jose Ramon Vazquez-Canteli, Kingsley Nweye, Zoltan Nagy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CityLearn
3
- Version: 2.4.0
3
+ Version: 2.4.2
4
4
  Summary: An open source Farama Foundation Gymnasium environment for benchmarking distributed energy resource control algorithms to provide energy flexibility in a district of buildings.
5
5
  Home-page: https://github.com/intelligent-environments-lab/CityLearn
6
6
  Author: Jose Ramon Vazquez-Canteli, Kingsley Nweye, Zoltan Nagy
@@ -0,0 +1 @@
1
+ __version__ = '2.4.2'
@@ -18,7 +18,7 @@ from citylearn.agents.base import Agent as CityLearnAgent
18
18
  from citylearn.citylearn import CityLearnEnv
19
19
  from citylearn.data import DataSet, get_settings
20
20
  from citylearn.__init__ import __version__
21
- from citylearn.utilities import read_pickle, write_json, write_pickle
21
+ from citylearn.utilities import FileHandler
22
22
  import pandas as pd
23
23
  import simplejson as json
24
24
 
@@ -291,7 +291,7 @@ class Simulator:
291
291
  def __save_agent(self):
292
292
  if isinstance(self.agent, CityLearnAgent):
293
293
  filepath = os.path.join(self.output_directory, f'{self.simulation_id}-agent.pkl')
294
- write_pickle(filepath, self.agent)
294
+ FileHandler.write_pickle(filepath, self.agent)
295
295
 
296
296
  else:
297
297
  filepath = os.path.join(self.output_directory, f'{self.simulation_id}-agent')
@@ -307,7 +307,7 @@ class Simulator:
307
307
 
308
308
  else:
309
309
  if str(self.agent_filepath).endswith('.pkl'):
310
- agent = read_pickle(self.agent_filepath)
310
+ agent = FileHandler.read_pickle(self.agent_filepath)
311
311
  agent.env = self.env
312
312
 
313
313
  else:
@@ -349,7 +349,7 @@ class Simulator:
349
349
  simulator = cls(**kwargs)
350
350
  simulator.__evaluate()
351
351
  filepath = os.path.join(simulator.output_directory, f'{simulator.simulation_id}-evaluation.json')
352
- write_json(filepath, simulator.__get_evaluation_summary())
352
+ FileHandler.write_json(filepath, simulator.__get_evaluation_summary())
353
353
 
354
354
  @classmethod
355
355
  def train(cls, episodes: int = None, evaluate: bool = None, evaluation_episode_time_steps: Tuple[int, int] = None, save_agent: bool = None, **kwargs):
@@ -357,7 +357,7 @@ class Simulator:
357
357
  episodes = 1 if episodes is None else episodes
358
358
  simulator.__train(episodes)
359
359
  filepath = os.path.join(simulator.output_directory, f'{simulator.simulation_id}-train.json')
360
- write_json(filepath, simulator.__get_training_summary())
360
+ FileHandler.write_json(filepath, simulator.__get_training_summary())
361
361
 
362
362
  if save_agent:
363
363
  simulator.__save_agent()
@@ -1356,8 +1356,6 @@ class Building(Environment):
1356
1356
 
1357
1357
  except NotImplementedError:
1358
1358
  pass
1359
-
1360
- self.update_variables()
1361
1359
 
1362
1360
  def update_cooling_demand(self, action: float):
1363
1361
  """Update space cooling demand for current time step."""
@@ -2243,8 +2241,6 @@ class Building(Environment):
2243
2241
  self.__chargers_electricity_consumption = np.zeros(self.episode_tracker.episode_time_steps, dtype='float32')
2244
2242
  self.__washing_machines_electricity_consumption = np.zeros(self.episode_tracker.episode_time_steps, dtype='float32')
2245
2243
 
2246
- self.update_variables()
2247
-
2248
2244
  def reset_power_outage_signal(self) -> np.ndarray:
2249
2245
  """Resets power outage signal time series.
2250
2246
 
@@ -10,7 +10,6 @@ from gymnasium import Env, spaces
10
10
  import csv
11
11
  import shutil
12
12
  import datetime
13
- from itertools import zip_longest
14
13
  import numpy as np
15
14
  import pandas as pd
16
15
  import random
@@ -21,7 +20,7 @@ from citylearn.data import CarbonIntensity, DataSet, ChargerSimulation, EnergySi
21
20
  from citylearn.electric_vehicle import ElectricVehicle
22
21
  from citylearn.energy_model import Battery, PV, WashingMachine
23
22
  from citylearn.reward_function import MultiBuildingRewardFunction, RewardFunction
24
- from citylearn.utilities import read_json
23
+ from citylearn.utilities import FileHandler
25
24
 
26
25
  LOGGER = logging.getLogger()
27
26
  logging.getLogger('matplotlib.font_manager').disabled = True
@@ -796,7 +795,7 @@ class CityLearnEnv(Environment, Env):
796
795
 
797
796
  if isinstance(schema, (str, Path)) and os.path.isfile(schema):
798
797
  schema_filepath = Path(schema) if isinstance(schema, str) else schema
799
- schema = read_json(schema)
798
+ schema = FileHandler.read_json(schema)
800
799
  schema['root_directory'] = os.path.split(schema_filepath.absolute())[0] if schema['root_directory'] is None \
801
800
  else schema['root_directory']
802
801
 
@@ -1454,6 +1453,9 @@ class CityLearnEnv(Environment, Env):
1454
1453
  return self.observations, self.get_info()
1455
1454
 
1456
1455
  def update_variables(self):
1456
+ for b in self.buildings:
1457
+ b.update_variables()
1458
+
1457
1459
  # net electricity consumption
1458
1460
  self.__net_electricity_consumption.append(sum([b.net_electricity_consumption[self.time_step] for b in self.buildings]))
1459
1461
 
@@ -10,9 +10,7 @@ import requests
10
10
  from requests.adapters import HTTPAdapter
11
11
  from urllib3.util.retry import Retry
12
12
  from citylearn.__init__ import __version__
13
- from citylearn.utilities import join_url, read_json, read_yaml, write_json
14
- from citylearn.utilities import read_json, read_yaml, write_json
15
- from citylearn.utils.noise import NoiseUtils
13
+ from citylearn.utilities import FileHandler, NoiseUtils
16
14
 
17
15
  LOGGER = logging.getLogger()
18
16
  logging.basicConfig(level=logging.INFO)
@@ -26,7 +24,7 @@ SETTINGS_FILEPATH = os.path.join(MISC_DIRECTORY, 'settings.yaml')
26
24
  def get_settings():
27
25
  directory = os.path.join(os.path.join(os.path.dirname(__file__), 'misc'))
28
26
  filepath = os.path.join(directory, 'settings.yaml')
29
- settings = read_yaml(filepath)
27
+ settings = FileHandler.read_yaml(filepath)
30
28
 
31
29
  return settings
32
30
 
@@ -36,10 +34,10 @@ class DataSet:
36
34
  GITHUB_ACCOUNT = 'intelligent-environments-lab'
37
35
  REPOSITORY_NAME = 'CityLearn'
38
36
  REPOSITORY_TAG = f'v{__version__}'
39
- REPOSITORY_DATA_PATH = join_url('data')
40
- REPOSITORY_DATA_DATASETS_PATH = join_url(REPOSITORY_DATA_PATH, 'datasets')
41
- REPOSITORY_DATA_MISC_PATH = join_url(REPOSITORY_DATA_PATH, 'misc')
42
- GITHUB_API_CONTENT_URL = join_url('https://api.github.com/repos/', GITHUB_ACCOUNT, REPOSITORY_NAME, 'contents')
37
+ REPOSITORY_DATA_PATH = FileHandler.join_url('data')
38
+ REPOSITORY_DATA_DATASETS_PATH = FileHandler.join_url(REPOSITORY_DATA_PATH, 'datasets')
39
+ REPOSITORY_DATA_MISC_PATH = FileHandler.join_url(REPOSITORY_DATA_PATH, 'misc')
40
+ GITHUB_API_CONTENT_URL = FileHandler.join_url('https://api.github.com/repos/', GITHUB_ACCOUNT, REPOSITORY_NAME, 'contents')
43
41
  DEFAULT_CACHE_DIRECTORY = os.path.join(user_cache_dir('citylearn'), REPOSITORY_TAG)
44
42
  BATTERY_CHOICES_FILENAME = 'battery_choices.yaml'
45
43
  PV_CHOICES_FILENAME = 'lbl-tracking_the_sun-res-pv.csv'
@@ -114,7 +112,7 @@ class DataSet:
114
112
 
115
113
  def get_schema(self, name: str) -> dict:
116
114
  schema_filepath = self.get_dataset(name)
117
- schema = read_json(schema_filepath)
115
+ schema = FileHandler.read_json(schema_filepath)
118
116
  schema['root_directory'] = os.path.split(Path(schema_filepath).absolute())[0]
119
117
 
120
118
  return schema
@@ -123,7 +121,7 @@ class DataSet:
123
121
  datasets_directory = os.path.join(self.cache_directory, 'datasets')
124
122
  root_directory = os.path.join(datasets_directory, name)
125
123
  schema_filepath = os.path.join(root_directory, 'schema.json')
126
- path = join_url(self.datasets_path, name)
124
+ path = FileHandler.join_url(self.datasets_path, name)
127
125
 
128
126
  # check that dataset does not already exist using the schema as a proxy
129
127
  LOGGER.info(f'Go here {schema_filepath} ')
@@ -172,7 +170,7 @@ class DataSet:
172
170
  filepath = os.path.join(self.cache_directory, 'dataset_names.json')
173
171
 
174
172
  if os.path.isfile(filepath):
175
- contents = read_json(filepath)
173
+ contents = FileHandler.read_json(filepath)
176
174
 
177
175
  else:
178
176
  LOGGER.info(f'The dataset names DNE in cache. Will download from '
@@ -184,7 +182,7 @@ class DataSet:
184
182
  if r.get('type') == 'dir'
185
183
  and r.get('path').replace(r['name'], '').strip('/') == self.datasets_path
186
184
  ]
187
- write_json(filepath, contents)
185
+ FileHandler.write_json(filepath, contents)
188
186
 
189
187
  contents = sorted(contents)
190
188
 
@@ -201,7 +199,7 @@ class DataSet:
201
199
  misc_directory = os.path.join(self.cache_directory, 'misc')
202
200
  os.makedirs(misc_directory, exist_ok=True)
203
201
  filepath = os.path.join(misc_directory, self.PV_CHOICES_FILENAME)
204
- path = join_url(self.misc_path)
202
+ path = FileHandler.join_url(self.misc_path)
205
203
 
206
204
  # check that file DNE
207
205
  if not os.path.isfile(filepath):
@@ -234,7 +232,7 @@ class DataSet:
234
232
  misc_directory = os.path.join(self.cache_directory, 'misc')
235
233
  os.makedirs(misc_directory, exist_ok=True)
236
234
  filepath = os.path.join(misc_directory, self.BATTERY_CHOICES_FILENAME)
237
- path = join_url(self.misc_path)
235
+ path = FileHandler.join_url(self.misc_path)
238
236
 
239
237
  # check that file DNE
240
238
  if not os.path.isfile(filepath):
@@ -252,7 +250,7 @@ class DataSet:
252
250
  else:
253
251
  pass
254
252
 
255
- data = read_yaml(filepath)
253
+ data = FileHandler.read_yaml(filepath)
256
254
  data = pd.DataFrame([{'model': k, **v['attributes']} for k, v in data.items()])
257
255
  data = data.set_index('model')
258
256
 
@@ -266,7 +264,7 @@ class DataSet:
266
264
  pass
267
265
 
268
266
  def get_github_contents(self, path: str = None) -> List[Mapping[str, Any]]:
269
- url = self.GITHUB_API_CONTENT_URL if path is None else join_url(self.GITHUB_API_CONTENT_URL, path)
267
+ url = self.GITHUB_API_CONTENT_URL if path is None else FileHandler.join_url(self.GITHUB_API_CONTENT_URL, path)
270
268
  params = dict(ref=self.tag)
271
269
  contents = self.get_requests_session().get(url, params=params)
272
270
 
@@ -23,7 +23,7 @@ from citylearn.end_use_load_profiles.clustering import MetadataClustering
23
23
  from citylearn.end_use_load_profiles.lstm_model.model_generation_wrapper import run_one_model
24
24
  from citylearn.end_use_load_profiles.simulate import EndUseLoadProfilesEnergyPlusPartialLoadSimulator
25
25
  from citylearn.preprocessing import PeriodicNormalization, Normalize
26
- from citylearn.utilities import read_json, write_json
26
+ from citylearn.utilities import FileHandler
27
27
 
28
28
  BuildingSimulators = Mapping[
29
29
  str,
@@ -255,7 +255,7 @@ class Neighborhood:
255
255
 
256
256
  def test_lstm(self, bldg_ix: int, training_data: pd.DataFrame, schema_filepath: Path) -> Tuple[int, pd.DataFrame]:
257
257
  # set data
258
- schema = read_json(schema_filepath)
258
+ schema = FileHandler.read_json(schema_filepath)
259
259
  schema_directory = Path(schema_filepath).parents[0]
260
260
  bldg_key = list(schema['buildings'].keys())[bldg_ix]
261
261
  dynamics_model = schema['buildings'][bldg_key]['dynamics']
@@ -511,7 +511,7 @@ class Neighborhood:
511
511
 
512
512
  schema_filepath = os.path.join(schema_directory, f'schema.json')
513
513
  template = user_customization_function(template) if user_customization_function is not None else template
514
- write_json(schema_filepath, template)
514
+ FileHandler.write_json(schema_filepath, template)
515
515
 
516
516
  return schema_filepath
517
517
 
@@ -4,7 +4,7 @@ import numpy as np
4
4
  from sklearn.tree import DecisionTreeClassifier
5
5
  from citylearn.base import Environment
6
6
  from citylearn.data import LogisticRegressionOccupantParameters
7
- from citylearn.utilities import read_pickle
7
+ from citylearn.utilities import FileHandler
8
8
 
9
9
  class Occupant(Environment):
10
10
  def __init__(self, **kwargs) -> None:
@@ -48,12 +48,12 @@ class LogisticRegressionOccupant(Occupant):
48
48
  @setpoint_increase_model_filepath.setter
49
49
  def setpoint_increase_model_filepath(self, value: Union[Path, str]):
50
50
  self.__setpoint_increase_model_filepath = value
51
- self.__setpoint_increase_model = read_pickle(self.setpoint_increase_model_filepath)
51
+ self.__setpoint_increase_model = FileHandler.read_pickle(self.setpoint_increase_model_filepath)
52
52
 
53
53
  @setpoint_decrease_model_filepath.setter
54
54
  def setpoint_decrease_model_filepath(self, value: Union[Path, str]):
55
55
  self.__setpoint_decrease_model_filepath = value
56
- self.__setpoint_decrease_model = read_pickle(self.setpoint_decrease_model_filepath)
56
+ self.__setpoint_decrease_model = FileHandler.read_pickle(self.setpoint_decrease_model_filepath)
57
57
 
58
58
  @delta_output_map.setter
59
59
  def delta_output_map(self, value: Mapping[Union[str, int], float]):
@@ -0,0 +1,175 @@
1
+ import pickle
2
+ from typing import Any, Iterable, Union
3
+ import numpy as np
4
+ import simplejson as json
5
+ import yaml
6
+
7
+ class FileHandler:
8
+ @staticmethod
9
+ def read_json(filepath: str, **kwargs) -> dict:
10
+ """Return JSON document as dictionary.
11
+
12
+ Parameters
13
+ ----------
14
+ filepath : str
15
+ pathname of JSON document.
16
+
17
+ Other Parameters
18
+ ----------------
19
+ **kwargs : dict
20
+ Other infrequently used keyword arguments to be parsed to `simplejson.load`.
21
+
22
+ Returns
23
+ -------
24
+ dict
25
+ JSON document converted to dictionary.
26
+ """
27
+
28
+ with open(filepath) as f:
29
+ json_file = json.load(f, **kwargs)
30
+
31
+ return json_file
32
+
33
+ @staticmethod
34
+ def write_json(filepath: str, dictionary: dict, **kwargs):
35
+ """Write dictionary to JSON file.
36
+
37
+ Parameters
38
+ ----------
39
+ filepath : str
40
+ pathname of JSON document.
41
+ dictionary: dict
42
+ dictionary to convert to JSON.
43
+
44
+ Other Parameters
45
+ ----------------
46
+ **kwargs : dict
47
+ Other infrequently used keyword arguments to be parsed to `simplejson.dump`.
48
+ """
49
+
50
+ kwargs = {'ignore_nan': True, 'sort_keys': False, 'default': str, 'indent': 2, **kwargs}
51
+
52
+ with open(filepath,'w') as f:
53
+ json.dump(dictionary, f, **kwargs)
54
+
55
+ @staticmethod
56
+ def read_yaml(filepath: str) -> dict:
57
+ """Return YAML document as dictionary.
58
+
59
+ Parameters
60
+ ----------
61
+ filepath : str
62
+ pathname of YAML document.
63
+
64
+ Returns
65
+ -------
66
+ dict
67
+ YAML document converted to dictionary.
68
+ """
69
+
70
+ with open(filepath, 'r') as f:
71
+ data = yaml.safe_load(f)
72
+
73
+ return data
74
+
75
+ @staticmethod
76
+ def write_yaml(filepath: str, dictionary: dict, **kwargs):
77
+ """Write dictionary to YAML file.
78
+
79
+ Parameters
80
+ ----------
81
+ filepath : str
82
+ pathname of YAML document.
83
+ dictionary: dict
84
+ dictionary to convert to YAML.
85
+
86
+ Other Parameters
87
+ ----------------
88
+ **kwargs : dict
89
+ Other infrequently used keyword arguments to be parsed to `yaml.safe_dump`.
90
+ """
91
+
92
+ kwargs = {'sort_keys': False, 'indent': 2, **kwargs}
93
+
94
+ with open(filepath, 'w') as f:
95
+ yaml.safe_dump(dictionary, f, **kwargs)
96
+
97
+ @staticmethod
98
+ def read_pickle(filepath: str, **kwargs) -> Any:
99
+ """Return pickle file as some Python class object.
100
+
101
+ Parameters
102
+ ----------
103
+ filepath : str
104
+ pathname of pickle file.
105
+
106
+ Other Parameters
107
+ ----------------
108
+ **kwargs : dict
109
+ Other infrequently used keyword arguments to be parsed to `pickle.load`.
110
+
111
+ Returns
112
+ -------
113
+ Any
114
+ Pickle file as a Python object.
115
+ """
116
+
117
+ with (open(filepath, 'rb')) as f:
118
+ data = pickle.load(f, **kwargs)
119
+
120
+ return data
121
+
122
+ @staticmethod
123
+ def write_pickle(filepath: str, data: Any, **kwargs):
124
+ """Write Python object to pickle file.
125
+
126
+ Parameters
127
+ ----------
128
+ filepath : str
129
+ pathname of pickle document.
130
+ data: dict
131
+ object to convert to pickle.
132
+
133
+ Other Parameters
134
+ ----------------
135
+ **kwargs : dict
136
+ Other infrequently used keyword arguments to be parsed to `pickle.dump`.
137
+ """
138
+
139
+ with open(filepath, 'wb') as f:
140
+ pickle.dump(data, f, **kwargs)
141
+
142
+ @staticmethod
143
+ def join_url(*args: str) -> str:
144
+ url = '/'.join([a.strip('/') for a in args])
145
+
146
+ return url
147
+
148
+ class NoiseUtils:
149
+ @staticmethod
150
+ def generate_gaussian_noise(input_data: Union[np.ndarray, Iterable[float]], noise_std: float) -> np.ndarray:
151
+ """Generates Gaussian noise matching input shape.
152
+
153
+ Parameters
154
+ ----------
155
+ input_data : Union[np.ndarray, Iterable[float]]
156
+ Time series to add noise to.
157
+ noise_std : float
158
+ Noise standard deviation (ignored if <= 0)
159
+
160
+ Returns
161
+ -------
162
+ noise: np.ndarray
163
+ Zero-mean noise array with same shape as input
164
+ """
165
+
166
+ arr = np.asarray(input_data) # Handles both ndarray and Iterable
167
+ if noise_std <= 0:
168
+ return np.zeros(arr.shape)
169
+ return np.random.normal(loc=0, scale=noise_std, size=arr.shape)
170
+
171
+ @staticmethod
172
+ def generate_scaled_noise(input_data: Union[np.ndarray, Iterable[float]], noise_std: float, scale: float = 1.0) -> np.ndarray:
173
+ """Generates pre-scaled noise (e.g., for percentage values)."""
174
+
175
+ return NoiseUtils.generate_gaussian_noise(input_data, noise_std) * scale
@@ -1 +0,0 @@
1
- __version__ = '2.4.0'
@@ -1,137 +0,0 @@
1
- import pickle
2
- from typing import Any
3
- import simplejson as json
4
- import yaml
5
-
6
- def read_json(filepath: str, **kwargs) -> dict:
7
- """Return JSON document as dictionary.
8
-
9
- Parameters
10
- ----------
11
- filepath : str
12
- pathname of JSON document.
13
-
14
- Other Parameters
15
- ----------------
16
- **kwargs : dict
17
- Other infrequently used keyword arguments to be parsed to `simplejson.load`.
18
-
19
- Returns
20
- -------
21
- dict
22
- JSON document converted to dictionary.
23
- """
24
-
25
- with open(filepath) as f:
26
- json_file = json.load(f, **kwargs)
27
-
28
- return json_file
29
-
30
- def write_json(filepath: str, dictionary: dict, **kwargs):
31
- """Write dictionary to JSON file.
32
-
33
- Parameters
34
- ----------
35
- filepath : str
36
- pathname of JSON document.
37
- dictionary: dict
38
- dictionary to convert to JSON.
39
-
40
- Other Parameters
41
- ----------------
42
- **kwargs : dict
43
- Other infrequently used keyword arguments to be parsed to `simplejson.dump`.
44
- """
45
-
46
- kwargs = {'ignore_nan': True, 'sort_keys': False, 'default': str, 'indent': 2, **kwargs}
47
-
48
- with open(filepath,'w') as f:
49
- json.dump(dictionary, f, **kwargs)
50
-
51
- def read_yaml(filepath: str) -> dict:
52
- """Return YAML document as dictionary.
53
-
54
- Parameters
55
- ----------
56
- filepath : str
57
- pathname of YAML document.
58
-
59
- Returns
60
- -------
61
- dict
62
- YAML document converted to dictionary.
63
- """
64
-
65
- with open(filepath, 'r') as f:
66
- data = yaml.safe_load(f)
67
-
68
- return data
69
-
70
- def write_yaml(filepath: str, dictionary: dict, **kwargs):
71
- """Write dictionary to YAML file.
72
-
73
- Parameters
74
- ----------
75
- filepath : str
76
- pathname of YAML document.
77
- dictionary: dict
78
- dictionary to convert to YAML.
79
-
80
- Other Parameters
81
- ----------------
82
- **kwargs : dict
83
- Other infrequently used keyword arguments to be parsed to `yaml.safe_dump`.
84
- """
85
-
86
- kwargs = {'sort_keys': False, 'indent': 2, **kwargs}
87
-
88
- with open(filepath, 'w') as f:
89
- yaml.safe_dump(dictionary, f, **kwargs)
90
-
91
- def read_pickle(filepath: str, **kwargs) -> Any:
92
- """Return pickle file as some Python class object.
93
-
94
- Parameters
95
- ----------
96
- filepath : str
97
- pathname of pickle file.
98
-
99
- Other Parameters
100
- ----------------
101
- **kwargs : dict
102
- Other infrequently used keyword arguments to be parsed to `pickle.load`.
103
-
104
- Returns
105
- -------
106
- Any
107
- Pickle file as a Python object.
108
- """
109
-
110
- with (open(filepath, 'rb')) as f:
111
- data = pickle.load(f, **kwargs)
112
-
113
- return data
114
-
115
- def write_pickle(filepath: str, data: Any, **kwargs):
116
- """Write Python object to pickle file.
117
-
118
- Parameters
119
- ----------
120
- filepath : str
121
- pathname of pickle document.
122
- data: dict
123
- object to convert to pickle.
124
-
125
- Other Parameters
126
- ----------------
127
- **kwargs : dict
128
- Other infrequently used keyword arguments to be parsed to `pickle.dump`.
129
- """
130
-
131
- with open(filepath, 'wb') as f:
132
- pickle.dump(data, f, **kwargs)
133
-
134
- def join_url(*args: str) -> str:
135
- url = '/'.join([a.strip('/') for a in args])
136
-
137
- return url
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes