| 12 | |
| 13 | |
| 14 | def get_modular_microgrid(remove_modules=(), |
| 15 | retain_only=None, |
| 16 | additional_modules=None, |
| 17 | add_unbalanced_module=True, |
| 18 | timeseries_length=100, |
| 19 | modules_only=False, |
| 20 | normalized_action_bounds=(0, 1)): |
| 21 | |
| 22 | modules = dict( |
| 23 | genset=GensetModule(running_min_production=10, |
| 24 | running_max_production=50, |
| 25 | genset_cost=0.5, |
| 26 | normalized_action_bounds=normalized_action_bounds), |
| 27 | |
| 28 | battery=BatteryModule(min_capacity=0, |
| 29 | max_capacity=100, |
| 30 | max_charge=50, |
| 31 | max_discharge=50, |
| 32 | efficiency=1.0, |
| 33 | init_soc=0.5, |
| 34 | normalized_action_bounds=normalized_action_bounds), |
| 35 | |
| 36 | renewable=RenewableModule(time_series=50*np.ones(timeseries_length), |
| 37 | normalized_action_bounds=normalized_action_bounds), |
| 38 | |
| 39 | load=LoadModule(time_series=60*np.ones(timeseries_length), |
| 40 | normalized_action_bounds=normalized_action_bounds), |
| 41 | |
| 42 | grid=GridModule(max_import=100, |
| 43 | max_export=100, |
| 44 | time_series=np.ones((timeseries_length, 3)), |
| 45 | normalized_action_bounds=normalized_action_bounds, |
| 46 | raise_errors=True) |
| 47 | ) |
| 48 | |
| 49 | if retain_only is not None: |
| 50 | modules = {k: v for k, v in modules.items() if k in retain_only} |
| 51 | if remove_modules: |
| 52 | raise RuntimeError('Can pass either remove_modules or retain_only, but not both.') |
| 53 | else: |
| 54 | for module in remove_modules: |
| 55 | try: |
| 56 | modules.pop(module) |
| 57 | except KeyError: |
| 58 | raise NameError(f"Module {module} not one of default modules {list(modules.keys())}.") |
| 59 | |
| 60 | modules = list(modules.values()) |
| 61 | modules.extend(additional_modules if additional_modules else []) |
| 62 | |
| 63 | if modules_only: |
| 64 | return modules |
| 65 | |
| 66 | return Microgrid(modules, add_unbalanced_module=add_unbalanced_module) |