SETIatHCRO / ATA-Utils

3 stars 7 forks source link

Create ephemeris + track_and_offset functions #8

Open wfarah opened 3 years ago

wfarah commented 3 years ago

@tkoumrian I added this in my local repository to do the ephemeris creation + track offsets. Maybe something like this can be added to our python library.

_create_ephem_offset_source = None
def create_ephem(source, **ephem_kwargs):
    logger = logger_defaults.getModuleLogger(__name__)
    endpoint = '/ephemeris'

    global _create_ephem_offset_source
    _create_ephem_offset_source = source

    try:
        ephem_kwargs['source'] = source
        set_ephemeris_defaults(ephem_kwargs)
        retval = ATARest.post(endpoint, json=ephem_kwargs)
        ephem_id = retval['id']
    except Exception as e:
        logger.error('{:s} got error: {:s}'.format(endpoint, str(e)))
        raise

def track_and_offset(source, antstr, **ephem_kwargs):
    logger = logger_defaults.getModuleLogger(__name__)
    assert source == _create_ephem_offset_source
    try:
        antstr = snap_array_helpers.input_to_string(antstr)
        logger.info("Tracking source {:s} with {:s}".format(source, antstr))
        ephem_id = source
        json = {'id': ephem_id, 'wait': True}
        json.update(ephem_kwargs)
        endpoint = '/antennas/{:s}/track'.format(antstr)
        ATARest.put(endpoint, json=json)
    except Exception as e:
        logger.error('{:s} got error: {:s}'.format(endpoint, str(e)))
        raise

An observing script will essentially look something like this:

from ATATools import ata_control
ants = ["1a", "1f"]

ata_control.reserve_antennas(ant_list)

# create ephemeris file
source = "GPS-BIIRM-3--PRN-12-"
ata_control.create_ephem(source)

# now start cycling through pointings:
offset = [10., 0.]
ata_control.track_and_offset(source, ant_list, offset=offset)
record_data()

offset = [10., 10.]
ata_control.track_and_offset(source, ant_list, offset=offset)
record_data()
...
wfarah commented 3 years ago

I believe there should also be a method to retrieve the ATA ephemeris, from what I think I would need for the pointing calibration. It's also generally a handy thing to have

wfarah commented 3 years ago

I pushed the above changes to the repo: https://github.com/SETIatHCRO/ATA-Utils/blob/master/pythonLibs/ATATools/ata_control.py#L1049

Not the cleanest solution, but it'll do for now