1
1
"""Functions for working with LOFAR single station data"""
2
2
3
- import os
4
3
import datetime
4
+ import os
5
5
from typing import List , Dict , Tuple , Union
6
6
7
- import numpy as np
8
- from packaging import version
9
- import tqdm
7
+ import astropy .units as u
10
8
import h5py
11
-
12
- import matplotlib . pyplot as plt
9
+ import lofarantpos
10
+ import lofargeotiff
13
11
import matplotlib .animation
14
- from matplotlib .ticker import FormatStrFormatter
15
- from matplotlib import cm
16
- from matplotlib .figure import Figure
17
- from matplotlib .colors import ListedColormap , Normalize
18
- from matplotlib .patches import Circle
19
12
import matplotlib .axes as maxes
20
- from mpl_toolkits .axes_grid1 import make_axes_locatable
21
-
13
+ import matplotlib .pyplot as plt
14
+ import numpy as np
15
+ import tqdm
22
16
from astropy .coordinates import SkyCoord , GCRS , EarthLocation , AltAz , get_sun , get_moon
23
- import astropy .units as u
24
17
from astropy .time import Time
25
-
26
- import lofargeotiff
27
18
from lofarantpos .db import LofarAntennaDatabase
28
- import lofarantpos
19
+ from matplotlib import cm
20
+ from matplotlib .colors import ListedColormap , Normalize
21
+ from matplotlib .figure import Figure
22
+ from matplotlib .patches import Circle
23
+ from matplotlib .ticker import FormatStrFormatter
24
+ from mpl_toolkits .axes_grid1 import make_axes_locatable
25
+ from packaging import version
29
26
30
- from .maputil import get_map , make_leaflet_map
31
- from .lofarimaging import nearfield_imager , sky_imager , skycoord_to_lmn , subtract_sources
32
27
from .hdf5util import write_hdf5
33
-
28
+ from .lofarimaging import nearfield_imager , sky_imager , skycoord_to_lmn , subtract_sources
29
+ from .maputil import get_map , make_leaflet_map
34
30
35
31
__all__ = ["sb_from_freq" , "freq_from_sb" , "find_caltable" , "read_caltable" ,
36
32
"rcus_in_station" , "read_acm_cube" , "get_station_pqr" , "get_station_type" ,
@@ -331,7 +327,7 @@ def get_station_pqr(station_name: str, rcu_mode: Union[str, int], db):
331
327
'intl' : GENERIC_INT_201512 , 'remote' : GENERIC_REMOTE_201512 , 'core' : GENERIC_CORE_201512
332
328
}
333
329
selected_dipoles = selected_dipole_config [station_type ] + \
334
- np .arange (len (selected_dipole_config [station_type ])) * 16
330
+ np .arange (len (selected_dipole_config [station_type ])) * 16
335
331
station_pqr = db .hba_dipole_pqr (full_station_name )[selected_dipoles ]
336
332
else :
337
333
raise RuntimeError ("Station name did not contain LBA or HBA, could not load antenna positions" )
@@ -340,7 +336,7 @@ def get_station_pqr(station_name: str, rcu_mode: Union[str, int], db):
340
336
341
337
342
338
def make_ground_plot (image : np .ndarray , background_map : np .ndarray , extent : List [float ], title : str = "Ground plot" ,
343
- subtitle : str = "" , opacity : float = 0.6 , fig : Figure = None , draw_contours : bool = True , ** kwargs ) \
339
+ subtitle : str = "" , opacity : float = 0.6 , fig : Figure = None , draw_contours : bool = True , ** kwargs ) \
344
340
-> Tuple [Figure , np .ndarray ]:
345
341
"""
346
342
Make a ground plot of an array with data
@@ -585,7 +581,6 @@ def make_xst_plots(xst_data: np.ndarray,
585
581
opacity: Opacity for map overlay. Defaults to 0.6.
586
582
hdf5_filename: Filename where hdf5 results can be written. Defaults to outputpath + '/results.h5'
587
583
outputpath: Directory where results can be saved. Defaults to 'results'
588
- subtract: List of sources to subtract. Defaults to None
589
584
590
585
591
586
Returns:
@@ -662,14 +657,14 @@ def make_xst_plots(xst_data: np.ndarray,
662
657
marked_bodies = {
663
658
'Cas A' : SkyCoord (ra = 350.85 * u .deg , dec = 58.815 * u .deg ),
664
659
'Cyg A' : SkyCoord (ra = 299.86815191 * u .deg , dec = 40.73391574 * u .deg ),
665
- 'Per A' : SkyCoord (ra = 49.95066567 * u .deg , dec = 41.51169838 * u .deg ),
666
- 'Her A' : SkyCoord (ra = 252.78343333 * u .deg , dec = 4.99303056 * u .deg ),
667
- 'Cen A' : SkyCoord (ra = 201.36506288 * u .deg , dec = - 43.01911267 * u .deg ),
668
- 'Vir A' : SkyCoord (ra = 187.70593076 * u .deg , dec = 12.39112329 * u .deg ),
669
- '3C295' : SkyCoord (ra = 212.83527917 * u .deg , dec = 52.20264444 * u .deg ),
660
+ 'Per A' : SkyCoord (ra = 49.95066567 * u .deg , dec = 41.51169838 * u .deg ),
661
+ 'Her A' : SkyCoord (ra = 252.78343333 * u .deg , dec = 4.99303056 * u .deg ),
662
+ 'Cen A' : SkyCoord (ra = 201.36506288 * u .deg , dec = - 43.01911267 * u .deg ),
663
+ 'Vir A' : SkyCoord (ra = 187.70593076 * u .deg , dec = 12.39112329 * u .deg ),
664
+ '3C295' : SkyCoord (ra = 212.83527917 * u .deg , dec = 52.20264444 * u .deg ),
670
665
'Moon' : get_moon (obstime_astropy , location = station_earthlocation ).transform_to (GCRS ),
671
666
'Sun' : get_sun (obstime_astropy ),
672
- '3C196' : SkyCoord (ra = 123.40023371 * u .deg , dec = 48.21739888 * u .deg )
667
+ '3C196' : SkyCoord (ra = 123.40023371 * u .deg , dec = 48.21739888 * u .deg )
673
668
}
674
669
675
670
marked_bodies_lmn = {}
@@ -752,7 +747,7 @@ def make_xst_plots(xst_data: np.ndarray,
752
747
"pixels_per_metre" : pixels_per_metre }
753
748
tags .update (calibration_info )
754
749
lon_min , lon_max , lat_min , lat_max = extent_lonlat
755
- lofargeotiff .write_geotiff (ground_img [::- 1 ,:], os .path .join (outputpath , f"{ fname } _nearfield_calibrated.tiff" ),
750
+ lofargeotiff .write_geotiff (ground_img [::- 1 , :], os .path .join (outputpath , f"{ fname } _nearfield_calibrated.tiff" ),
756
751
(lon_min , lat_max ), (lon_max , lat_min ), as_pqr = False ,
757
752
stationname = station_name , obsdate = obstime , tags = tags )
758
753
@@ -769,7 +764,7 @@ def make_sky_movie(moviefilename: str, h5file: h5py.File, obsnums: List[str], vm
769
764
"""
770
765
Make movie of a list of observations
771
766
"""
772
- fig = plt .figure (figsize = (10 ,10 ))
767
+ fig = plt .figure (figsize = (10 , 10 ))
773
768
for obsnum in tqdm .tqdm (obsnums ):
774
769
obs_h5 = h5file [obsnum ]
775
770
skydata_h5 = obs_h5 ["sky_img" ]
@@ -787,7 +782,28 @@ def make_sky_movie(moviefilename: str, h5file: h5py.File, obsnums: List[str], vm
787
782
788
783
# Thanks to Maaijke Mevius for making this animation work!
789
784
ims = fig .get_children ()[1 :]
790
- ims = [ims [i :i + 2 ] for i in range (0 , len (ims ), 2 )]
785
+ ims = [ims [i :i + 2 ] for i in range (0 , len (ims ), 2 )]
791
786
ani = matplotlib .animation .ArtistAnimation (fig , ims , interval = 30 , blit = False , repeat_delay = 1000 )
792
787
writer = matplotlib .animation .writers ['ffmpeg' ](fps = 5 , bitrate = 800 )
793
788
ani .save (moviefilename , writer = writer , dpi = fig .dpi )
789
+
790
+
791
+ def compute_baselines (station_name , rcu_mode ):
792
+ # Setup the database
793
+ db = LofarAntennaDatabase ()
794
+
795
+ station_pqr = get_station_pqr (station_name , rcu_mode , db )
796
+
797
+ station_name = get_full_station_name (station_name , rcu_mode )
798
+
799
+ # Rotate station_pqr to a north-oriented xyz frame, where y points North, in a plane through the station.
800
+ rotation = db .rotation_from_north (station_name )
801
+
802
+ pqr_to_xyz = np .array ([[np .cos (- rotation ), - np .sin (- rotation ), 0 ],
803
+ [np .sin (- rotation ), np .cos (- rotation ), 0 ],
804
+ [0 , 0 , 1 ]])
805
+
806
+ station_xyz = (pqr_to_xyz @ station_pqr .T ).T
807
+
808
+ baselines = station_xyz [:, np .newaxis , :] - station_xyz [np .newaxis , :, :]
809
+ return baselines
0 commit comments