Esempio n. 1
0
    def test_coordsystem(self):
        for val in (CoordSystem.ICRS, CoordSystem.GAL):
            self.assertIsInstance(val, int)
            self.assertIsInstance(CoordSystem.get_name(val), unicode)

        self.assertFalse(CoordSystem.is_valid(0))
        self.assertTrue(CoordSystem.is_valid(1))
        self.assertFalse(CoordSystem.is_valid(999))

        opt = CoordSystem.get_options()
        self.assertIsInstance(opt, OrderedDict)

        names = set(opt.values())
        for name in ('ICRS', 'Galactic'):
            self.assertIn(name, names)
Esempio n. 2
0
    def test_coordsystem(self):
        for val in (CoordSystem.ICRS, CoordSystem.GAL):
            self.assertIsInstance(val, int)
            self.assertIsInstance(CoordSystem.get_name(val), unicode)

        self.assertFalse(CoordSystem.is_valid(0))
        self.assertTrue(CoordSystem.is_valid(1))
        self.assertFalse(CoordSystem.is_valid(999))

        opt = CoordSystem.get_options()
        self.assertIsInstance(opt, OrderedDict)

        names = set(opt.values())
        for name in ('ICRS', 'Galactic'):
            self.assertIn(name, names)
Esempio n. 3
0
def write_target_file(file_, targets):
    """
    Write an JSON file listing the targets for each project.
    """

    target_objects = OrderedDict()

    # Construct JSON "object" (i.e. a dictionary) for each target with
    # coordinates.
    for (proposal_code, proposal_targets) in targets.items():
        proposal_target_objects = []
        for target in proposal_targets.values():
            if ((target.x is None) or (target.y is None) or
                    (target.system is None)):
                continue

            proposal_target_objects.append({
                'name': target.name,
                'x': target.x,
                'y': target.y,
                'system': CoordSystem.get_name(target.system),
            })

        if proposal_target_objects:
            target_objects[proposal_code] = proposal_target_objects

    # Write the JSON file.
    json.dump(target_objects, file_, indent=4, separators=(',', ': '))

    # Add final line feed.
    print('', file=file_)