# HG changeset patch # User Henry S. Thompson # Date 1621965686 14400 # Node ID 56508a6033a9a6cbb7ef71b05bf83cb9cec4f18a # Parent 870e13483642431dc213f14be332c06e49a4af65 minutor chunk hacking diff -r 870e13483642 -r 56508a6033a9 python/cluster.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/cluster.py Tue May 25 14:01:26 2021 -0400 @@ -0,0 +1,84 @@ +#!/usr/bin/python3 +'''Read a minutor block lockation tsv and resort it to show clusters''' +import sys + +from util import * + +if len(sys.argv)==1 or sys.argv[1]=='-h': + print("""Usage: cluster.py [-h] [-c n] infile.tsv [outfile.tsv] + n is cluster diameter, default is 5 + default outfile is [infile]_c[n].tsv""") + exit(1) +if sys.argv[1]=='-c': + sys.argv.pop(1) + n=float(sys.argv.pop(1)) +else: + n=5.0 + +infile_name=sys.argv.pop(1) +if len(sys.argv)>1: + outfile_name=sys.argv.pop(1) +else: + outfile_name="%s_c%s.tsv"%(infile_name.split('.')[0],n) + +cc=[] + +with open(infile_name,'r') as infile: + with open(outfile_name,'w') as outfile: + l=infile.readline().rstrip() + print(l,file=outfile) + ff=PPAT.split(l) + (nr,ox,oy,oz)=intsMaybe(ff) + et=ff[9] + l=infile.readline().rstrip() + print(l,file=outfile) + (orad,ymin,ymax)=intsMaybe(PPAT.split(l)) + print(nr,ox,oy,oz,et,orad,ymin,ymax) + _=infile.readline() + for l in infile: + found=False + q=[float(i) for i in l.split('\t')[2].split(',')] + for c in cc: + for p in c: + if d(p,q)<=n: + c.append(q) + found=True + break + if found: + break + if not found: + cc.append([q]) + oc=cc + cc=[] # lose + w=0 + ow=-1 + nc=[] # win + while True: + for i,c in enumerate(oc): + win=False + for p in c: + for g in oc[i+1:]: + for q in g: + if d(p,q)<=n: + win=True + w+=1 + nc.append(c+g) + break + if win: + break + if win: + break + if not win: + cc.append(c) + print(len(cc),len(nc),ow,w,file=sys.stderr) + if ow==w: + break + ow=w + oc=nc + nc=[] + for c in sorted(cc,reverse=True,key=lambda x:len(x)): + print(c,file=outfile) + + + + diff -r 870e13483642 -r 56508a6033a9 python/safe.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/safe.py Tue May 25 14:01:26 2021 -0400 @@ -0,0 +1,73 @@ +#!/usr/bin/python3 +'''Find a safe landing space (i.e. in air, not above lava) near a cluster''' +import sys, math + +from util import * + +def usage(): + print("""Usage: safe.py [-d n] + n is maximum distance of landing to some point in the cluster, default is 10. + + Feed stdin with lines from the output of cluster.py, having produced + air.tsv with the same settings as the cluster input, and lava.tsv + with a lower-bound on Y of 0""") + +if len(sys.argv)>1: + if sys.argv.pop(1)!='-d': + usage() + exit(1) + n=float(sys.argv.pop(1)) +else: + n=10.0 + +class Block: + pass + +Block.__init__=readHeaders + +class Air(Block): + def __init__(self,filename): + 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={} + for a in aa: + k=(a[0],a[2]) + h=ad.get(k,500.0) + if a[1]