worker_code_inspect_locids.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. def after_simulation(ctrltree, datfile, opener, mpart_opener, options):
  2. print 'comparing measurements'
  3. import numpy as np
  4. runid = ctrltree.getroot().attrib['runid']
  5. url = options.url + '/transferResultAtLocIDs?worker=%s&runid=%s' % (WORKER_ID, runid)
  6. vi = VolumeImage()
  7. for i in range(3):
  8. try:
  9. vi.read(datfile)
  10. except Exception:
  11. time.sleep(0.5)
  12. else:
  13. break
  14. #~ dbdata = vi.asDecibelData(-130)
  15. result = {}
  16. print 'all locations: ', ctrltree.getroot().xpath('locations/loc')
  17. for e in ctrltree.getroot().xpath('locations/loc'):
  18. locid, x, y, z = e.attrib['id'], e.attrib['x'], e.attrib['y'], e.attrib['z']
  19. #estimated = vi.data[vi.translate(float(x), float(y), float(z))]
  20. estimated = vi.getPoint(float(x), float(y), float(z))
  21. print 'loc id:', locid, estimated
  22. #~ if np.isnan(estimated):
  23. #~ result[locid] = -130
  24. #~ else:
  25. result[locid] = estimated
  26. params = urllib.urlencode({'data': str(result)}) # transfer string repr of dict
  27. try:
  28. opener.open(url, data=params)
  29. except Exception:
  30. log.exception('cannot send data to %s' % url)
  31. else:
  32. log.info('transmitted locid data')