|
@@ -56,23 +56,21 @@ def configure_logging():
|
|
|
|
|
|
|
|
|
def reconstruct_scan(input_path, output_path):
|
|
|
- filenames = os.listdir(input_path)
|
|
|
log = logging.getLogger(APP_NAME)
|
|
|
|
|
|
- if 'radios' in filenames:
|
|
|
- params = tofu.config.TomoParams().get_defaults()
|
|
|
- params.input = os.path.join(input_path, 'radios')
|
|
|
- params.from_projections = True
|
|
|
- params.output = os.path.join(output_path, 'data', 'slices', 'slice-%05i.tif')
|
|
|
- params.number = 1698
|
|
|
- params.axis = 500
|
|
|
- params.angle_step = math.radians(0.105945)
|
|
|
+ params = tofu.config.TomoParams().get_defaults()
|
|
|
+ params.input = os.path.join(input_path, 'radios')
|
|
|
+ params.from_projections = True
|
|
|
+ params.output = os.path.join(output_path, 'data', 'slices', 'slice-%05i.tif')
|
|
|
+ params.number = 1698
|
|
|
+ params.axis = 500
|
|
|
+ params.angle_step = math.radians(0.105945)
|
|
|
|
|
|
- log.info(" Reconstruct ...")
|
|
|
- proc = RecoProcess(params)
|
|
|
- proc.start()
|
|
|
- proc.join()
|
|
|
- log.info(" Finished [output={}]".format(params.output))
|
|
|
+ log.info(" Reconstructing ... writing to {}".format(params.output))
|
|
|
+ proc = RecoProcess(params)
|
|
|
+ proc.start()
|
|
|
+ proc.join()
|
|
|
+ log.info(" Done.")
|
|
|
|
|
|
|
|
|
class Application(object):
|
|
@@ -82,51 +80,52 @@ class Application(object):
|
|
|
|
|
|
def run(self):
|
|
|
last_update = get_last_timestamp()
|
|
|
- self.objects = {o.uuid: o for o in self.client.get_objects(limit=100)}
|
|
|
+ self.objects = {o.uuid: o for o in self.client.get_objects() if o.label == 'raw'}
|
|
|
self.accesspoint = self.client.get_accesspoints('file://')[0]
|
|
|
|
|
|
- for ingest in self.client.get_ingests():
|
|
|
- self.log.info("Found ingest={}".format(ingest.id))
|
|
|
- if ingest.staging_url and ingest.id == 1:
|
|
|
- self.reconstruct(ingest)
|
|
|
+ downloads = {d.object_uuid: d for d in self.client.get_downloads()}
|
|
|
|
|
|
- now = datetime.datetime.now()
|
|
|
- update_timestamp(now)
|
|
|
+ for uuid, obj in self.objects.items():
|
|
|
+ self.log.info("Checking downloads for {}".format(obj))
|
|
|
|
|
|
- def reconstruct(self, ingest):
|
|
|
- prefix, path = ingest.staging_url.split('file:', 1)
|
|
|
-
|
|
|
- if os.access(path, os.R_OK):
|
|
|
- self.log.info("Using ingest={} [path={} status={}]".format(ingest.id, path, ingest.status))
|
|
|
+ if uuid in downloads:
|
|
|
+ download = downloads[uuid]
|
|
|
+ self.log.info("Using download={}".format(download))
|
|
|
+ self.reconstruct(obj, download)
|
|
|
+ else:
|
|
|
+ download = obj.create_download(ap)
|
|
|
+ self.log.warn("No download found, created {}".format(download))
|
|
|
|
|
|
- if ingest.object_uuid in self.objects:
|
|
|
- obj = self.objects[ingest.object_uuid]
|
|
|
+ now = datetime.datetime.now()
|
|
|
+ update_timestamp(now)
|
|
|
|
|
|
- user_client, new_ingest = self.create_ingest(obj)
|
|
|
+ def reconstruct(self, obj, download):
|
|
|
+ _, path = download.url.split('file:', 1)
|
|
|
+ data_path = os.path.join(path, 'data')
|
|
|
|
|
|
- if new_ingest:
|
|
|
- prefix, output_path = new_ingest.staging_url.split('file:', 1)
|
|
|
- reconstruct_scan(os.path.join(path, 'data'), output_path)
|
|
|
+ if os.path.isdir(data_path) and 'radios' in os.listdir(data_path):
|
|
|
+ user_client, new_ingest = self.create_ingest(obj)
|
|
|
|
|
|
- new_ingest.status = dm.models.IngestStatus.PRE_INGEST_FINISHED
|
|
|
- else:
|
|
|
- self.log.warn("Object {} not found for {}".format(ingest.object_uuid, ingest.staging_url))
|
|
|
+ if new_ingest:
|
|
|
+ _, output_path = new_ingest.staging_url.split('file:', 1)
|
|
|
+ reconstruct_scan(data_path, output_path)
|
|
|
+ new_ingest.status = dm.models.IngestStatus.PRE_INGEST_FINISHED
|
|
|
else:
|
|
|
- self.log.error("Cannot access {}".format(path))
|
|
|
+ self.log.error("No raw data found in {}".format(data_path))
|
|
|
|
|
|
def create_ingest(self, obj):
|
|
|
try:
|
|
|
user = self.client.get_user(obj.uploader)
|
|
|
user_client = dm.Client(token=user.credentials.key, token_secret=user.credentials.secret)
|
|
|
|
|
|
- new_obj = user_client.create_object(obj.investigation_id, user, label='foo2')
|
|
|
- self.log.info(" Created new object={} [uuid={}]".format(new_obj.id, new_obj.uuid))
|
|
|
+ new_obj = user_client.create_object(obj.investigation_id, user, label='reco')
|
|
|
+ self.log.info(" Created new object={}".format(new_obj))
|
|
|
|
|
|
new_ingest = new_obj.create_ingest(self.accesspoint)
|
|
|
|
|
|
# get the ingest again to acccess the staging url ...
|
|
|
- new_ingest = user_client.get_ingest(new_ingest.id)
|
|
|
- self.log.info(" Created new ingest={} [url={}]".format(new_ingest.id, new_ingest.staging_url))
|
|
|
+ new_ingest = dm.models.Ingest(user_client, new_ingest.id)
|
|
|
+ self.log.info(" Created new ingest={}".format(new_ingest))
|
|
|
return (user_client, new_ingest)
|
|
|
except dm.exceptions.NotFoundError:
|
|
|
self.log.warn(" No credentials found for user={}".format(obj.uploader))
|