Esempio n. 1
0
    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')
Esempio n. 2
0
    def post(self, request, *args, **kwargs):
        serial_number = request.POST.get('serialNumber')
        status = request.POST.get('status', 'ERROR')

        log.debug("PixInsight Webhook called for %s: %s" % (serial_number, status))

        solution = get_object_or_404(Solution, pixinsight_serial_number=serial_number)

        if status == 'OK':
            svg_hd = request.POST.get('svgAnnotation', None)
            svg_regular = request.POST.get('svgAnnotationSmall', svg_hd)

            solution.pixinsight_svg_annotation_hd.save(serial_number + ".svg", ContentFile(svg_hd))
            solution.pixinsight_svg_annotation_regular.save(serial_number + ".svg", ContentFile(svg_regular))
            solution.status = Solver.ADVANCED_SUCCESS

            solution.advanced_ra = request.POST.get('centerRA', None)
            solution.advanced_ra_top_left = request.POST.get('topLeftRA', None)
            solution.advanced_ra_top_right = request.POST.get('topRightRA', None)
            solution.advanced_ra_bottom_left = request.POST.get('bottomLeftRA', None)
            solution.advanced_ra_bottom_right = request.POST.get('bottomRightRA', None)

            solution.advanced_dec = request.POST.get('centerDec', None)
            solution.advanced_dec_top_left = request.POST.get('topLeftDec', None)
            solution.advanced_dec_top_right = request.POST.get('topRightDec', None)
            solution.advanced_dec_bottom_left = request.POST.get('bottomLeftDec', None)
            solution.advanced_dec_bottom_right = request.POST.get('bottomRightDec', None)

            solution.advanced_orientation = request.POST.get('rotation', None)
            solution.advanced_pixscale = corrected_pixscale(solution, request.POST.get('resolution', None))
            solution.advanced_flipped = request.POST.get('flipped', None) == 'true'
            solution.advanced_wcs_transformation = request.POST.get('wcs_transformation', None)

            solution.advanced_matrix_rect = request.POST.get('matrixRect', None)
            solution.advanced_matrix_delta = request.POST.get('matrixDelta', None)
            solution.advanced_ra_matrix = request.POST.get('raMatrix', None)
            solution.advanced_dec_matrix = request.POST.get('decMatrix', None)

            solution.advanced_annotations = request.POST.get('labelInfo', None)
            solution.advanced_annotations_regular = request.POST.get('labelInfoSmall', None)
        else:
            solution.status = Solver.ADVANCED_FAILED
            log.error(request.POST.get('errorMessage', 'Unknown error'))

        solution.save()

        return HttpResponse("OK")
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        serial_number = request.POST.get('serialNumber')
        status = request.POST.get('status', 'ERROR')
        error_message = request.POST.get('errorMessage')

        log.debug("PixInsight Webhook called for %s: %s" %
                  (serial_number, status))

        PlateSolvingAdvancedTask.objects.filter(
            serial_number=serial_number).update(
                status=status,
                error_message=error_message,
            )

        solution = get_object_or_404(Solution,
                                     pixinsight_serial_number=serial_number)

        if status == 'OK':
            svg_hd = request.POST.get('svgAnnotation')
            svg_regular = request.POST.get('svgAnnotationSmall', svg_hd)
            pixscale = request.POST.get('resolution')
            finding_chart = request.POST.get('findingChart')
            finding_chart_small = request.POST.get('findingChartSmall')

            if svg_hd:
                solution.pixinsight_svg_annotation_hd.save(
                    serial_number + ".svg",
                    ContentFile(svg_hd.encode('utf-8')))

            if svg_regular:
                solution.pixinsight_svg_annotation_regular.save(
                    serial_number + ".svg",
                    ContentFile(svg_regular.encode('utf-8')))

            if finding_chart:
                data = base64.b64decode(urllib.parse.unquote(finding_chart))
                solution.pixinsight_finding_chart = ContentFile(
                    data, name=f'{uuid.uuid4()}.png')

            if finding_chart_small:
                data = base64.b64decode(
                    urllib.parse.unquote(finding_chart_small))
                solution.pixinsight_finding_chart_small = ContentFile(
                    data, name=f'{uuid.uuid4()}.png')

            solution.status = Solver.ADVANCED_SUCCESS

            solution.advanced_ra = request.POST.get('centerRA')
            solution.advanced_ra_top_left = request.POST.get('topLeftRA')
            solution.advanced_ra_top_right = request.POST.get('topRightRA')
            solution.advanced_ra_bottom_left = request.POST.get('bottomLeftRA')
            solution.advanced_ra_bottom_right = request.POST.get(
                'bottomRightRA')

            solution.advanced_dec = request.POST.get('centerDec')
            solution.advanced_dec_top_left = request.POST.get('topLeftDec')
            solution.advanced_dec_top_right = request.POST.get('topRightDec')
            solution.advanced_dec_bottom_left = request.POST.get(
                'bottomLeftDec')
            solution.advanced_dec_bottom_right = request.POST.get(
                'bottomRightDec')

            solution.advanced_orientation = request.POST.get('rotation')
            solution.advanced_pixscale = pixscale \
                if solution.advanced_settings and solution.advanced_settings.sample_raw_frame_file \
                else corrected_pixscale(solution, pixscale)
            solution.advanced_flipped = request.POST.get('flipped') == 'true'
            solution.advanced_wcs_transformation = request.POST.get(
                'wcsTransformation')

            solution.advanced_matrix_rect = request.POST.get('matrixRect')
            solution.advanced_matrix_delta = request.POST.get('matrixDelta')
            solution.advanced_ra_matrix = request.POST.get('raMatrix')
            solution.advanced_dec_matrix = request.POST.get('decMatrix')

            solution.advanced_annotations = request.POST.get('labelInfo')
            solution.advanced_annotations_regular = request.POST.get(
                'labelInfoSmall')
        else:
            solution.status = Solver.ADVANCED_FAILED
            log.error(request.POST.get('errorMessage', 'Unknown error'))

        solution.save()

        return HttpResponse("OK")