Skip to content
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

Add node_id column to Node table #1149

Merged
merged 7 commits into from
Feb 22, 2024
Merged

Add node_id column to Node table #1149

merged 7 commits into from
Feb 22, 2024

Conversation

Hofer-Julian
Copy link
Contributor

@Hofer-Julian Hofer-Julian commented Feb 19, 2024

Breaking ⚠️

  • Document changes
  • Make sure that existing scripts still work
  • Adapt tests
  • Add update script for
    • Adding node_id to Node table if it doesn't exist already
    • Renaming type to node_type in Node table

Upgrade information

import geopandas as gpd

path = "path/to/database.gpkg"

# Load the GeoPackage as a GeoDataFrame
gdf = gpd.read_file(path, layer="Node", fid_as_index=True)

# Rename the column "type" to "node_type"
gdf.rename(columns={"type": "node_type"}, inplace=True)

# Add a new column "node_id" with the values of the index
gdf["node_id"] = gdf.index

# Save it back to a GeoPackage
gdf.to_file(path, layer="Node", driver="GPKG")

Breaking ⚠️

- Document changes
- Make sure that existing scripts still work
- Adapt tests
@Hofer-Julian Hofer-Julian requested a review from visr February 20, 2024 08:49
@Hofer-Julian Hofer-Julian marked this pull request as ready for review February 20, 2024 08:49
docs/core/usage.qmd Outdated Show resolved Hide resolved
Copy link
Member

@visr visr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to merge from my side, if you can still add upgrade information with a script, similar to #992.

@Hofer-Julian
Copy link
Contributor Author

This is good to merge from my side, if you can still add upgrade information with a script, similar to #992.

You want me to add a script which purpose is to adapt an existing Ribasim model so that it can be read by an up-to-date version of Ribasim Python?

@visr
Copy link
Member

visr commented Feb 20, 2024

Yeah, using Ribasim Python if possible or sqlite3 if not. I know it is a bit of a hassle, but otherwise it becomes impossible to debug user models.

@Hofer-Julian
Copy link
Contributor Author

Yeah, using Ribasim Python if possible or sqlite3 if not. I know it is a bit of a hassle, but otherwise it becomes impossible to debug user models.

I can take a look, but would be curious about the motivation.
I assumed you can always just take an older Ribasim Python version.

@visr
Copy link
Member

visr commented Feb 21, 2024

You can take an older Ribasim Python to load the model, but to debug possible issues we need to be able to run the core on the main branch.

Ideally it is always fully reproducible and we can just regenerate models with scripts, but that is often not possible. Only for our test models it is that simple.

I think at some point we should start making an upgrade script that automatically updates models to the current version. For that to work we should start adding ribasim_version to the TOML file as well.

@Hofer-Julian Hofer-Julian added the breaking A change that breaks existing models label Feb 21, 2024
@Hofer-Julian Hofer-Julian merged commit 72c5f92 into main Feb 22, 2024
20 checks passed
@Hofer-Julian Hofer-Julian deleted the node_id branch February 22, 2024 12:08
Hofer-Julian added a commit that referenced this pull request Feb 22, 2024
Breaking ⚠️

- Document changes
- Make sure that existing scripts still work
- Adapt tests
- Add update script for
   - Adding `node_id` to `Node` table if it doesn't exist already
   - Renaming `type` to `node_type` in `Node` table

```python
import geopandas as gpd

path = "path/to/database.gpkg"

# Load the GeoPackage as a GeoDataFrame
gdf = gpd.read_file(path, layer="Node")

# Rename the column "type" to "node_type"
gdf.rename(columns={"type": "node_type"}, inplace=True)

# Add a new column "node_id" with the values of the index
gdf["node_id"] = gdf.index

# Save it back to a GeoPackage
gdf.to_file(path, layer="Node", driver="GPKG")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A change that breaks existing models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants