Skip to main content

MeerKAT Extension (SCU) (lib)rary for the MKE antennas and some basic simulators

Project description

mke_sculib

MeerKAT Extension (MKE) (SCU) Science Computation Unit interface (lib)rary for the MKE antennas and some basic simulators

See also examples (especially examples/getting_started.ipynb) for examples on how to use this library.


Installing

    pip install mke_sculib

Usage for Antenna Control:

The main class is scu_api.scu.scu which can be loaded as scu_api from mke_sculib. This class provides an interface to the MeerKAT Extension Telescopes' dish structure controllers.

It does so by connecting to the Antenna Control Unit (ACU) via the HTTP REST API and websockets of the Science Computation Unit (SCU) both developed by OHB Digital Connect GmbH. It's designed for use with the SKA-MPI Demonstrator Radio Telescope in South Africa and the MeerKAT Extension Radio Telescopes.

Construct

In order to connect to the REST API of the Telescope SCU use the library as follows:

   import mke_sculib
   dish = mke_sculib.scu_api(ip='134.104.22.44')
   dish.determine_dish_type()
   dish.status()

Load

NOTE: This only works for telescopes in the Karoo with access to the Karoo site network (engineering network)

   import mke_sculib
   # direct loading by full name
   dish = mke_sculib.load('skampi')
   dish.status()
   # partial names "119" vs "119A" also work
   dish = mke_sculib.load('119')
   dish.status()
   # If you want to interactively select which dish to load use load withut an antenna_id
   dish = mke_sculib.load()
   dish.status()

Dish Status

show full status by:

dish = mke_sculib.scu_api(ip='134.104.22.44')
dish.show() # dish.print_info() to force ascii

Antenna Movement

This is how to control the dish:

dish.status()
dish.start()
dish.move(az=15, el=85) # or equivalent dish.move(15, 85)
dish.status()
dish.move(band='Band 5b')
dish.shutdown()
dish.status()

Minimal Tracking Table Example

minimal example

import pandas as pd
import numpy as np

tmjd = (Time.now() + np.arange(-10, 30, 0.5) * u.s).mjd
azs = np.arange(0, 40, 0.5)
els = np.arange(90, 50, 0.5)
dish.run_track_table(tmjd, azs, els)
history = dish.get_session_as_df()

Minimal Tracking Table Example for a Position On Sky

this is how to observe an astronomical Target using a tracking table

import pandas as pd
import numpy as np
from astropy.time import Time
from astropy import units as u
from astropy.coordinates import get_icrs_coordinates, EarthLocation, AltAz, SkyCoord


# make a tracking table for 'HIP104382' using astropy
loc = EarthLocation(lat = -30.778551, lon = 21.397161, height = 1094.6*u.m)  
t = Time.now() + np.arange(-10, 60, 1.0) * u.s
altaz = get_icrs_coordinates('HIP104382').transform_to(AltAz(location=loc, obstime=t))
tracking_table = pd.DataFrame({'time': t.mjd, 'az': altaz.az.deg, 'el': altaz.alt.deg})


with dish.with_tt(df=tracking_table) as track:
    print('tracking...')
    while track.get_t_remaining() > 0:
        print(f'{track.get_t_remaining()=} {dish.azel=} {dish.get_state()}')
        dish.wait_duration(1)

last_session = track.session
mke_sculib.plot_motion(last_session, df_tt = tracking_table)

Interfacing with a Local Instance of Stellarium

If you have Stellarium installed on a machine somewhere (or locally) and have "remote control" plugin enabled (see below for instructions how to do this) you can interface between a MKE dish and Stellarium like this.

dish = scu('134.104.22.44', use_socket=True, wait_done_by_uuid=True)
dish.link_stellarium() # url for stellatium is 'http://localhost:8090' by default

or in one go using the convenience function in the mke_sculib root library:

import mke_sculib
 # will query data for dish on pad 119 automatically and interface with stellarium
mke_sculib.link_stellarium('119')

The remote Control Plugin in Stellarium can be enabled by

  1. starting or opening Stellarium
  2. opening "Config" (the "Wrench" icon in the lower left corner menu),
  3. opening Tab "Plugins"
  4. selecting "Remote Control" on the left
  5. click "configure"
  6. check "Server enabled"
  7. check "Enable automatically on startup"
  8. set your desired port (8090 recommended)
  9. click "Save setting"
  10. close window
  11. check "Load at startup" in the previous menu
  12. close window
  13. restart Stellarium

you now able to interface between stellarium and the mke_sculib as shown above.

Subscribing to callbacks

Data callbacks subscription example:

# this is a simple logging function, which will log data updates to stdout
def print_new_data(time_astropy, data_dict):
    print(f'{time.time():.2f} new data tick at {time_astropy.iso}, with data for N={len(data_dict)} channels | {id(data_dict)=}, {sys.getsizeof(data_dict)=}')

dish.callbacks_on_new_data.append(print_new_data)

Event callback subscription example:

def on_new_event(e):
    print(f'{time.time():.2f}, new event wiith uuid {e.uuid}!')
    print(e.to_str())
dish.callbacks_on_new_events.append(on_new_event)

clear callbacks like this:

dish.clear_all_callbacks()

Usage as Simulator:

Using the simulator with the same script as used for operating the telescope can be achieved like this:

   from mke_sculib.sim import plot_motion_pyplot as plot_motion
   
   # instead of THIS:
   # from mke_sculib.scu import scu
   # mpi = scu('134.104.22.44', '8080')

   # do THIS for simulation:
   from mke_sculib.sim import scu_sim as scu
   mpi = scu()

After a test has been done, the whole test history can be plotted in pyplot via:

   # show the history data
   dfh = mpi.get_history_df(interval_ms = None)
   axs = plot_motion(dfh)

Using the library within Test Scripts:

After installation, the library can be used to script automatic tests. A minimal example for a tracking test is given below:

   # Init
   import astropy.units as u
   from astropy.time import Time
   import numpy as np
   import pandas as pd

   import matplotlib.pyplot as plt
   from mke_sculib.sim import plot_motion_pyplot as plot_motion
   from mke_sculib.sim import scu_sim as scu

   mpi = scu()

   # Startup 
   mpi.unstow()
   mpi.wait_duration(30) # sec
   mpi.activate_dmc()
   mpi.wait_duration(wait10)

   # Move to starting az, el
   mpi.abs_azimuth(-90, 3) # degree, degree / s
   mpi.abs_elevation(53, 1) # degree, degree / s
   mpi.wait_settle()
   mpi.wait_duration(5) # sec

   # move to Band 2
   mpi.move_to_band('Band 2')
   mpi.wait_settle()
   mpi.wait_duration(wait5)

   # make a dummy tracking table
   t = mpi.t_internal + (np.arange(5) * astropy.units.u.s)
   az = np.linspace(-90, -89, len(t))
   el = np.linspace(53, 54, len(t))

   # start a tracking table
   mpi.upload_track_table(t, az, el)

   # start logging for my testrun
   mpi.start_logger('full_configuration')
   
   # wait for track table to finish
   mpi.wait_duration(np.ptp(t) + 5)

   # shut down
   mpi.stop_logger()
   mpi.wait_duration(5)
   mpi.deactivate_dmc()
   mpi.wait_duration(10)
   mpi.stow()

   # show the sessions data
   df = mpi.get_session_as_df(interval_ms = 100)
   plot_motion(df)
   df.to_csv('testdata_acu.csv')

HTTP Dummy server

This library has a dummy server with dashboard implemented which can run on any machine with anaconda installed.

See: servers for the examples.

NOTE: Change the absolut path in the files if necessary

   python /servers/dashboard.py

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mke_sculib-2.8.3.tar.gz (110.7 kB view details)

Uploaded Source

File details

Details for the file mke_sculib-2.8.3.tar.gz.

File metadata

  • Download URL: mke_sculib-2.8.3.tar.gz
  • Upload date:
  • Size: 110.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mke_sculib-2.8.3.tar.gz
Algorithm Hash digest
SHA256 2bca6f169e3ed35d11a940dbfcd8344b439ad1a5a100305b543435b192e1a856
MD5 ea892437c596501beebcfb993c286fe8
BLAKE2b-256 a1e4ba861c5add20f75944122bc10eb0f04cd4ab6c50746e0f0b4e06ea9d66f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page