How to use the jplephem.spk.SPK function in jplephem

To help you get started, we’ve selected a few jplephem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astropy / astropy / astropy / coordinates / solar_system.py View on Github external
try:
        from jplephem.spk import SPK
    except ImportError:
        raise ImportError("Solar system JPL ephemeris calculations require "
                          "the jplephem package "
                          "(https://pypi.org/project/jplephem/)")

    if value.lower() == 'jpl':
        value = DEFAULT_JPL_EPHEMERIS

    if value.lower() in ('de430', 'de432s'):
        value = ('https://naif.jpl.nasa.gov/pub/naif/generic_kernels'
                 '/spk/planets/{:s}.bsp'.format(value.lower()))

    elif os.path.isfile(value):
        return SPK.open(value)

    else:
        try:
            urlparse(value)
        except Exception:
            raise ValueError('{} was not one of the standard strings and '
                             'could not be parsed as a file path or URL'.format(value))

    return SPK.open(download_file(value, cache=True))
github astropy / astropy / astropy / coordinates / solar_system.py View on Github external
if value.lower() in ('de430', 'de432s'):
        value = ('https://naif.jpl.nasa.gov/pub/naif/generic_kernels'
                 '/spk/planets/{:s}.bsp'.format(value.lower()))

    elif os.path.isfile(value):
        return SPK.open(value)

    else:
        try:
            urlparse(value)
        except Exception:
            raise ValueError('{} was not one of the standard strings and '
                             'could not be parsed as a file path or URL'.format(value))

    return SPK.open(download_file(value, cache=True))
github nanograv / PINT / pint / solar_system_ephemerides.py View on Github external
def _load_kernel_local(ephem, path=''):
    load_kernel = False # a flag for checking if the kernel has been loaded
    if path.endswith("%s.bsp" % ephem):
        custom_path = path
    else:
        custom_path = os.path.join(path, "%s.bsp" % ephem)
    search_list = [custom_path, datapath("%s.bsp" % ephem)]
    for p in search_list:
        if load_kernel:
            break
        try:# Bipass the astropy kernel loading system.
            coor.solar_system_ephemeris._kernel = SPK.open(p)
            coor.solar_system_ephemeris._value = p
            coor.solar_system_ephemeris._kernel.origin = coor.solar_system_ephemeris._value
            load_kernel = True
        except:
            load_kernel = False
    return load_kernel
github aerospaceresearch / orbitdeterminator / orbitdeterminator / kep_determination / radec_LS_mpc.py View on Github external
# print('radec_res = ', radec_res)
        # observed minus computed residual:
        rv[2*i-2], rv[2*i-1] = radec_res
        tv[i] = timeobs.tdb.jd
    return tv, rv

# path of file of optical MPC-formatted observations
body_fname_str = '../example_data/mpc_eros_data.txt'

#body name
body_name_str = 'Eros'

# load JPL DE430 ephemeris SPK kernel, including TT-TDB difference
# 'de430t.bsp' may be downloaded from
# ftp://ssd.jpl.nasa.gov/pub/eph/planets/bsp/de430t.bsp
spk_kernel = SPK.open('de430t.bsp')
# print(spk_kernel)

# load MPC data for a given NEA
# mpc_object_data_unfiltered = gm.load_mpc_data(body_fname_str)
# # print('mpc_object_data_unfiltered = ', mpc_object_data)
# mpc_object_data = mpc_object_data_unfiltered[mpc_object_data_unfiltered['observatory'] != 'C51'][0]
# # print('mpc_object_data = ', mpc_object_data)
mpc_object_data = gm.load_mpc_data(body_fname_str)

# print('MPC observation data:\n', mpc_object_data[ inds ], '\n')

#load MPC data of listed observatories (longitude, parallax constants C, S) (~7,000 observations)
mpc_observatories_data = gm.load_mpc_observatories_data('mpc_observatories.txt')

#lines of observations file to be used for orbit determination
# obs_arr = [2341,2352,2362,2369,2377,2386,2387]
github skyfielders / python-skyfield / skyfield / jpllib.py View on Github external
def __init__(self, path):
        self.path = path
        self.filename = os.path.basename(path)
        self.spk = SPK.open(path)
        self.segments = [SPICESegment(self, s) for s in self.spk.segments]
        self.codes = set(s.center for s in self.segments).union(
                         s.target for s in self.segments)
github skyfielders / python-skyfield / skyfield / contrib / iosurvey.py View on Github external
def get_summary(url, spk=True):
    ''' simple function to retrieve the header of a BSP file and return SPK object'''
    # connect to file at URL
    bspurl = urllib2.urlopen(url)
    # retrieve the "tip" of a file at URL
    bsptip = bspurl.read(10**5) # first 100kB
    # save data in fake file object (in-memory)
    bspstr = StringIO(bsptip)
    # load into DAF object
    daf = DAF(bspstr)
    # return either SPK or DAF object
    if spk:
      # make a SPK object
      spk = SPK(daf)
      # return representation 
      return spk
    else:
      # return representation 
      return daf
github waqasbhatti / astrobase / astrobase / timeutils.py View on Github external
#################
## JPL KERNELS ##
#################

modpath = os.path.abspath(os.path.dirname(__file__))
planetdatafile = os.path.join(modpath,'data/de430.bsp')

# we'll try to load the SPK kernel. if that fails, we'll download it direct from
# JPL so the source distribution is kept small

try:

    # load the JPL kernel
    jplkernel = SPK.open(planetdatafile)
    HAVEKERNEL = True

except Exception:

    # this is so we don't download the JPL kernel when this module is imported
    # as part of a docs build on RTD
    import os
    RTD_INVOCATION = os.environ.get('RTD_IGNORE_HTLS_FAIL')

    if not RTD_INVOCATION:

        # this function is used to check progress of the download
        def on_download_chunk(transferred,blocksize,totalsize):
            progress = transferred*blocksize/float(totalsize)*100.0
            print('{progress:.1f}%'.format(progress=progress),end='\r')
github nanograv / PINT / pint / astropy_solar_system_ephem.py View on Github external
astropy.coordinates.olar_system_ephemeris.bodies attribution.
    t: Astropy.time.Time object
        Observation time in Astropy.time.Time object format.
    ephem: str
        The ephem to for computing solar system object position and velocity
    """
    ephem = ephem.lower()
    objname = objname.lower()
    # Use astropy to compute postion.
    try:
        pos = coor.get_body_barycentric(objname, t, ephemeris=ephem)
    except ValueError:
        pos = coor.get_body_barycentric(objname, t, ephemeris= kernel_link_base + "%s.bsp" % ephem)
    # Use jplephem to compute velocity.
    # TODO: Astropy 1.3 will have velocity calculation availble.
    kernel = SPK.open(datapath("%s.bsp" % ephem))
    # Compute vel from planet barycenter to solar system barycenter
    lcod = len(str(jpl_obj_code[objname]))
    tjd1 = t.tdb.jd1
    tjd2 = t.tdb.jd2
    # Planets with barycenter computing
    if lcod == 3:
        _, vel_pbary_ssb = kernel[0,jpl_obj_code[objname]/100].compute_and_differentiate(tjd1, tjd2)
        _, vel_p_pbary = kernel[jpl_obj_code[objname]/100,
                        jpl_obj_code[objname]].compute_and_differentiate(tjd1, tjd2)
        vel = vel_pbary_ssb + vel_p_pbary
    # Planets without barycenter computing
    else:
         _, vel = kernel[0,jpl_obj_code[objname]].compute_and_differentiate(tjd1, tjd2)
    return PosVel(pos.xyz, vel / SECS_PER_DAY * u.km/u.second, origin='ssb', obj=objname)
github waqasbhatti / astrobase / astrobase / timeutils.py View on Github external
# this is the URL to the SPK
        spkurl = (
            'https://naif.jpl.nasa.gov/'
            'pub/naif/generic_kernels/spk/planets/de430.bsp'
        )

        LOGINFO('JPL kernel de430.bsp not found. Downloading from:\n\n%s\n' %
                spkurl)
        from urllib.request import urlretrieve

        localf, headerr = urlretrieve(
            spkurl,planetdatafile,reporthook=on_download_chunk
        )
        if os.path.exists(localf):
            print('\nDone.')
            jplkernel = SPK.open(planetdatafile)
            HAVEKERNEL = True
        else:
            print('failed to download the JPL kernel!')
            HAVEKERNEL = False

    else:
        HAVEKERNEL = False


######################
## USEFUL CONSTANTS ##
######################

# physical constants
CLIGHT_KPS = 299792.458
github galactics / beyond / beyond / env / jpl.py View on Github external
:py:class:`~beyond.constants.Body`
    """

    return Pck()[name]


if __name__ == "__main__":  # pragma: no cover

    import sys

    config.update({"eop": {"missing_policy": "pass"}})

    for file in sys.argv[1:]:
        print(file)
        print("*" * len(file))
        for segment in SPK.open(file).segments:

            start = Date(segment.start_jd - Date.JD_MJD)
            end = Date(segment.end_jd - Date.JD_MJD)

            center = target_names.get(segment.center, "Unknown")
            target = target_names.get(segment.target, "Unknown")
            print(
                "from {start:{fmt}} to {end:{fmt}} : {center} -> {target}".format(
                    start=start, end=end, center=center, target=target, fmt="%Y-%m-%d"
                )
            )
        print()