示例#1
0
    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')
示例#2
0
    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()
示例#3
0
    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 solution.advanced_settings is None:
            advanced_settings, created = SolutionService.get_or_create_advanced_settings(
                target)
            solution.advanced_settings = advanced_settings
            Solution.objects.filter(pk=solution.pk).update(
                advanced_settings=advanced_settings)

        if solution.pixinsight_serial_number is None or solution.status == SolverBase.SUCCESS:
            solver = AdvancedSolver()

            try:
                observation_time = None
                latitude = None
                longitude = None
                altitude = None

                if target._meta.model_name == 'image':
                    image = target
                else:
                    image = target.image

                if solution.advanced_settings.sample_raw_frame_file:
                    url = solution.advanced_settings.sample_raw_frame_file.url
                else:
                    url = image.thumbnail(
                        'hd_sharpened' if image.sharpen_thumbnails else 'hd',
                        '0' if target._meta.model_name == 'image' else
                        target.label,
                        sync=True)

                acquisitions = DeepSky_Acquisition.objects.filter(image=image)
                if acquisitions.count() > 0 and acquisitions[0].date:
                    observation_time = acquisitions[0].date.isoformat()

                locations = image.locations.all()
                if locations.count() > 0:
                    location = locations[0]  # Type: Location
                    latitude = degrees_minutes_seconds_to_decimal_degrees(
                        location.lat_deg, location.lat_min, location.lat_sec,
                        location.lat_side)
                    longitude = degrees_minutes_seconds_to_decimal_degrees(
                        location.lon_deg, location.lon_min, location.lon_sec,
                        location.lon_side)
                    altitude = location.altitude

                submission = solver.solve(
                    url,
                    ra=solution.ra,
                    dec=solution.dec,
                    pixscale=solution.pixscale,
                    observation_time=observation_time,
                    latitude=latitude,
                    longitude=longitude,
                    altitude=altitude,
                    advanced_settings=solution.advanced_settings,
                    image_width=target.w,
                    image_height=target.h)

                solution.status = Solver.ADVANCED_PENDING
                solution.pixinsight_serial_number = submission
                solution.save()
            except Exception as e:
                log.error("Error during advanced plate-solving: %s" % str(e))
                solution.status = Solver.MISSING
                solution.submission_id = None
                solution.save()

        context = {
            'solution': solution.id,
            'submission': solution.pixinsight_serial_number,
            'status': solution.status,
        }
        return HttpResponse(simplejson.dumps(context),
                            content_type='application/json')