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

Added local hazard visualization #147

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

ywkim312
Copy link
Member

@ywkim312 ywkim312 commented Nov 16, 2023

Added local hazard visualization for earthquake, flood, hurricane, and tsunami. To test this, install the PR branch first, then create a test notebook file using the following code and run the notebook with attached zip file after unzip it.
data.zip

import os
import json

from pyincore import Hurricane, Flood, Earthquake, Tsunami

from pyincore_viz.geoutil import GeoUtil as viz
from pyincore_viz.plotutil import PlotUtil as plot

# create local hurricane and visualize
workspace = 'data/hurricane'

with open(os.path.join(workspace, "hurricane-dataset.json"), 'r') as file:
    hurricane_dataset_json = file.read()
    print(json.dumps(json.loads(hurricane_dataset_json), indent=4))

# create the hurricane object
hurricane = Hurricane.from_json_file((os.path.join(workspace, "hurricane-dataset.json")))

# attach datasets from local files
hurricane.hazardDatasets[0].from_file((os.path.join(workspace, "Wave_Raster.tif")),
                                      data_type="ncsa:deterministicHurricaneRaster")
hurricane.hazardDatasets[1].from_file(os.path.join(workspace, "Surge_Raster.tif"),
                                      data_type="ncsa:deterministicHurricaneRaster")
hurricane.hazardDatasets[2].from_file(os.path.join(workspace, "Inundation_Raster.tif"),
                                      data_type="ncsa:deterministicHurricaneRaster")

# display the hurricane
for hurricane in hurricane.hazardDatasets:
    # visualize
    viz.plot_local_hurricane(hurricane)
    
# create local earthquake and visualize
workspace = os.path.join("data", "earthquake")
eq = Earthquake.from_json_file(os.path.join(workspace, "eq-dataset.json"))

# attach datasets from local files
eq.hazardDatasets[0].from_file((os.path.join(workspace, "eq-dataset-SA.tif")),
                               data_type="ergo:probabilisticEarthquakeRaster")
eq.hazardDatasets[1].from_file((os.path.join(workspace, "eq-dataset-PGA.tif")),
                               data_type="ergo:probabilisticEarthquakeRaster")

# display the earthquake
for earthquake in eq.hazardDatasets:
    # visualize
    viz.plot_local_earthquake(earthquake)

# create local tsunami and visualize
workspace = 'data/tsunami'

with open(os.path.join(workspace, "tsunami.json"), 'r') as file:
    tsunami_dataset_json = file.read()
    print(json.dumps(json.loads(tsunami_dataset_json), indent=4))

# create the tsunami object
tsunami = Tsunami.from_json_file(os.path.join(workspace, "tsunami.json"))

# attach datasets from local files
tsunami.hazardDatasets[0].from_file((os.path.join(workspace, "Tsu_100yr_Vmax.tif")),
                                    data_type="ncsa:probabilisticTsunamiRaster")
tsunami.hazardDatasets[1].from_file((os.path.join(workspace, "Tsu_100yr_Mmax.tif")),
                                    data_type="ncsa:probabilisticTsunamiRaster")
tsunami.hazardDatasets[2].from_file((os.path.join(workspace, "Tsu_100yr_Hmax.tif")),
                                    data_type="ncsa:probabilisticTsunamiRaster")

for tsunami in tsunami.hazardDatasets:
    viz.plot_local_tsunami(tsunami)

# create local flood and visualize
workspace = 'data/flood'

with open(os.path.join(workspace, "flood-dataset.json"), 'r') as file:
    flood_dataset_json = file.read()
    print(json.dumps(json.loads(flood_dataset_json), indent=4))

# create the flood object
flood = Flood.from_json_file(os.path.join(workspace, "flood-dataset.json"))

# attach datasets from local files
flood.hazardDatasets[0].from_file((os.path.join(workspace, "flood-inundationDepth-50ft.tif")),
                                  data_type="ncsa:probabilisticFloodRaster")
flood.hazardDatasets[1].from_file(os.path.join(workspace, "flood-WSE-50ft.tif"),
                                  data_type="ncsa:probabilisticFloodRaster")

for flood in flood.hazardDatasets:
    viz.plot_local_flood(flood)

# create local tornado
workspace = os.path.join('data', 'tornado')

with open(os.path.join(workspace, "tornado_dataset.json"), 'r') as file:
    tornado_dataset_json = file.read()
    print(json.dumps(json.loads(tornado_dataset_json), indent=4))

# create the tornado object
tornado = Tornado.from_json_file(os.path.join(workspace, "tornado_dataset.json"))

# attach dataset from local file
tornado.hazardDatasets[0].from_file((os.path.join(workspace, "joplin_path_wgs84.shp")),
                                    data_type="incore:tornadoWindfield")

# visualize the tornado
outmap = viz.plot_local_tornado(tornado)
outmap

@ywkim312 ywkim312 self-assigned this Nov 16, 2023
@ywkim312 ywkim312 linked an issue Nov 16, 2023 that may be closed by this pull request
@longshuicy
Copy link
Member

Just curious, is tornado (shapefile) not possible yet?

@ywkim312
Copy link
Member Author

ywkim312 commented Dec 1, 2023

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

pyincore_viz/geoutil.py Show resolved Hide resolved
@longshuicy
Copy link
Member

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

@ywkim312
Copy link
Member Author

ywkim312 commented Dec 1, 2023

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

I am not very sure if it is worthwhile because it might

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

We've been started using gdf.explore() for the shapefile visualization and it can't be wrapped. So maybe we can just add an example of showing tornado using gdf.explore() instead of creating the method, like we did in workshop session 2.

@ywkim312
Copy link
Member Author

ywkim312 commented Dec 1, 2023

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

I am not very sure if it is worthwhile because it might

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

We've been started using gdf.explore() for the shapefile visualization and it can't be wrapped. So maybe we can just add an example of showing tornado using gdf.explore() instead of creating the method, like we did in workshop session 2.

I can create a wrapper for using our existing ones but that wouldn't be any better than using gdf.explore()

@ywkim312
Copy link
Member Author

ywkim312 commented Dec 1, 2023

Just curious, is tornado (shapefile) not possible yet?

Tornado is not included in here since it is a shapefile. So just use the local shapefile dataset visualization and it should work

For consistency of the API maybe it is worthwhile to add a similar method even though it's just wrap around the visualize local dataset?

Anyway, I added the local visualization of tornado using the existing method of pyincore-viz. I also updated the description part to include the local tornado visualization. However, still, using gdf.explore() will be better way.

@longshuicy
Copy link
Member

Code looks good. You might want to include tornado example in the data.zip for easy testing.

@ywkim312
Copy link
Member Author

ywkim312 commented Dec 6, 2023

Code looks good. You might want to include tornado example in the data.zip for easy testing.

Updated data.zip

demand_units = eq_dataset.demand_units
hazard_type = eq_dataset.hazard_type
period = eq_dataset.period
title = "Demand Type: " + demand_type.upper() + ", Demand Units: " + demand_units + ", Period: " + \
Copy link
Member

Choose a reason for hiding this comment

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

Just an aesthetic suggestion, not necessary... but we can use .title() instead of .upper() for the title so the resulting title is not all in uppercase?

@Vismayak
Copy link
Member

Vismayak commented Dec 6, 2023

Code looks good and testing worked. Just left a small comment about aesthetic but not important

@ywkim312 ywkim312 merged commit 3a64357 into develop Dec 6, 2023
8 checks passed
@ywkim312 ywkim312 deleted the 143-create-visualization-for-local-hazard branch December 6, 2023 21:30
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.

Create a visualization for local hazard
3 participants