Repository navigation
tifxyz writer: overwrite=True keeps the other files in the segment directory - #2108
Merged
bruniss merged 1 commit intoOct 30, 2026
Conversation
write_tifxyz(path, surface, overwrite=True) wrote the surface into a sibling temp directory, then removed the existing directory and moved the temp one into its place, so every file it did not write itself (label images, generations.tif, approval.tif, overlapping.json, trace.json, ...) was deleted without a word. Before the swap, regular files of the old directory that the new write did not produce are now copied across, the same rule QuadSurface::saveWithUuid applies when it overwrites a segment.
|
@CVasilopoulos is attempting to deploy a commit to the scroll Team on Vercel. A member of the Team first needs to authorize it. |
CVasilopoulos
marked this pull request as ready for review
October 23, 2026 07:35
Contributor
Author
|
Marked ready for review. Re-checked on current AI-assisted, human-directed. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In one sentence:
write_tifxyz(path, surface, overwrite=True)now replaces the surface files and keeps every other file in the segment directory, asQuadSurface::saveWithUuiddoes, instead of deleting the directory and putting back onlyx/y/z.tif,meta.jsonandmask.tif.One real example: Starting with a copy of PHercParis4 segment 20231007101619 (the 45.532 µm tifxyz) with an ink label next to it, I rewrote the surface in place with
s = read_tifxyz(seg); write_tifxyz(seg, s, overwrite=True). The label was the published 2.4 µm ink prediction for this segment, resized to the surface's full resolution and saved as20231007101619_ink.png. On main the call returns normally and the label is gone:list_labels()goes from 1 label to 0. With this PR the label is still there, byte-identical, and the surface files are rewritten as before.Before:
TifxyzWriter.writewrites the surface into a sibling temp directory, then runsshutil.rmtreeon the existing directory and moves the temp directory into its place. Anything the writer does not produce itself is deleted without a warning: label images,generations.tif,approval.tif,overlapping.json,trace.json.After this PR: just before the swap, every regular file of the old directory that the new write did not produce is copied into the temp directory, so the swap keeps it. Files the writer does produce are replaced by the new ones. This is the same rule
QuadSurface::saveWithUuidfollows when it overwrites a segment ("Preserve auxiliary files from the existing directory before replacing"). Writing to a new directory, andoverwrite=False, are unchanged.Proof: upstream main
5432721dcagainst this branch, same segment copy, same call, same container. Look at the20231007101619_ink.pngrow and the label lists.The rewritten
x/y/z.tif,meta.jsonandmask.tif(the writer adds one; the published segment has none) have the same hashes on both sides. The only difference is the label: deleted on main, untouched here.Why / where this is useful:
The sheets tracer re-traces into an existing directory with
write_surface(..., overwrite=True)and deliberately keeps the surface uuid across re-traces, so the directory is treated as one persistent surface; every re-trace still wiped whatever else had been put in it.autoreg_mesh/infer.pywrites its prediction to<save_path>/<segment uuid>withoverwrite=True.Rewriting a segment in place is the natural way to refresh its
meta.jsonfrom Python: the writer recomputes the bbox from the valid points, which makes the read-time fix from tifxyz: recompute the bbox from valid points when the stored one carries the -1 marker (refs #1618) #1731 permanent. Ink labels are often hand-drawn and the only copy, and losing them raised nothing.I personally verified that the example and proof above were produced by this PR on the stated data.
Details
vesuvius/src/vesuvius/tifxyz/writer.pyTifxyzWriter.write, in the overwrite branch only: beforeshutil.rmtree(original_path), regular files oforiginal_paththat do not exist in the temp directory are copied there withshutil.copy2. The original directory stays intact until the copies are done, so a failure leaves it as it was.vesuvius/tests/tifxyz/test_writer_overwrite.py. One test puts a label PNG,generations.tifandoverlapping.jsonnext to a written surface, rewrites it withoverwrite=True, and checks the three files are byte-identical,x.tifholds the new coordinates and no temp directory is left. The other checks thatmask.tif, which the writer produces, is replaced by the new surface's mask rather than carried over. The first test fails on main; both pass here, as do the existingtests/tifxyztests.TifxyzReader.discover_labels(validate_shapes=True)already flags label shapes that do not match the grid.ink-detection/downsampled/...-2.4um-...-ds8.jpgfor the same segment (13518 × 6505, same aspect ratio as the surface), resized withINTER_AREAand saved as an 8-bit PNG.python:3.12-slim, Linux x86_64; numpy 2, tifffile, opencv-python-headless 5.0.0. Not tested on Windows or macOS.write_tifxyz,TifxyzWriterandtifxyz writer overwrite. vesuvius: tifxyz write_metadata recomputes the bbox from valid vertices #1606 (closed) and tifxyz: recompute the bbox from valid points when the stored one carries the -1 marker (refs #1618) #1731 changed the bbox, UUID alignment #2077 the uuid; none touches the overwrite branch.Evidence script (evidence.py)
AI-assisted, human-directed.