summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGard Spreemann <gspreemann@gmail.com>2016-03-29 13:05:25 +0200
committerGard Spreemann <gspreemann@gmail.com>2016-03-29 13:05:25 +0200
commitb096d37130b7f597e5e0ac377b24591282c66150 (patch)
tree03881f64a391ecefd8642ce64eca98124e381740
parent4a11698e58ca5323a4dccf593878a2955548a982 (diff)
Image data support.
-rw-r--r--phstuff/diphawrapper.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/phstuff/diphawrapper.py b/phstuff/diphawrapper.py
index f6ab403..45444c8 100644
--- a/phstuff/diphawrapper.py
+++ b/phstuff/diphawrapper.py
@@ -18,6 +18,7 @@ optionally manage running the DIPHA executable.
# DIPHA header files.
DIPHA_MAGIC = 8067171840
DIPHA_WEIGHTED_BOUNDARY_MATRIX = 0
+DIPHA_IMAGE_DATA = 1
DIPHA_PERSISTENCE_DIAGRAM = 2
DIPHA_DISTANCE_MATRIX = 7
DIPHA_SPARSE_DISTANCE_MATRIX = 8
@@ -148,8 +149,36 @@ def save_edge_list(fname, edge_list):
for j in range(0, len(edge_list[i])):
f.write(struct.pack('<d', factor*edge_list[i][j][1]))
+def save_cubical(fname, complex):
+ """Save a (any-dimensional) array that will be interpreted as a
+ cubical complex with top-dimensional cells entering the filtration
+ at the scale given by the array values.
+
+ Parameters:
+ -----------
+
+ fname: Name of file to write.
+
+ complex: Any-dimensional array with floating-point values giving
+ the filtration values of the top-dimensional cells.
+
+ """
+
+ with open(fname, "wb") as f:
+ f.write(struct.pack("<q", DIPHA_MAGIC))
+ f.write(struct.pack("<q", DIPHA_IMAGE_DATA))
+ f.write(struct.pack("<q", np.product(complex.shape)))
+ f.write(struct.pack("<q", len(complex.shape)))
+
+ for n in complex.shape:
+ f.write(struct.pack("<q", n))
+
+ for w in complex.flat:
+ f.write(struct.pack("<d", w))
+
def load_barcode(fname, top_dim = None):
+
"""Load a barcode as written by DIPHA.
Parameters:
@@ -213,6 +242,7 @@ def save_text_barcode(fname, barcode):
f.write("%d %g %g\n" %(dim, interval.birth, interval.death))
else:
f.write("%d %g inf\n" %(dim, interval.birth))
+
class DiphaRunner: