Mercurial > hg > lib > markup
changeset 7:3ee329b129c6
rename block properties, slightly revise result format
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 26 May 2021 09:18:49 -0400 |
parents | a01ff74f9fd7 |
children | fcef94b6324c |
files | python/cluster.py python/safe.py |
diffstat | 2 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cluster.py Tue May 25 17:20:04 2021 -0400 +++ b/python/cluster.py Wed May 26 09:18:49 2021 -0400 @@ -5,8 +5,9 @@ from util import * if len(sys.argv)==1 or sys.argv[1]=='-h': - print("""Usage: cluster.py [-h] [-c n] infile.tsv [outfile.tsv] + print("""Usage: cluster.py [-h] [-c n] [-s] infile.tsv [outfile.tsv] n is cluster diameter, default is 5 + -s for strict circle distance, reduces number of candidates default outfile is [infile]_c[n].tsv""") exit(1) if sys.argv[1]=='-c': @@ -15,6 +16,12 @@ else: n=5.0 +if sys.argv[1]=='-s': + sys.argv.pop(1) + strict=True +else: + strict=False + infile_name=sys.argv.pop(1) if len(sys.argv)>1: outfile_name=sys.argv.pop(1) @@ -40,8 +47,9 @@ (_,td,qd)=l.rstrip().split('\t') q=[float(i) for i in qd.split(',')] td=float(td) - if td>orad: + if strict and td>orad: # Enforce a circular region, not square + print(td,orad,file=sys.stderr) break for c in cc: for p in c:
--- a/python/safe.py Tue May 25 17:20:04 2021 -0400 +++ b/python/safe.py Wed May 26 09:18:49 2021 -0400 @@ -30,8 +30,8 @@ with open(filename,'r') as air: Block.__init__(self,air) air.readline() - aa=self.aa=[[float(i) for i in l.split('\t')[2].split(',')] for l in air] - ad=self.ad={} + aa=self.blocks=[[float(i) for i in l.split('\t')[2].split(',')] for l in air] + ad=self.columns={} for a in aa: k=(a[0],a[2]) h=ad.get(k,500.0) @@ -45,12 +45,12 @@ with open(filename,'r') as lava: Block.__init__(self,lava) lava.readline() - ll=self.ll={} + ll=self.columns={} for l in lava: x=[float(i) for i in l.split('\t')[2].split(',')] k=(x[0],x[2]) kk=ll.setdefault(k,list()) - kk.append(x) + kk.append(x[1]) L=Lava('lava.tsv') @@ -60,14 +60,14 @@ dy=p1[2]-p2[2] return math.sqrt((dx*dx)+(dy*dy)+(dz*dz)) -def safety(p): - ka=[(a[0],a[2]) for a in A.aa if d(a,p)<=n] - return [(k,ll[k]) for k in ka if k in L.ll] +def unsafe(p): + ka=[(a[0],a[2]) for a in A.blocks if d(a,p)<=n] + return [(k,A.columns[k],L.columns[k]) for k in ka if k in L.columns] readHeaders(sys.modules['__main__'],sys.stdin,False) for l in sys.stdin: c=eval(l) - s=[(p,safety(p)) for p in c] + s=[(p,unsafe(p)) for p in c] print(s if s else 'No air',c)