示例#1
0
def separation(obj1, obj2):
    """Return the apparent angular separation between two objects."""
    try:
        first = ongc.Dso(obj1)
        second = ongc.Dso(obj2)
        click.echo('Apparent angular separation between ' +
                   click.style(first.name, fg='cyan') + ' and ' +
                   click.style(second.name, fg='cyan') + ' is:')
        click.secho(ongc.getSeparation(obj1, obj2, style="text"), bold=True)
    except Exception as e:
        click.echo(f'{click.style("ERROR:", fg="red", bold=True)} {e}')
示例#2
0
 def test_nameRecognition(self):
     """Test the regex used to convert the name of the object inputted by the user to the
             correct form.
             """
     self.assertEqual(ongc.Dso("ngc1")._name, 'NGC0001')
     self.assertEqual(ongc.Dso("ic 1")._name, 'IC0001')
     self.assertEqual(ongc.Dso("ic80 ned1")._name, 'IC0080 NED01')
     self.assertEqual(ongc.Dso("ngc61a")._name, 'NGC0061A')
     self.assertRaisesRegexp(ValueError, "Wrong object name", ongc.Dso,
                             "M15")
     self.assertRaisesRegexp(ValueError, "not found in the database",
                             ongc.Dso, "NGC0001A")
示例#3
0
def neighbors(name, radius, catalog):
    """List objects in proximity of another DSO."""
    try:
        start_obj = ongc.Dso(name)
        object_list = ongc.getNeighbors(start_obj, radius, catalog)
        if len(object_list) == 0:
            click.secho('\nNo objects found within search radius!', bold=True)
            return
        if len(object_list) > 20:
            if click.confirm(
                    click.style('WARNING: ', fg='yellow', bold=True) +
                    'the result list is long. Do you want to see it via a pager?'
            ):
                click.echo_via_pager('\n'.join(f'{dso[1]:.2f}° --> {dso[0]}'
                                               for dso in object_list))
                return

        click.secho(f'\n{start_obj.name} neighbors from nearest to farthest:',
                    bold=True)
        for dso in object_list:
            click.echo(f'{dso[1]:.2f}° --> {dso[0]}')
        if catalog != 'all':
            search_filter = f' and showing {catalog} objects only'
        else:
            search_filter = ''
        click.secho(
            f'(using a search radius of {radius} arcmin{search_filter})\n',
            fg='cyan')
    except Exception as e:
        click.echo(f'{click.style("ERROR:", fg="red", bold=True)} {e}')
    def __init__(self, object_name, session):
        super().__init__(object_name, session)
        if type(object_name) == ongc.Dso:
            self.dso = object_name  # If class initialized directly with a Dso, use it, else create a new one.
        else:
            try:
                self.dso = ongc.Dso(object_name)
            except Exception as e:
                logging.warning(e)
        #print("DSO:", self.dso, type(self.dso))

        #self.kind = 'Deep Space object'  # TODO: distinguish between stars, galaxies...
        #self.constellation = ''
        ra_arr, dec_arr = self.dso.getCoords()
        self.ra, self.dec = tuple(ra_arr), tuple(dec_arr)
        self.alt_ids = self.dso.getIdentifiers()
        self.constellation = self.dso.getConstellation()
        self.kind = self.dso.getType()
        self.star = Star(ra_hours=self.ra, dec_degrees=self.dec)
        self.star_astro_now = self.astrometric = self.session.here.at(
            self.session.start).observe(self.star)
        self.apparent = self.astrometric.apparent()

        self.alt, self.az, self.distance = self.apparent.altaz('standard')

        ra_arr, dec_arr = self.dso.getCoords()
        self.ra, self.dec = tuple(ra_arr), tuple(dec_arr)
        self.alt_ids = self.dso.getIdentifiers()
        self.messier = self.alt_ids[0]
        self.constellation = self.dso.getConstellation()
        self.kind = self.dso.getType()
示例#5
0
def view(name, details):
    """Print out object information."""
    try:
        if details:
            click.echo(ongc.printDetails(ongc.Dso(name)))
        else:
            click.secho(f'{ongc.Dso(name)}', bold=True)
    except Exception as e:
        click.echo(f'{click.style("ERROR:", fg="red", bold=True)} {e}')
示例#6
0
 def test_duplicateResolving(self):
     """Test that a duplicated object is returned as himself when asked to do so."""
     self.assertEqual(ongc.Dso("ngc20")._name, 'NGC0006')
     self.assertEqual(ongc.Dso("ngc20", returnDup=True)._name, 'NGC0020')