Refactor write_evr to public API similar to read_evr and read_regions_csv - #291
Refactor write_evr to public API similar to read_evr and read_regions_csv#291ctuguinay wants to merge 6 commits into
write_evr to public API similar to read_evr and read_regions_csv#291Conversation
|
Sorry, I know y'all are probably swamped with some things, but when one of you has time, could you take a look at this PR? I think this refactoring makes more sense than what I previously had which felt very disconnected from the other public API parts, but let me know if any of this doesn't make sense. |
leewujung
left a comment
There was a problem hiding this comment.
Hey @ctuguinay : I like this change! It is much cleaner than having a flying function to write to evr.
The only question I have is when the mask has a hole - in this case does open_cv return 2 contours, one the outer contour and one the inner contour? If so, then in this case they will become 2 separate region_id entries in an Regions2D object, is that right?
|
@leewujung Ah good point, there's a hierarchy structure to the contour format that I didn't encounter in my simple example. Let me figure that out and change how the opencv output is parsed and I'll add an example with a hole. I'll also add an example with two patches that are separated (not contained within each other). |
|
@leewujung Once you get back, could we briefly talk about the inner/outer region case? I found strange contours in one of my test cases (potentially a bug in the in opencv??). A little hard to explain with this thread. |
|
Sounds good! Let's chat tomorrow! |
|
Also just noting that merging this will close #103 |
Addresses #243:
The
write_evr/evr_writer.pywas refactored/removed so that reading a mask now goes through a similar workflow as.csvand.evrfiles, withread_masktaking in the xarray mask and creating aRegions2Dobject and this function is calling an underlying parser handling mask checking and contour extraction inregions2d_parser.py. Once the mask data is inRegions2Dform, we can choose to save to either.evror to.csv. Included is a simple values check that the mask is being correctly encoded. The test constructs a 4x4 mask and then within that box there is a smaller 2x2 box that is 1s (everything else is 0s) and then theRegions2Dtime and depth arrays are easy to check against.