Skip to content
Snippets Groups Projects
Commit 37577372 authored by Philipp Arras's avatar Philipp Arras
Browse files

Intermediate

parent e130a8de
No related branches found
No related tags found
No related merge requests found
# custom
*.ms
.pytest_cache
git_version.py
*.pickle
......
import resolve as rve
import argparse
# parser = argparse.ArgumentParser()
# # parser.add_argument('-j', type=int, default=1)
# parser.add_argument('ms')
# args = parser.parse_args()
for ms in ['./CYG-ALL-2052-2MHZ.ms', './CYG-D-6680-64CH-10S.ms']:
rve.ms2observations(ms, 'DATA')
rve.ms2observations('./AM754_A030124_flagged.ms', 'DATA', 0)
rve.ms2observations('./AM754_A030124_flagged.ms', 'DATA', 1)
from .version import gitversion
from .ms_import import ms2observations
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright(C) 2019-2020 Max-Planck-Society
# Author: Philipp Arras
import numpy as np
ARCMIN2RAD = np.pi/60/180
AS2RAD = ARCMIN2RAD/60
DEG2RAD = np.pi/180
SPEEDOFLIGHT = 299792458
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright(C) 2020 Max-Planck-Society
# Author: Philipp Arras
from .util import my_assert
class Direction:
def __init__(self, phase_center, equinox):
my_assert(len(phase_center) == 2)
equinox = str(equinox)[1:]
if equinox == "1950_VLA":
equinox = 1950
self._e = float(equinox)
self._pc = phase_center
self._e = equinox
@property
def phase_center(self):
return self._pc
@property
def equinox(self):
return self._e
def __repr__(self):
return f'Direction({self._pc}, equinox {self._e})'
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright(C) 2019-2020 Max-Planck-Society
# Author: Philipp Arras
from os.path import isdir, join, splitext
import numpy as np
from .direction import Direction
from .observation import Observation
from .util import my_assert
def ms2observations(ms, data_column, spectral_window=None):
from casacore.tables import table
CFG = {'readonly': True, 'ack': False}
if not isdir(ms) or splitext(ms)[1] != '.ms':
raise RuntimeError
with table(join(ms, 'SPECTRAL_WINDOW'), **CFG) as t:
freqs = t.getcol('CHAN_FREQ')
with table(join(ms, 'POLARIZATION'), **CFG) as t:
polarization = t.getcol('CORR_TYPE')
with table(join(ms, 'FIELD'), **CFG) as t:
equ = t.coldesc('REFERENCE_DIR')['desc']['keywords']['MEASINFO']['Ref']
dirs = []
for pc in t.getcol('REFERENCE_DIR'):
my_assert(pc.shape == (1, 2))
dirs.append(Direction(pc[0], equ))
dirs = tuple(dirs)
with table(ms, **CFG) as t:
vis = t.getcol(data_column)
print(f'vis data type is {vis.dtype}')
uvw = t.getcol('UVW')
col = 'WEIGHT_SPECTRUM' if 'WEIGHT_SPECTRUM' in t.colnames() else 'WEIGHT'
weight = t.getcol(col)
flags = t.getcol('FLAG')
fieldid = t.getcol('FIELD_ID')
spw = t.getcol("DATA_DESC_ID")
nspws = len(np.unique(spw))
if nspws > 1:
if spectral_window is None:
raise RuntimeError
spwmask = spw == spectral_window
freqs = freqs[spectral_window]
else:
freqs = freqs[0]
observations = []
for ii in set(fieldid):
mask = fieldid == ii
if nspws > 1:
mask = np.logical_and(mask, spwmask)
my_assert(polarization.ndim == 2)
my_assert(polarization.shape[0] == 1)
observations.append(Observation(uvw[mask], vis[mask], weight[mask],
flags[mask], polarization[0], freqs,
dirs[ii]))
return observations
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright(C) 2019-2020 Max-Planck-Society
# Author: Philipp Arras
import h5py
import numpy as np
from .direction import Direction
from .util import my_assert
class Observation:
def __init__(self, uvw, vis, weight, flags, polarization, freq, direction):
nrows = uvw.shape[0]
my_assert(isinstance(direction, Direction))
my_assert(nrows == vis.shape[0])
my_assert(flags.shape == vis.shape)
my_assert(len(freq) == vis.shape[1])
my_assert(len(polarization) == vis.shape[2])
# Fallunterscheidung weight weightspectrum
# spw = t.getcol("DATA_DESC_ID")
def save_to_hdf5(self, file_name):
raise NotImplementedError
@staticmethod
def load_from_hdf5(self, file_name):
raise NotImplementedError
def my_assert(cond):
if not cond:
raise RuntimeError
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright(C) 2019 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
# Author: Philipp Arras
from setuptools import find_packages, setup
def write_version():
import subprocess
p = subprocess.Popen(
["git", "describe", "--dirty", "--tags", "--always"],
stdout=subprocess.PIPE)
res = p.communicate()[0].strip().decode('utf-8')
with open("resolve/git_version.py", "w") as file:
file.write('gitversion = "{}"\n'.format(res))
write_version()
exec(open('resolve/version.py').read())
setup(
name="resolve",
author="Philipp Arras",
......@@ -40,7 +14,7 @@ setup(
packages=find_packages(include=["resolve", "resolve.*"]),
zip_safe=True,
dependency_links=[],
install_requires=["nifty5>=5.0"],
install_requires=["nifty7>=5.0"],
license="GPLv3",
classifiers=[
"Development Status :: 3 - Alpha", "Topic :: Utilities",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment