diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-08-17 11:08:46 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-08-17 11:08:46 +0000 |
commit | 777ed59f7d723139114b072682729eaed8596881 (patch) | |
tree | 680a581443271457f8e0b160f6e193e2358dccaa /src/cython/example | |
parent | 15ad63c814fbb30783c240c57b079e1a66094aa9 (diff) |
Fix persistent_betti_numbers in Persistent_cohomology to make it work with cubical
Cython examples renaming and fixing
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1439 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: ab84ba3acd6241257f1787e29ac2e3ac005bbd80
Diffstat (limited to 'src/cython/example')
-rwxr-xr-x | src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py (renamed from src/cython/example/alpha_complex_from_file_example.py) | 47 | ||||
-rwxr-xr-x | src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py (renamed from src/cython/example/cubical_complex_from_perseus_file_example.py) | 46 |
2 files changed, 56 insertions, 37 deletions
diff --git a/src/cython/example/alpha_complex_from_file_example.py b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py index 81c4c0b7..8e534061 100755 --- a/src/cython/example/alpha_complex_from_file_example.py +++ b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import gudhi -import pandas import argparse """This file is part of the Gudhi Library. The Gudhi library @@ -30,35 +29,35 @@ __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -print("#####################################################################") -print("AlphaComplex creation from points read in a file") - parser = argparse.ArgumentParser(description='AlphaComplex creation from ' - 'points read in a file.', + 'points read in a OFF file.', epilog='Example: ' - 'example/alpha_complex_from_file_example.py ' - 'data/500_random_points_on_3D_Torus.csv ' + 'example/alpha_complex_diagram_persistence_from_off_file_example.py ' + '../data/points/tore3D_1307.off ' '- Constructs a alpha complex with the ' 'points from the given file. File format ' 'is X1, X2, ..., Xn') -parser.add_argument('file', type=argparse.FileType('r')) +parser.add_argument("-f", "--file", type=str, required=True) parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') args = parser.parse_args() -points = pandas.read_csv(args.file, header=None) - -print("AlphaComplex with max_alpha_square=0.5") - -alpha_complex = gudhi.AlphaComplex(points=points.values, - max_alpha_square=0.5) - -alpha_complex.initialize_filtration() -diag = alpha_complex.persistence(homology_coeff_field=2, min_persistence=0.1) - -print("betti_numbers()=") -print(alpha_complex.betti_numbers()) - -if args.no_diagram == False: - gudhi.diagram_persistence(diag) - gudhi.barcode_persistence(diag) +with open(args.file, 'r') as f: + first_line = f.readline() + if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + + print("#####################################################################") + print("AlphaComplex creation from points read in a OFF file") + alpha_complex = gudhi.AlphaComplex(off_file=args.file, max_alpha_square=0.5) + + diag = alpha_complex.persistence(homology_coeff_field=2, min_persistence=0.1) + + print("betti_numbers()=") + print(alpha_complex.betti_numbers()) + + if args.no_diagram == False: + gudhi.diagram_persistence(diag) + else: + print(args.file, "is not a valid OFF file") + + f.close() diff --git a/src/cython/example/cubical_complex_from_perseus_file_example.py b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index 23f7ece6..e6ba94e1 100755 --- a/src/cython/example/cubical_complex_from_perseus_file_example.py +++ b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -1,10 +1,7 @@ #!/usr/bin/env python import gudhi -import numpy import argparse -import operator -import os """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -32,25 +29,48 @@ __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -parser = argparse.ArgumentParser(description='Cubical complex from a perseus' - 'file style name.', +def is_file_perseus(file): + num_lines = open(file).read().count('\n') + try: + f = open(file) + num_dim = int(f.readline()) + coeff = 1 + for dim in range(0, num_dim): + try: + line = int(f.readline()) + coeff *= abs(line) + except ValueError: + return False + if num_lines == (1 + num_dim + coeff): + return True + else: + return False + except ValueError: + return False + +parser = argparse.ArgumentParser(description='Periodic cubical complex from a ' + 'perseus file style name.', epilog='Example: ' - './cubical_complex_from_perseus_file_example.py' + './periodic_cubical_complex_from_perseus_file_example.py' ' -f ../data/bitmap/CubicalTwoSphere.txt') parser.add_argument("-f", "--file", type=str, required=True) +parser.add_argument('--no-barcode', default=False, action='store_true' , help='Flag for not to display the barcodes') args = parser.parse_args() -if os.access(args.file, os.R_OK): +if is_file_perseus(args.file): print("#####################################################################") - print("CubicalComplex creation") - cubical_complex = gudhi.CubicalComplex(perseus_file=args.file) + print("PeriodicCubicalComplex creation") + periodic_cubical_complex = gudhi.PeriodicCubicalComplex(perseus_file=args.file) - print("persistence(homology_coeff_field=2, min_persistence=0)=") - print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) + print("persistence(homology_coeff_field=3, min_persistence=0)=") + diag = periodic_cubical_complex.persistence(homology_coeff_field=3, min_persistence=0) + print(diag) print("betti_numbers()=") - print(cubical_complex.betti_numbers()) + print(periodic_cubical_complex.betti_numbers()) + if args.no_barcode == False: + gudhi.barcode_persistence(diag) else: - print(args.file, "is unreachable") + print(args.file, "is not a valid perseus style file") |