-
Notifications
You must be signed in to change notification settings - Fork 65
removing and mitigating all remaining references to data_files #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| !temoa/ | ||
| !tests/ | ||
| !docs/ | ||
| !data_files/ | ||
| !notebooks/ | ||
| !output_files/ | ||
| !.github/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -443,7 +443,8 @@ def migrate( | |
| if input_path.is_dir(): | ||
| if output_path is not None: | ||
| rich.print( | ||
| '[yellow]Warning: --output is ignored when migrating a directory. Originals are overwritten after backup.[/yellow]' | ||
| '[yellow]Warning: --output is ignored when migrating a directory. Originals are ' | ||
| 'overwritten after backup.[/yellow]' | ||
| ) | ||
|
|
||
| migration_script = Path(__file__).parent / 'utilities' / 'master_migration.py' | ||
|
|
@@ -570,6 +571,7 @@ def _copy_tutorial_resources(target_config: Path, target_database: Path) -> None | |
| base = resources.files('temoa') / 'tutorial_assets' | ||
| config_resource = base / 'config_sample.toml' | ||
| sql_resource = base / 'utopia.sql' | ||
| mc_settings_resource = base / 'mc_settings.csv' | ||
|
|
||
| # Copy configuration file | ||
| with config_resource.open('rb') as source: | ||
|
|
@@ -585,11 +587,18 @@ def _copy_tutorial_resources(target_config: Path, target_database: Path) -> None | |
| with sqlite3.connect(target_database) as conn: | ||
| conn.executescript(sql_content) | ||
|
|
||
| # Copy Monte Carlo settings | ||
| with mc_settings_resource.open('rb') as source: | ||
| target_mc = target_config.parent / 'mc_settings.csv' | ||
| with open(target_mc, 'wb') as target: | ||
| shutil.copyfileobj(source, target) | ||
|
Comment on lines
+590
to
+594
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include This helper now writes a third file into the target directory, but 🛡️ Suggested fix def tutorial(
@@
current_dir = Path.cwd()
target_config = current_dir / f'{config_name}.toml'
target_database = current_dir / f'{database_name}.sqlite'
+ target_mc = current_dir / 'mc_settings.csv'
# Check for existing files and handle conflicts
existing_files = []
if target_config.exists():
existing_files.append(str(target_config))
if target_database.exists():
existing_files.append(str(target_database))
+ if target_mc.exists():
+ existing_files.append(str(target_mc))🤖 Prompt for AI Agents |
||
|
|
||
| except (ModuleNotFoundError, FileNotFoundError, AttributeError) as e: | ||
| logger.exception('Failed to load tutorial resources from package') | ||
| # Fallback to development paths (for development environments) | ||
| fallback_config = Path(__file__).parent / 'tutorial_assets' / 'config_sample.toml' | ||
| fallback_sql = Path(__file__).parent / 'tutorial_assets' / 'utopia.sql' | ||
| fallback_mc = Path(__file__).parent / 'tutorial_assets' / 'mc_settings.csv' | ||
|
|
||
| if not fallback_config.exists(): | ||
| raise FileNotFoundError( | ||
|
|
@@ -614,6 +623,9 @@ def _copy_tutorial_resources(target_config: Path, target_database: Path) -> None | |
| with sqlite3.connect(target_database) as conn: | ||
| conn.executescript(fallback_sql.read_text(encoding='utf-8')) | ||
|
|
||
| # Copy mc_settings from fallback | ||
| shutil.copy2(fallback_mc, target_config.parent / 'mc_settings.csv') | ||
|
|
||
|
|
||
| def _update_toml_database_paths(config_path: Path, new_database_name: str) -> None: | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,12 +34,14 @@ relevant `config.toml` file which can then be run. | |
|
|
||
| ### Example: `morris_utopia` | ||
|
|
||
| 1. Convert the `.sql` file in the `example_dbs` folder back to a database: | ||
| 1. Convert the `.sql` source file to a database. If you have the `morris_utopia.sql` file: | ||
|
|
||
| `data_files/example_dbs % sqlite3 morris_utopia.sqlite < morris_utopia.sql` | ||
| ```bash | ||
| sqlite3 morris_utopia.sqlite < morris_utopia.sql | ||
| ``` | ||
|
|
||
| 2. Observe the markings (3 groups) in the `MMAnalysis` columns in `cost_variable` and `efficiency`. | ||
| 3. Observe the `morris` configuration comments in the corresponding `morris_utopia.toml` file in `my_configs`. | ||
| 3. Observe the `morris` configuration comments in the relevant config file (e.g., `morris_utopia.toml`). | ||
|
Comment on lines
+37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify where the Morris example assets must live.
📝 Suggested doc update-1. Convert the `.sql` source file to a database. If you have the `morris_utopia.sql` file:
+1. Place the Morris example assets next to `morris.py` in `temoa/extensions/method_of_morris/`.
+ If you have the `morris_utopia.sql` source, generate the database in that directory:
```bash
+ cd temoa/extensions/method_of_morris
sqlite3 morris_utopia.sqlite < morris_utopia.sql
```
+ Ensure `morris_utopia.toml` is present in the same directory before running the example.🤖 Prompt for AI Agents |
||
| 4. Run the config as normal. | ||
| 5. MM analysis is reported on screen and in 2 csv files for the objective and `co2` in the Outputs folder | ||
| 6. The DB will contain updated values (tagged by scenario name and "dash run") in `output_objective` and `output_emissions` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,23 @@ | |
| """ | ||
| from importlib import resources | ||
| from math import sqrt | ||
| from pathlib import Path | ||
| from sqlite3 import Connection | ||
|
|
||
| from matplotlib import pyplot as plt | ||
|
|
||
| scenario_name = 'Purple Onion' # must match config file | ||
| db_resource = resources.files('data_files.example_dbs') / 'utopia.sqlite' | ||
| with resources.as_file(db_resource) as db_path, Connection(str(db_path)) as conn: | ||
| # To run this example, ensure tutorial_database.sqlite is in your current directory. | ||
| # You can generate it using: temoa tutorial | ||
| db_resource = 'tutorial_database.sqlite' | ||
|
|
||
| if not Path(db_resource).exists(): | ||
| raise FileNotFoundError( | ||
| f"Database file '{db_resource}' not found. " | ||
| "Please run 'temoa tutorial' to create the required files." | ||
| ) | ||
|
|
||
| with Connection(db_resource) as conn: | ||
|
Comment on lines
+12
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This only guarantees that 📝 Suggested fix-# To run this example, ensure tutorial_database.sqlite is in your current directory.
-# You can generate it using: temoa tutorial
+# To run this example, first create the tutorial assets and then run the
+# tutorial model so `output_objective` contains `Purple Onion-*` rows:
+# temoa tutorial
+# temoa run tutorial_config.toml
...
obj_values = cur.execute(
f"SELECT total_system_cost FROM output_objective WHERE scenario LIKE '{scenario_name}-%'"
).fetchall()
+ if not obj_values:
+ raise RuntimeError(
+ f"No results found for '{scenario_name}'. Run the tutorial model before analyzing it."
+ )🧰 Tools🪛 Ruff (0.15.9)[warning] 17-20: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
| cur = conn.cursor() | ||
| obj_values = cur.execute( | ||
| f"SELECT total_system_cost FROM output_objective WHERE scenario LIKE '{scenario_name}-%'" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| run,param,index,mod,value,notes | ||
| 1,cost_invest,utopia|TXD|2010,a,-44.0,reduce invest cost to 1000 | ||
| 2,demand,utopia|2010|RH,r,0.1,increase demand by 10% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point readers to
temoa tutorial, not the internal resource path.config_sample.tomlundertemoa/tutorial_assetsis not runnable by itself; the tutorial flow also generates the SQLite database and copiesmc_settings.csvalongside it. As written, this suggests users can use the packaged file directly.📝 Suggested doc tweak
📝 Committable suggestion
🤖 Prompt for AI Agents