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

refactor(adapter,object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings #473

Open
wants to merge 169 commits into
base: main
Choose a base branch
from

Conversation

LuukBlom
Copy link
Contributor

@LuukBlom LuukBlom commented Jun 21, 2024

@GundulaW : I didnt get the refactor working yet (its getting quite big but im not sure how to nicely split it up into more PRs).
I have not removed the majority of old code, so the repo might seem a bit busy (and I didnt do imports yet so pretty much all that uses the Hazard class is broken, including all tests).

The low-level intelligence in the Forcing classes is not yet implemented, as I'd like to get your take on it before spending too much time.

I'd love some feedback on the more domain related functionality (the SfincsAdapter is the main one, but also the Adapter interfaces, Forcings, EventModels & Events). for the SfincsAdapter, I tried to move the code from hazard.py to the adapter with as little chages as possible, but it is a lot of code so I probably introduced some bugs.

I added the Timeseries class I've told you about here as well, even though its less nice than I wanted it to be.. It can create any 1D timeseries from a SyntheticTimeseriesModel (with attrs = shapetype, shape_duration, peak_time, peak_value/cumulative), interpolate the data to a timestep, then write to a pdDataFrame while taking into account the start time & end time of an event, before adding it to a dataframe. I think it simplifies the use of Timeseries data for other parts of the code, but I also think its not perfect as it can only handle 1D Timeseries (Synthetic or csv). So wind(2D with speed and angle) is already more difficult, not to mention spatially varying gridded timeseries.

LuukBlom added 5 commits June 17, 2024 18:26
move sfincs specific code from hazard.py to SfincsAdapter.
implement IForcing + child classes
create interfaces for the adapters
create interface for mediator (the one im not sure of, but we need some kind of management class to handle the adapters)
create HazardOutput enum, needs more work/thought
@LuukBlom LuukBlom requested a review from GundulaW June 21, 2024 16:06
Copy link
Contributor

@GundulaW GundulaW left a comment

Choose a reason for hiding this comment

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

I think this is on a really good track. Some things might still get messy, for example, when event.water_level is set to from_model, we need to add wind and pressure to the offshore model of it's an historic_offshore event.

Overall, I really like it. I made some comments in the SFINCS adapter, where I think the existing functions should go in the new hazard class logic. And I also made some overall comments. Perhaps not all of them make sense to you. Then we should catch up.

Small note: Where are we plotting the timeseries of event forcings (that are shown in the event pop up window)?

flood_adapt/object_model/io/hazard_output.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/interface/hazard_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/interface/hazard_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/interface/hazard_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/interface/impact_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/interface/impact_adapter.py Outdated Show resolved Hide resolved
flood_adapt/object_model/io/unitfulvalue.py Outdated Show resolved Hide resolved
flood_adapt/object_model/io/unitfulvalue.py Outdated Show resolved Hide resolved
@savente93 savente93 mentioned this pull request Jul 22, 2024
Copy link
Contributor

@GundulaW GundulaW left a comment

Choose a reason for hiding this comment

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

Hi,

I reviewed it all (just skipped the tests). My biggest comments are:

  1. Keep any model processing and execution out of the event classes because events are agnostic of SLR.
  2. How we deal with event sets is messy. Let's discuss
  3. Keep the postprocessing (rp_floodmaps) outside of the event class as well. This needs to remain in the hazard class (for now, we can move later, but let's not make this PR even bigger). This is only applicable to event sets, which can be recognized by MODE=="risk"

flood_adapt/integrator/interface/impact_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/integrator/sfincs_adapter.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
flood_adapt/object_model/hazard/event/timeseries.py Outdated Show resolved Hide resolved
df.index = pd.to_datetime(df.index, format=DEFAULT_DATETIME_FORMAT)
return df

def to_dataframe(
Copy link
Contributor

Choose a reason for hiding this comment

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

No, timeseries do not need the same timestep. All forcings just need to cover the entire simulation period.

flood_adapt/object_model/hazard/hazard.py Outdated Show resolved Hide resolved
Copy link
Contributor

@savente93 savente93 left a comment

Choose a reason for hiding this comment

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

went through it at speed, so didn't have time to comment on deeper issues like the approach taken. Especially the tests I kinda glossed over. I could do a deeper review but that will take significantly more time, so we'll have to see how that does or doesn't fit in the planning. In the mean time I hope there are some useful comments in here for you

.vscode/launch.json Show resolved Hide resolved
.vscode/settings.json Show resolved Hide resolved
docs/4_user_guide/compare/index.qmd Outdated Show resolved Hide resolved
docs/3_setup_guide/risk_analysis.qmd Outdated Show resolved Hide resolved
docs/_make_pdf.qmd Outdated Show resolved Hide resolved
tests/test_object_model/test_scenarios.py Outdated Show resolved Hide resolved
tests/test_object_model/test_scenarios_new.py Outdated Show resolved Hide resolved
flood_adapt/dbs_classes/dbs_template.py Outdated Show resolved Hide resolved
flood_adapt/dbs_classes/interface/database.py Show resolved Hide resolved
adapter.logger.warning = mock.Mock()

# make sure model is as expected
# ? is it correct that the template model has waterlevels?
Copy link
Contributor

Choose a reason for hiding this comment

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

is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this comment this week.
@GundulaW

@LuukBlom LuukBlom changed the title Refactor/hazard adapter and events Refactor(adapter, object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings Dec 6, 2024
remove `--no-cache-dir` from make env script
@savente93 savente93 changed the title Refactor(adapter, object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings Refactor(adapter,object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings Dec 9, 2024
@savente93 savente93 changed the title Refactor(adapter,object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings refactor(adapter,object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings Dec 9, 2024
df = pd.DataFrame({"name": names, "description": descriptions})
# TODO: make crs flexible and add this as a parameter to site.toml?
gdf = gpd.GeoDataFrame(
gdf = gpd.gpd.GeoDataFrame(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you accidentally duplicated the gdp. prefix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants