def test_transform(jplfiles): mars = get_orbit('Mars', Date(2018, 2, 25)) mars.frame = "SolarSystemBarycenter" mars.form = "keplerian" assert mars.frame.center.name == "Sun" assert mars.frame.center.m > 1.9e30 assert 1.3 * AU <= mars.a <= 1.7 * AU
def test_propagate(jplfiles): venus = get_orbit('VenusBarycenter', Date(2018, 1, 14)) venus = venus.propagate(Date(2018, 1, 15, 12, 27)) assert abs(32.18435609745404946124835987575 + venus.date._offset) <= np.finfo(float).eps assert str(venus.frame) == "SolarSystemBarycenter" assert str(venus.form) == "cartesian" assert np.allclose(venus, [ 5.23110445e+10, -8.51235950e+10, -4.16279990e+10, 3.05086795e+04, 1.58745616e+04, 5.21182159e+03 ])
def test_get(jplfiles): mars = get_orbit('Mars', Date(2018, 1, 14)) assert isinstance(mars, Orbit) assert mars.date.scale.name == "TDB" assert abs(32.184313430881999806842941325158 + mars.date._offset) <= np.finfo(float).eps assert mars.date.change_scale("UTC") == Date(2018, 1, 14) assert str(mars.frame) == "MarsBarycenter" assert mars.frame.center.name == "Mars Barycenter" assert str(mars.form) == "cartesian" # Check if conversion to other frame works as espected mars.frame = "EME2000" assert np.allclose(mars, [ -1.69346160e+11, -2.00501413e+11, -8.26925988e+10, 36908.14137465, -7756.92562483, -4081.22549533 ]) with raises(UnknownBodyError): get_orbit('Jupiter', Date(2018, 1, 14))
def space_phase(*argv): """Compute the phase of the moon or other solar system bodies Usage: space-phase <body> [<date>] [--graph] [--frame <frame>] [-a] [--file <file>] Options: <body> Body <date> Date to compute the moon phase at [default: now] (format %Y-%m-%dT%H:%M:%S) -g, --graph Display the moon phase -a, --analytical Use analytical model instead of JPL files --file <file> File """ import sys from .clock import Date from .utils import docopt, parse_date from .station import StationDb args = docopt(space_phase.__doc__) if args["<date>"] is None: args["<date>"] = "now" try: date = parse_date(args["<date>"]) except ValueError as e: print(e, file=sys.stderr) sys.exit(1) StationDb.list() body = args["<body>"] if body == "Moon": center = "EME2000" second = "Sun" else: center = body body = "Sun" second = "Earth" if args["--analytical"] and body.lower() == "moon": first = solar.get_body(body).propagate(date) second = solar.get_body(second).propagate(first.date) src = "analytical" else: src = "JPL" if args["--analytical"]: log.warning( "No analytical model available for '{}'. Switching to JPL source" .format(body)) jpl.create_frames() first = jpl.get_orbit(body, date) second = jpl.get_orbit(second, first.date) if body == "Moon": phase = compute_phase(first, second, center) else: phase = np.pi - compute_phase(first, second, center) body = center illumin = illumination(phase) log.debug("Computing {} phase using source '{}'".format(body, src)) log.info("{} at {:%Y-%m-%dT%H:%M:%S} : {:0.2f}%".format( body, date, illumin * 100)) if args["--graph"] or args["--file"]: draw_phase(date, phase, body=args["<body>"], filepath=args["--file"])
def space_planet(*args): """Compute position of a planet of the solar system and its major moons Usage: space-planet space-planet fetch space-planet <planet>... [options] Options: fetch Retrieve .bsp file <planet> Names of the planet to compute the ephemeris of. If absent, list all bodies available -f, --frame <frame> Frame in which to display the ephemeris to [default: EME2000] -d, --date <date> Start date of the ephem (%Y-%m-%d) [default: midnight] -r, --range <days> Duration of extrapolation [default: 3d] -s, --step <step> Step size of the ephemeris. [default: 60m] -a, --analytical Force analytical model instead of .bsp files Example: space-planet Mars # Position of Mars in EME2000 space-planet Moon -f Phobos # Position of the moon as seen from Phobos This command relies on .bsp files, parsed by the incredible jplephem lib. Bsp file can be retrieved at https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/ Files examples: de432s.bsp Moon, Sun, Mercury, Venus and main bodies barycentre mar097.bsp Mars, Phobos and Deimos jup310.bsp Jupiter and its major moons sat360xl.bsp Saturn and its major moons The 'beyond.env.jpl' config variable must be set to a list of bsp files paths. See beyond documentation about JPL files: http://beyond.readthedocs.io/en/latest/api/env.html#module-beyond.env.jpl If no .bsp file is provided, the command falls back to analytical methods for Moon and Sun. Other bodies are not provided. """ import requests from logging import getLogger log = getLogger(__name__) args = docopt(space_planet.__doc__) if args["fetch"]: folder = ws.folder / "jpl" if not folder.exists(): folder.mkdir() naif = "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/" baseurl = { "de403_2000-2020.bsp": naif + "spk/planets/a_old_versions/", # Data until 2020-01-01 "de430.bsp": naif + "spk/planets/", "de432s.bsp": naif + "spk/planets/", "de435.bsp": naif + "spk/planets/", "jup310.bsp": naif + "spk/satellites/", "sat360xl.bsp": naif + "spk/satellites/", "mar097.bsp": naif + "spk/satellites/", "pck00010.tpc": naif + "pck/", "gm_de431.tpc": naif + "pck/", } success = [] filelist = ws.config.get("beyond", "env", "jpl", fallback="de403_2000-2020.bsp") if not isinstance(filelist, list): filelist = [filelist] for filepath in filelist: filepath = Path(filepath) if not filepath.is_absolute(): filepath = folder / filepath if not filepath.exists(): url = baseurl.get(filepath.name, "") + str(filepath.name) log.info("Fetching {}".format(filepath.name)) log.debug(url) try: r = requests.get(url, stream=True) except requests.exceptions.ConnectionError as e: log.error(e) else: try: r.raise_for_status() except requests.exceptions.HTTPError as e: log.error("{} {}".format(filepath.name, e)) else: total = int(r.headers.get("content-length", 0)) size = 0 with filepath.open("bw") as fp: for chunk in r.iter_content(chunk_size=1024): fp.write(chunk) if total: size += len(chunk) print( "\r> {:6.2f} % {} / {}".format( 100 * size / total, humanize(size), humanize(total), ), end="", ) if total: print("\r", " " * 40, end="\r") success.append(str(filepath.absolute())) log.debug("Adding {} to the list of jpl files".format( filepath.name)) else: success.append(str(filepath.absolute())) log.info("File {} already downloaded".format(filepath.name)) # Adding the file to the list and saving the new state of configuration if success: ws.config.set("beyond", "env", "jpl", success) ws.config.save() elif args["<planet>"]: try: date = parse_date(args["--date"], fmt="date") stop = parse_timedelta(args["--range"]) step = parse_timedelta(args["--step"]) except ValueError as e: print(e, file=sys.stderr) sys.exit(1) if not args["--analytical"]: # Create all frames from .bsp files, if they are available try: jpl.create_frames() except jpl.JplError: jpl_error = True else: jpl_error = False # Create all frames from stations database StationDb.list() try: frame = get_frame(args["--frame"]) except UnknownFrameError as e: print(e, file=sys.stderr) sys.exit(1) # Computation ephems = [] for body_name in args["<planet>"]: try: if args["--analytical"] or jpl_error: body = solar.get_body(body_name).propagate(date) else: body = jpl.get_orbit(body_name, date) except UnknownBodyError as e: print(e, file=sys.stderr) sys.exit(1) ephem = body.ephem(start=date, stop=stop, step=step) ephem.frame = frame ephem.name = body_name ephems.append(ephem) else: print(ccsds.dumps(ephems)) else: print("List of all available bodies") try: jpl.create_frames() txt = recurse(jpl.get_frame("Earth").center.node, set()) except jpl.JplError as e: print(" Sun") print(" Moon") else: print(txt)
config.update({ "env": { "jpl": [ "/home/jules/.space/jpl/jup310.bsp" ] } }) date = Date.now() # Definition of the location of observation station = create_station('TLS', (43.428889, 1.497778, 178.0)) # Retrieve Jupiter and its moons state-vectors jupiter = get_orbit('Jupiter', date) io = get_orbit('Io', date) europa = get_orbit('Europa', date) ganymede = get_orbit('Ganymede', date) callisto = get_orbit('Callisto', date) # Convert them to the observer frame jupiter.frame = station io.frame = station europa.frame = station ganymede.frame = station callisto.frame = station # Change the orbit form in order to get azimuth and elevation europa.form = 'spherical' io.form = 'spherical'
from beyond.dates import Date from beyond.env.jpl import get_orbit from beyond.frames import create_station from beyond.config import config # Load the ".bsp" file config.update({"env": {"jpl": ["/home/jules/.space/jpl/jup310.bsp"]}}) date = Date.now() # Definition of the location of observation station = create_station('TLS', (43.428889, 1.497778, 178.0)) # Retrieve Jupiter and its moons state-vectors jupiter = get_orbit('Jupiter', date) io = get_orbit('Io', date) europa = get_orbit('Europa', date) ganymede = get_orbit('Ganymede', date) callisto = get_orbit('Callisto', date) # Convert them to the observer frame jupiter.frame = station io.frame = station europa.frame = station ganymede.frame = station callisto.frame = station # Change the orbit form in order to get azimuth and elevation europa.form = 'spherical' io.form = 'spherical'