def post(self, request, *args, **kwargs): target = get_target(kwargs.get('object_id'), kwargs.get('content_type_id')) solution = get_solution(kwargs.get('object_id'), kwargs.get('content_type_id')) error = None if target._meta.model_name == 'image': image = target else: image = target.image if solution.settings is None: settings = PlateSolvingSettings.objects.create() solution.settings = settings Solution.objects.filter(pk=solution.pk).update(settings=settings) if solution.submission_id is None: solver = Solver() try: url = image.thumbnail( 'hd_sharpened' if image.sharpen_thumbnails else 'hd', '0' if target._meta.model_name == 'image' else target.label, sync=True) if solution.settings.blind: submission = solver.solve(url) else: submission = solver.solve( url, scale_units=solution.settings.scale_units, scale_lower=solution.settings.scale_min, scale_upper=solution.settings.scale_max, center_ra=solution.settings.center_ra, center_dec=solution.settings.center_dec, radius=solution.settings.radius, ) solution.status = Solver.PENDING solution.submission_id = submission solution.save() except Exception as e: log.error("Error during basic plate-solving: %s" % str(e)) solution.status = Solver.MISSING solution.submission_id = None solution.save() error = str(e) context = { 'solution': solution.id, 'submission': solution.submission_id, 'status': solution.status, 'error': error } return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): solution = get_object_or_404(Solution, pk=kwargs.pop('pk')) solver = None status = None error = None queue_size = None pixinsight_stage = None pixinsight_log = None try: if solution.status < SolverBase.ADVANCED_PENDING: solver = Solver() status = solver.status(solution.submission_id) else: status = solution.status try: task = PlateSolvingAdvancedTask.objects.get( serial_number=solution.pixinsight_serial_number) queue_size = PlateSolvingAdvancedTask.objects.filter( active=True, created__lt=task.created).count() error = task.error_message except PlateSolvingAdvancedTask.DoesNotExist: log.error("PixInsight task %s does not exist!" % solution.pixinsight_serial_number) live_log_entry = PlateSolvingAdvancedLiveLogEntry.objects.filter( serial_number=solution.pixinsight_serial_number).order_by( '-timestamp').first() if live_log_entry: pixinsight_stage = live_log_entry.stage pixinsight_log = live_log_entry.log if status == Solver.MISSING: solution.status = status solution.save() except Exception as e: log.error("Error during basic plate-solving: %s" % str(e)) solution.status = Solver.MISSING solution.submission_id = None solution.save() error = str(e) context = { 'status': status, 'started': solution.created.timestamp() * 1000, 'submission_id': solution.submission_id, 'pixinsight_serial_number': solution.pixinsight_serial_number, 'pixinsight_stage': pixinsight_stage, 'pixinsight_log': pixinsight_log, 'queue_size': queue_size, 'error': error } return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): solution = get_object_or_404(Solution, pk = kwargs.pop('pk')) solver = Solver() status = solver.status(solution.submission_id) if status == Solver.MISSING: solution.status = status solution.save() context = {'status': status} return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): solution = get_object_or_404(Solution, pk=kwargs.pop('pk')) solver = Solver() status = solver.status(solution.submission_id) if status == Solver.MISSING: solution.status = status solution.save() context = {'status': status} return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): target = get_target(kwargs.get('object_id'), kwargs.get('content_type_id')) solution = get_solution(kwargs.get('object_id'), kwargs.get('content_type_id')) if target._meta.model_name == u'image': image = target else: image = target.image if solution.settings is None: solution.settings = PlateSolvingSettings.objects.create() solution.save() if solution.submission_id is None: solver = Solver() try: url = target.thumbnail( 'hd_sharpened' if image.sharpen_thumbnails else 'hd', { 'sync': True, 'revision_label': '0' if target._meta.model_name == u'image' else target.label }) if solution.settings.blind: submission = solver.solve(url) else: submission = solver.solve( url, scale_units=solution.settings.scale_units, scale_lower=solution.settings.scale_min, scale_upper=solution.settings.scale_max, center_ra=solution.settings.center_ra, center_dec=solution.settings.center_dec, radius=solution.settings.radius, ) solution.status = Solver.PENDING solution.submission_id = submission solution.save() except Exception, e: log.error(e) solution.status = Solver.MISSING solution.submission_id = None solution.save()
def post(self, request, *args, **kwargs): object_id = kwargs.pop('object_id') content_type_id = kwargs.pop('content_type_id') content_type = ContentType.objects.get_for_id(content_type_id) manager = content_type.model_class() if hasattr(manager, 'objects_including_wip'): manager = manager.objects_including_wip target = get_object_or_404(manager, pk=object_id) solution, created = Solution.objects.get_or_create( object_id=object_id, content_type=content_type) if solution.settings is None: solution.settings = PlateSolvingSettings.objects.create() solution.save() if solution.submission_id is None: solver = Solver() try: f = getFromStorage(target, 'hd') if solution.settings.blind: submission = solver.solve(f) else: submission = solver.solve( f, scale_units=solution.settings.scale_units, scale_lower=solution.settings.scale_min, scale_upper=solution.settings.scale_max, center_ra=solution.settings.center_ra, center_dec=solution.settings.center_dec, radius=solution.settings.radius, ) solution.status = Solver.PENDING solution.submission_id = submission solution.save() except: solution.status = Solver.MISSING solution.submission_id = None solution.save() context = { 'solution': solution.id, 'submission': solution.submission_id, 'status': solution.status, } return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): object_id = kwargs.pop('object_id') content_type_id = kwargs.pop('content_type_id') content_type = ContentType.objects.get_for_id(content_type_id) manager = content_type.model_class() if hasattr(manager, 'objects_including_wip'): manager = manager.objects_including_wip target = get_object_or_404(manager, pk = object_id) solution, created = Solution.objects.get_or_create(object_id = object_id, content_type = content_type) if solution.settings is None: solution.settings = PlateSolvingSettings.objects.create() solution.save() if solution.submission_id is None: solver = Solver() try: f = getFromStorage(target, 'hd') if solution.settings.blind: submission = solver.solve(f) else: submission = solver.solve(f, scale_units = solution.settings.scale_units, scale_lower = solution.settings.scale_min, scale_upper = solution.settings.scale_max, center_ra = solution.settings.center_ra, center_dec = solution.settings.center_dec, radius = solution.settings.radius, ) solution.status = Solver.PENDING solution.submission_id = submission solution.save() except: solution.status = Solver.MISSING solution.submission_id = None solution.save() context = { 'solution': solution.id, 'submission': solution.submission_id, 'status': solution.status, } return HttpResponse(simplejson.dumps(context), content_type='application/json')
def post(self, request, *args, **kwargs): solution = get_object_or_404(Solution, pk=kwargs.pop('pk')) solver = Solver() status = solver.status(solution.submission_id) if status == Solver.SUCCESS: info = solver.info(solution.submission_id) solution.objects_in_field = ', '.join(info['objects_in_field']) solution.ra = "%.3f" % info['calibration']['ra'] solution.dec = "%.3f" % info['calibration']['dec'] solution.orientation = "%.3f" % info['calibration']['orientation'] solution.radius = "%.3f" % info['calibration']['radius'] solution.pixscale = "%.3f" % corrected_pixscale(solution, info['calibration']['pixscale']) try: target = solution.content_type.get_object_for_this_type(pk=solution.object_id) except solution.content_type.model_class().DoesNotExist: # Target image was deleted meanwhile context = {'status': Solver.FAILED} return HttpResponse(simplejson.dumps(context), content_type='application/json') # Annotate image annotations_obj = solver.annotations(solution.submission_id) solution.annotations = simplejson.dumps(annotations_obj) annotator = Annotator(solution) try: annotated_image = annotator.annotate() except ThumbnailNotReadyException: solution.status = Solver.PENDING solution.save() context = {'status': solution.status} return HttpResponse(simplejson.dumps(context), content_type='application/json') filename, ext = os.path.splitext(target.image_file.name) annotated_filename = "%s-%d%s" % (filename, int(time.time()), ext) if annotated_image: solution.image_file.save(annotated_filename, annotated_image) # Get sky plot image url = solver.sky_plot_zoom1_image_url(solution.submission_id) if url: img = NamedTemporaryFile(delete=True) img.write(urllib2.urlopen(url).read()) img.flush() img.seek(0) f = File(img) try: solution.skyplot_zoom1.save(target.image_file.name, f) except IntegrityError: pass solution.status = status solution.save() context = {'status': solution.status} return HttpResponse(simplejson.dumps(context), content_type='application/json')
def __init__(self, solution): self.solution = solution self.resampling_factor = 2.0 self.line_thickness = 2 * int(round(self.resampling_factor)) self.solver = Solver()
def post(self, request, *args, **kwargs): solution = get_object_or_404(Solution, pk = kwargs.pop('pk')) solver = Solver() status = solver.status(solution.submission_id) if status == Solver.SUCCESS: info = solver.info(solution.submission_id) solution.objects_in_field = ', '.join(info['objects_in_field']) solution.ra = "%.3f" % info['calibration']['ra'] solution.dec = "%.3f" % info['calibration']['dec'] solution.orientation = "%.3f" % info['calibration']['orientation'] solution.radius = "%.3f" % info['calibration']['radius'] # Get the images 'w' and adjust pixscale if solution.content_object: w = solution.content_object.w pixscale = info['calibration']['pixscale'] if w and pixscale: hd_w = settings.THUMBNAIL_ALIASES['']['hd']['size'][0] if hd_w > w: hd_w = w ratio = hd_w / float(w) corrected_scale = float(pixscale) * ratio solution.pixscale = "%.3f" % corrected_scale else: solution.pixscale = None try: target = solution.content_type.get_object_for_this_type(pk = solution.object_id) except solution.content_type.model_class().DoesNotExist: # Target image was deleted meanwhile context = {'status': Solver.FAILED} return HttpResponse(simplejson.dumps(context), content_type='application/json') # Annotate image annotations_obj = solver.annotations(solution.submission_id) solution.annotations = simplejson.dumps(annotations_obj) annotator = Annotator(solution) annotated_image = annotator.annotate() filename, ext = os.path.splitext(target.image_file.name) annotated_filename = "%s-%d%s" % (filename, int(time.time()), ext) if annotated_image: solution.image_file.save(annotated_filename, annotated_image) # Get sky plot image url = solver.sky_plot_zoom1_image_url(solution.submission_id) if url: img = NamedTemporaryFile(delete=True) img.write(urllib2.urlopen(url).read()) img.flush() img.seek(0) f = File(img) try: solution.skyplot_zoom1.save(target.image_file.name, f) except IntegrityError: pass solution.status = status solution.save() context = {'status': solution.status} return HttpResponse(simplejson.dumps(context), content_type='application/json')