示例#1
0
def write_ephemeris(doc: dominate.document):
    """
    Write ephemeris in HTML document
    :param doc: Dominate document
    """
    ephemeris = Ephemeris('data\\ephemeris-fr.json')
    today_eph = ephemeris.get_today_ephemeris()
    string_eph = today_eph[1] + ' ' + today_eph[0] if today_eph[
        1] else today_eph[0]
    doc.add(tags.h3(string_eph))
示例#2
0
def get_ephemeris(navigation_entry, satellite_name):
    satellite = navigation_entry.sel(sv=satellite_name)
    ephem_list = []

    M0_array = satellite.get('M0').data
    deltaN_array = satellite.get('DeltaN').data
    sqrtA_array = satellite.get('sqrtA').data
    time_array = satellite.get('time').data
    e_array = satellite.get('Eccentricity').data
    omega_array = satellite.get('omega').data
    Crs_array = satellite.get('Crs').data
    Crc_array = satellite.get('Crc').data
    Cuc_array = satellite.get('Cuc').data
    Cus_array = satellite.get('Cus').data
    Cic_array = satellite.get('Cic').data
    Cis_array = satellite.get('Cis').data
    IDOT_array = satellite.get('IDOT').data
    Io_array = satellite.get('Io').data
    omega0_array = satellite.get('Omega0').data
    omegaDot_array = satellite.get('OmegaDot').data
    Toe_array = satellite.get('Toe').data

    for index, time in enumerate(time_array):
        M0 = M0_array[index]
        e = e_array[index]
        omega = omega_array[index]
        Crs = Crs_array[index]
        Crc = Crc_array[index]
        Cuc = Cuc_array[index]
        Cus = Cus_array[index]
        Cic = Cic_array[index]
        Cis = Cis_array[index]
        IDOT = IDOT_array[index]
        Io = Io_array[index]
        omega0 = omega0_array[index]
        omegaDot = omegaDot_array[index]
        deltaN = deltaN_array[index]
        sqrtA = sqrtA_array[index]
        Toe = Toe_array[index]
        if not np.isnan(
                np.array([
                    e, M0, deltaN, sqrtA, omega, Crs, Crc, Cuc, Cus, Cic, Cis,
                    IDOT, Io, omega0, omegaDot, Toe
                ])).any():
            ephemeris = Ephemeris(time, e, M0, deltaN, sqrtA, omega, Crs, Crc,
                                  Cuc, Cus, Cic, Cis, IDOT, Io, omega0,
                                  omegaDot, Toe)
            ephem_list.append(ephemeris)
    return ephem_list
示例#3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('date',
                        type=str,
                        help="ISO date string to optimize the pointings too")
    parser.add_argument('runid',
                        help="CFHT RUN ID")
    parser.add_argument('pointing_objects',
                        type=str,
                        help="Name of file that contains list of objects to try and observe.")
    parser.add_argument('required_objects',
                        type=str,
                        help="name of file that contains a list of required objects")
    parser.add_argument('--nattempts', type=int,
                        help="Number of random variations of pointings to try",
                        default=2)
    parser.add_argument('--camera', default="MEGACAM_40",
                        choices=Camera.known_cameras,
                        help="Name of camera")
    parser.add_argument('--ephem-format', default='CFHT_API',
                        choices=['CFHT_API', 'CFHT_ET', 'GEMINI_ET', 'KECK'])

    args = parser.parse_args()

    logging.basicConfig(level=logging.INFO)

    pointing_date = args.date

    logging.info("Date for orbit predictions: {}".format(args.date))
    logging.info("Building pointings that include all targets in {}".format(args.required_objects))
    logging.info("Optimized to include as many objects in {} as possible".format(args.pointing_objects))

    required_objects = []
    required_filename = args.required_objects
    for required_object in open(required_filename):
        if '#' in required_object:
            continue
        required_objects.append(required_object.strip())

    pointings_filename = os.path.splitext(required_filename)[0] + "_pointings.txt"

    filenames = open(args.pointing_objects).readlines()

    orbits = {}
    tokens = []

    # load the orbits of all objects of interest.
    for filename in filenames:
        filename = filename.strip()
        token = os.path.splitext(os.path.basename(filename))[0]
        try:
            abg_filename = os.path.splitext(filename)[0] + ".abg"
            orbits[token] = mp_ephem.BKOrbit(None, ast_filename=filename, abg_file=abg_filename)
        except Exception as ex:
            # Try loading an 'autoclouds10' file.
            token = os.path.splitext(os.path.basename(filename))[0].removesuffix('_autoclouds10')
            ephem_filename = os.path.join(filename, f"{token}_autoclouds10_sep21_ephem.txt")
            orbits[token] = Ephemeris(token, ephem_filename)

        tokens.append(token)

    # Turn the object locations at the time of interest into a SkyCoord numpy array.
    tokens = np.array(tokens)
    minimum_number_of_pointings = len(required_objects)

    best_pointing_list = []
    for attempt in range(args.nattempts):
        locations = []
        for token in tokens:
            orbits[token].predict(pointing_date)
            locations.append([orbits[token].coordinate.ra.degree, orbits[token].coordinate.dec.degree])
        locations = SkyCoord(locations, unit='degree')
        logging.info("Attempt : {} \n".format(attempt))
        pointings = optimize(orbits, required_objects, locations, tokens)
        if minimum_number_of_pointings >= len(pointings):
            minimum_number_of_pointings = len(pointings)
            best_pointing_list = deepcopy(pointings)

    with open(pointings_filename, 'w') as pobj:
        pobj.write("index {}\n".format(pointing_date))
        pointing_number = 0
        for token in best_pointing_list:
            pobj.write("{} {} {} {} # {}\n".format(pointing_number + 1,
                                                   "{}".format(token),
                                                   best_pointing_list[token][0].coord.to_string("hmsdms", sep=" "),
                                                   2000,
                                                   len(best_pointing_list[token][1])))
            pointing_number += 1
            create_ephemeris_file(token, best_pointing_list[token][0], best_pointing_list[token][1], orbits,
                                  pointing_date, args.runid, ephem_format=args.ephem_format.replace("_", " "))