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

Create a one main plotting for local hazard #155

Merged
merged 5 commits into from
Jan 31, 2024

Conversation

ywkim312
Copy link
Member

@ywkim312 ywkim312 commented Jan 5, 2024

Currently, there are individual methods for plotting local hazard. This PR allows the user just give any local hazard dataset to plot without finding the correct method.

To test:
After installing this PR in your local, please use the following code to test the PR.
data.zip
Use the attached zip file to test.

import os 
import json
from pyincore import Hurricane, Flood, Earthquake, Tornado, Tsunami
from pyincore_viz.geoutil import GeoUtil as viz

# indicate the path
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")

viz.plot_local_hazard(flood)

##################################

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")

viz.plot_local_hazard(tsunami)

##################################
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
viz.plot_local_hazard(hurricane)

##################################
workspace = "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
viz.plot_local_hazard(eq)

##################################
workspace = '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")

viz.plot_local_hazard(tornado)

Copy link
Contributor

@ylyangtw ylyangtw left a comment

Choose a reason for hiding this comment

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

Tested data.zip and it created several plots as expected. Approving~

BTW I found some duplicated import and removed it

@ylyangtw
Copy link
Contributor

ylyangtw commented Jan 30, 2024

Tested data.zip and it created several plots as expected. Approving~

BTW I found some duplicated import and removed it

Oops... seems like my commit breaks the pytest... let me revert it :P

Copy link

@Rashmil-1999 Rashmil-1999 left a comment

Choose a reason for hiding this comment

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

looks good! I get all the visualizations correctly

@ywkim312 ywkim312 merged commit d2c3939 into develop Jan 31, 2024
4 of 8 checks passed
@ywkim312 ywkim312 deleted the 153-create-a-one-main-plotting-for-hazard-dataset branch January 31, 2024 22:48
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 single overall plotting method for local hazard dataset
3 participants