diff --git a/lofarimaging.ipynb b/lofarimaging.ipynb index 8b145a7..4775629 100644 --- a/lofarimaging.ipynb +++ b/lofarimaging.ipynb @@ -61,7 +61,8 @@ "import warnings\n", "from mpl_toolkits.axes_grid1 import make_axes_locatable\n", "import matplotlib.axes as maxes\n", - "from matplotlib.ticker import FormatStrFormatter" + "from matplotlib.ticker import FormatStrFormatter\n", + "import re" ] }, { @@ -118,8 +119,7 @@ "outputs": [], "source": [ "data_dir = \"./test\"\n", - "caltable_dir = \"./test/CalTables\" # Root directory under which station information is stored in subdirectories DE602C/etc/, RS106/etc/, ...\n", - "station_name = 'DE603'" + "caltable_dir = \"./test/CalTables\" # Root directory under which station information is stored in subdirectories DE602C/etc/, RS106/etc/, ..." ] }, { @@ -139,7 +139,7 @@ "metadata": {}, "outputs": [], "source": [ - "station_type = get_station_type(station_name)" + "os.makedirs('results', exist_ok=True)" ] }, { @@ -147,22 +147,13 @@ "execution_count": 11, "metadata": {}, "outputs": [], - "source": [ - "os.makedirs('results', exist_ok=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], "source": [ "start1 = time.time()" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -170,7 +161,7 @@ "output_type": "stream", "text": [ "Searching for available files in ./test\n", - "0: ./test/20200525_084652_mode_5_xst_sb100.dat\n", + "0: ./test/20170621_072634_mode_sparseeven_xst_sb350.dat\n", "1: ./test/20170720_095816_mode_3_xst_sb297.dat\n" ] } @@ -185,27 +176,58 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "File selected: ./test/20200525_084652_mode_5_xst_sb100.dat\n" + "File selected: ./test/20170720_095816_mode_3_xst_sb297.dat\n" ] } ], "source": [ "# Select a file\n", - "xst_filename = files[0]\n", + "xst_filename = \"./test/20170720_095816_mode_3_xst_sb297.dat\" # files[0]\n", "\n", "print(\"File selected:\", xst_filename)" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "station_name = \"DE603\"\n", + "\n", + "rcu_mode = re.search(\"mode_([^_]*)\", xst_filename).groups(0)[0]\n", + "subband = int(re.search(\"sb([0-9]*)\", xst_filename).groups(0)[0])\n", + "obsdatestr, obstimestr, *_ = os.path.basename(xst_filename).rstrip(\".dat\").split(\"_\")" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "rcu_mode = rcu_mode.replace(\"sparseeven\", \"sparse_even\").replace(\"sparseodd\", \"sparse_odd\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "station_type = get_station_type(station_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -225,10 +247,6 @@ } ], "source": [ - "# Distill metadata from filename\n", - "cubename = os.path.basename(xst_filename)\n", - "obsdatestr, obstimestr, _, rcu_mode, _, subbandname = cubename.rstrip(\".dat\").split(\"_\")\n", - "subband = int(subbandname[2:])\n", "station_name = get_full_station_name(station_name, rcu_mode)\n", "\n", "# Get the data\n", @@ -260,27 +278,7 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'20170720_095816_DE603LBA_SB297'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fname" - ] - }, - { - "cell_type": "code", - "execution_count": 17, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -290,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -299,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -315,7 +313,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -324,7 +322,7 @@ "((29, 96, 96), (29, 96, 96), (96, 96), dtype('complex128'))" ] }, - "execution_count": 20, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -408,7 +406,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -418,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -452,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ @@ -487,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 51, "metadata": {}, "outputs": [ { diff --git a/lofarimaging/hdf5util.py b/lofarimaging/hdf5util.py index fa29cbd..d168637 100644 --- a/lofarimaging/hdf5util.py +++ b/lofarimaging/hdf5util.py @@ -101,6 +101,9 @@ def write_hdf5(filename: str, xst_data: np.ndarray, visibilities: np.ndarray, sk """ short_station_name = station_name[:5] + if subtracted is None: + subtracted = [] + with h5py.File(filename, 'a') as h5file: new_obsname = get_new_obsname(h5file) obs_group = h5file.create_group(new_obsname) diff --git a/lofarimaging/singlestationutil.py b/lofarimaging/singlestationutil.py index 4f74dcc..300cabe 100644 --- a/lofarimaging/singlestationutil.py +++ b/lofarimaging/singlestationutil.py @@ -100,16 +100,18 @@ def freq_from_sb(sb: int, rcu_mode: Union[str, int] = 1): 58007812.5 """ clock = 200e6 - if int(rcu_mode) == 6: - clock = 160e6 - freq_offset = 0 - if int(rcu_mode) == 5: - freq_offset = 100e6 - elif int(rcu_mode) == 6: - freq_offset = 160e6 - elif int(rcu_mode) == 7: - freq_offset = 200e6 + + if 'sparse' not in str(rcu_mode): + if int(rcu_mode) == 6: + clock = 160e6 + + if int(rcu_mode) == 5: + freq_offset = 100e6 + elif int(rcu_mode) == 6: + freq_offset = 160e6 + elif int(rcu_mode) == 7: + freq_offset = 200e6 sb_bandwidth = 0.5 * clock / 512. freq = (sb * sb_bandwidth) + freq_offset @@ -657,6 +659,14 @@ def make_xst_plots(xst_data: np.ndarray, >>> type(leafletmap) + + >>> xst_data = read_acm_cube("test/20170621_072634_sb350_xst.dat", "remote")[0] + >>> obstime = datetime.datetime(2017, 6, 21, 7, 26, 34) + >>> sky_fig, ground_fig, leafletmap = make_xst_plots(xst_data, "RS509", obstime, 350, \ + 'sparse_even', \ + caltable_dir="test/CalTables", \ + hdf5_filename="test/test.h5") + Maximum at 2m east, -2m north of station center (lat/long 53.40884, 6.78531) """ if extent is None: extent = [-150, 150, -150, 150] diff --git a/test/20170621_072634_sb350_xst.dat b/test/20170621_072634_sb350_xst.dat new file mode 100644 index 0000000..52a36b7 Binary files /dev/null and b/test/20170621_072634_sb350_xst.dat differ