From ca01dde4621cfb136f93096dc65a05d7fd0bbc2a Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Mon, 16 Oct 2017 17:38:17 +0200 Subject: Saving barcodes in DIPHA's format. --- phstuff/diphawrapper.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/phstuff/diphawrapper.py b/phstuff/diphawrapper.py index 1b633b5..517a929 100644 --- a/phstuff/diphawrapper.py +++ b/phstuff/diphawrapper.py @@ -303,6 +303,35 @@ def save_text_barcode(fname, barcode): else: f.write("%d %g inf\n" %(dim, interval.birth)) +def save_barcode(fname, barcode): + """Saves a barcode in DIPHA's format. + + Parameters: + ----------- + + fname: File name to save to. + + barcode: The barcode to save, a dictionary keyed on degree, each + entry being a list of `Interval`s. + + """ + + with open(fname, "wb") as f: + f.write(struct.pack("