Exemplo n.º 1
0
    def setUp(self):
        self.meta1 = Metadata(**TestData.metadata1)
        self.wcs1 = Wcs(**TestData.wcs1)
        self.std1 = StandardizedHeader(metadata=self.meta1, wcs=[self.wcs1])

        self.meta2 = Metadata(**TestData.metadata2)
        self.wcs2 = Wcs(**TestData.wcs2)
        self.std2 = StandardizedHeader(metadata=self.meta2, wcs=[self.wcs2])

        self.std3 = StandardizedHeader(metadata=self.meta1,
                                       wcs=[self.wcs1, self.wcs2])
Exemplo n.º 2
0
    def setUp(self):
        info = UploadInfo()
        info.save()

        meta = Metadata(upload_info=info,
                        processor_name="MultiExtensionFits",
                        standardizer_name="astro_metadaor",
                        instrument="HSC",
                        telescope="Subaru",
                        science_program="asdfasdf",
                        obs_lon=-101,
                        obs_lat=1.0,
                        obs_height=1.0,
                        datetime_begin='2009-10-17T01:53:42.1',
                        datetime_end='2009-10-18T01:53:42.1',
                        exposure_duration=30.0,
                        filter_name='r')
        meta2 = Metadata(upload_info=info,
                         processor_name="SingleExtensionFits",
                         standardizer_name="astro_metadaor",
                         instrument="HSC",
                         telescope="Subaru",
                         science_program="asdfasdf",
                         obs_lon=-101,
                         obs_lat=1.0,
                         obs_height=1.0,
                         datetime_begin='2009-10-17T01:53:42.1',
                         datetime_end='2009-10-18T01:53:42.1',
                         exposure_duration=30.0,
                         filter_name='i')
        wcs1 = {
            'metadata': meta,
            'radius': 1,
            'center_x': 0.4,
            'center_y': 0.3,
            'center_z': 0.7,
            'corner_x': 16,
            'corner_y': 17,
            'corner_z': 0.7
        }

        meta.save()
        meta2.save()

        self.wcs = Wcs(**wcs1)
        self.wcs.save()
 def standardizeWcs(self, **kwargs):
     # no matter how hard I try, I do not understand how it would ever be
     # possible to extract WCS data out of this header. This entire header
     # is nonsense...
     wcs = Wcs(wcs_radius=-999.999,
               wcs_center_x=-999.999,
               wcs_center_y=-999.999,
               wcs_center_z=-999.999,
               wcs_corner_x=-999.999,
               wcs_corner_y=-999.999,
               wcs_corner_z=-999.999)
     return wcs
Exemplo n.º 4
0
class RestQueryTest(APITestCase):
    def setUp(self):
        info = UploadInfo()
        info.save()

        meta = Metadata(upload_info=info,
                        processor_name="MultiExtensionFits",
                        standardizer_name="astro_metadaor",
                        instrument="HSC",
                        telescope="Subaru",
                        science_program="asdfasdf",
                        obs_lon=-101,
                        obs_lat=1.0,
                        obs_height=1.0,
                        datetime_begin='2009-10-17T01:53:42.1',
                        datetime_end='2009-10-18T01:53:42.1',
                        exposure_duration=30.0,
                        filter_name='r')
        meta2 = Metadata(upload_info=info,
                         processor_name="SingleExtensionFits",
                         standardizer_name="astro_metadaor",
                         instrument="HSC",
                         telescope="Subaru",
                         science_program="asdfasdf",
                         obs_lon=-101,
                         obs_lat=1.0,
                         obs_height=1.0,
                         datetime_begin='2009-10-17T01:53:42.1',
                         datetime_end='2009-10-18T01:53:42.1',
                         exposure_duration=30.0,
                         filter_name='i')
        wcs1 = {
            'metadata': meta,
            'radius': 1,
            'center_x': 0.4,
            'center_y': 0.3,
            'center_z': 0.7,
            'corner_x': 16,
            'corner_y': 17,
            'corner_z': 0.7
        }

        meta.save()
        meta2.save()

        self.wcs = Wcs(**wcs1)
        self.wcs.save()

    def test_metadata_get(self):
        """Test basic Metadata REST queries."""
        url = reverse("metadata")

        # test querying /query/metadata just returns all of the data
        response = self.client.get(url, {}, format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        serialized = MetadataSerializer(Metadata.objects.all(), many=True)
        self.assertEqual(serialized.data, response.data)

        # test querying with parameters, i.e. querying:
        # /query/metadata?instrument=HSC&filter_name=r
        response = self.client.get(url, {
            "instrument": "HSC",
            "filter_name": "r"
        },
                                   format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        queryset = Metadata.objects.filter(instrument="HSC", filter_name="r")
        serialized = MetadataSerializer(queryset, many=True)
        self.assertEqual(serialized.data, response.data)

        # test querying with bad params returns a bad request response
        response = self.client.get(url, {"nonsense": "bad_data"},
                                   format="json")
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_metadata_get_fields(self):
        """Test Metadata REST queries with specified return fields."""
        url = reverse("metadata")

        # test querying /query/metadata just returns all of the data
        response = self.client.get(url, {
            "instrument": "HSC",
            "fields": ["instrument", "telescope"]
        },
                                   format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        qset = Metadata.objects.filter(instrument__icontains="HSC")
        serialized = MetadataSerializer(qset,
                                        many=True,
                                        fields=["instrument", "telescope"])
        self.assertEqual(serialized.data, response.data)

    def test_metadata_get_non_exact_match(self):
        """Test Metadata REST queries with exact match being False."""
        url = reverse("metadata")

        # test querying /query/metadata just returns all of the data
        response = self.client.get(url, {
            "instrument": "hsc",
            "exactMatch": False
        },
                                   format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        qset = Metadata.objects.filter(instrument__icontains="hsc")
        serialized = MetadataSerializer(qset, many=True)
        self.assertEqual(serialized.data, response.data)

    def test_wcs_get(self):
        """Tests basic Wcs REST queries."""
        url = reverse("wcs")

        # because they inherit from same basic view we do not have to be detailed here
        response = self.client.get(url, {}, format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        serialized = WcsSerializer(Wcs.objects.all(), many=True)
        self.assertEqual(serialized.data, response.data)

    def test_get_metadata_and_wcs(self):
        """Tests basic Wcs REST queries."""
        url = reverse("metadata")

        # because they inherit from same basic view we do not have to be detailed here
        response = self.client.get(url, {
            "getWcs": True,
        }, format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        qset = Metadata.objects.all().prefetch_related("wcs")
        serialized = MetadataSerializer(qset, many=True, keepWcs=True)
        self.assertEqual(serialized.data, response.data)

    def test_get_metadata_in_sky_region(self):
        """Tests basic Wcs REST queries."""
        url = reverse("metadata")

        # because they inherit from same basic view we do not have to be detailed here
        qparams = {
            "raLow": 0,
            "raHigh": 1,
            "decLow": 0,
            "decHigh": 1,
            "getWcs": True
        }
        response = self.client.get(url, qparams, format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        queryset, qparams = Metadata.query_sky_region(qparams)
        serialized = MetadataSerializer(queryset, many=True, keepWcs=True)
        self.assertEqual(serialized.data, response.data)
Exemplo n.º 5
0
 def setUp(self):
     self.wcs1 = Wcs(**TestData.wcs1)
     self.wcs2 = copy(self.wcs1)
     self.wcs3 = Wcs(**TestData.wcs2)
Exemplo n.º 6
0
class StandardizedHeaderTestCase(TestCase):
    def setUp(self):
        self.meta1 = Metadata(**TestData.metadata1)
        self.wcs1 = Wcs(**TestData.wcs1)
        self.std1 = StandardizedHeader(metadata=self.meta1, wcs=[self.wcs1])

        self.meta2 = Metadata(**TestData.metadata2)
        self.wcs2 = Wcs(**TestData.wcs2)
        self.std2 = StandardizedHeader(metadata=self.meta2, wcs=[self.wcs2])

        self.std3 = StandardizedHeader(metadata=self.meta1, wcs=[self.wcs1, self.wcs2])

    def testFromDict(self):
        """Tests StandardizedHeader instantiation from dictionary."""
        # Django equality is something really specific, so comparing Metadata
        # and Wcs objects directly compares their PKs by identity. This will of
        # course fail for any non-saved model...
        std = StandardizedHeader.fromDict(TestData.nested)
        self.assertEqual(std.metadata.values(), self.meta1.values())
        self.assertEqual(std.wcs[0].values(), self.wcs1.values())
        self.assertEqual(std.wcs[1].values(), self.wcs2.values())

        std = StandardizedHeader.fromDict(TestData.flat)
        self.assertEqual(std.metadata.values(), self.meta1.values())
        self.assertEqual(std.wcs[0].values(), self.wcs1.values())

    def testIsClose(self):
        """Test StandardizedHeader approximate equality."""
        std = StandardizedHeader.fromDict(TestData.flat)
        msg = (
            "\nStandardized headers differ! Expected values \n "
            f"  {self.std1.toDict()}\n"
            "got \n"
            f"  {std.toDict()}\n"
            "values instead!"
        )
        self.assertEqual(std, self.std1, msg=msg)
        self.assertTrue(self.std1 == std)

    def testUpdateMetadata(self):
        """Test updating metadata works."""
        std = copy(self.std1)
        std.updateMetadata(self.meta2)
        self.assertEqual(std.metadata.values(), self.meta2.values())

        std.updateMetadata(TestData.metadata1)
        self.assertEqual(std, self.std1)

    def testAppendWcs(self):
        """Test we can append a WCS."""
        std = copy(self.std1)
        std.appendWcs(self.wcs2)
        # This should be exactly true
        self.assertEqual(std.wcs[-1].values(), self.wcs2.values())

        # but this might not complete a full circle because of potential casts
        # that could exist in Django ORM
        std.appendWcs(TestData.wcs1)
        self.assertEqual(std.wcs[-1].values(), self.wcs1.values())

    def testExtendWcs(self):
        """Test we can append a list of WCSs"""
        # no need to test from dict because this essentially calls append
        std = copy(self.std1)
        std.extendWcs([self.wcs1, self.wcs2])
        self.assertEqual(std.wcs[-2].values(), self.wcs1.values())
        self.assertEqual(std.wcs[-1].values(), self.wcs2.values())

    def toDict(self):
        """Tests StandardizedHeader conversion to dictionary"""
        self.assertEqual(self.std1.toDict(), TestData.flat)
        self.assertEqual(self.std3.toDict(), TestData.nested)