lofarantpos package
lofarantpos.db
LOFAR antenna database
Module for manipulating LOFAR antenna databases. Typical usage is to create an instance of a LofarAntennaDatabase:
>>> import lofarantpos, numpy
>>> db = lofarantpos.db.LofarAntennaDatabase()
>>> db.phase_centres['CS001LBA']
array([3826923.942, 460915.117, 5064643.229])
>>> numpy.set_printoptions(suppress=True)
>>> db.antenna_pqr('RS210LBA')[:5]
array([[ 0. , 0. , 0. ],
[-0.00006..., 2.55059..., 0.00185...],
[ 2.24997..., 1.3499502 , 0.00130...],
[ 2.24982..., -1.35031..., -0.0004149 ],
[ 0.00006..., -2.55059..., -0.00185...]])
>>> db.cabinet_etrs['CS002']
array([3826609.602, 460990.583, 5064879.514])
- class lofarantpos.db.LofarAntennaDatabase(path_to_files=None)
Bases:
objectDatabase with LOFAR antenna positions
This database contains the LOFAR antenna positions in both ETRS and the station/field specific pqr coordinate system. The upstream source is the LOFAR svn repository at https://svn.astron.nl/LOFAR.
- antenna_etrs(field_name)
Return a list of all ETRS antenna coordinates for a given antenna field
- Parameters:
field_name (str) – Field name (e.g. ‘CS001HBA0’)
- Returns:
array of ETRS coordinates
- Return type:
array
- antenna_pqr(field_name)
Return a list of all PQR antenna coordinates for a given antenna field
- Parameters:
field_name (str) – Field name (e.g. ‘CS001HBA0’)
- Returns:
array of PQR coordinates
- Return type:
array
- hba_dipole_etrs(field_name)
Return a list of all ETRS dipole coordinates for a given HBA antenna field
- Parameters:
field_name (str) – Field name (e.g. ‘CS001HBA0’)
- Returns:
array of ETRS coordinates
- Return type:
array
Example
>>> import lofarantpos.db >>> import numpy >>> db = lofarantpos.db.LofarAntennaDatabase() >>> db.hba_dipole_etrs("IE613HBA")[:5] array([[3801679.57332033, -528959.80788382, 5076969.80405122], [3801680.56726901, -528959.55814198, 5076969.08837304], [3801681.56121763, -528959.30839824, 5076968.37269509], [3801682.55516625, -528959.0586545 , 5076967.65701715], [3801679.7113895 , -528961.02799576, 5076969.57003303]])
- hba_dipole_pqr(field_name)
Return a list of all PQR dipole coordinates for a given HBA antenna field
- Parameters:
field_name (str) – Field name (e.g. “CS001HBA0”)
- Returns:
array of PQR coordinates
- Return type:
array
Example
>>> import lofarantpos.db >>> import numpy >>> db = lofarantpos.db.LofarAntennaDatabase() >>> db.hba_dipole_pqr("CS001HBA0")[:5] array([[ 1.9336444 , 15.284... , 0.00008769], [ 3.075576 , 14.776116 , 0.00008769], [ 4.217508 , 14.267695 , 0.00008769], [ 5.3594... , 13.7592745 , 0.00008769], [ 1.4252236 , 14.142605 , 0.00008769]], dtype=float32)
- pqr_to_localnorth(field_name)
Compute a rotation matrix from local coordinates (pointing North) to PQR
- Parameters:
field_name (str) – Field name (e.g. ‘IE613LBA’)
Example
>>> import lofarantpos.db >>> db = lofarantpos.db.LofarAntennaDatabase() >>> db.pqr_to_localnorth("IE613LBA") array([[ 0.97847792, -0.20633485, -0.00262657], [ 0.20632893, 0.97847984, -0.00235784], [ 0.00305655, 0.00176516, 0.99999377]])
- rotation_from_north(field_name)
Compute the angle in radians between the positive Q-axis (projected onto a local tangent to the WGS84 ellipsoid) and the local north. Positive means Q is East of North.
- Parameters:
field_name (str) – Field name (e.g. ‘IE613LBA’)
- Returns:
angle (in radians)
- Return type:
Example
>>> import lofarantpos.db >>> import numpy >>> db = lofarantpos.db.LofarAntennaDatabase() >>> numpy.rad2deg(db.rotation_from_north("IE613LBA")) -11.907669843448476
- lofarantpos.db.getcol(rows, col_name)
- lofarantpos.db.install_prefix()
- lofarantpos.db.parse_csv(file_name, data_type)
Read a CSV file and convert the elements to a given data type
- lofarantpos.db.parse_hba_rotations(file_name)
lofarantpos.geo
Functions for geographic transformations commonly used for LOFAR
- lofarantpos.geo.geographic_array_from_xyz(xyz_m)
xyz_m is a (N,3) array. Compute lon, lat, and height Output an (N, 3) array with latitude (rad), longitude (rad) and height (m)
Examples
>>> xyz_m = [3836811, 430299, 5059823] >>> geographic_array_from_xyz([xyz_m, xyz_m]) array([[ 0.11168349, 0.92223593, -0.28265955], [ 0.11168349, 0.92223593, -0.28265955]])
>>> geographic_array_from_xyz([[xyz_m, xyz_m]]).shape (1, 2, 3)
- lofarantpos.geo.geographic_from_xyz(xyz_m)
- Compute longitude, latitude and height (from the WGS84 ellipsoid) of a given point or list
of points
- Parameters:
xyz_m (Union[array, list]) – xyz-coordinates (in m) of the given point.
- Returns:
- Dictionary with ‘lon_rad’, ‘lat_rad’, ‘height_m’,
values are float for a single input, arrays for multiple inputs
- Return type:
Dict[Union[array, float]
Examples
>>> from pprint import pprint >>> xyz_m = [3836811, 430299, 5059823] >>> pprint(geographic_from_xyz(xyz_m)) {'height_m': -0.28265954554080963, ...'lat_rad': 0.9222359279580563, ...'lon_rad': 0.11168348969295486}
>>> xyz2_m = array([3828615, 438754, 5065265]) >>> pprint(geographic_from_xyz([xyz_m, xyz2_m])) {'height_m': array([-0.28265955, -0.74483879]), ...'lat_rad': array([0.92223593, 0.92365033]), ...'lon_rad': array([0.11168349, 0.11410087])}
>>> geographic_from_xyz([[xyz_m, xyz2_m]])['lon_rad'].shape (1, 2)
- lofarantpos.geo.localnorth_to_etrs(centerxyz_m)
Compute a matrix that transforms from a local coordinate system tangent to the WGS84 ellipsoid to ETRS89 ECEF XYZ coordinates.
- Parameters:
centerxyz_m (array) – xyz-coordinates of the center of the local coordinate system
- Returns:
3x3 rotation matrix
- Return type:
array
Example
>>> set_printoptions(suppress=True) >>> station1_etrs = [3801633.868, -529022.268, 5076996.892] >>> station2_etrs = [3826577.462, 461022.624, 5064892.526] >>> localnorth_to_etrs(array(station1_etrs)) array([[ 0.13782846, -0.79200355, 0.59475516], [ 0.99045611, 0.11021248, -0.08276408], [ 0. , 0.60048613, 0.79963517]]) >>> localnorth_to_etrs([[station1_etrs, station2_etrs]]).shape (1, 2, 3, 3)
- lofarantpos.geo.normal_vector_ellipsoid(lon_rad, lat_rad)
Make a vector normal to the ellipsoid at given longitude and latitude
Examples
>>> normal_vector_ellipsoid(0.12, 0.92) array([0.60146348, 0.07252407, 0.79560162]) >>> normal_vector_ellipsoid([[0.12, 0.13]], [[0.92, 0.93]]).shape (1, 2, 3)
- lofarantpos.geo.normal_vector_meridian_plane(xyz_m)
Return a unit vector normal to the meridian plane. If a vector of xyz’s is given, xyz should be the fastest varying axis.
Example
>>> test_coord = [3802111.6, -528822.8, 5076662.2] >>> normal_vector_meridian_plane(test_coord) array([-0.1377605 , -0.99046557, 0. ])
>>> normal_vector_meridian_plane(array(test_coord)) array([-0.1377605 , -0.99046557, 0. ])
>>> normal_vector_meridian_plane(array([test_coord, test_coord])) array([[-0.1377605 , -0.99046557, 0. ], [-0.1377605 , -0.99046557, 0. ]])
- lofarantpos.geo.normalized_earth_radius(latitude_rad)
Compute the normalized radius of the WGS84 ellipsoid at a given latitude
- lofarantpos.geo.projection_matrix(xyz0_m, normal_vector)
Create a projection matrix that will project a vector to the plane orthogonal to normal_vector, with local north defined at xyz0_m. The xyz should be the fastest varying axis.
Example
>>> test_coord = [3802111.6, -528822.8, 5076662.2] >>> cs002_normal = [0.59866826, 0.07212702, 0.79774307] >>> projection_matrix(test_coord, cs002_normal) array([[ 0.04616828, -0.79966543, 0.59866826], [ 0.99117465, 0.11122275, 0.07212702], [-0.12426302, 0.59005482, 0.79774307]]) >>> projection_matrix([[test_coord, test_coord]], ... [[cs002_normal, cs002_normal]]).shape (1, 2, 3, 3)
- lofarantpos.geo.transform(xyz_m, xyz0_m, mat)
Perform a coordinate transformation on an array of points
- Parameters:
xyz_m (array) – Array of points
xyz0_m (array) – Origin of transformation
mat (array) – Transformation matrix
- Returns:
Array of transformed points
- Return type:
array
- lofarantpos.geo.xyz_from_geographic(lon_rad, lat_rad, height_m)
Compute cartesian xyz coordinates from a longitude, latitude and height (from the WGS84 ellipsoid)
- Parameters:
- Returns:
xyz coordinates in meters
- Return type:
array
Examples
>>> xyz_from_geographic(-0.1382, 0.9266, 99.115) array([3802111.62491437, -528822.82583168, 5076662.15079859]) >>> coords = array([[-0.1382, 0.9266, 99.115], [ 0.2979, 0.9123, 114.708]]) >>> xyz_from_geographic(coords[:,0], coords[:,1], coords[:,2]).T array([[3802111.62491437, -528822.82583168, 5076662.15079859], [3738960.12012956, 1147998.32536741, 5021398.44437063]])
lofarantpos.plotutil
Functions for plotting LOFAR stations with matplotlib
- lofarantpos.plotutil.add_background(ax, centre, background, zoom=18)
Add openstreetmap background to axes. Assumes the axes extents are given in metres w.r.t. a local coordinates system with origin centre (given in ETRS XYZ)
- Parameters:
ax – existing matplotlib Axes object
centre – ETRS XYZ coordinates of the centre
background – name of background to draw, e.g. “openstreetmap” or “luchtfoto” (Dutch stations only)
zoom – zoom level for the background tiles
Example
>>> from lofarantpos.plotutil import plot_station, add_background >>> from lofarantpos.db import LofarAntennaDatabase >>> db = LofarAntennaDatabase() >>> centre = db.phase_centres["CS002LBA"] >>> fig, ax = plt.subplots() >>> plot_station("CS002", ax=ax) >>> plot_station("CS001", ax=ax, centre=centre) >>> add_background(ax, centre, 'osm')
- lofarantpos.plotutil.plot_core(ax=None, labels=False, circle=True, centre=None, tilestyle='lines', background=None)
Plot the LOFAR core
- Parameters:
ax – existing matplotlib axes object to use
labels – add labels for each dipole
circle – plot a circle around the superterp
centre – ETRS xyz coordinates of centre (default is centre of the superterp)
tilestyle – style for HBA tiles (“lines”, “filled”, or None)
background – name of background to draw, e.g. “openstreetmap” or “luchtfoto”
Example
>>> from lofarantpos.plotutil import plot_core >>> plot_core()
- lofarantpos.plotutil.plot_hba(station_name, ax=None, centre=None, subfield='', labels=False, tilestyle='lines', **kwargs)
Plot LOFAR HBA tiles for one station. If keyword-arguments are given, they are passed to a scatter plot with the tile centers.
- Parameters:
station_name – Station name, without suffix. E.g. “CS001”
ax – existing matplotlib axes object to use
centre – etrs coordinates of origin. Default: HBA phase centre of station.
subfield – ‘0’, ‘1’ or ‘’to suffix after ‘HBA’ for e.g. CS002HBA1)
labels – add labels
Example
>>> from lofarantpos.plotutil import plot_hba >>> plot_hba("CS001") >>> plot_hba("CS001", c=list(range(48)))
- lofarantpos.plotutil.plot_lba(station_name, ax=None, centre=None, labels=False, **kwargs)
Plot LOFAR LBA locations for one station
- Parameters:
station_name – Station name, without suffix. E.g. “CS001”
ax – existing matplotlib axes object to use
centre – etrs coordinates of origin. Default: LBA phase centre of station.
labels – add labels
kwargs – all other keyword-arguments are passed to matplotlib.scatter
Example
>>> from lofarantpos.plotutil import plot_lba >>> plot_lba("IE613", labels=True) >>> plot_lba("CS001", c=list(range(96)))
- lofarantpos.plotutil.plot_station(station_name, ax=None, centre=None, labels=False, tilestyle='lines', background=None, **kwargs)
Plot a LOFAR station
- Parameters:
station_name – Station name, without suffix. E.g. “CS001”
ax – existing matplotlib axes object to use
labels – add labels
centre – centre of projection, as ETRS xyz coordinate. Default is station’s LBA phase centre.
tilestyle – style for HBA tiles (“filled”, “lines” or None)
background – name of background to draw, e.g. “openstreetmap” or “luchtfoto” (Dutch stations only)
Example
>>> from lofarantpos.plotutil import plot_station >>> plot_station("CS002") >>> plot_station("CS011", background="openstreetmap", c=list(range(96 + 48))) >>> plot_station("RS210", background="luchtfoto")
- lofarantpos.plotutil.plot_superterp(ax=None, labels=False, circle=True, centre=None, tilestyle='lines', background=None)
Plot the LOFAR superterp
- Parameters:
ax – existing matplotlib axes object to use
labels – add labels
circle – plot a surrounding circle
centre – ETRS xyz coordinates of centre (default is the centre of the superterp)
tilestyle – style for HBA tiles (“lines”, “filled” or None)
background – name of background to draw, e.g. “openstreetmap” or “luchtfoto” (Dutch stations only)
Example
>>> from lofarantpos.plotutil import plot_superterp >>> plot_superterp(background='openstreetmap', tilestyle=None)