-
Notifications
You must be signed in to change notification settings - Fork 12
Add reconstruction unit tests #128
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
Open
sebastianrowan
wants to merge
17
commits into
USACE:reconstruction-lifecycle
Choose a base branch
from
sebastianrowan:building-reconstruction
base: reconstruction-lifecycle
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
56c6014
add computeConsequencesWithReconstruction
sebastianrowan 465b359
add brainstorm comments
sebastianrowan 8c156c1
add reconstruction curves to occtypes.json
sebastianrowan 7ad8877
include reconstruction in computeConsequences(). possibly temporary.
sebastianrowan abacef3
add reconstruction to computeConsequences
sebastianrowan c7ddc10
add default reconstruction function
sebastianrowan e92de2d
Add the "default" damage function for all reconstruction.
sebastianrowan 7a3249f
roll back implementation pending unit tests
sebastianrowan 6c5764c
add computeConsequencesMulti().
sebastianrowan 1bb954d
undo unneccesary edits
sebastianrowan ec0a212
update reconstruction following g2crm methods. close but not quite ri…
sebastianrowan 8786c04
calculate pct_complete based on total damage, not just previous event
sebastianrowan fef6b6c
fix test completion date chack
sebastianrowan f3497b2
add MultiHazardEvent interface and corresponding Compute logic for st…
sebastianrowan 0646fb2
add json hazardprovider for ArrivalDepthandDurationEventMulti
sebastianrowan 8c8f1ff
change format of results for computeConsequencesMultiHazard
sebastianrowan f464e67
test StreamAbstract with MultiHazardProvider
sebastianrowan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package hazardproviders | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/USACE/go-consequences/geography" | ||
| "github.com/USACE/go-consequences/hazards" | ||
| ) | ||
|
|
||
| type jsonArrivalDepthDurationMultiHazardProvider struct { | ||
| arrivals []time.Time | ||
| depthCRs []cogReader | ||
| durations []float64 | ||
| process HazardFunction | ||
| } | ||
|
|
||
| type ADDProperties struct { // will try to not use this | ||
| Year float64 `json:"year"` | ||
| Month float64 `json:"month"` | ||
| Day float64 `json:"day"` | ||
| Depth float64 `json:"depth"` | ||
| Depthgrid string `json:"depthgrid"` | ||
| Duration float64 `json:"duration"` | ||
| Xmin float64 `json:"xmin"` | ||
| Xmax float64 `json:"xmax"` | ||
| Ymin float64 `json:"ymin"` | ||
| Ymax float64 `json:"ymax"` | ||
| } | ||
|
|
||
| type ADDEvents struct { | ||
| Events []ADDProperties `json:"events"` | ||
| } | ||
|
|
||
| func InitADDMHP(fp string) (jsonArrivalDepthDurationMultiHazardProvider, error) { | ||
| fmt.Println("Connecting to: " + fp) | ||
| c, err := os.ReadFile(fp) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| var events ADDEvents | ||
| json.Unmarshal(c, &events) | ||
|
|
||
| arrivalTimes := make([]time.Time, len(events.Events)) | ||
| durations := make([]float64, len(events.Events)) | ||
| depthCRs := make([]cogReader, len(events.Events)) | ||
|
|
||
| for i, e := range events.Events { | ||
| at := time.Date(int(e.Year), time.Month(e.Month), int(e.Day), 0, 0, 0, 0, time.UTC) | ||
| cr, err := initCR(e.Depthgrid) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| arrivalTimes[i] = at | ||
| durations[i] = e.Duration | ||
| depthCRs[i] = cr | ||
| } | ||
|
|
||
| return jsonArrivalDepthDurationMultiHazardProvider{ | ||
| arrivals: arrivalTimes, | ||
| depthCRs: depthCRs, | ||
| durations: durations, | ||
| process: ArrivalDepthAndDurationHazardFunction(), | ||
| }, nil | ||
| } | ||
|
|
||
| func (j jsonArrivalDepthDurationMultiHazardProvider) Close() { | ||
| for _, c := range j.depthCRs { | ||
| c.Close() | ||
| } | ||
| } | ||
|
|
||
| func (j jsonArrivalDepthDurationMultiHazardProvider) Hazard(l geography.Location) (hazards.HazardEvent, error) { | ||
| var hm hazards.ArrivalDepthandDurationEventMulti | ||
| for i, cr := range j.depthCRs { | ||
| d, err := cr.ProvideValue(l) | ||
| if err != nil { | ||
| return hm, err | ||
| } | ||
| hd := hazards.HazardData{ | ||
| Depth: d, | ||
| Velocity: 0, | ||
| ArrivalTime: j.arrivals[i], | ||
| Erosion: 0, | ||
| Duration: j.durations[i], | ||
| WaveHeight: 0, | ||
| Salinity: false, | ||
| Qualitative: "", | ||
| } | ||
| var h hazards.HazardEvent | ||
| h, err = j.process(hd, h) | ||
| hm.Append(h.(hazards.ArrivalDepthandDurationEvent)) | ||
| } | ||
| return &hm, nil | ||
| } | ||
|
|
||
| func (j jsonArrivalDepthDurationMultiHazardProvider) HazardBoundary() (geography.BBox, error) { | ||
| // We'll probably want to do something different here. | ||
| // Probably allow user to define study bbox with a | ||
| // shapefile/geojson/directly entering bbox coords | ||
| return j.depthCRs[0].GetBoundingBox() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package hazardproviders | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/USACE/go-consequences/geography" | ||
| "github.com/USACE/go-consequences/hazards" | ||
| ) | ||
|
|
||
| func TestInitADDMHP(t *testing.T) { | ||
| file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.json" | ||
|
|
||
| ADDMHP, err := InitADDMHP(file) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| loc := geography.Location{ | ||
| X: -71.481, | ||
| Y: 43.001, | ||
| SRID: "", | ||
| } | ||
|
|
||
| haz, err := ADDMHP.Hazard(loc) | ||
| h := haz.(hazards.ArrivalDepthandDurationEventMulti) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| for { | ||
| fmt.Printf( | ||
| "%d: Depth: %3.2f, Duration: %3.2f, Arrival: %v\n", | ||
| h.Index(), h.Depth(), h.Duration(), h.ArrivalTime(), | ||
| ) | ||
| if h.HasNext() { | ||
| h.Increment() | ||
| } else { | ||
| break | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
huh. did you write this code? it is a pretty neat idea.