예제 #1
0
    def test_get_objects_in_field_capitals(self):
        basic = 'Merope nebula'
        advanced = 'Label,1,2,3,Merope Nebula'

        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)
        solution.objects_in_field = basic
        solution.advanced_annotations = advanced

        self.assertEqual(
            ['Merope nebula'],
            SolutionService(solution).get_objects_in_field(clean=False))
        self.assertEqual(['Merope nebula'],
                         SolutionService(solution).get_objects_in_field())
예제 #2
0
    def test_get_or_create_advanced_settings_image_does_not_inherit_file(self):
        image = Generators.image()

        solution = PlateSolvingGenerators.solution(image)
        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            image)
        advanced_settings.sample_raw_frame_file = File(
            open('astrobin/fixtures/test.fits'), "test.fits")
        advanced_settings.scaled_font_size = "L"

        solution.advanced_settings = advanced_settings
        solution.content_object = image
        solution.save()
        advanced_settings.save()

        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            Generators.image(user=image.user))

        self.assertIsNone(advanced_settings.sample_raw_frame_file.name)
        self.assertEquals(advanced_settings.scaled_font_size, "L")
        self.assertFalse(created)
예제 #3
0
파일: api.py 프로젝트: MattBlack85/astrobin
    def dehydrate_subjects(self, bundle):
        if bundle.obj.solution:
            subjects = SolutionService(bundle.obj.solution).get_objects_in_field()
            solar_system_main_subject = bundle.obj.solar_system_main_subject

            ret = subjects

            if solar_system_main_subject:
                ret.append(ImageService(bundle.obj).get_solar_system_main_subject_label())

            return ret
        return []
예제 #4
0
    def test_get_objects_in_field_2(self):
        basic = \
            'M 43, Mairan\'s Nebula, NGC 1982, Upper Sword, NGC 1981, Lower Sword, NGC 1980, the Running Man Nebula, ' \
            'NGC 1977, M 42, Orion Nebula, Great Orion Nebula, NGC 1976, NGC 1975, NGC 1973, The star 45Ori, ' \
            'The star ιOri, The star θ2Ori, The star θ1Ori, The star 42Ori'
        advanced = \
            'GridLabel,2100.97,889.69,2133.97,899.69,−7°30′\n' \
            'GridLabel,1752.10,661.34,1785.10,671.34,−6°45′\n' \
            'GridLabel,1403.90,433.37,1420.90,443.37,−6°\n' \
            'GridLabel,1055.90,205.27,1088.90,215.27,−5°15′\n' \
            'GridLabel,707.92,-23.04,740.92,-13.04,−4°30′\n' \
            'GridLabel,359.61,-251.42,392.61,-241.42,−3°45′\n' \
            'GridLabel,2014.56,-503.48,2047.56,-493.48,5h24m\n' \
            'GridLabel,1708.58,-41.88,1741.58,-31.88,5h28m\n' \
            'GridLabel,1403.90,419.37,1436.90,429.37,5h32m\n' \
            'GridLabel,1100.39,880.64,1133.39,890.64,5h36m\n' \
            'GridLabel,797.83,1342.59,830.83,1352.59,5h40m\n' \
            'Label,1047.55,803.40,1090.55,814.40,44 iot Ori\n' \
            'Label,1050.55,780.40,1090.55,793.40,Hatysa\n' \
            'Label,840.08,653.15,912.08,664.15,43 the02 Ori\n' \
            'Label,835.68,597.86,907.68,608.86,41 the01 Ori\n' \
            'Label,577.89,515.42,612.89,526.42,45 Ori\n' \
            'Label,618.81,462.10,663.81,473.10,42 c Ori\n' \
            'Label,883.02,616.32,955.02,627.32,41 the01 Ori\n' \
            'Label,783.97,590.40,808.97,602.40,M43\n' \
            'Label,668.97,618.90,790.97,630.90,De Mairan\'s nebula\n' \
            'Label,1412.06,1150.52,1471.06,1162.52,NGC1999\n' \
            'Label,1116.54,791.05,1175.54,803.05,NGC1980\n' \
            'Label,590.69,425.52,648.69,437.52,NGC1977\n' \
            'Label,552.36,377.02,610.36,389.02,NGC1973\n' \
            'Label,473.70,416.32,531.70,428.32,NGC1975\n' \
            'Label,447.67,310.97,505.67,322.97,NGC1981\n' \
            'Label,1330.13,255.41,1357.13,263.41,VdB42\n' \
            'Label,684.14,18.22,711.14,26.22,VdB44\n' \
            'Label,946.28,588.09,979.28,596.09,Sh2-281\n' \
            'Label,550.18,457.48,583.18,465.48,Sh2-279\n'

        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)
        solution.objects_in_field = basic
        solution.advanced_annotations = advanced

        self.assertEqual([
            '41 the01 Ori', '42 c Ori', '43 the02 Ori', '44 iot Ori', '45 Ori',
            'De Mairan\'s nebula', 'Great Orion Nebula', 'Hatysa',
            'Lower Sword', 'M 42', 'M 43', 'Mairan\'s Nebula', 'NGC 1973',
            'NGC 1975', 'NGC 1976', 'NGC 1977', 'NGC 1980', 'NGC 1981',
            'NGC 1982', 'NGC 1999', 'Orion Nebula', 'Sh2-279', 'Sh2-281',
            'The star 42Ori', 'The star 45Ori', 'The star θ1Ori',
            'The star θ2Ori', 'The star ιOri', 'Upper Sword', 'VdB42', 'VdB44',
            'the Running Man Nebula'
        ],
                         SolutionService(solution).get_objects_in_field())
예제 #5
0
    def test_get_or_create_advanced_settings_revision_inherits_everything(
            self):
        image = Generators.image()

        solution = PlateSolvingGenerators.solution(image)
        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            image)
        advanced_settings.sample_raw_frame_file = File(
            open('astrobin/fixtures/test.fits'), "test.fits")
        advanced_settings.scaled_font_size = "L"

        solution.advanced_settings = advanced_settings
        solution.content_object = image
        solution.save()
        advanced_settings.save()

        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            Generators.imageRevision(image=image))

        self.assertNotEquals(advanced_settings.sample_raw_frame_file.name, "")
        self.assertEquals(advanced_settings.scaled_font_size, "L")
        self.assertFalse(created)
예제 #6
0
    def test_duplicate_objects_in_field_by_catalog_space(self):
        basic = "Orion Nebula, M 42, M 43"
        advanced = \
            "Label,1,2,3,M42\n" \
            "Label,1,2,3,M43\n" \
            "Label,1,2,3,M 45\n" \
            "Label,1,2,3,LDN123\n" \
            "Label,1,2,3,LDN 999\n" \
            "Label,1,2,3,LBN456\n"

        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)
        solution.objects_in_field = basic
        solution.advanced_annotations = advanced

        objects = SolutionService(
            solution).duplicate_objects_in_field_by_catalog_space()

        self.assertTrue("Orion Nebula" in objects)

        self.assertTrue("M42" in objects)
        self.assertTrue("M 42" in objects)

        self.assertTrue("M43" in objects)
        self.assertTrue("M 43" in objects)

        self.assertTrue("M45" in objects)
        self.assertTrue("M 45" in objects)

        self.assertTrue("LDN123" in objects)
        self.assertTrue("LDN 123" in objects)

        self.assertTrue("LDN999" in objects)
        self.assertTrue("LDN 999" in objects)

        self.assertTrue("LBN456" in objects)
        self.assertTrue("LBN 456" in objects)
예제 #7
0
 def test_get_or_create_advanced_settings_only_image(self):
     image = Generators.image()
     advanced_settings, created = SolutionService.get_or_create_advanced_settings(
         image)
     self.assertIsNone(advanced_settings.sample_raw_frame_file.name)
     self.assertTrue(created)
예제 #8
0
    def get_context_data(self, **kwargs):
        context = super(ImageDetailView, self).get_context_data(**kwargs)

        image = context['object']
        r = self.kwargs.get('r')
        if r is None:
            r = '0'

        revision_image = None
        instance_to_platesolve = image
        is_revision = False
        if r != '0':
            try:
                revision_image = ImageRevision.objects.filter(image=image,
                                                              label=r)[0]
                instance_to_platesolve = revision_image
                is_revision = True
            except:
                pass

        #############################
        # GENERATE ACQUISITION DATA #
        #############################
        from astrobin.moon import MoonPhase

        gear_list = (
            (_('Imaging telescopes or lenses'), image.imaging_telescopes.all(),
             'imaging_telescopes'),
            (_('Imaging cameras'), image.imaging_cameras.all(),
             'imaging_cameras'),
            (_('Mounts'), image.mounts.all(), 'mounts'),
            (_('Guiding telescopes or lenses'), image.guiding_telescopes.all(),
             'guiding_telescopes'),
            (_('Guiding cameras'), image.guiding_cameras.all(),
             'guiding_cameras'),
            (_('Focal reducers'), image.focal_reducers.all(),
             'focal_reducers'),
            (_('Software'), image.software.all(), 'software'),
            (_('Filters'), image.filters.all(), 'filters'),
            (_('Accessory'), image.accessories.all(), 'accessories'),
        )

        makes_list = ','.join(
            filter(
                None,
                reduce(lambda x, y: x + y, [
                    list(x.values_list('make', flat=True))
                    for x in [y[1] for y in gear_list]
                ])))

        deep_sky_acquisitions = DeepSky_Acquisition.objects.filter(image=image)
        ssa = None
        image_type = None
        deep_sky_data = {}

        if is_revision:
            w, h = get_image_resolution(revision_image)
        else:
            w, h = get_image_resolution(image)

        try:
            ssa = SolarSystem_Acquisition.objects.get(image=image)
        except SolarSystem_Acquisition.DoesNotExist:
            pass

        if deep_sky_acquisitions:
            image_type = 'deep_sky'

            moon_age_list = []
            moon_illuminated_list = []

            dsa_data = {
                'dates': [],
                'frames': {},
                'integration': 0,
                'darks': [],
                'flats': [],
                'flat_darks': [],
                'bias': [],
                'bortle': [],
                'mean_sqm': [],
                'mean_fwhm': [],
                'temperature': [],
            }
            for a in deep_sky_acquisitions:
                if a.date is not None and a.date not in dsa_data['dates']:
                    dsa_data['dates'].append(a.date)
                    m = MoonPhase(a.date)
                    moon_age_list.append(m.age)
                    moon_illuminated_list.append(m.illuminated * 100.0)

                if a.number and a.duration:
                    key = ""
                    if a.filter is not None:
                        key = "filter(%s)" % a.filter.get_name()
                    if a.iso is not None:
                        key += '-ISO(%d)' % a.iso
                    if a.gain is not None:
                        key += '-gain(%.2f)' % a.gain
                    if a.sensor_cooling is not None:
                        key += '-temp(%d)' % a.sensor_cooling
                    if a.binning is not None:
                        key += '-bin(%d)' % a.binning
                    key += '-duration(%d)' % a.duration

                    try:
                        current_frames = dsa_data['frames'][key]['integration']
                    except KeyError:
                        current_frames = '0x0"'

                    integration_re = re.match(r'^(\d+)x(\d+)"$',
                                              current_frames)
                    current_number = int(integration_re.group(1))

                    dsa_data['frames'][key] = {}
                    dsa_data['frames'][key][
                        'filter_url'] = a.filter.get_absolute_url(
                        ) if a.filter is not None else '#'
                    dsa_data['frames'][key][
                        'filter'] = a.filter if a.filter is not None else ''
                    dsa_data['frames'][key][
                        'iso'] = 'ISO%d' % a.iso if a.iso is not None else ''
                    dsa_data['frames'][key][
                        'gain'] = '(gain: %.2f)' % a.gain if a.gain is not None else ''
                    dsa_data['frames'][key][
                        'sensor_cooling'] = '%dC' % a.sensor_cooling if a.sensor_cooling is not None else ''
                    dsa_data['frames'][key]['binning'] = 'bin %sx%s' % (
                        a.binning, a.binning) if a.binning else ''
                    dsa_data['frames'][key]['integration'] = '%sx%s"' % (
                        current_number + a.number, a.duration)

                    dsa_data['integration'] += (a.duration * a.number / 3600.0)

                for i in ['darks', 'flats', 'flat_darks', 'bias']:
                    if a.filter and getattr(a, i):
                        dsa_data[i].append("%d" % getattr(a, i))
                    elif getattr(a, i):
                        dsa_data[i].append(getattr(a, i))

                if a.bortle:
                    dsa_data['bortle'].append(a.bortle)

                if a.mean_sqm:
                    dsa_data['mean_sqm'].append(a.mean_sqm)

                if a.mean_fwhm:
                    dsa_data['mean_fwhm'].append(a.mean_fwhm)

                if a.temperature:
                    dsa_data['temperature'].append(a.temperature)

            def average(values):
                if not len(values):
                    return 0
                return float(sum(values)) / len(values)

            frames_list = sorted(dsa_data['frames'].items())

            deep_sky_data = (
                (_('Dates'), sorted(dsa_data['dates'])),
                (_('Frames'), ('\n' if len(frames_list) > 1 else '') +
                 u'\n'.join("%s %s" % (
                     "<a href=\"%s\">%s</a>:" %
                     (f[1]['filter_url'],
                      f[1]['filter']) if f[1]['filter'] else '',
                     "%s %s %s %s %s" %
                     (f[1]['integration'], f[1]['iso'], f[1]['gain'],
                      f[1]['sensor_cooling'], f[1]['binning']),
                 ) for f in frames_list)),
                (_('Integration'),
                 "%.1f %s" % (dsa_data['integration'], _("hours"))),
                (_('Darks'), '~%d' %
                 (int(reduce(lambda x, y: int(x) + int(y), dsa_data['darks']))
                  / len(dsa_data['darks'])) if dsa_data['darks'] else 0),
                (_('Flats'), '~%d' %
                 (int(reduce(lambda x, y: int(x) + int(y), dsa_data['flats']))
                  / len(dsa_data['flats'])) if dsa_data['flats'] else 0),
                (_('Flat darks'), '~%d' % (int(
                    reduce(lambda x, y: int(x) + int(y),
                           dsa_data['flat_darks'])) /
                                           len(dsa_data['flat_darks']))
                 if dsa_data['flat_darks'] else 0),
                (_('Bias'), '~%d' %
                 (int(reduce(lambda x, y: int(x) + int(y), dsa_data['bias'])) /
                  len(dsa_data['bias'])) if dsa_data['bias'] else 0),
                (_('Avg. Moon age'), ("%.2f " % (average(moon_age_list), ) +
                                      _("days")) if moon_age_list else None),
                (_('Avg. Moon phase'),
                 "%.2f%%" % (average(moon_illuminated_list), )
                 if moon_illuminated_list else None),
                (_('Bortle Dark-Sky Scale'),
                 "%.2f" % (average([float(x) for x in dsa_data['bortle']]))
                 if dsa_data['bortle'] else None),
                (_('Mean SQM'),
                 "%.2f" % (average([float(x) for x in dsa_data['mean_sqm']]))
                 if dsa_data['mean_sqm'] else None),
                (_('Mean FWHM'),
                 "%.2f" % (average([float(x) for x in dsa_data['mean_fwhm']]))
                 if dsa_data['mean_fwhm'] else None),
                (_('Temperature'),
                 "%.2f" % (average([float(x)
                                    for x in dsa_data['temperature']]))
                 if dsa_data['temperature'] else None),
            )

        elif ssa:
            image_type = 'solar_system'

        profile = None
        if self.request.user.is_authenticated():
            profile = self.request.user.userprofile

        ##############
        # BASIC DATA #
        ##############

        published_on = \
            to_user_timezone(image.uploaded, profile) \
                if profile else image.uploaded
        if image.published:
            published_on = \
                to_user_timezone(image.published, profile) \
                    if profile else image.published

        alias = 'regular' if not image.sharpen_thumbnails else 'regular_sharpened'
        mod = self.request.GET.get('mod')
        if mod == 'inverted':
            alias = 'regular_inverted'

        subjects = []
        skyplot_zoom1 = None

        if image.solution:
            subjects = SolutionService(image.solution).get_objects_in_field()
            skyplot_zoom1 = image.solution.skyplot_zoom1

        if is_revision and revision_image.solution:
            subjects = SolutionService(
                revision_image.solution).get_objects_in_field()
            if revision_image.solution.skyplot_zoom1:
                skyplot_zoom1 = revision_image.solution.skyplot_zoom1

        licenses = (
            (0, 'cc/c.png', LICENSE_CHOICES[0][1]),
            (1, 'cc/cc-by-nc-sa.png', LICENSE_CHOICES[1][1]),
            (2, 'cc/cc-by-nc.png', LICENSE_CHOICES[2][1]),
            (3, 'cc/cc-by-nc-nd.png', LICENSE_CHOICES[3][1]),
            (4, 'cc/cc-by.png', LICENSE_CHOICES[4][1]),
            (5, 'cc/cc-by-sa.png', LICENSE_CHOICES[5][1]),
            (6, 'cc/cc-by-nd.png', LICENSE_CHOICES[6][1]),
        )

        locations = '; '.join([u'%s' % (x) for x in image.locations.all()])

        ######################
        # PREFERRED LANGUAGE #
        ######################

        preferred_language = image.user.userprofile.language
        if preferred_language:
            try:
                preferred_language = LANGUAGES[preferred_language]
            except KeyError:
                preferred_language = _("English")
        else:
            preferred_language = _("English")

        ##########################
        # LIKE / BOOKMARKED THIS #
        ##########################
        like_this = image.toggleproperties.filter(property_type="like")
        bookmarked_this = image.toggleproperties.filter(
            property_type="bookmark")

        ##############
        # NAVIGATION #
        ##############
        image_next = None
        image_prev = None
        try:
            nav_ctx = self.request.GET.get('nc')
            if nav_ctx is None:
                nav_ctx = self.request.session.get('nav_ctx')
            if nav_ctx is None:
                nav_ctx = 'user'

            nav_ctx_extra = self.request.GET.get('nce')
            if nav_ctx_extra is None:
                nav_ctx_extra = self.request.session.get('nav_ctx_extra')

            # Always only lookup public, non corrupted images!
            if nav_ctx == 'user':
                image_next = Image.objects \
                                 .exclude(corrupted=True) \
                                 .filter(user=image.user, pk__gt=image.pk).order_by('pk')[0:1]
                image_prev = Image.objects \
                                 .exclude(corrupted=True) \
                                 .filter(user=image.user, pk__lt=image.pk).order_by('-pk')[0:1]
            elif nav_ctx == 'collection':
                try:
                    try:
                        collection = image.collections.get(pk=nav_ctx_extra)
                    except ValueError:
                        # Maybe this image is in a single collection
                        collection = image.collections.all()[0]

                    if collection.order_by_tag:
                        collection_images = Image.objects \
                            .exclude(corrupted=True) \
                            .filter(user=image.user, collections=collection, keyvaluetags__key=collection.order_by_tag) \
                            .order_by('keyvaluetags__value')

                        current_index = 0
                        for iter_image in collection_images.all():
                            if iter_image.pk == image.pk:
                                break
                            current_index += 1

                        image_next = collection_images.all()[current_index + 1] \
                            if current_index < collection_images.count() - 1 \
                            else None
                        image_prev = collection_images.all()[current_index - 1] \
                            if current_index > 0 \
                            else None
                    else:
                        image_next = Image.objects \
                                         .exclude(corrupted=True) \
                                         .filter(user=image.user, collections=collection,
                                                 pk__gt=image.pk).order_by('pk')[0:1]
                        image_prev = Image.objects \
                                         .exclude(corrupted=True) \
                                         .filter(user=image.user, collections=collection,
                                                 pk__lt=image.pk).order_by('-pk')[0:1]
                except Collection.DoesNotExist:
                    # image_prev and image_next will remain None
                    pass
            elif nav_ctx == 'group':
                try:
                    group = image.part_of_group_set.get(pk=nav_ctx_extra)
                    if group.public:
                        image_next = Image.objects \
                                         .exclude(corrupted=True) \
                                         .filter(part_of_group_set=group, pk__gt=image.pk).order_by('pk')[0:1]
                        image_prev = Image.objects \
                                         .exclude(corrupted=True) \
                                         .filter(part_of_group_set=group, pk__lt=image.pk).order_by('-pk')[0:1]
                except (Group.DoesNotExist, ValueError):
                    # image_prev and image_next will remain None
                    pass
            elif nav_ctx == 'all':
                image_next = Image.objects.exclude(corrupted=True).filter(
                    pk__gt=image.pk).order_by('pk')[0:1]
                image_prev = Image.objects.exclude(corrupted=True).filter(
                    pk__lt=image.pk).order_by('-pk')[0:1]
        except Image.DoesNotExist:
            image_next = None
            image_prev = None

        if image_next and isinstance(image_next, QuerySet):
            image_next = image_next[0]
        if image_prev and isinstance(image_prev, QuerySet):
            image_prev = image_prev[0]

        #################
        # RESPONSE DICT #
        #################

        from astrobin_apps_platesolving.solver import Solver

        if skyplot_zoom1 and not skyplot_zoom1.name.startswith('images/'):
            skyplot_zoom1.name = 'images/' + skyplot_zoom1.name

        response_dict = context.copy()
        response_dict.update({
            'SHARE_PATH': settings.SHORT_BASE_URL,

            'alias': alias,
            'mod': mod,
            'revisions': ImageService(image) \
                .get_revisions(include_corrupted=self.request.user == image.user) \
                .select_related('image__user__userprofile'),
            'revisions_with_description': ImageService(image) \
                .get_revisions_with_description(include_corrupted=self.request.user == image.user) \
                .select_related('image__user__userprofile'),
            'is_revision': is_revision,
            'revision_image': revision_image,
            'revision_label': r,

            'instance_to_platesolve': instance_to_platesolve,
            'show_solution': instance_to_platesolve.mouse_hover_image == "SOLUTION"
                             and instance_to_platesolve.solution
                             and instance_to_platesolve.solution.status >= Solver.SUCCESS,
            'show_advanced_solution': instance_to_platesolve.mouse_hover_image == "SOLUTION"
                                      and instance_to_platesolve.solution
                                      and instance_to_platesolve.solution.status == Solver.ADVANCED_SUCCESS,
            'skyplot_zoom1': skyplot_zoom1,

            'image_ct': ContentType.objects.get_for_model(Image),
            'like_this': like_this,
            'user_can_like': can_like(self.request.user, image),
            'bookmarked_this': bookmarked_this,

            'comments_number': NestedComment.objects.filter(
                deleted=False,
                content_type__app_label='astrobin',
                content_type__model='image',
                object_id=image.id).count(),
            'gear_list': gear_list,
            'makes_list': makes_list,
            'image_type': image_type,
            'ssa': ssa,
            'deep_sky_data': deep_sky_data,
            'private_message_form': PrivateMessageForm(),
            'promote_form': ImagePromoteForm(instance=image),
            'upload_revision_form': ImageRevisionUploadForm(),
            'upload_uncompressed_source_form': UncompressedSourceUploadForm(instance=image),
            'dates_label': _("Dates"),
            'published_on': published_on,
            'show_contains': (image.subject_type == SubjectType.DEEP_SKY and subjects) or
                             (image.subject_type != SubjectType.DEEP_SKY),
            'subjects': subjects,
            'subject_type': ImageService(image).get_subject_type_label(),
            'hemisphere': ImageService(image).get_hemisphere(r),
            'license_icon': static('astrobin/icons/%s' % licenses[image.license][1]),
            'license_title': licenses[image.license][2],
            'resolution': '%dx%d' % (w, h) if (w and h) else None,
            'locations': locations,
            'solar_system_main_subject': ImageService(image).get_solar_system_main_subject_label(),
            'content_type': ContentType.objects.get(app_label='astrobin', model='image'),
            'preferred_language': preferred_language,
            'select_group_form': GroupSelectForm(
                user=self.request.user) if self.request.user.is_authenticated() else None,
            'in_public_groups': Group.objects.filter(Q(public=True, images=image)),
            'image_next': image_next,
            'image_prev': image_prev,
            'nav_ctx': nav_ctx,
            'nav_ctx_extra': nav_ctx_extra,
        })

        return response_dict
예제 #9
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')
예제 #10
0
 def prepare_objects_in_field(self, obj):
     return SolutionService(
         obj.solution).get_objects_in_field() if obj.solution else None
def duplicate_objects_in_field_by_catalog_space(solution: Solution) -> List[str]:
    return SolutionService(solution).duplicate_objects_in_field_by_catalog_space()
def get_search_query_around(solution, degrees):
    # type: (Solution, int) -> str
    return SolutionService(solution).get_search_query_around(degrees)
예제 #13
0
    def test_get_objects_in_field(self):
        self.maxDiff = None
        basic = \
            'Merope Nebula, NGC 1435, Maia Nebula, NGC 1432, Barnard\'s Merope Nebula, IC 349, ' \
            'The star Pleione (28Tau), The star Atlas (27Tau), The star ηTau, The star Merope (23Tau), ' \
            'The star Sterope I (21Tau), The star Taygeta (19Tau), The star 18Tau, The star Electra (17Tau), ' \
            'The star Celaeno (16Tau)'
        advanced = \
            'GridLabel,2357.38,1145.92,2380.38,1154.92,+21°\nGridLabel,1942.40,889.69,1965.40,898.69,+22°\n' \
            'GridLabel,1528.86,631.94,1551.86,641.94,+23°\n' \
            'GridLabel,1113.79,377.34,1136.79,386.34,+24°\n' \
            'GridLabel,700.20,120.49,723.20,130.49,+25°\n' \
            'GridLabel,285.09,-136.42,308.09,-126.42,+26°\n' \
            'GridLabel,1994.54,-147.41,2027.54,-137.41,3h36m\n' \
            'GridLabel,1762.26,236.24,1795.26,246.24,3h40m\n' \
            'GridLabel,1528.86,617.94,1561.86,627.94,3h44m\n' \
            'GridLabel,1290.74,998.51,1323.74,1008.51,3h48m\n' \
            'GridLabel,1051.11,1376.96,1084.11,1386.96,3h52m\n' \
            'Label,892.38,870.27,931.38,881.27,26 Tau\n' \
            'Label,948.59,588.56,987.59,599.56,23 Tau\n' \
            'Label,945.59,609.56,987.59,622.56,Merope\n' \
            'Label,798.97,828.40,837.97,839.40,27 Tau\n' \
            'Label,798.97,850.40,827.97,861.40,Atlas\n' \
            'Label,803.78,667.12,854.78,680.12,25 eta Tau\n' \
            'Label,843.28,684.62,888.28,697.62,Alcyone\n' \
            'Label,1026.51,420.43,1064.51,431.43,17 Tau\n' \
            'Label,965.51,420.43,1004.51,431.43,Electra\n' \
            'Label,880.10,641.68,919.10,652.68,24 Tau\n' \
            'Label,702.22,820.08,741.22,831.08,28 Tau\n' \
            'Label,721.22,803.58,761.22,814.58,Pleione\n' \
            'Label,957.99,368.50,995.99,379.50,16 Tau\n' \
            'Label,923.99,352.00,969.99,363.00,Celaeno\n' \
            'Label,865.82,444.53,904.82,455.53,20 Tau\n' \
            'Label,817.82,444.53,843.82,455.53,Maia\n' \
            'Label,789.96,359.80,838.96,372.80,19 q Tau\n' \
            'Label,825.96,342.30,873.96,355.30,Taygeta\n' \
            'Label,745.37,440.50,784.37,451.50,22 Tau\n' \
            'Label,709.87,423.00,764.87,436.00,Sterope II\n' \
            'Label,784.14,403.94,823.14,414.94,21 Tau\n' \
            'Label,710.14,391.94,762.14,404.94,Asterope\n' \
            'Label,710.28,260.68,748.28,271.68,18 Tau\n' \
            'Label,877.04,672.33,930.04,684.33,Pleiades\n' \
            'Label,830.04,645.73,855.04,657.73,M45\n' \
            'Label,1014.65,642.27,1072.65,654.27,NGC1435\n' \
            'Label,1094.65,619.27,1188.65,633.27,Merope nebula\n' \
            'Label,1012.63,602.11,1048.63,614.11,IC349\n'

        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)
        solution.objects_in_field = basic
        solution.advanced_annotations = advanced

        self.assertEqual([
            "16 Tau", "17 Tau", "18 Tau", "19 q Tau", "20 Tau", "21 Tau",
            "22 Tau", "23 Tau", "24 Tau", "25 eta Tau", "26 Tau", "27 Tau",
            "28 Tau", "Alcyone", "Asterope", "Atlas",
            "Barnard's Merope Nebula", "Celaeno", "Electra", "IC 349", "M 45",
            "Maia", "Maia Nebula", "Merope", "Merope Nebula", "NGC 1432",
            "NGC 1435", "Pleiades", "Pleione", "Sterope II", "Taygeta",
            "The star 18Tau", "The star Atlas (27Tau)",
            "The star Celaeno (16Tau)", "The star Electra (17Tau)",
            "The star Merope (23Tau)", "The star Pleione (28Tau)",
            "The star Sterope I (21Tau)", "The star Taygeta (19Tau)",
            "The star ηTau"
        ],
                         SolutionService(solution).get_objects_in_field())
예제 #14
0
 def prepare_objects_in_field(self, obj):
     return SolutionService(
         obj.solution).duplicate_objects_in_field_by_catalog_space(
         ) if obj.solution else None