Mercurial > hg > python
changeset 33:a5a353728540
merged
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 29 Jul 2021 12:49:13 +0100 |
parents | 4d9778ade7b2 (current diff) 5488b5d3ba10 (diff) |
children | 30f8af85c3fd |
files | |
diffstat | 2 files changed, 44 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/safe.py Thu Jul 29 12:44:47 2021 +0100 +++ b/safe.py Thu Jul 29 12:49:13 2021 +0100 @@ -119,7 +119,22 @@ done[k[0]]=1 aa,ll=hits[k] laa=sorted(list(aa)) - print("(%s %s %s)@%0.1f: %s %s"%(k[0][0],laa[0][0],k[0][1],k[1],laa,sorted(list(ll)))) + lll=sorted(list(ll)) + lowAir=laa[0][0] + highLava=-1 + j=-1 + for i,(_,h) in enumerate(lll): + if h>highLava and h<lowAir: + highLava=h + if h+1==lowAir: + j=i + break + if j>-1: + lava='['+','.join(str(e) if i!=j else \ + "(%s,%s)"%(e[0],RedFmt%e[1]) for i,e in enumerate(lll))+']' + lowAir=RedFmt%lowAir + print("%s(%s %s %s)@%0.1f: %s %s"%(' ' if j>-1 else '', + k[0][0],lowAir,k[0][1],k[1],laa,lava)) else: print(' No nearby landing zones')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util.py Thu Jul 29 12:49:13 2021 +0100 @@ -0,0 +1,28 @@ +'''Utility fns for dealing with block .tsv files''' +import math,re + +IPAT=re.compile('-?[0-9][0-9]*$') +PPAT=re.compile('[ ,;\[\]]') + +Red='[31m' +eRed='[39m' +RedFmt=Red+'%s'+eRed + +def intsMaybe(ii): + return (int(i) for i in ii if IPAT.match(i)) + +def readHeaders(host,infile,skipColHdrs=True): + l=infile.readline().rstrip() + ff=PPAT.split(l) + (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff) + host.et=ff[9] + l=infile.readline().rstrip() + (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l)) + if skipColHdrs: + _=infile.readline() + +def d(p1,p2): + dx=p1[0]-p2[0] + dz=p1[1]-p2[1] + dy=p1[2]-p2[2] + return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))