How to use the ephem.FixedBody function in ephem

To help you get started, we’ve selected a few ephem 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 panoptes / POCS / panoptes / utils / convert.py View on Github external
def HA_to_Dec(self, J2000_coordinate, site):
        """
            HA to Dec
        """
        assert type(J2000_coordinate) == coords.FK5
        assert J2000_coordinate.equinox.value == 'J2000.000'

        # Coordinate precessed to Jnow (as an astropy coordinate object)
        Jnow_coordinate = J2000_coordinate.precess_to(Time.now())

        # Coordinate as a pyephem coordinate (J2000)
        RA_string, Dec_string = J2000_coordinate.to_string(
            precision=2, sep=':').split(' ')
        ephem_coordinate = ephem.FixedBody(
            RA_string, Dec_string, epoch=ephem.J2000)
        ephem_coordinate = ephem.readdb(
            'Polaris,f|M|F7,{},{},2.02,2000'.format(RA_string, Dec_string))
        ephem_coordinate.compute(site)

        HourAngle = ephem_coordinate.ra - site.sidereal_time()

        self.logger.info('Astropy J2000: {}'.format(
            J2000_coordinate.to_string(precision=2, sep=':')))
        self.logger.info(
            'pyephem Jnow:  {} {}'.format(ephem_coordinate.ra, ephem_coordinate.dec))
        self.logger.info('RA decimal = {:f}'.format(ephem_coordinate.ra))
        self.logger.info('LST decimal = {:f}'.format(site.sidereal_time()))
        self.logger.info('HA decimal = {:f}'.format(HourAngle))

        return HourAngleimport
github lofar-astron / RMextract / RMextract / PosTools.py View on Github external
location_lat, location_lon, location_height = ITRFToWGS84(position[0], position[1], position[2])
        location = ephem.Observer()
        # convert geodetic latitude to geocentric
        # flattening, f, defined above for WGS84 stuff
        geodet_lat = math.radians(location_lat)
        tan_geocentric_latitude =  math.tan(geodet_lat) * (1 - f) **2
        geocentric_latitude = GeodeticToGeocentricLat(geodet_lat, location_height)
        location.lat = geocentric_latitude
        location.lon = math.radians(location_lon)
        location.elevation = location_height
        location.pressure = 0.0
        #  convert to Dublin Julian Date for PyEphem
        location.date =  time/86400.0 - 15019.5
        lst = location.sidereal_time()
        equatorial = ephem.Equatorial(str(12.0 * math.degrees(pointing[0])/180),str(math.degrees(pointing[1])))
        body = ephem.FixedBody()
        body._ra = equatorial.ra
        body._dec = equatorial.dec
        body._epoch = equatorial.epoch
        body.compute(location)
        az = math.degrees(body.az)   * math.pi / 180.0
        el = math.degrees(body.alt) * math.pi / 180.0
    else: 
      print ('failure to get azimuth and elevation! Exiting!')
      return -1,-1
    return az,el
github ledatelescope / bifrost / python / bifrost / addon / leda / model_block.py View on Github external
def compute_antenna_phase_delays(self, source_position_ra, source_position_dec):
        """Calculate antenna phase delays based on the source position
        @param[in] source_position_ra Should be a string
        @param[in] source_position_dec Should be a string"""
        source_position = ephem.FixedBody()
        source_position._ra = source_position_ra
        source_position._dec = source_position_dec
	source_position.compute(self.observer)
	az = np.float(repr(source_position.az))
        alt = np.float(repr(source_position.alt))
        cartesian_direction_to_source = horizontal_to_cartesian(az, alt)
        antenna_distance_to_observatory = np.sum(
            self.antenna_coordinates*cartesian_direction_to_source, axis=-1)
        antenna_time_delays = antenna_distance_to_observatory/299792458.
        antenna_phase_delays = np.exp(-1j*2*np.pi*antenna_time_delays*self.frequencies)
        return antenna_phase_delays
    def generate_model(self):
github HERA-Team / aipy / src / phs.py View on Github external
def __init__(self, ra, dec, mfreq=.150, name='', epoch=ephem.J2000,
            ionref=(0.,0.), srcshape=(0.,0.,0.), **kwargs):
        RadioBody.__init__(self, name, mfreq, ionref, srcshape)
        ephem.FixedBody.__init__(self)
        self._ra, self._dec = ra, dec
        self._epoch = epoch
    def __str__(self):
github HERA-Team / aipy / src / phs.py View on Github external
assert(ncrd in (2,3))
        if crdsys == 'eq':
            if ncrd == 2: return (self.ra, self.dec)
            return coord.radec2eq((self.ra, self.dec))
        else:
            if ncrd == 2: return (self.az, self.alt)
            return coord.azalt2top((self.az, self.alt))

#  ____           _ _       _____ _              _ ____            _       
# |  _ \ __ _  __| (_) ___ |  ___(_)_  _____  __| | __ )  ___   __| |_   _ 
# | |_) / _` |/ _` | |/ _ \| |_  | \ \/ / _ \/ _` |  _ \ / _ \ / _` | | | |
# |  _ < (_| | (_| | | (_) |  _| | |>  <  __/ (_| | |_) | (_) | (_| | |_| |
# |_| \_\__,_|\__,_|_|\___/|_|   |_/_/\_\___|\__,_|____/ \___/ \__,_|\__, |
#                                                                    |___/ 

class RadioFixedBody(ephem.FixedBody, RadioBody):
    """A source at fixed RA,DEC.  Combines ephem.FixedBody with RadioBody."""
    def __init__(self, ra, dec, mfreq=.150, name='', epoch=ephem.J2000,
            ionref=(0.,0.), srcshape=(0.,0.,0.), **kwargs):
        RadioBody.__init__(self, name, mfreq, ionref, srcshape)
        ephem.FixedBody.__init__(self)
        self._ra, self._dec = ra, dec
        self._epoch = epoch
    def __str__(self):
        if self._dec<0: return RadioBody.__str__(self) + '\t' + str(self._ra) +'\t'+ str(self._dec)
        else: return RadioBody.__str__(self) + '\t' + str(self._ra) +'\t'+'+' + str(self._dec)
    def compute(self, observer):
        ephem.FixedBody.compute(self, observer)
        RadioBody.compute(self, observer)

#  ____           _ _      ____                  _       _ 
# |  _ \ __ _  __| (_) ___/ ___| _ __   ___  ___(_) __ _| |
github HERA-Team / aipy / scripts / srclist.py View on Github external
clist,coff,catalogs = a.scripting.parse_srcs(opts.centers, opts.cat)
    if opts.cal != None:
        ccat = a.cal.get_catalog(opts.cal, clist, coff, catalogs)
    else:
        ccat = a.src.get_catalog(clist, coff, catalogs)
else: ccat = {}
    
if opts.juldate is None: date = ephem.J2000
else: 
    date = a.phs.juldate2ephem(opts.juldate)
    aa = a.scripting.get_null_aa()
    aa.set_jultime(opts.juldate)

for c in [cat, xcat, ccat]:
    for s in c.keys():
        try: ephem.FixedBody.compute(c[s], date)
        except(TypeError):
            if opts.juldate is None: del(c[s])
            else: c[s].compute(aa)

srcs = cat.keys()
srcs = [s for s in srcs if s not in xcat]
if opts.sep != None:
    nsrcs = []
    for s1 in srcs:
        for s2 in ccat.keys():
            if ephem.separation(cat[s1], ccat[s2]) <= opts.sep * a.img.deg2rad:
                nsrcs.append(s1)
                break
    srcs = nsrcs
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata.py View on Github external
raise ValueError('The data is already phased; can only phase '
                             'drift scan data. Use unphase_to_drift to '
                             'convert to a drift scan.')
        else:
            raise ValueError('The phasing type of the data is unknown. '
                             'Set the phase_type to "drift" or "phased" to '
                             'reflect the phasing status of the data')

        obs = ephem.Observer()
        # obs inits with default values for parameters -- be sure to replace them
        latitude, longitude, altitude = self.telescope_location_lat_lon_alt
        obs.lat = latitude
        obs.lon = longitude

        # create a pyephem object for the phasing position
        precess_pos = ephem.FixedBody()
        precess_pos._ra = ra
        precess_pos._dec = dec
        precess_pos._epoch = epoch

        # calculate RA/DEC in J2000 and write to object
        obs.date, obs.epoch = ephem.J2000, ephem.J2000
        precess_pos.compute(obs)

        self.phase_center_ra = precess_pos.a_ra + \
            0.0  # force to be a float not ephem.Angle
        self.phase_center_dec = precess_pos.a_dec + \
            0.0  # force to be a float not ephem.Angle
        # explicitly set epoch to J2000
        self.phase_center_epoch = 2000.0

        unique_times, unique_inds = np.unique(
github HERA-Team / aipy / src / phs.py View on Github external
def __init__(self, ra, dec, mfreq=.150, name='', epoch=ephem.J2000,
            ionref=(0.,0.), srcshape=(0.,0.,0.), **kwargs):
        RadioBody.__init__(self, name, mfreq, ionref, srcshape)
        ephem.FixedBody.__init__(self)
        self._ra, self._dec = ra, dec
        self._epoch = epoch
    def __str__(self):
github HERA-Team / aipy / src / phs.py View on Github external
assert(ncrd in (2,3))
        if crdsys == 'eq':
            if ncrd == 2: return (self.ra, self.dec)
            return coord.radec2eq((self.ra, self.dec))
        else:
            if ncrd == 2: return (self.az, self.alt)
            return coord.azalt2top((self.az, self.alt))

#  ____           _ _       _____ _              _ ____            _       
# |  _ \ __ _  __| (_) ___ |  ___(_)_  _____  __| | __ )  ___   __| |_   _ 
# | |_) / _` |/ _` | |/ _ \| |_  | \ \/ / _ \/ _` |  _ \ / _ \ / _` | | | |
# |  _ < (_| | (_| | | (_) |  _| | |>  <  __/ (_| | |_) | (_) | (_| | |_| |
# |_| \_\__,_|\__,_|_|\___/|_|   |_/_/\_\___|\__,_|____/ \___/ \__,_|\__, |
#                                                                    |___/ 

class RadioFixedBody(ephem.FixedBody, RadioBody):
    """A source at fixed RA,DEC.  Combines ephem.FixedBody with RadioBody."""
    def __init__(self, ra, dec, mfreq=.150, name='', epoch=ephem.J2000,
            ionref=(0.,0.), srcshape=(0.,0.,0.), **kwargs):
        RadioBody.__init__(self, name, mfreq, ionref, srcshape)
        ephem.FixedBody.__init__(self)
        self._ra, self._dec = ra, dec
        self._epoch = epoch
    def __str__(self):
        if self._dec<0: return RadioBody.__str__(self) + '\t' + str(self._ra) +'\t'+ str(self._dec)
        else: return RadioBody.__str__(self) + '\t' + str(self._ra) +'\t'+'+' + str(self._dec)
    def compute(self, observer):
        ephem.FixedBody.compute(self, observer)
        RadioBody.compute(self, observer)

#  ____           _ _      ____                  _       _ 
# |  _ \ __ _  __| (_) ___/ ___| _ __   ___  ___(_) __ _| |