Miscellaneous

Base class

class darc.base.DARCBase(source_queue, target_queue=None, second_target_queue=None, control_queue=None, config_file='/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/darc/config.yaml')

Bases: multiprocessing.context.Process

DARC Base class

Provides common methods to services

Parameters
  • source_queue (Queue) – Input queue

  • target_queue (Queue) – Output queue

  • second_target_queue (Queue) – second output queue

  • control_queue (Queue) – Control queue

  • config_file (str) – Path to config file

cleanup(abort=False)

Stub for commands to run upon service stop, defaults to self.stop_observation

Parameters

abort (bool) – Whether to abort running observation

get_attribute(command)

Get attribute as given in input command

Parameters

command (dict) – Command received over queue

load_config()

Load config file

process_command(command, *args, **kwargs)

Process command from queue, other than start_observation and stop_observation. By default only provides get_attribute command

Parameters
  • command (dict) – Input command

  • args (list) – process command arguments

  • kwargs (dict) – process command keyword arguments

run()

Main loop

Receive commands on input queue, calls self.start_observation, self.stop_observation, else self.process_command

start_observation(*args, reload=True, **kwargs)

Start observation. By default only (re)loads config file.

Parameters
  • args (list) – start_observation arguments

  • reload (bool) – reload service settings (default: True)

  • kwargs (dict) – start_observation keyword arguments

stop(abort=False)

Stop this service

Parameters

abort (bool) – Whether to abort running observation

stop_observation(*args, **kwargs)

Stop observation stub, should be overridden by subclass if commands need to be executed at observation stop

Parameters
  • args (list) – stop_observation arguments

  • kwargs (dict) – stop_observation keyword arguments

Control

darc.control.main()

DARC command line interface

This function is called by the darc executable

Run darc –help for usage

darc.control.send_command(timeout, service, command, payload=None, host='localhost', port=None)

Send a command to the DARC master service

Parameters
  • timeout (float) – Timeout for reply in seconds

  • service (str) – Service to send command to

  • command (str) – Which command to send

  • payload (str) – Payload for command (optional)

  • host (str) – Hostname to connect to (default: localhost)

  • port (int) – Port to connect to (default: get from DARC config file)

Returns

reply from DARC master

Definitions

darc.definitions.AP_EFF = 0.6

Apertif/ARTS aperture efficiency

darc.definitions.ARRAY_ITRF = <Quantity [3828630.63486201, 443593.39226634, 5064922.99755 ] m>

ITRF WSRT reference position

darc.definitions.BANDWIDTH = <Quantity 300. MHz>

Apertif/ARTS bandwidth

darc.definitions.CONFIG_FILE = '/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/darc/config.yaml'

Full path to config file: $HOME/darc/config.yaml if present, else default shipped with package

darc.definitions.DISH_DIAM = <Quantity 25. m>

WSRT dish diameter

darc.definitions.MASTER = 'arts041'

ARTS master name

darc.definitions.NCHAN = 1536

Apertif/ARTS number of channels

darc.definitions.NDISH = 8

Apertif/ARTS number of dishes in use

darc.definitions.NTAB = 12

Number of tied-array beams

darc.definitions.NUMCB = 40

Apertif/ARTS number of compound beams

darc.definitions.TIME_UNIT = 781250

Beamformer time constant: number of samples per second

darc.definitions.TSAMP = <Quantity 8.192e-05 s>

Apertif/ARTS sampling time

darc.definitions.TSYS = <Quantity 85. K>

Apertif/ARTS system temperature

darc.definitions.WORKERS = ['arts001', 'arts002', 'arts003', 'arts004', 'arts005', 'arts006', 'arts007', 'arts008', 'arts009', 'arts010', 'arts011', 'arts012', 'arts013', 'arts014', 'arts015', 'arts016', 'arts017', 'arts018', 'arts019', 'arts020', 'arts021', 'arts022', 'arts023', 'arts024', 'arts025', 'arts026', 'arts027', 'arts028', 'arts029', 'arts030', 'arts031', 'arts032', 'arts033', 'arts034', 'arts035', 'arts036', 'arts037', 'arts038', 'arts039', 'arts040']

ARTS worker names

Logger

darc.logger.get_logger(name, log_file, level=20)

Create logger

Parameters
  • name (str) – name to use in log prints

  • log_file (str) – Path to log file

  • level (int) – log level (default: logging.INFO)

Returns

logger

Synthesized Beam Generator

class darc.sb_generator.SBGenerator(fname=None, science_case=None, config_file='/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/darc/config.yaml')

Bases: object

Synthesized beam generator

__init__ should be called by cls.from_science_case or cls.from_table

Parameters
  • fname – path to synthesized beam table

  • science_case – ARTS science case (3 or 4)

  • config_file (str) – Path to config file

_load_table()

Load SB table

classmethod from_science_case(science_case, config_file='/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/darc/config.yaml')

Initalize default table for given science case

Parameters
  • science_case (int) – science case (3 or 4)

  • config_file (str) – Path to config file

Returns

SBGenerator object

classmethod from_table(fname, config_file='/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/darc/config.yaml')

Initalize with provided SB table

Parameters
  • fname (str) – Path to SB table

  • config_file (str) – Path to config file

Returns

SBGenerator object

get_map(sb)

Return mapping of requested SB

Parameters

sb (int) – beam to return mapping for

Returns

SB mapping for requested beam

property reversed

Whether or not the SB table is reversed for use on filterbank data

Returns

reversed (bool)

synthesize_beam(data, sb)

Synthesize beam

Parameters
  • data (np.ndarray) – TAB data with shape [TAB, freq, time]

  • sb (int) – SB index

Returns

SB data with shape [freq, time]

exception darc.sb_generator.SBGeneratorException

Bases: Exception

Utilities

darc.util.calc_snr_amber(data, thresh=3)

Calculate peak S/N using the same method as AMBER: Outliers are removed four times before calculating the S/N as peak - median / sigma The result is scaled by 1.048 to account for the removed values

Parameters
  • data (array) – timeseries data

  • thresh (float) – sigma threshold for outliers (Default: 3)

Returns

peak S/N

darc.util.calc_snr_matched_filter(data, widths=None)

Calculate S/N using several matched filter widths, then pick the highest S/N

Parameters
  • data (np.ndarray) – timeseries data

  • widths (np.ndarray) – matched filters widths to try (Default: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500])

Returns

highest S/N, corresponding matched filter width

darc.util.clear_queue(queue)

Read all remaining items in a queue and discard them

Parameters

queue (queue.Queue) – queue to clear

darc.util.decode_parset(parset_bytes)

Decode parset into string

Parameters

parset_bytes (bytes) – raw parset bytes

Returns

parset as string

darc.util.dm_to_delay(dm, flo, fhi)

Convert DM to time delay

Parameters
  • dm (astropy.units.quantity.Quantity) – dispersion measure

  • flo (astropy.units.quantity.Quantity) – lowest frequency

  • fhi (astropy.units.quantity.Quantity) – highest frequency

Returns

time delay (astropy quantity)

darc.util.dm_to_smearing(dm, f, df)

Calculate intra-channel smearing time

Parameters
  • dm (astropy.units.quantity.Quantity) – dispersion measure

  • f (astropy.units.quantity.Quantity) – frequency

  • df (astropy.units.quantity.Quantity) – channel width

darc.util.encode_parset(parset_str)

Encode parset string into bytes

Parameters

parset_str (str) – parset as one string

Returns

encoded parset as bytes

darc.util.get_flux(snr, width, ndish=8, npol=2, coherent=True)

Compute single pulse flux density using radiometer equation

Parameters
  • snr (float) – S/N

  • width (astropy.units.quantity.Quantity) – Width

  • ndish (int) – Number of dishes used (default: 8)

  • npol (int) – Number of polarizations (default: 2)

  • coherent (bool) – Using coherent beamforming (default: True)

Returns

Peak flux density (astropy.units.quantity.Quantity)

darc.util.get_ymw16(parset, beam=0, logger=None)

Get YMW16 DM

Parameters
  • parset (dict) – Observation parset

  • beam (int) – CB for which to get YMW16 DM

  • logger (Logger) – Logger object (optional)

Returns

YMW16 DM (float)

darc.util.hadec_to_radec(ha, dec, t)

Convert apparent HA, Dec to J2000 RA, Dec

Parameters
  • ha – hour angle with unit

  • dec – declination with unit

  • t (Time/str) – Observing time

Returns

SkyCoord object of J2000 coordinates

darc.util.hadec_to_rot(ha, dec)

Convert WSRT HA, Dec to TAB rotation angle

Parameters
  • ha (astropy.units.quantity.Quantity) – hour angle with unit

  • dec (astropy.units.quantity.Quantity) – declination with unit

darc.util.makedirs(path)

Mimic os.makedirs, but do not error when directory already exists

Parameters

path (str) – path to recursively create

darc.util.parse_parset(parset_str)

Parse parset into dict with proper types

Parameters

parset_str (str) – raw parset as string

Returns

parset as dict

darc.util.radec_to_hadec(ra, dec, t)

Convert RA, Dec to apparent WSRT HA, Dec

Parameters
  • ra (Quantity) – Right ascension

  • dec (Quantity) – Declination

  • t (Time/str) – Observing time

Returns

HA (Quantity), Dec (Quantity)

darc.util.send_email(frm, to, subject, body, attachments=None)

Send email, only possible to ASTRON addresses

Parameters
  • frm (str) – From address

  • to (str/list) – To addresses, either single or list of addresses

  • subject (str) – Subject of email

  • body (dict) – Dict with e-mail content (str) and type (str)

  • attachments (dict/list) – optional dict or list of dicts with attachment path (str), type (str), and name (str)

darc.util.sleepuntil_utc(end_time, event=None)

Sleep until specified time

Parameters
  • end_time (datetime.datetime/astropy.time.Time/str) – sleep until this time

  • event (threading.Event) – if specified, uses event.wait instead of time.sleep

darc.util.tail(f, event, interval=0.1)

Read all lines of a file, then tail until stop event is set

Parameters
  • f (filehandle) – handle to file to tail

  • event (threading.Event) – stop event

  • interval (float) – sleep time between checks for new lines (default: .1)