getData.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. import sys
  3. import config
  4. def getDataset(db,setup,datasetName,qfilter=[]):
  5. ds=db.selectRows(setup['project'],setup['schemaName'],\
  6. setup[datasetName],qfilter)
  7. try:
  8. rows=ds['rows']
  9. except KeyError:
  10. rows=[]
  11. return rows
  12. def updateDataset(db,setup,datasetName,mode,rows):
  13. db.modifyRows(mode,setup['project'],setup['schemaName'],\
  14. setup[datasetName],rows)
  15. def getPatients(db,setup,qfilter=[]):
  16. return getDataset(db,setup,'queryName',qfilter)
  17. def getSegmentation(db,setup,qfilter=[]):
  18. return getDataset(db,setup,'segmentationQueryName',qfilter)
  19. def getSummary(db,setup,qfilter=[]):
  20. return getDataset(db,setup,'summaryQueryName',qfilter)
  21. def updatePatients(db,setup,mode,rows):
  22. updateDataset(db,setup,'queryName',mode,rows)
  23. def updateSegmentation(db,setup,mode,rows):
  24. updateDataset(db,setup,'segmentationQueryName',mode,rows)
  25. def updateSummary(db,setup,mode,rows):
  26. updateDataset(db,setup,'summaryQueryName',mode,rows)
  27. def downloadNode(fb,fileName,rPath,lPath):
  28. rPath1=rPath+'/'+fileName
  29. available=fb.entryExists(rPath1)
  30. if not available:
  31. print('Missing {}'.format(fileName))
  32. return
  33. lPath1=os.path.join(lPath,fileName)
  34. if os.path.isfile(lPath1):
  35. return
  36. print('Loading {}'.format(fileName))
  37. fb.readFileToFile(rPath1,lPath1)
  38. def downloadFiles(fb,r,setup):
  39. rPath=fb.formatPathURL(setup['project'],config.getOutputDir(r,setup))
  40. lPath=config.getLocalDir(r,setup)
  41. if not os.path.isdir(lPath):
  42. os.makedirs(lPath)
  43. #CT
  44. fileName=config.getNodeName(r,setup,'CT')+'.nrrd'
  45. downloadNode(fb,fileName,rPath,lPath)
  46. for i in range(20):
  47. fileName=config.getNodeName(r,setup,'NM',i)+'.nrrd'
  48. downloadNode(fb,fileName,rPath,lPath)
  49. fileName=config.getNodeName(r,setup,'Dummy')+'.mcsv'
  50. downloadNode(fb,fileName,rPath,lPath)
  51. def downloadPatientFiles(db,fb,setup):
  52. rows=getPatients(db,setup)
  53. for r in rows:
  54. #download
  55. downloadFiles(fb,r,setup)