Skip to content

Commit 897e15a

Browse files
committed
fix docs for pip
1 parent fe011db commit 897e15a

5 files changed

Lines changed: 126 additions & 35 deletions

File tree

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11

2-
## WEC-Grid: Integrating Wave Energy Converters into Power Grid Simulations
2+
# WEC-Grid: Integrating Wave Energy Converters into Power Grid Simulations
3+
4+
<div style="clear: both; text-align: center;">
5+
<img src="./docs/assets/WEC-Grid_mini_white.png" alt="WEC-Grid Logo" style="width: 80%; height: auto;">
6+
</div>
37

48
**WEC-Grid** is an open-source Python library crafted to simulate the integration of Wave Energy Converters (WECs) power grid simulators like [PSS®E](https://new.siemens.com/global/en/products/energy/services/transmission-distribution-smart-grid/consulting-and-planning/pss-software/pss-e.html) & [PyPSA](https://pypsa.org/).
59

610
**Documentation**: [acep-uaf.github.io/WEC-Grid](https://acep-uaf.github.io/WEC-Grid/)
711

8-
9-
### Introduction
10-
11-
<!-- Amidst the global shift towards sustainable energy solutions, Wave Energy Converters (WECs) emerge as groundbreaking innovations. These tools harbor the potential to tap into the energy reserves of our oceans. Yet, to weave them into intricate systems like microgrids, a profound modeling, testing, and analysis regimen is indispensable. WEC-Grid, presented through this Jupyter notebook, is a beacon of both demonstration and guidance, capitalizing on an open-source software to transcend these integration impediments. -->
12-
13-
### Overview
14-
15-
16-
<!-- WEC-Grid is in its nascent stages, yet it presents a Python Jupyter Notebook that successfully establishes a PSSe API connection. It can solve both static AC & DC power flows, injecting data from a WEC device. Additionally, WEC-Grid comes equipped with rudimentary formatting tools for data analytics. The modular design ensures support for a selected power flow solving software and WEC devices.
17-
18-
For the current implementations, WEC-Grid is compatible with PSSe and [WEC-SIM](https://wec-sim.github.io/WEC-Sim/). The widespread application of PSSe in the power systems industry, coupled with its robust API, makes it an ideal choice. -->
19-
2012
---
2113

2214
### Software Setup
@@ -78,3 +70,21 @@ For the current implementations, WEC-Grid is compatible with PSSe and [WEC-SIM](
7870
```bash
7971
pytest -v
8072
```
73+
74+
---
75+
76+
### Configuration
77+
78+
You can configure paths via code or environment variables.
79+
80+
- Database path
81+
- Quick (env var): set `WECGRID_DB_PATH` to your SQLite database
82+
- Windows (PowerShell): `$env:WECGRID_DB_PATH = "C:\\path\\to\\WECGrid.db"`
83+
- macOS/Linux (bash/zsh): `export WECGRID_DB_PATH=~/path/to/WECGrid.db`
84+
- Persistent (code): `engine.database.set_database_path("/path/to/WECGrid.db")`
85+
- This writes a JSON config into your user config directory (e.g., `~/.wecgrid/database_config.json`).
86+
87+
- WEC‑Sim path (MATLAB install)
88+
- Quick (env var): set `WECGRID_WECSIM_PATH` to the WEC‑Sim folder
89+
- Persistent (code): `engine.wecsim.set_wec_sim_path("/path/to/WEC-Sim")`
90+
- Stored in your user config directory (e.g., `~/.wecgrid/wecsim_config.json`).

docs/wecgrid/database.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,25 @@ from wecgrid import Engine
220220
# Initialize engine with database configuration
221221
engine = Engine()
222222

223-
# First-time setup: configure database path
223+
# First-time setup: configure database path (persists to user config)
224224
engine.database.set_database_path(r"C:\path\to\WECGrid.db")
225225

226226
# Or initialize new database with schema
227227
engine.database.initialize_database(r"C:\path\to\new_database.db")
228228
```
229229

230+
Alternatively, set an environment variable to point to the database (no code needed):
231+
232+
```text
233+
# Windows PowerShell
234+
$env:WECGRID_DB_PATH = "C:\path\to\WECGrid.db"
235+
236+
# macOS/Linux
237+
export WECGRID_DB_PATH=~/path/to/WECGrid.db
238+
```
239+
240+
Note: WEC‑Grid stores persistent configuration in a user‑writable directory (e.g., `~/.wecgrid/`).
241+
230242
### Storing Simulation Results
231243

232244
```python
@@ -296,9 +308,9 @@ voltage_diff = abs(psse_buses['v_mag'] - pypsa_buses['v_mag'])
296308
- **Indexing**: Composite indexes optimize time-series query performance
297309

298310
### Configuration Management
299-
- **JSON Configuration**: Database path stored in `database_config.json`
300-
- **First-Time Setup**: User-guided configuration process
301-
- **Path Flexibility**: Support for absolute paths and relative workspace locations
311+
- **Environment Variable**: `WECGRID_DB_PATH` can set the database path
312+
- **User Config**: `database_config.json` stored in your user config dir (e.g., `~/.wecgrid/`)
313+
- **First-Time Setup**: User-guided configuration via `set_database_path()` or `initialize_database()`
302314

303315
---
304316

@@ -365,4 +377,3 @@ recent_power = engine.database.query(
365377
- **[PSS®E Integration](psse.md)**: Commercial power system backend
366378
- **[PyPSA Integration](pypsa.md)**: Open-source power system backend
367379
- **[WEC Integration](wec.md)**: WEC farm and device data management
368-

docs/wecgrid/wecsim.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ wecsim.set_wec_sim_path("/path/to/WEC-Sim")
159159
wecsim.show_config() # Verify configuration
160160
```
161161

162+
Alternatively, configure via environment variable (overrides config file):
163+
164+
```text
165+
# Windows PowerShell
166+
$env:WECGRID_WECSIM_PATH = "C:\\path\\to\\WEC-Sim"
167+
168+
# macOS/Linux
169+
export WECGRID_WECSIM_PATH=~/path/to/WEC-Sim
170+
```
171+
172+
WECSimRunner stores persistent configuration in a user‑writable directory (e.g., `~/.wecgrid/wecsim_config.json`).
173+
162174
### Model Directory Structure
163175
```
164176
model_path/
@@ -212,4 +224,4 @@ wec_sim_id = wecsim(
212224
### Performance Considerations
213225
- Reduce simulation length for testing workflows
214226
- Increase time step for faster execution (trade-off with accuracy)
215-
- Use smaller wave heights to avoid numerical instabilities
227+
- Use smaller wave heights to avoid numerical instabilities

src/wecgrid/modelers/wec_sim/runner.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@
1818
# Local
1919
from wecgrid.util import WECGridDB
2020

21-
# Configuration file path
22-
_CURR_DIR = os.path.dirname(os.path.abspath(__file__))
23-
_CONFIG_FILE = os.path.join(_CURR_DIR, "wecsim_config.json")
21+
from pathlib import Path
22+
23+
24+
def _user_config_dir() -> Path:
25+
"""Return a user-writable config directory for WEC-Grid.
26+
27+
Uses ``platformdirs`` if available, otherwise falls back to ``~/.wecgrid``.
28+
"""
29+
try:
30+
from platformdirs import user_config_dir # type: ignore
31+
32+
return Path(user_config_dir(appname="wecgrid", appauthor=False))
33+
except Exception:
34+
return Path.home() / ".wecgrid"
35+
36+
37+
# Configuration file path (user-specific)
38+
_CONFIG_FILE = _user_config_dir() / "wecsim_config.json"
2439

2540

2641
class WECSimRunner:
@@ -58,18 +73,25 @@ def __init__(self, database: WECGridDB):
5873
self.matlab_engine = None
5974

6075
def _load_config(self) -> None:
61-
"""Load WEC-Sim configuration from JSON file."""
76+
"""Load WEC-Sim configuration from env var or JSON file."""
77+
# Highest priority: environment variable
78+
env_path = os.getenv("WECGRID_WECSIM_PATH")
79+
if env_path:
80+
self.wec_sim_path = env_path
81+
return
82+
6283
try:
63-
if os.path.exists(_CONFIG_FILE):
84+
if _CONFIG_FILE.exists():
6485
with open(_CONFIG_FILE, "r") as f:
6586
config = json.load(f)
6687
self.wec_sim_path = config.get("wec_sim_path")
6788
except Exception as e:
6889
print(f"Warning: Could not load WEC-Sim config: {e}")
6990

7091
def _save_config(self) -> None:
71-
"""Save WEC-Sim configuration to JSON file."""
92+
"""Save WEC-Sim configuration to user JSON file."""
7293
try:
94+
_CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
7395
config = {"wec_sim_path": self.wec_sim_path}
7496
with open(_CONFIG_FILE, "w") as f:
7597
json.dump(config, f, indent=2)
@@ -106,10 +128,11 @@ def show_config(self) -> None:
106128
Prints the currently configured WEC-Sim path along with the location of
107129
the configuration file used to persist this setting.
108130
"""
109-
print(f"WEC-Sim Configuration:")
131+
print("WEC-Sim Configuration:")
110132
print(f" Path: {self.wec_sim_path or 'Not configured'}")
111133
print(f" Config file: {_CONFIG_FILE}")
112-
print(f" Config exists: {os.path.exists(_CONFIG_FILE)}")
134+
print(f" Config exists: {_CONFIG_FILE.exists()}")
135+
print(" Env var: WECGRID_WECSIM_PATH (overrides config if set)")
113136

114137
def start_matlab(self) -> bool:
115138
"""Initialize MATLAB engine and configure WEC-Sim framework paths.

src/wecgrid/util/database.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
"""Database utilities for WEC-Grid."""
1+
"""Database utilities for WEC-Grid.
2+
3+
Configuration resolution order for database path:
4+
- Environment variable ``WECGRID_DB_PATH`` (if set)
5+
- User config file at ``<user-config>/wecgrid/database_config.json``
6+
- Otherwise, user is prompted to configure a path via API methods
7+
"""
28

39
# Standard library
410
import json
@@ -17,20 +23,44 @@
1723
import pandas as pd
1824

1925

26+
def _user_config_dir() -> Path:
27+
"""Return a user-writable config directory for WEC-Grid.
28+
29+
Uses ``platformdirs`` if available, otherwise falls back to ``~/.wecgrid``.
30+
"""
31+
try:
32+
from platformdirs import user_config_dir # type: ignore
33+
34+
return Path(user_config_dir(appname="wecgrid", appauthor=False))
35+
except Exception:
36+
return Path.home() / ".wecgrid"
37+
38+
39+
def _db_config_file() -> Path:
40+
return _user_config_dir() / "database_config.json"
41+
42+
2043
def get_database_config():
21-
"""Load database configuration from JSON file.
44+
"""Resolve database path from env var or user config file.
45+
46+
Resolution order:
47+
1) ``WECGRID_DB_PATH`` environment variable
48+
2) ``<user-config>/wecgrid/database_config.json``
2249
2350
Returns:
24-
str or None: Database path if found and valid, None otherwise.
51+
str | None: Database path, or None if not configured.
2552
"""
26-
config_file = Path(__file__).parent / "database_config.json"
53+
env_path = os.getenv("WECGRID_DB_PATH")
54+
if env_path:
55+
return str(Path(env_path).expanduser().absolute())
2756

57+
config_file = _db_config_file()
2858
if config_file.exists():
2959
try:
3060
with open(config_file, "r") as f:
3161
config = json.load(f)
3262
db_path = config.get("database_path")
33-
if db_path and os.path.exists(db_path):
63+
if db_path:
3464
return str(Path(db_path).absolute())
3565
except (json.JSONDecodeError, KeyError) as e:
3666
print(f"Error reading database config: {e}")
@@ -39,14 +69,15 @@ def get_database_config():
3969

4070

4171
def save_database_config(db_path):
42-
"""Save database path to configuration file.
72+
"""Persist database path in user config directory.
4373
4474
Args:
4575
db_path (str): Path to database file.
4676
"""
47-
config_file = Path(__file__).parent / "database_config.json"
77+
cfg_dir = _user_config_dir()
78+
cfg_dir.mkdir(parents=True, exist_ok=True)
79+
config_file = _db_config_file()
4880
config = {"database_path": str(Path(db_path).absolute())}
49-
5081
with open(config_file, "w") as f:
5182
json.dump(config, f, indent=2)
5283

@@ -66,6 +97,10 @@ def _show_database_setup_message():
6697
print(
6798
'2. Create new database: engine.database.initialize_database(r"path/to/new_database.db")'
6899
)
100+
print(
101+
'3. Or set env var WECGRID_DB_PATH to point to your database file'
102+
)
103+
print(f"Config file (user): {_db_config_file()}\n")
69104
print("=" * 60 + "\n")
70105

71106

0 commit comments

Comments
 (0)