Esempio n. 1
0
    def __init__(self, config):
        self.config = config

        self.resource_index_input = GammaCatResourceIndex.from_list(
            load_json(gammacat_info.in_path / 'input-datasets.json'))
        self.resource_index_output = GammaCatResourceIndex.from_list(
            load_json(gammacat_info.out_path / 'gammacat-datasets.json'))

        self.sources_data = self.make_sources_data()
        self.references_data = self.make_references_data()
Esempio n. 2
0
 def setup(self):
     self.resource_index = GammaCatResourceIndex([
         GammaCatResource(source_id=99, reference_id="2014ApJ...780..168A"),
         GammaCatResource(
             source_id=42,
             reference_id="2010A&A...516A..62A",
             file_id=2,
             type="sed",
         ),
         GammaCatResource(source_id=42,
                          reference_id="2010A&A...516A..62A",
                          file_id=1),
     ])
Esempio n. 3
0
 def test_pandas_roundtrip(self):
     df = self.resource_index.to_pandas()
     actual = GammaCatResourceIndex.from_pandas(df)
     assert actual == self.resource_index
Esempio n. 4
0
 def test_table_roundtrip(self):
     table = self.resource_index.to_table()
     actual = GammaCatResourceIndex.from_table(table)
     assert actual == self.resource_index
Esempio n. 5
0
 def test_list_roundtrip(self):
     data = self.resource_index.to_list()
     actual = GammaCatResourceIndex.from_list(data)
     assert actual == self.resource_index
Esempio n. 6
0
    def test_eq(self):
        resource_index1 = self.resource_index
        resource_index2 = GammaCatResourceIndex(resource_index1.resources[:-1])

        assert resource_index1 == resource_index1
        assert resource_index1 != resource_index2
Esempio n. 7
0
class TestGammaCatResourceIndex:
    def setup(self):
        self.resource_index = GammaCatResourceIndex([
            GammaCatResource(source_id=99, reference_id="2014ApJ...780..168A"),
            GammaCatResource(
                source_id=42,
                reference_id="2010A&A...516A..62A",
                file_id=2,
                type="sed",
            ),
            GammaCatResource(source_id=42,
                             reference_id="2010A&A...516A..62A",
                             file_id=1),
        ])

    def test_repr(self):
        assert repr(
            self.resource_index) == "GammaCatResourceIndex(n_resources=3)"

    def test_eq(self):
        resource_index1 = self.resource_index
        resource_index2 = GammaCatResourceIndex(resource_index1.resources[:-1])

        assert resource_index1 == resource_index1
        assert resource_index1 != resource_index2

    def test_unique_source_ids(self):
        expected = [42, 99]
        assert self.resource_index.unique_source_ids == expected

    def test_unique_reference_ids(self):
        expected = ["2010A&A...516A..62A", "2014ApJ...780..168A"]
        assert self.resource_index.unique_reference_ids == expected

    def test_global_ids(self):
        expected = [
            "99|2014ApJ...780..168A|-1|none",
            "42|2010A&A...516A..62A|2|sed",
            "42|2010A&A...516A..62A|1|none",
        ]
        assert self.resource_index.global_ids == expected

    def test_sort(self):
        expected = [
            "42|2010A&A...516A..62A|1|none",
            "42|2010A&A...516A..62A|2|sed",
            "99|2014ApJ...780..168A|-1|none",
        ]
        assert self.resource_index.sort().global_ids == expected

    def test_to_list(self):
        result = self.resource_index.to_list()
        assert isinstance(result, list)
        assert len(result) == 3

    def test_list_roundtrip(self):
        data = self.resource_index.to_list()
        actual = GammaCatResourceIndex.from_list(data)
        assert actual == self.resource_index

    def test_to_table(self):
        table = self.resource_index.to_table()
        assert len(table) == 3
        assert table.colnames == [
            "source_id",
            "reference_id",
            "file_id",
            "type",
            "location",
        ]

    def test_table_roundtrip(self):
        table = self.resource_index.to_table()
        actual = GammaCatResourceIndex.from_table(table)
        assert actual == self.resource_index

    @requires_dependency("pandas")
    def test_to_pandas(self):
        df = self.resource_index.to_pandas()
        df2 = df.query("source_id == 42")
        assert len(df2) == 2

    @requires_dependency("pandas")
    def test_pandas_roundtrip(self):
        df = self.resource_index.to_pandas()
        actual = GammaCatResourceIndex.from_pandas(df)
        assert actual == self.resource_index

    @requires_dependency("pandas")
    def test_query(self):
        resource_index = self.resource_index.query(
            'type == "sed" and source_id == 42')
        assert len(resource_index.resources) == 1
        assert resource_index.resources[
            0].global_id == "42|2010A&A...516A..62A|2|sed"
Esempio n. 8
0
def get_resource_index():
    path = gammacat_info.out_path / 'gammacat-datasets.json'
    return GammaCatResourceIndex.from_list(load_json(path))