changeset 11:e411408d64ec

from python repo
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 11 Dec 2021 16:13:04 -0500
parents 73bb35b96624
children 1e42c0147a49
files python/cluster.py python/safe.py python/util.py
diffstat 3 files changed, 90 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/python/cluster.py	Thu May 27 06:09:01 2021 -0400
+++ b/python/cluster.py	Sat Dec 11 16:13:04 2021 -0500
@@ -40,7 +40,12 @@
     et=ff[9]
     l=infile.readline().rstrip()
     print(l,file=outfile)
-    (orad,ymin,ymax)=intsMaybe(PPAT.split(l))
+    l2=PPAT.split(l)
+    if l2[-1]=='bounded':
+      orad=int(l2[1])
+      ymin=ymax=-1
+    else:
+      (orad,ymin,ymax)=intsMaybe(l2)
     _=infile.readline()
     for l in infile:
       found=False
--- a/python/safe.py	Thu May 27 06:09:01 2021 -0400
+++ b/python/safe.py	Sat Dec 11 16:13:04 2021 -0500
@@ -13,17 +13,6 @@
   air.tsv with the same settings as the cluster input, and lava.tsv
   with a lower-bound on Y of 0""")
 
-n=10.0
-if len(sys.argv)>1:
-  if sys.argv[1]=='-d':
-    sys.argv.pop()
-    n=float(sys.argv.pop(1))
-
-if len(sys.argv)>1:
-  infile=open(sys.argv.pop(1))
-else:
-  infile=sys.stdin
-
 class Block:
   '''Shared by Air and Lava,
   holds points and columns.
@@ -48,6 +37,8 @@
     for k,yy in tc.items():
       tyy=[yy]
       ii=[]
+      if k==(108.5, -45.5):
+        pass
       while True:
         clean=True
         for j,yy in enumerate(tyy):
@@ -57,7 +48,7 @@
             clean=False
             for i in range(len(yy)-1):
               if yy[i]+1!=yy[i+1]:
-                ii+=(yy[0],yy[i])
+                ii.append((yy[0],yy[i]))
                 tyy=[yy[i+1:]]+tyy[j+1:]
             break
         if clean:
@@ -73,13 +64,10 @@
 class Air(Block):
   pass
 
-A=Air('air.tsv')
 
 class Lava(Block):
   pass
 
-L=Lava('lava.tsv')
-
 def d(p1,p2):
   dx=p1[0]-p2[0]
   dz=p1[1]-p2[1]
@@ -87,35 +75,77 @@
   return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))
 
 def safety(p):
-  ka=[(a[0],a[2]) for a in A.points if d(a,p)<=n]
-  return [(k,A.columns[k],L.columns[k]) for k in ka if k in L.columns]
+  ka=[((a[0],a[2]),d(a,p)) for a in A.points if d(a,p)<=n]
+  return [(k,A.columns[k[0]],L.columns.get(k[0],None)) for k in ka]
+
+if __name__=='__main__':
+  n=10.0
+  if len(sys.argv)>1:
+    if sys.argv[1]=='-d':
+      sys.argv.pop(1)
+      n=float(sys.argv.pop(1))
+
+  if len(sys.argv)>1:
+    infile=open(sys.argv.pop(1))
+  else:
+    infile=sys.stdin
+
+  A=Air('air.tsv')
+
+  L=Lava('lava.tsv')
+
+  readHeaders(sys.modules['__main__'],infile,False)
 
-readHeaders(sys.modules['__main__'],infile,False)
-for l in infile:
-  c=eval(l)
-  ss=[]
-  hits={}
-  misses=[]
-  for p in c:
-    ss=safety(p)
-    if ss:
-      for (k,a,l) in ss:
-        try:
-          (aa,ll)=hits[k]
-          aa.update(a)
-          ll.update(l)
-        except KeyError:
-          hits[k]=(a,l)
+  for l in infile:
+    c=eval(l)
+    ss=[]
+    hits={}
+    misses=[]
+    for p in c:
+      ss=safety(p)
+      if ss:
+        for (k,a,l) in ss:
+          try:
+            (aa,ll)=hits[k]
+            aa.update(a)
+            if l is not None:
+              ll.update(l)
+          except KeyError:
+            hits[k]=(a,l)
+      else:
+        misses.append(p)
+    print(c)
+    if hits:
+      print(' %s nearby landing columns'%len(hits))
+      done={}
+      for k in sorted(hits.keys(),key=lambda k:k[1]):
+        if k[0] not in done:
+          done[k[0]]=1
+          aa,ll=hits[k]
+          laa=sorted(list(aa))
+          lowAir=laa[0][0]
+          j=-1
+          if ll is not None:
+            lll=sorted(list(ll))
+            highLava=-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
+            else:
+              lava=None
+          else:
+            lava=None
+          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:
-      misses.append(p)
-  print(c)
-  if hits:
-    print(' %s nearby landing columns'%len(hits))
-    for k in sorted(hits.keys(),key=lambda k:k[0]):
-      aa,ll=hits[k]
-      print("%s: %s %s"%(k,sorted(list(aa)),sorted(list(ll))))
-  else:
-    print(' No nearby landing zones')
+      print(' No nearby landing zones')
 
-if infile!=sys.stdin:
-  infile.close()
+  if infile!=sys.stdin:
+    infile.close()
--- a/python/util.py	Thu May 27 06:09:01 2021 -0400
+++ b/python/util.py	Sat Dec 11 16:13:04 2021 -0500
@@ -4,6 +4,10 @@
 IPAT=re.compile('-?[0-9][0-9]*$')
 PPAT=re.compile('[ ,;\[\]]')
 
+Red=''
+eRed=''
+RedFmt=Red+'%s'+eRed
+
 def intsMaybe(ii):
   return (int(i) for i in ii if IPAT.match(i))
 
@@ -13,7 +17,12 @@
     (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))
+    l2=PPAT.split(l)
+    if l2[-1]=='bounded':
+      host.orad=int(l2[1])
+      host.ymin=host.ymax=-1
+    else:
+      (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l))
     if skipColHdrs:
       _=infile.readline()