def dmod(redshift,dist=False): if dist: dist_10pc = redshift.to(u.parsec).value/10. else: dist_10pc = Distance(z=redshift).parsec/10. dm=5*np.log10(dist_10pc-5) return dm
def __init__(self, afn, sep, distance, _PA=np.NaN * u.deg, *, differentials=None, copy: bool = True, afn_name: T.Optional[str] = None): if differentials is not None: # TODO, allow differentials raise ValueError() super().__init__( afn, sep, distance, _PA=_PA, copy=copy, differentials=differentials, ) if self._distance.unit.physical_type == "length": try: self._distance = Distance(self._distance, copy=False) except ValueError as e: if e.args[0].startswith("Distance must be >= 0"): raise ValueError( "Distance must be >= 0. To allow negative " "distance values, you must explicitly pass" " in a `Distance` object with the the " "argument 'allow_negative=True'.") else: raise
def get(self, name): """Load the data on the star from the local database, or online if not available locally. Parameters ---------- name : str Name of the star / planet Returns ------- star : exoorbit.bodies.Star recovered Star """ # self.backend.auto_fill(name) data = self.backend.load(name) if "distance" in data: distance = data["distance"] elif "parallax" in data: distance = Distance(parallax=data["parallax"]) else: distance = None # Convert names # Stellar parameters star = Star( name=name, mass=data.get("mass"), radius=data.get("radius"), teff=data.get("t_eff"), logg=data.get("logg"), monh=data.get("metallicity"), vmac=data.get("velocity_turbulence", 1 * u.km/u.s), coordinates=data.get("coordinates"), distance=distance, radial_velocity=data.get("radial_velocity"), ) planets = {} for pname, p in data["planets"].items(): planet = Planet( name=pname, radius=p.get("radius"), mass=p.get("mass"), inc=p.get("inclination", 90 * u.deg), sma=p.get("semi_major_axis", 0 * u.AU), period=p.get("period"), ecc=p.get("eccentricity"), omega=p.get("periastron", 90 * u.deg), time_of_transit=p.get("transit_epoch"), transit_duration=p.get("transit_duration", 0 * u.day), ) planets[pname] = planet star.planets = planets return star
def flux_to_nulnu(flux, z, wav, ld=None, lsun=None, cosmo=None,mujy=None): if cosmo is None: # print 'no preset cosmology,use FlatLCDM w/ h0.7' cosmo = FlatLambdaCDM(H0=70, Om0=0.3) dlum = Distance(z=z, unit=u.cm, cosmology=cosmo).value freq = 3e14/wav if mujy:jy2erg=1e29 else:jy2erg=1e23 nulnu = np.log10(flux*4*np.pi*dlum**2*freq/((1.+z)*jy2erg)) if lsun is True: nulnu -= 33.5827 return nulnu
def flux_to_nulnu(flux, z, wav, ld=None, lsun=None, cosmo=None, mujy=None): # convert a flux to nulnu at a certain wavelength in the unit of erg/s # wav should be in micron, and flux should be in Jy if cosmo is None: # print 'no preset cosmology,use FlatLCDM w/ h0.7' cosmo = FlatLambdaCDM(H0=70, Om0=0.3) dlum = Distance(z=z, unit=u.cm, cosmology=cosmo).value freq = 3e14 / wav if mujy: jy2erg = 1e29 else: jy2erg = 1e23 nulnu = np.log10(flux * 4 * np.pi * dlum**2 * freq / ((1. + z) * jy2erg)) if lsun is True: nulnu -= 33.5827 return nulnu
assert_allclose([m31_in_m31.lon, m31_in_m31.lat], [0, 0] * u.deg, atol=1e-10 * u.deg) assert_allclose([m33_in_m31.lon, m33_in_m31.lat], [11.13135175, -9.79084759] * u.deg) assert_allclose(m33.separation(m31), np.hypot(m33_in_m31.lon, m33_in_m31.lat), atol=.1 * u.deg) # used below in the next parametrized test m31_sys = [ICRS, FK5, Galactic] m31_coo = [(10.6847929, 41.2690650), (10.6847929, 41.2690650), (121.1744050, -21.5729360)] m31_dist = Distance(770, u.kpc) convert_precision = 1 * u.arcsec roundtrip_precision = 1e-4 * u.degree dist_precision = 1e-9 * u.kpc m31_params = [] for i in range(len(m31_sys)): for j in range(len(m31_sys)): if i < j: m31_params.append((m31_sys[i], m31_sys[j], m31_coo[i], m31_coo[j])) @pytest.mark.parametrize(('fromsys', 'tosys', 'fromcoo', 'tocoo'), m31_params) def test_m31_coord_transforms(fromsys, tosys, fromcoo, tocoo): """ This tests a variety of coordinate conversions for the Chandra point-source
def find_opp_and_retro(self, start_time): cur_time = Time(start_time) last_RA = 0. last_dist = Distance(999, unit=units.au) pre_closest = True self.retrograding = False retro_start = None retro_end = None opptime = None # Earth location to use for calculating Mars' position. # Setting it to None will (I think? docs aren't clear) calculate # from the center of the Earth; this is much faster, skips # calculations like parallax due to earth's rotation, # and avoids seeing a lot of spurious retrograde/direct # transitions due solely to the observer's position changing # as the earth rotates. location = None # A place to store the data points self.planettrack = [] # When a planet is approaching opposition, its elongation is negative. # When it flips to positive (-180 to 180), it just passed opposition. # Can't check for exactly 180 if we're only checking time coarsely. last_elong = -1 # We'll look for the end of retrograde then go a few days # past it; but first, put a limit on how far we can go. end_time = cur_time + TimeDelta(300, format='jd') # Initially, go one day at a time: coarsemode = TimeDelta(1, format='jd') # but in fine mode, we'll go one hour at a time: finemode = TimeDelta(60 * 60, format='sec') # and near opposition we'll go even finer for a few days: superfinemode = TimeDelta(60 * 5, format='sec') timeslice = coarsemode while cur_time < end_time: cur_time += timeslice mars = get_body(planetname, cur_time) flags = '' # Are we starting or stopping retrograde? if ((mars.ra == last_RA) or (mars.ra < last_RA and not self.retrograding) or (mars.ra > last_RA and self.retrograding)): # Are we still in coarse mode? If so, jump back # in time a few days and go to fine mode. if timeslice == coarsemode: print("Switching to fine mode on", cur_time) print(" RA", mars.ra.hour, ", dec", mars.dec.degree) timeslice = finemode cur_time -= TimeDelta(EXTRA_DAYS, format='jd') continue # We're in fine mode. Record dates when the planet # starts or ends retrograde, hits opposition or makes # its closest approach. if self.retrograding: flags += END_RETROGRADE # Don't consider this the actual end of retrograde # unless we're already past opposition. # There are potentially a lot of false retrogrades. # We can get them from parallax if we calculate # Mars' position from a specific earth location; # but even if we don't, pyastro gives us a lot # of false little retrogrades and I don't know why. if opptime: retro_end = cur_time else: flags += START_RETROGRADE retro_start = cur_time if mars.ra == last_RA: flags += STATIONARY self.retrograding = not self.retrograding # Calculate elongation to find the opposition time: sun = get_body('sun', cur_time) elongation = (mars.ra - sun.ra).degree # print(cur_time, "\n RA", # mars.ra.hour, "dec", mars.dec.degree, # "elongation", elongation) if last_elong > 180. and elongation <= 180.: if timeslice == superfinemode: flags += OPPOSITION opptime = cur_time timeslice = finemode print("Opposition on", cur_time, ", switching back to fine") # XXX it would be nice not to go back to finemode # until after we've found closest approach. # But astropy randomly finds a closest approach # date weeks before the actual closest approach, # at the start of retrograde. else: # Looks like opposition. But let's go back a day and # get a finer view of the time. print("Switching to superfine mode on", cur_time) timeslice = superfinemode cur_time -= TimeDelta(1, format='jd') if mars.distance >= last_dist and pre_closest: flags += CLOSEST_APPROACH # self.find_parallax(cur_time) pre_closest = False elif mars.distance < last_dist: # receding pre_closest = True if flags or self.save_all_points: self.planettrack.append([ cur_time.datetime, mars.ra.radian, mars.dec.radian, mars.distance.km, flags ]) last_RA = mars.ra last_dist = mars.distance last_elong = elongation # If we've seen the opposition as well as retro_start and retro_end # then we're done. Switch back to coarse mode and record a # few more days. if timeslice == finemode and retro_start and retro_end and opptime: timeslice = coarsemode end_time = cur_time + TimeDelta(EXTRA_DAYS, format='jd') # We're done calculating all the points. # Now calculate the retrograde midpoint, if we have both start and end. if retro_start and retro_end: mid_retro_date = retro_start + (retro_end - retro_start) / 2 mars = get_body(planetname, mid_retro_date) # Insert that into our planettrack list: for i, point in enumerate(self.planettrack): if point[IDATE] == mid_retro_date: point[IFLAGS] += MIDPOINT_RETRO break elif point[IDATE] > mid_retro_date: self.planettrack.insert(i, [ mid_retro_date.datetime, mars.ra.radian, mars.dec.radian, mars.distance.km, MIDPOINT_RETRO ]) # We've just changed a list in the middle of looping # over that list, but it's okay because we're breaking out. break else: print("don't have both retro start and end") # Now print what we found. print("%20s %-19s %-11s %-10s %s" % ('', 'Date', 'RA', 'Dec', 'Dist (mi)')) for point in self.planettrack: if point[IFLAGS]: # print("%20s %-19s %-11s %-10s %d" % \ # (self.flags_to_string(point[4]), str(point[0]), # point[1], point[2], # point[3] * 9.2956e7)) print("%20s %-19s %-11.7f %-10.7f %d" % \ (self.flags_to_string(point[IFLAGS]), str(point[IDATE]), self.rads_to_hours(point[IRA]), self.rads_to_degrees(point[IDEC]), point[IDIST] / 1.609344))