Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/azure-sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- bash: cranko release-workflow apply-versions
displayName: Apply Cranko versions

- bash: cranko zenodo preregister --metadata=ci/zenodo.json5 pwkit CHANGELOG.md
- bash: cranko zenodo preregister --metadata=ci/zenodo.json5 pwkit CHANGELOG.md pwkit/__init__.py
displayName: "Preregister Zenodo DOI"
${{ if and(eq(variables['Build.SourceBranchName'], 'rc'), ne(variables['build.reason'], 'PullRequest')) }}:
env:
Expand Down
3 changes: 3 additions & 0 deletions pwkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

__version__ = "0.dev0" # cranko project-version

# This will be filled in during the release process by Cranko.
__version_doi__ = "xx.xxxx/dev-build.pwkit.version"

# Archaic Python 2/3 compatibility support

binary_type = bytes
Expand Down
27 changes: 12 additions & 15 deletions pwkit/astutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def _observe_from_bcrs(self, observer):
del Star, T0


_vizurl = "https://vizier.u-strasbg.fr/viz-bin/asu-tsv"
_vizurl = "http://vizier.cds.unistra.fr/viz-bin/asu-tsv"


def get_2mass_epoch(tmra, tmdec, debug=False):
Expand All @@ -867,24 +867,21 @@ def get_2mass_epoch(tmra, tmdec, debug=False):
be returned.

"""
from urllib.parse import urlencode
from urllib.request import urlopen
import codecs

try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
postdata = b"""-mime=csv
-source=2MASS
-out=_q,JD
-c=%.6f %.6f
-c.eq=J2000""" % (
tmra * R2D,
tmdec * R2D,
)

postdata = {
"-mime": "csv",
"-source": "2MASS",
"-out": "_q,JD",
"-c": f"{tmra * R2D:.6f} {tmdec * R2D:.6f}",
"-c.eq": "J2000",
}
url = f"{_vizurl}?{urlencode(postdata)}"
jd = None

for line in codecs.getreader("utf-8")(urlopen(_vizurl, postdata)):
for line in codecs.getreader("utf-8")(urlopen(url)):
line = line.strip()
if debug:
print_("D: 2M >>", line)
Expand Down
31 changes: 14 additions & 17 deletions pwkit/environments/casa/dftdynspec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright 2013, 2016-2018 Peter Williams <peter@newton.cx> and collaborators
# Copyright Peter Williams <peter@newton.cx> and collaborators
# Licensed under the MIT License.

# NB. This is super-redundant with both dftphotom and dftspect; things are
Expand All @@ -23,7 +22,6 @@
from ...io import get_stdout_bytes
from ...kwargv import ParseKeywords, Custom
from . import util
from .util import sanitize_unicode as b

dftdynspec_doc = """
casatask dftdynspec vis=<MS> [keywords...]
Expand Down Expand Up @@ -147,14 +145,14 @@ def dftdynspec(cfg):
)
warn("this is NOT IMPLEMENTED; I will process the whole spw instead")

ms.open(b(cfg.vis))
ms.open(cfg.vis)
totrows = ms.nrow()
ms_sels = dict(
(n, cfg.get(n)) for n in util.msselect_keys if cfg.get(n) is not None
)
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

rangeinfo = ms.range(b"data_desc_id field_id".split())
rangeinfo = ms.range("data_desc_id field_id".split())
ddids = rangeinfo["data_desc_id"]
fields = rangeinfo["field_id"]
colnames = [cfg.datacol] + "flag weight time axis_info".split()
Expand All @@ -165,19 +163,19 @@ def dftdynspec(cfg):
# not rephasing.
die("selected data should contain precisely one field; got %d", fields.size)

tb.open(b(os.path.join(cfg.vis, "DATA_DESCRIPTION")))
ddspws = tb.getcol(b"SPECTRAL_WINDOW_ID")
tb.open(os.path.join(cfg.vis, "DATA_DESCRIPTION"))
ddspws = tb.getcol("SPECTRAL_WINDOW_ID")
tb.close()

# Get frequencies and precompute merged, sorted frequency array
# FIXME: below we get 'freqs' on the fly; should honor that.
# But then mapping and data storage get super inefficient.

tb.open(b(os.path.join(cfg.vis, "SPECTRAL_WINDOW")))
tb.open(os.path.join(cfg.vis, "SPECTRAL_WINDOW"))
nspw = tb.nrows()
spwfreqs = []
for i in range(nspw):
spwfreqs.append(tb.getcell(b"CHAN_FREQ", i) * 1e-9) # -> GHz
spwfreqs.append(tb.getcell("CHAN_FREQ", i) * 1e-9) # -> GHz
tb.close()

allfreqs = set()
Expand All @@ -192,8 +190,8 @@ def dftdynspec(cfg):

if rephase:
fieldid = fields[0]
tb.open(b(os.path.join(cfg.vis, "FIELD")))
phdirinfo = tb.getcell(b"PHASE_DIR", fieldid)
tb.open(os.path.join(cfg.vis, "FIELD"))
phdirinfo = tb.getcell("PHASE_DIR", fieldid)
tb.close()

if phdirinfo.shape[1] != 1:
Expand All @@ -217,18 +215,17 @@ def dftdynspec(cfg):
colnames.append("uvw")

tbins = {}
colnames = b(colnames)

for ddindex, ddid in enumerate(ddids):
# Starting in CASA 4.6, selectinit(ddid) stopped actually filtering
# your data to match the specified DDID! What garbage. Work around
# with our own filtering.
ms_sels["taql"] = "DATA_DESC_ID == %d" % ddid
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

ms.selectinit(ddid)
if cfg.polarization is not None:
ms.selectpolarization(b(cfg.polarization.split(",")))
ms.selectpolarization(cfg.polarization.split(","))
ms.iterinit(maxrows=4096)
ms.iterorigin()

Expand All @@ -253,8 +250,8 @@ def dftdynspec(cfg):
# the safest conversion in terms of being helpful while remaining
# close to the fundamental data, but TT is possible and should
# be perfectly precise for standard applications.
mq = me.epoch(b"utc", b({"value": time / 86400.0, "unit": "d"}))
mjdtt = me.measure(b(mq), b"tt")["m0"]["value"]
mq = me.epoch("utc", {"value": time / 86400.0, "unit": "d"})
mjdtt = me.measure(mq, "tt")["m0"]["value"]

tdata = tbins.get(mjdtt)
if tdata is None:
Expand Down
30 changes: 11 additions & 19 deletions pwkit/environments/casa/dftphotom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright 2012-2015 Peter Williams <peter@newton.cx> and collaborators.
# Copyright Peter Williams <peter@newton.cx> and collaborators.
# Licensed under the MIT License.

"""This module implements an algorithm to compute light curves for point
Expand All @@ -12,7 +11,6 @@
found here.

"""
from __future__ import absolute_import, division, print_function

__all__ = "Config dftphotom dftphotom_cli".split()

Expand All @@ -23,7 +21,6 @@
from ...cli import check_usage, die, warn
from ...kwargv import ParseKeywords, Custom
from . import util
from .util import sanitize_unicode as b

dftphotom_doc = """
casatask dftphotom vis=MS [keywords...]
Expand Down Expand Up @@ -141,6 +138,7 @@ class Config(ParseKeywords):
def outstream(val):
if val is None:
return sys.stdout

try:
return open(val, "w")
except Exception as e:
Expand Down Expand Up @@ -225,14 +223,14 @@ def dftphotom(cfg):
)
warn("this is NOT IMPLEMENTED; I will average over the whole spw instead")

ms.open(b(cfg.vis))
ms.open(cfg.vis)
totrows = ms.nrow()
ms_sels = dict(
(n, cfg.get(n)) for n in util.msselect_keys if cfg.get(n) is not None
)
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

rangeinfo = ms.range(b"data_desc_id field_id".split())
rangeinfo = ms.range("data_desc_id field_id".split())
ddids = rangeinfo["data_desc_id"]
fields = rangeinfo["field_id"]
colnames = [cfg.datacol] + "flag weight time axis_info".split()
Expand All @@ -245,8 +243,8 @@ def dftphotom(cfg):

if rephase:
fieldid = fields[0]
tb.open(b(os.path.join(cfg.vis, "FIELD")))
phdirinfo = tb.getcell(b"PHASE_DIR", fieldid)
tb.open(os.path.join(cfg.vis, "FIELD"))
phdirinfo = tb.getcell("PHASE_DIR", fieldid)
tb.close()

if phdirinfo.shape[1] != 1:
Expand All @@ -269,24 +267,18 @@ def dftphotom(cfg):
lmn = np.asarray([l, m, n])
colnames.append("uvw")

# Also need this although 99% of the time `ddid` and `spwid` are the same
tb.open(b(os.path.join(cfg.vis, "DATA_DESCRIPTION")))
ddspws = np.asarray(tb.getcol(b"SPECTRAL_WINDOW_ID"))
tb.close()

tbins = {}
colnames = b(colnames)

for ddindex, ddid in enumerate(ddids):
# Starting in CASA 4.6, selectinit(ddid) stopped actually filtering
# your data to match the specified DDID! What garbage. Work around
# with our own filtering.
ms_sels["taql"] = "DATA_DESC_ID == %d" % ddid
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

ms.selectinit(ddid)
if cfg.polarization is not None:
ms.selectpolarization(b(cfg.polarization.split(",")))
ms.selectpolarization(cfg.polarization.split(","))
ms.iterinit(maxrows=4096)
ms.iterorigin()

Expand All @@ -309,8 +301,8 @@ def dftphotom(cfg):
# the safest conversion in terms of being helpful while remaining
# close to the fundamental data, but TT is possible and should
# be perfectly precise for standard applications.
mq = me.epoch(b"utc", b({"value": time / 86400.0, "unit": "d"}))
mjdtt = me.measure(b(mq), b"tt")["m0"]["value"]
mq = me.epoch("utc", {"value": time / 86400.0, "unit": "d"})
mjdtt = me.measure(mq, "tt")["m0"]["value"]

tdata = tbins.get(mjdtt, None)
if tdata is None:
Expand Down
27 changes: 12 additions & 15 deletions pwkit/environments/casa/dftspect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright 2012, 2016, 2018 Peter Williams <peter@newton.cx> and collaborators.
# Copyright Peter Williams <peter@newton.cx> and collaborators.
# Licensed under the MIT License.

# NB. This is super-redundant with msphotom but it seems impractical
Expand All @@ -20,7 +19,6 @@
from ...cli import die
from ...kwargv import ParseKeywords, Custom
from . import util
from .util import sanitize_unicode as b

dftspect_doc = """
casatask dftspect vis=<MS> [keywords...]
Expand Down Expand Up @@ -184,13 +182,13 @@ def dftspect(cfg):
# selectinit() is broken, but the invocation here is good because it
# affects the results from ms.range() and friends.

ms.open(b(cfg.vis))
ms.open(cfg.vis)
ms_sels = dict(
(n, cfg.get(n)) for n in util.msselect_keys if cfg.get(n) is not None
)
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

rangeinfo = ms.range(b"data_desc_id field_id".split())
rangeinfo = ms.range("data_desc_id field_id".split())
ddids = rangeinfo["data_desc_id"]
fields = rangeinfo["field_id"]
colnames = [cfg.datacol] + "flag weight axis_info".split()
Expand All @@ -201,20 +199,20 @@ def dftspect(cfg):
# not rephasing.
die("selected data should contain precisely one field; got %d", fields.size)

tb.open(b(os.path.join(cfg.vis, "DATA_DESCRIPTION")))
ddspws = tb.getcol(b"SPECTRAL_WINDOW_ID")
tb.open(os.path.join(cfg.vis, "DATA_DESCRIPTION"))
ddspws = tb.getcol("SPECTRAL_WINDOW_ID")
tb.close()

tb.open(b(os.path.join(cfg.vis, "SPECTRAL_WINDOW")))
tb.open(os.path.join(cfg.vis, "SPECTRAL_WINDOW"))
spwmfreqs = np.zeros(tb.nrows())
for i in range(spwmfreqs.size):
spwmfreqs[i] = tb.getcell(b"CHAN_FREQ", i).mean() * 1e-9 # -> GHz
spwmfreqs[i] = tb.getcell("CHAN_FREQ", i).mean() * 1e-9 # -> GHz
tb.close()

if rephase:
fieldid = fields[0]
tb.open(b(os.path.join(cfg.vis, "FIELD")))
phdirinfo = tb.getcell(b"PHASE_DIR", fieldid)
tb.open(os.path.join(cfg.vis, "FIELD"))
phdirinfo = tb.getcell("PHASE_DIR", fieldid)
tb.close()

if phdirinfo.shape[1] != 1:
Expand All @@ -238,18 +236,17 @@ def dftspect(cfg):
colnames.append("uvw")

spwbins = {}
colnames = b(colnames)

for ddid in ddids:
# Starting in CASA 4.6, selectinit(ddid) stopped actually filtering
# your data to match the specified DDID! What garbage. Work around
# with our own filtering.
ms_sels["taql"] = "DATA_DESC_ID == %d" % ddid
ms.msselect(b(ms_sels))
ms.msselect(ms_sels)

ms.selectinit(ddid)
if cfg.polarization is not None:
ms.selectpolarization(b(cfg.polarization.split(",")))
ms.selectpolarization(cfg.polarization.split(","))
ms.iterinit()
ms.iterorigin()

Expand Down