def queryMPC(designation): """Query JPL Horizons for information about object 'designation'. Parameters ---------- designation: str A name for the object that the MPC will understand. This can be a number, proper name, or the packed designation. Returns ------- pd.Series Series containing orbit and select physical information. """ try: number = int(designation) mpc = MPC.query_object('asteroid', number=number) except ValueError: mpc = MPC.query_object('asteroid', designation=designation) mpc = mpc[0] orbit = pd.Series( data={ 'des': designation, 'fullname': mpc['name'], 'FORMAT': 'KEP', 'a': float(mpc['semimajor_axis']), 'q': float(mpc['perihelion_distance']), 'e': float(mpc['eccentricity']), 'inc': float(mpc['inclination']), 'Omega': float(mpc['ascending_node']), 'argPeri': float(mpc['argument_of_perihelion']), 'tPeri': float(mpc['perihelion_date_jd']) - 2400000.5, # to MJD 'meanAnomaly': float(mpc['mean_anomaly']), 'epoch': float(mpc['epoch_jd']) - 2400000.5, # to MJD 'H': float(mpc['absolute_magnitude']), 'g': float(mpc['phase_slope']), 'diam': -999, 'albedo': -999, 'rot': -999 }) return orbit
def search_code_mpc(): """ Reads the MPC Observer Database Returns: observatories (dict): A python dictionaty with all the sites as an Astropy EarthLocation object """ obs = MPC.get_observatory_codes() observatories = {} for line in obs: code = line['Code'] lon = line['Longitude'] * u.deg rcphi = line['cos'] * 6378.137 * u.km rsphi = line['sin'] * 6378.137 * u.km name = line['Name'] site = EarthLocation.from_geocentric(rcphi * np.cos(lon), rcphi * np.sin(lon), rsphi) observatories[code] = (name, site) return observatories
def from_mpc(cls, targetid, epochs=None, location='500', **kwargs): """Load ephemerides from the `Minor Planet Center <http://minorplanetcenter.net>`_. Parameters ---------- targetid : str Target identifier, resolvable by the Minor Planet Ephemeris Service [MPES]_, e.g., 2P, C/1995 O1, P/Encke, (1), 3200, Ceres, and packed designations. epochs : various, optional Request ephemerides at these epochs. May be a single epoch as a string or `~astropy.time.Time`, an array of epochs, or a dictionary describing a linearly-spaced array of epochs. If ``None`` (default), the current date and time will be used. For the dictionary format, the keys ``start`` (start epoch), ``step`` (step size), ``stop`` (end epoch), and/or ``number`` (number of epochs total) are used. Only one of ``stop`` and ``number`` may be specified at a time. ``step``, ``stop``, and ``number`` are optional. See `~astroquery.mpc.MPC.get_ephemeris` for defaults. Epochs, including ``start`` and ``stop``, are `~astropy.time.Time` objects, anything that can initialize a ``Time`` object, or a float indicating a Julian date. Unless otherwise specified, the UTC scale is assumed. ``step`` should be an integer in units of seconds, minutes, hours, or days. Anythng that can initialize an `~astropy.units.Quantity` object is allowed. location : various, optional Location of the observer as an IAU observatory code [OBSCODES]_ (string), a 3-element array of Earth longitude, latitude, altitude, or an `~astropy.coordinates.EarthLocation`. Longitude and latitude should be parseable by `~astropy.coordinates.Angle`, and altitude should be parsable by `~astropy.units.Quantity` (with units of length). If ``None``, then the geocenter (code 500) is used. **kwargs Additional keyword arguments are passed to `~astroquery.mpc.MPC.get_ephemerides`: ``eph_type``, ``ra_format``, ``dec_format``, ``proper_motion``, ``proper_motion_unit``, ``suppress_daytime``, ``suppress_set``, ``perturbed``, ``unc_links``, ``cache``. Returns ------- `~Ephem` object Examples -------- >>> from sbpy.data import Ephem >>> from astropy.time import Time >>> epoch = Time('2018-05-14', scale='utc') >>> eph = Ephem.from_mpc('ceres', epoch, location='568' ... ) # doctest: +REMOTE_DATA +IGNORE_OUTPUT >>> epochs = {'start': '2019-01-01', 'step': '1d', 'number': 365} >>> eph = Ephem.from_mpc('2P', epochs=epochs, location='568' ... ) # doctest: +REMOTE_DATA +IGNORE_OUTPUT Notes ----- See `~astroquery.mpc.MPC.get_ephemerides` and the Minor Planet Ephemeris Service user's guide [MPES]_ for details, including accetable target names. References ---------- .. [MPES] Wiliams, G. The Minor Planet Ephemeris Service. https://minorplanetcenter.org/iau/info/MPES.pdf .. [OBSCODES] IAU Minor Planet Center. List of observatory codes. https://minorplanetcenter.org/iau/lists/ObsCodesF.html """ # parameter check if isinstance(epochs, dict): start = epochs['start'] # required step = epochs.get('step') stop = epochs.get('stop') number = epochs.get('number') if isinstance(start, (float, int)): start = Time(start, format='jd', scale='utc') if isinstance(stop, (float, int)): stop = Time(stop, format='jd', scale='utc') if step is not None: step = u.Quantity(step) if step.unit not in (u.d, u.h, u.min, u.s): raise ValueError( 'step must have units of days, hours, minutes,' ' or seconds') if stop is not None: if step is None: raise ValueError( 'step is required when start and stop are provided') # start and stop both defined, estimate number of steps dt = (Time(stop).jd - Time(start).jd) * u.d number = int((dt / step).decompose()) + 1 else: start = None if epochs is None: epochs = Time.now() if not iterable(epochs) or isinstance(epochs, str): epochs = [epochs] # check for Julian dates for i in range(len(epochs)): if isinstance(epochs[i], (float, int)): epochs[i] = Time(epochs[i], format='jd', scale='utc') # get ephemeris if start is None: eph = [] for i in range(len(epochs)): start = Time(epochs[i], scale='utc') e = MPC.get_ephemeris(targetid, location=location, start=start, number=1, **kwargs) e['Date'] = e['Date'].iso # for vstack to work eph.append(e) eph = vstack(eph) eph['Date'] = Time(eph['Date'], scale='utc') else: eph = MPC.get_ephemeris(targetid, location=location, start=start, step=step, number=number, **kwargs) # if ra_format or dec_format is defined, then units must be # dropped or else QTable will raise an exception because # strings cannot have units if 'ra_format' in kwargs: eph['RA'].unit = None if 'dec_format' in kwargs: eph['Dec'].unit = None # only UTC scale is supported eph.add_column(Column(['UTC'] * len(eph), name='timescale'), index=eph.colnames.index('Date') + 1) return cls.from_table(eph)
def from_mpc(cls, targetids, id_type=None, target_type=None, **kwargs): """Load latest orbital elements from the `Minor Planet Center <https://minorplanetcenter.net>`_. Parameters ---------- targetids : str or iterable of str Target identifier, resolvable by the Minor Planet Ephemeris Service. If multiple targetids are provided in a list, the same format (number, name, or designation) must be used. id_type : str, optional ``'name'``, ``'number'``, ``'designation'``, or ``None`` to indicate type of identifiers provided in ``targetids``. If ``None``, automatic identification is attempted using `~sbpy.data.names`. Default: ``None`` target_type : str, optional ``'asteroid'``, ``'comet'``, or ``None`` to indicate target type. If ``None``, automatic identification is attempted using `~sbpy.data.names`. Default: ``None`` **kwargs : optional Additional keyword arguments are passed to `~astroquery.mpc.MPC.query_object` Returns ------- `~Orbit` object The resulting object will be populated with most columns as defined in `~astroquery.mpc.query_object`; refer to that document on information on how to modify the list of queried parameters. Examples -------- >>> from sbpy.data import Orbit >>> orb = Orbit.from_mpc('Ceres') # doctest: +REMOTE_DATA >>> orb # doctest: +SKIP <QTable length=1> absmag Q arc w ... a Tj moid_uranus moid_venus mag AU d deg ... AU AU AU float64 float64 float64 float64 ... float64 float64 float64 float64 ------- ------- ------- -------- ... --------- ------- ----------- ---------- 3.34 2.98 79653.0 73.59764 ... 2.7691652 3.3 15.6642 1.84632 """ from ..data import Names # if targetids is a list, run separate Horizons queries and append if not isinstance(targetids, (list, ndarray, tuple)): targetids = [targetids] for targetid in targetids: if target_type is None: target_type = Names.asteroid_or_comet(targetid) if id_type is None: if target_type == 'asteroid': ident = Names.parse_asteroid(targetid) elif target_type == 'comet': ident = Names.parse_comet(targetid) if 'name' in ident: id_type = 'name' elif 'desig' in ident: id_type = 'designation' elif 'number' in ident: id_type = 'number' # append ephemerides table for each targetid all_elem = None for targetid in targetids: # get elements kwargs[id_type] = targetid e = MPC.query_object(target_type, **kwargs) # parse results from MPC.query_object results = {} for key, val in e[0].items(): # skip if key not in Conf.mpc_orbit_fields if key not in Conf.mpc_orbit_fields: continue fieldname, fieldunit = Conf.mpc_orbit_fields[key] # try to convert to float try: val = float(val) except (ValueError, TypeError): pass if fieldname == 'mpc_orbit_type': results[fieldname] = [{ 0: 'Unclassified', 1: 'Atira', 2: 'Aten', 3: 'Apollo', 4: 'Amor', 5: 'Mars Crosser', 6: 'Hungaria', 7: 'Phocaeas', 8: 'Hilda', 9: 'Jupiter Trojan', 10: 'Distant Object'}[int(val)]] elif fieldunit is None: results[fieldname] = [val] elif fieldunit == 'time_jd_utc': results[fieldname] = Time([val], scale='utc', format='jd') else: if val is None: continue results[fieldname] = [val]*u.Unit(fieldunit) if all_elem is None: all_elem = QTable(results) else: all_elem = vstack([all_elem, QTable(results)]) return cls.from_table(all_elem)
def from_mpc(cls, targetids, epochs=None, location='500', **kwargs): """Load ephemerides from the `Minor Planet Center <https://minorplanetcenter.net>`_. Parameters ---------- targetids : str or iterable of str Target identifier, resolvable by the Minor Planet Ephemeris Service [MPES]_, e.g., 2P, C/1995 O1, P/Encke, (1), 3200, Ceres, and packed designations, for one or more targets. epochs : `~astropy.time.Time` object, or dictionary, optional Request ephemerides at these epochs. May be a single epoch or multiple epochs as `~astropy.time.Time` (see :ref:`epochs`)or a dictionary describing a linearly-spaced array of epochs. All epochs should be provided in UTC; if not, they will be converted to UTC and a `~sbpy.data.TimeScaleWarning` will be raised. If ``None`` (default), the current date and time will be used. For the dictionary format, the keys ``start`` (start epoch), ``step`` (step size), ``stop`` (end epoch), and/or ``number`` (number of epochs total) are used. Only one of ``stop`` and ``number`` may be specified at a time. ``step``, ``stop``, and ``number`` are optional. The values of of ``start`` and ``stop`` must be `~astropy.time.Time` objects. ``number`` should be an integer value; ``step`` should be a `~astropy.units.Quantity` with an integer value and units of seconds, minutes, hours, or days. All epochs should be provided in UTC; if not, they will be converted to UTC and a `~sbpy.data.TimeScaleWarning` will be raised. location : various, optional Location of the observer as an IAU observatory code [OBSCODES]_ (string), a 3-element array of Earth longitude, latitude, altitude, or an `~astropy.coordinates.EarthLocation`. Longitude and latitude should be parseable by `~astropy.coordinates.Angle`, and altitude should be parsable by `~astropy.units.Quantity` (with units of length). If ``None``, then the geocenter (code 500) is used. **kwargs Additional keyword arguments are passed to `~astroquery.mpc.MPC.get_ephemerides`: ``eph_type``, ``ra_format``, ``dec_format``, ``proper_motion``, ``proper_motion_unit``, ``suppress_daytime``, ``suppress_set``, ``perturbed``, ``unc_links``, ``cache``. Returns ------- `~Ephem` object The resulting object will be populated with columns as defined in `~astroquery.mpc.get_ephemerides`; refer to that document on information on how to modify the list of queried parameters. Examples -------- Query a single set of ephemerides of Ceres as observed from Maunakea: >>> from sbpy.data import Ephem >>> from astropy.time import Time >>> epoch = Time('2018-05-14', scale='utc') >>> eph = Ephem.from_mpc('ceres', epoch, 568) # doctest: +REMOTE_DATA Query a range of ephemerides of comet 2P/Encke as observed from Maunakea: >>> epochs = {'start': Time('2019-01-01'), ... 'step': 1*u.d, 'number': 365} >>> eph = Ephem.from_mpc('2P', epochs, 568) # doctest: +REMOTE_DATA Notes ----- * All properties are provided in the J2000.0 reference system. * See `astroquery.mpc.MPC.get_ephemerides` and the Minor Planet Ephemeris Service user's guide [MPES]_ for details, including acceptable target names. References ---------- .. [MPES] Wiliams, G. The Minor Planet Ephemeris Service. https://minorplanetcenter.org/iau/info/MPES.pdf .. [OBSCODES] IAU Minor Planet Center. List of observatory codes. https://minorplanetcenter.org/iau/lists/ObsCodesF.html """ # parameter check # if targetids is a list, run separate Horizons queries and append if not isinstance(targetids, (list, ndarray, tuple)): targetids = [targetids] if isinstance(epochs, Time): if epochs.scale is not 'utc': warn(('converting {} epochs to utc for use in ' 'astroquery.mpc').format(epochs.scale), TimeScaleWarning) epochs = epochs.utc start = None elif isinstance(epochs, dict): start = epochs['start'] # required if start.scale is not 'utc': warn(('converting {} start epoch to utc for use in ' 'astroquery.mpc').format(start.scale), TimeScaleWarning) start = start.utc step = epochs.get('step') stop = epochs.get('stop') if stop is not None and stop.scale is not 'utc': warn(('converting {} stop epoch to utc for use in ' 'astroquery.mpc').format(stop.scale), TimeScaleWarning) stop = stop.utc number = epochs.get('number') if step is not None and stop is None: step = u.Quantity(step) if step.unit not in (u.d, u.h, u.min, u.s): raise QueryError( 'step must have units of days, hours, minutes,' ' or seconds') if stop is not None: if step is not None and number is None: # start and stop both defined, estimate number of steps dt = (Time(stop).jd - Time(start).jd) * u.d number = int((dt / step).decompose()) + 1 elif step is None and number is not None: step = int( (stop - start).jd * 1440 / (number - 1)) * u.minute else: raise QueryError( ('epoch definition unclear; step xor number ' 'must be provided with start and stop')) else: start = None if epochs is None: epochs = Time.now() if not iterable(epochs): epochs = [epochs] # append ephemerides table for each targetid all_eph = None for targetid in targetids: try: # get ephemeris if start is None: eph = [] for i in range(len(epochs)): e = MPC.get_ephemeris(targetid, location=location, start=Time(epochs[i], scale='utc'), number=1, **kwargs) e['Date'] = e['Date'].iso # for vstack to work eph.append(e) eph = vstack(eph) eph['Date'] = Time(eph['Date'], scale='utc') else: eph = MPC.get_ephemeris(targetid, location=location, start=start, step=step, number=number, **kwargs) except InvalidQueryError as e: raise QueryError('Error raised by astroquery.mpc: {:s}'.format( str(e))) # add targetname column eph.add_column(Column([targetid] * len(eph), name='Targetname'), index=0) if all_eph is None: all_eph = eph else: all_eph = vstack([all_eph, eph]) # if ra_format or dec_format is defined, then units must be # dropped or else QTable will raise an exception because # strings cannot have units if 'ra_format' in kwargs: all_eph['RA'].unit = None if 'dec_format' in kwargs: all_eph['Dec'].unit = None return cls.from_table(all_eph)
def get_named_object(target_name, tstamp, pressure=0.0, temperature=0.0, relative_humidity=0.0, obswl=1): """Returns an Astropy SkyCoord object or None if the object cannot be found. target_name is a string such as "Mars" tstamp is a python datetime or Astropy Time object""" if not target_name: return p = pressure * u.hPa t = temperature * u.deg_C rh = relative_humidity * u.dimensionless_unscaled obswl = obswl * u.micron solar_system_ephemeris.set('jpl') obsloc = observatory_location() if not isinstance(tstamp, Time): tstamp = Time(tstamp, format='datetime', scale='utc') target_name_lower = target_name.lower() aaframe = AltAz(obstime=tstamp, location=obsloc, pressure=p, temperature=t, relative_humidity=rh, obswl=obswl) if target_name_lower == "sun": target = get_sun(tstamp) target_altaz = target.transform_to(aaframe) return target_altaz if target_name_lower == "moon": target = get_moon(tstamp) target_altaz = target.transform_to(aaframe) return target_altaz if target_name_lower in ('mercury', 'venus', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune', 'pluto'): target = get_body(target_name_lower, tstamp, obsloc) target_altaz = target.transform_to(aaframe) return target_altaz # not a planet, see if it is something like M45 or star name try: target = SkyCoord.from_name(target_name) except name_resolve.NameResolveError: # failed to find name, maybe a minor planet pass else: target_altaz = target.transform_to(aaframe) return target_altaz # minor planet location try: eph = MPC.get_ephemeris(target_name, location=obsloc, start=tstamp, number=1) # eph is a table of a single line, set this into a SkyCoord object target = SkyCoord(eph['RA'][0] * u.deg, eph['Dec'][0] * u.deg, obstime=tstamp, location=obsloc, frame='gcrs') target_altaz = target.transform_to(aaframe) except InvalidQueryError: return return target_altaz
def from_mpc(cls, targetid, id_type=None, **kwargs): """Load available observations for a target from the `Minor Planet Center <http://minorplanetcenter.net>`_ using `~astroquery.mpc.MPCClass.get_observations`. Parameters ---------- targetid : str Target identifier, resolvable by the Minor Planet Ephemeris Service. id_type : str, optional ``'asteroid number'``, ``'asteroid designation'``, ``'comet number'``, ``'comet designation'``, or ``None``. ``None`` attempts to automatically identify the target id type using `~sbpy.data.Names`. Default: ``None`` **kwargs : optional Additional keyword arguments are passed to `~astroquery.mpc.MPC.query_object` Returns ------- `~Obs` object The resulting object will be populated with the same fields defined in `~astroquery.mpc.MPCClass.get_observations`. Examples -------- >>> from sbpy.data import Obs >>> obs = Obs.from_mpc('12893') # doctest: +REMOTE_DATA >>> orb[:3] # doctest: +SKIP number desig discovery note1 ... DEC mag band observatory ... deg mag ------ --------- --------- ----- ... ------------------- --- ---- ----------- 12893 1998 QS55 -- -- ... -15.78888888888889 0.0 -- 413 12893 1998 QS55 -- -- ... -15.788944444444445 0.0 -- 413 12893 1998 QS55 * 4 ... 5.526472222222222 0.0 -- 809 """ from ..data import Names if id_type is None: id_type = Names.asteroid_or_comet(targetid) if id_type == 'asteroid': ident = Names.parse_asteroid(targetid) elif id_type == 'comet': ident = Names.parse_comet(targetid) if 'number' in ident: id_type += ' number' elif 'designation' in ident: id_type += ' designation' try: results = MPC.get_observations(targetid, id_type=id_type, **kwargs) except (RuntimeError, ValueError) as e: raise QueryError(('Error raised by ' 'astroquery.mpc.MPCClass.get_observations: ' '{}').format(e)) results['epoch'] = Time(results['epoch'].to('d').value, scale='utc', format='jd') return cls.from_table(results)
LONGITUDE = -3.74 HEIGHT = 50 UTC_OFFSET = +1 # Get the datetime of midnight tonight date_tomorrow = datetime.today() + timedelta(days=1) next_midnight = date_tomorrow.replace(hour=0, minute=0, second=0, microsecond=0) # Find NEOWISE in the MPC database # result = MPC.query_object('comet', designation='C/2020 F3') # Get the NEOWISE ephemeris data for midnight from the Minor Planet Ephemeris Service neo_ephemeris = MPC.get_ephemeris('C/2020 F3', start=next_midnight, number=1) print(neo_ephemeris['Date'][0]) print(neo_ephemeris['RA'][0]) print(neo_ephemeris['Dec'][0]) # Extract the RA and Dec from the ephemeris data neowise_ra = neo_ephemeris['RA'][0] neowise_dec = neo_ephemeris['Dec'][0] # Define the location in the sky of C/2020 F3 NEOWISE based on the RA and Dec from the Ephemeris neowise = SkyCoord(neowise_ra, neowise_dec, frame='icrs', unit='deg') # Set the observing location based on the lat, long and height defined in settings observing_location = EarthLocation(lat=LATITUDE * u.deg, lon=LONGITUDE * u.deg, height=HEIGHT * u.m)
def query(self, term): self.catalog_data = MPC.query_object('asteroid', name=term)
import os from astropy.io import ascii from astroquery.mpc import MPC targets = ascii.read('ztf.txt') mpc = MPC() errored = [] for target in targets: outf = '{}.csv'.format(target['desg'].replace(' ', '').replace('/', '').lower()) if os.path.exists(outf): continue try: eph = mpc.get_ephemeris(target['desg'], start='2022-05-01', step='5d', number=150, unc_links=False, cache=True) except: errored.append(target['desg']) continue i = (eph['Elongation'] > 85) * (eph['Elongation'] < 135) eph[i].write(outf) print('errored:\n', '\n'.join(errored))
def finding_charts(target, observer, start, surveys=['SDSSr', 'DSS Red', 'DSS'], text=None, size=15, step=1, lstep=6, number=25, lformat='%H:%M', alpha=0.5, lalpha=1, **kwargs): """Generate finding charts for a moving target. The downloaded images are saved as gzipped FITS with a name based on the ephemeris position. If an image has already been downloaded for an ephemeris position, then it will read the file instead of fetching a new one. The finding charts are saved with the RA, Dec, and time of the center ephemeris point. Parameters ---------- target : string Target designation. observer : string Observer location. date : array-like of string Start date for the finding charts. Processed with `astropy.time.Time`. surveys : array-like, optional List of surveys to display in order of preference. See `astroquery.skyview`. size : int, optional Field of view in arcmin. text : string, optiona Additional text to add to the upper-left corner of the plot. step : float, optional Length of each time step. [hr] lstep : float, optional Length of time steps between labels. [hr] number : int, optional Number of steps. lformat : string, optional Label format, using strftime format codes. alpha : float, optional Transparency for figure annotations. 0 to 1 for transparent to solid. lalpha : float, optional Transparency for labels. **kwargs Additional keyword arguments are passed to `astroquery.mpc.MPC.get_ephemeris`. """ import os import matplotlib.pyplot as plt from astropy.io import fits from astropy.wcs import WCS from astropy.wcs.utils import skycoord_to_pixel from astropy.time import Time import astropy.units as u import astropy.coordinates as coords from astropy.table import vstack from astroquery.skyview import SkyView from astroquery.mpc import MPC import aplpy from .. import util # nominal tick marks t0 = Time(start) current = 0 tab = None while True: t1 = t0 + current * u.hr n = min(number - current, 1440) if n <= 0: break e = MPC.get_ephemeris(target, location=observer, start=t1, step=step * u.hr, number=n, **kwargs) if tab is None: tab = e else: tab = vstack((tab, e)) current += n dates = tab['Date'] eph = coords.SkyCoord(u.Quantity(tab['RA']), u.Quantity(tab['Dec'])) # label tick marks current = 0 tab = None number_lsteps = int(number * step / lstep) while True: t1 = t0 + current * u.hr n = min(number_lsteps - current, 1440) if n <= 0: break e = MPC.get_ephemeris(target, location=observer, start=t1, step=lstep * u.hr, number=n, **kwargs) if tab is None: tab = e else: tab = vstack((tab, e)) current += n dates_labels = tab['Date'] labels = coords.SkyCoord(u.Quantity(tab['RA']), u.Quantity(tab['Dec'])) step = 0 while step < len(eph): print('This step: ', dates[step], eph[step].to_string('hmsdms', sep=':', precision=0)) fn = '{}'.format( eph[step].to_string('hmsdms', sep='', precision=0).replace(' ', '')) if os.path.exists('sky-{}.fits.gz'.format(fn)): print('reading from file') im = fits.open('sky-{}.fits.gz'.format(fn)) else: print('reading from URL') # note, radius seems to be size of image position = eph[step].to_string('decimal', precision=6) opts = dict(position=position, radius=size * u.arcmin, pixels=int(900 / 15 * size)) im = None for survey in surveys: print(survey) try: im = SkyView.get_images(survey=survey, **opts)[0] except: continue break if im is None: raise ValueError("Cannot download sky image.") im.writeto('sky-{}.fits.gz'.format(fn)) wcs = WCS(im[0].header) c = skycoord_to_pixel(eph, wcs, 0) i = (c[0] > 0) * (c[0] < 900) * (c[1] > 0) * (c[1] < 900) c = skycoord_to_pixel(labels, wcs, 0) j = (c[0] > 0) * (c[0] < 900) * (c[1] > 0) * (c[1] < 900) fig = aplpy.FITSFigure(im) fig.set_title(target) vmin = np.min(im[0].data) if vmin < 0: vmid = vmin * 1.5 else: vmid = vmin / 2 fig.show_colorscale(cmap='viridis', stretch='log', vmid=vmid) fig.show_lines([np.vstack((eph[i].ra.degree, eph[i].dec.degree))], color='w', alpha=alpha) fig.show_markers(eph[i].ra.degree, eph[i].dec.degree, c='w', marker='x', alpha=alpha) for k in np.flatnonzero(j): d = dates_labels[k] fig.add_label(labels.ra[k].degree, labels.dec[k].degree, d.datetime.strftime(lformat), color='w', alpha=lalpha, size='small') fig.show_rectangles(eph[step].ra.degree, eph[step].dec.degree, 1 / 60, 1 / 60, edgecolors='w', alpha=alpha) if text is not None: ax = plt.gca() ax.text(0.03, 0.98, text, va='top', transform=ax.transAxes, size=16, color='w') t = target.replace(' ', '').replace('/', '').replace("'", '').lower() d = dates[step] d = d.isot[:16].replace('-', '').replace(':', '').replace('T', '_') fig.save('{}-{}-{}.png'.format(t, d, fn), dpi=300) step = np.flatnonzero(i)[-1] + 1
import sys from astroquery.mpc import MPC name = sys.argv[1] dateobs = sys.argv[2] geolon = sys.argv[3] geolat = sys.argv[4] eph = MPC.get_ephemeris(name, start=dateobs, location=(geolon, geolat, '1000m'), number=1) print(eph['RA'][0], eph['Dec'][0])