Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LSMTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ResearchAndDevelopment
LSMTool
Commits
a4b0f603
Commit
a4b0f603
authored
2 years ago
by
David Rafferty
Browse files
Options
Downloads
Patches
Plain Diff
Fix handling of LogarithmicSI and OrientationIsAbsolute columns
parent
84ab38d2
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!43
Fix handling of LogarithmicSI and OrientationIsAbsolute columns
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lsmtool/tableio.py
+157
-103
157 additions, 103 deletions
lsmtool/tableio.py
with
157 additions
and
103 deletions
lsmtool/tableio.py
+
157
−
103
View file @
a4b0f603
...
...
@@ -38,6 +38,7 @@ except AttributeError:
# Python 3
def
itervalues
(
d
):
return
iter
(
d
.
values
())
def
iteritems
(
d
):
return
iter
(
d
.
items
())
numpy_type
=
"
U
"
...
...
@@ -45,6 +46,7 @@ else:
# Python 2
def
itervalues
(
d
):
return
d
.
itervalues
()
def
iteritems
(
d
):
return
d
.
iteritems
()
numpy_type
=
"
S
"
...
...
@@ -70,7 +72,8 @@ except NameError:
# https://www.astron.nl/lofarwiki/doku.php?id=public:user_software:documentation:makesourcedb
allowedColumnNames
=
{
'
name
'
:
'
Name
'
,
'
type
'
:
'
Type
'
,
'
patch
'
:
'
Patch
'
,
'
ra
'
:
'
Ra
'
,
'
dec
'
:
'
Dec
'
,
'
i
'
:
'
I
'
,
'
q
'
:
'
Q
'
,
'
u
'
:
'
U
'
,
'
v
'
:
'
V
'
,
'
majoraxis
'
:
'
MajorAxis
'
,
'
minoraxis
'
:
'
MinorAxis
'
,
'
orientation
'
:
'
Orientation
'
,
'
orientationisabsolute
'
:
'
OrientationIsAbsolute
'
,
'
majoraxis
'
:
'
MajorAxis
'
,
'
minoraxis
'
:
'
MinorAxis
'
,
'
orientation
'
:
'
Orientation
'
,
'
orientationisabsolute
'
:
'
OrientationIsAbsolute
'
,
'
ishapelet
'
:
'
IShapelet
'
,
'
qshapelet
'
:
'
QShapelet
'
,
'
ushapelet
'
:
'
UShapelet
'
,
'
vshapelet
'
:
'
VShapelet
'
,
'
category
'
:
'
Category
'
,
'
logarithmicsi
'
:
'
LogarithmicSI
'
,
'
rotationmeasure
'
:
'
RotationMeasure
'
,
'
polarizationangle
'
:
'
PolarizationAngle
'
,
...
...
@@ -79,18 +82,20 @@ allowedColumnNames = {'name':'Name', 'type':'Type', 'patch':'Patch',
allowedColumnUnits
=
{
'
name
'
:
None
,
'
type
'
:
None
,
'
patch
'
:
None
,
'
ra
'
:
'
degree
'
,
'
dec
'
:
'
degree
'
,
'
i
'
:
'
Jy
'
,
'
i-apparent
'
:
'
Jy
'
,
'
q
'
:
'
Jy
'
,
'
u
'
:
'
Jy
'
,
'
v
'
:
'
Jy
'
,
'
majoraxis
'
:
'
arcsec
'
,
'
minoraxis
'
:
'
arcsec
'
,
'
orientation
'
:
'
degree
'
,
'
orientationisabsolute
'
:
None
,
'
majoraxis
'
:
'
arcsec
'
,
'
minoraxis
'
:
'
arcsec
'
,
'
orientation
'
:
'
degree
'
,
'
orientationisabsolute
'
:
None
,
'
ishapelet
'
:
None
,
'
qshapelet
'
:
None
,
'
ushapelet
'
:
None
,
'
vshapelet
'
:
None
,
'
category
'
:
None
,
'
logarithmicsi
'
:
None
,
'
rotationmeasure
'
:
'
rad/m^2
'
,
'
polarizationangle
'
:
'
rad
'
,
'
polarizedfraction
'
:
'
PolarizedFraction
'
,
'
referencewavelength
'
:
'
ReferenceWavelength
'
,
'
polarizedfraction
'
:
'
PolarizedFraction
'
,
'
referencewavelength
'
:
'
ReferenceWavelength
'
,
'
referencefrequency
'
:
'
Hz
'
,
'
spectralindex
'
:
None
}
allowedColumnDefaults
=
{
'
name
'
:
'
N/A
'
,
'
type
'
:
'
N/A
'
,
'
patch
'
:
'
N/A
'
,
'
ra
'
:
0.0
,
'
dec
'
:
0.0
,
'
i
'
:
0.0
,
'
q
'
:
0.0
,
'
u
'
:
0.0
,
'
v
'
:
0.0
,
'
majoraxis
'
:
0.0
,
'
minoraxis
'
:
0.0
,
'
orientation
'
:
0.0
,
'
orientationisabsolute
'
:
F
alse
,
'
minoraxis
'
:
0.0
,
'
orientation
'
:
0.0
,
'
orientationisabsolute
'
:
'
f
alse
'
,
'
ishapelet
'
:
'
N/A
'
,
'
qshapelet
'
:
'
N/A
'
,
'
ushapelet
'
:
'
N/A
'
,
'
vshapelet
'
:
'
N/A
'
,
'
category
'
:
2
,
'
logarithmicsi
'
:
T
rue
,
'
vshapelet
'
:
'
N/A
'
,
'
category
'
:
2
,
'
logarithmicsi
'
:
'
t
rue
'
,
'
rotationmeasure
'
:
0.0
,
'
polarizationangle
'
:
0.0
,
'
polarizedfraction
'
:
0.0
,
'
referencewavelength
'
:
'
N/A
'
,
'
referencefrequency
'
:
0.0
,
'
spectralindex
'
:
[
0.0
]}
...
...
@@ -102,6 +107,63 @@ allowedVOServices = {
'
wenss
'
:
'
http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=VIII/62A&
'
}
def
raformat
(
val
):
"""
Column formatter for RA values.
Parameters
----------
val : float
Input RA value in deg
Returns
-------
valstr : str
Formatted string as
'
hh:mm:ss.s
'
"""
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
hourangle
'
,
sep
=
'
:
'
)
def
decformat
(
val
):
"""
Column formatter for Dec values.
Parameters
----------
val : float
Input Dec value in deg
Returns
-------
valstr : str
Formatted string as
'
dd.mm.ss.s
'
"""
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
degree
'
,
sep
=
'
.
'
)
def
fluxformat
(
val
):
"""
Column formatter for flux density values.
Parameters
----------
val : float
Input flux density value in Jy
Returns
-------
valstr : str
Formatted string to 3 digits
"""
if
type
(
val
)
is
ma
.
core
.
MaskedConstant
:
return
'
{}
'
.
format
(
val
)
else
:
return
'
{0:0.3f}
'
.
format
(
val
)
def
skyModelReader
(
fileName
):
"""
Reads a makesourcedb sky model file into an astropy table.
...
...
@@ -132,7 +194,7 @@ def skyModelReader(fileName):
# Read format line
formatString
=
None
for
l
,
line
in
enumerate
(
modelFile
)
:
for
line
in
modelFile
:
if
'
format
'
in
line
.
lower
():
formatString
=
line
break
...
...
@@ -182,25 +244,37 @@ def createTable(outlines, metaDict, colNames, colDefaults):
log
=
logging
.
getLogger
(
'
LSMTool.Load
'
)
# Before loading table into an astropy Table object, set lengths of Name,
# Patch, and Type columns to 100 characters. Due to a change in the astropy
# table API with v4.1, we have to check the version and use the appropriate
# column names
# Patch, and Type columns to 100 characters to ensure long names are not
# truncated. The LogarithmicSI and OrientationIsAbsolute columns are set
# to 5 characters to allow true/false values to be stored as strings without
# truncation. Due to a change in the astropy table API with v4.1, we have to
# check the version and use the appropriate column names
if
LooseVersion
(
astropy
.
__version__
)
<
LooseVersion
(
'
4.1
'
):
# Use the input column names for the converters
nameCol
=
'
col{0}
'
.
format
(
colNames
.
index
(
'
Name
'
)
+
1
)
typeCol
=
'
col{0}
'
.
format
(
colNames
.
index
(
'
Type
'
)
+
1
)
if
'
Patch
'
in
colNames
:
patchCol
=
'
col{0}
'
.
format
(
colNames
.
index
(
'
Patch
'
)
+
1
)
if
'
LogarithmicSI
'
in
colNames
:
logSICol
=
'
col{0}
'
.
format
(
colNames
.
index
(
'
LogarithmicSI
'
)
+
1
)
if
'
OrientationIsAbsolute
'
in
colNames
:
orienCol
=
'
col{0}
'
.
format
(
colNames
.
index
(
'
OrientationIsAbsolute
'
)
+
1
)
else
:
# Use the output column names for the converters
nameCol
=
'
Name
'
typeCol
=
'
Type
'
patchCol
=
'
Patch
'
logSICol
=
'
LogarithmicSI
'
orienCol
=
'
OrientationIsAbsolute
'
converters
=
{}
converters
[
nameCol
]
=
[
ascii
.
convert_numpy
(
'
{}100
'
.
format
(
numpy_type
))]
converters
[
typeCol
]
=
[
ascii
.
convert_numpy
(
'
{}100
'
.
format
(
numpy_type
))]
if
'
Patch
'
in
colNames
:
converters
[
patchCol
]
=
[
ascii
.
convert_numpy
(
'
{}100
'
.
format
(
numpy_type
))]
if
'
LogarithmicSI
'
in
colNames
:
converters
[
logSICol
]
=
[
ascii
.
convert_numpy
(
'
{}5
'
.
format
(
numpy_type
))]
if
'
OrientationIsAbsolute
'
in
colNames
:
converters
[
orienCol
]
=
[
ascii
.
convert_numpy
(
'
{}5
'
.
format
(
numpy_type
))]
log
.
debug
(
'
Creating table...
'
)
table
=
Table
.
read
(
'
\n
'
.
join
(
outlines
),
guess
=
False
,
format
=
'
ascii.no_header
'
,
delimiter
=
'
,
'
,
...
...
@@ -213,12 +287,12 @@ def createTable(outlines, metaDict, colNames, colDefaults):
specVec
=
[]
maskVec
=
[]
maxLen
=
0
for
l
in
specOld
:
for
entry
in
specOld
:
try
:
if
type
(
l
)
is
float
or
type
(
l
)
is
int
:
if
type
(
entry
)
is
float
or
type
(
entry
)
is
int
:
maxLen
=
1
else
:
specEntry
=
[
float
(
f
)
for
f
in
l
.
split
(
'
;
'
)]
specEntry
=
[
float
(
f
)
for
f
in
entry
.
split
(
'
;
'
)]
if
len
(
specEntry
)
>
maxLen
:
maxLen
=
len
(
specEntry
)
except
:
...
...
@@ -227,14 +301,14 @@ def createTable(outlines, metaDict, colNames, colDefaults):
if
defSpeclen
>
maxLen
:
maxLen
=
defSpeclen
log
.
debug
(
'
Maximum number of spectral-index terms in model: {0}
'
.
format
(
maxLen
))
for
l
in
specOld
:
for
entry
in
specOld
:
try
:
# Take existing entry and fix type
if
type
(
l
)
is
float
or
type
(
l
)
is
int
:
specEntry
=
[
float
(
l
)]
if
type
(
entry
)
is
float
or
type
(
entry
)
is
int
:
specEntry
=
[
float
(
entry
)]
specMask
=
[
False
]
else
:
specEntry
=
[
float
(
f
)
for
f
in
l
.
split
(
'
;
'
)]
specEntry
=
[
float
(
f
)
for
f
in
entry
.
split
(
'
;
'
)]
specMask
=
[
False
]
*
len
(
specEntry
)
except
:
# No entry in table, so use default value
...
...
@@ -256,8 +330,6 @@ def createTable(outlines, metaDict, colNames, colDefaults):
log
.
debug
(
'
Converting RA...
'
)
RARaw
=
table
[
'
Ra
'
].
data
.
tolist
()
RACol
=
Column
(
name
=
'
Ra
'
,
data
=
RA2Angle
(
RARaw
))
def
raformat
(
val
):
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
hourangle
'
,
sep
=
'
:
'
)
RACol
.
format
=
raformat
RAIndx
=
table
.
keys
().
index
(
'
Ra
'
)
table
.
remove_column
(
'
Ra
'
)
...
...
@@ -266,18 +338,11 @@ def createTable(outlines, metaDict, colNames, colDefaults):
log
.
debug
(
'
Converting Dec...
'
)
DecRaw
=
table
[
'
Dec
'
].
data
.
tolist
()
DecCol
=
Column
(
name
=
'
Dec
'
,
data
=
Dec2Angle
(
DecRaw
))
def
decformat
(
val
):
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
degree
'
,
sep
=
'
.
'
)
DecCol
.
format
=
decformat
DecIndx
=
table
.
keys
().
index
(
'
Dec
'
)
table
.
remove_column
(
'
Dec
'
)
table
.
add_column
(
DecCol
,
index
=
DecIndx
)
def
fluxformat
(
val
):
if
type
(
val
)
is
ma
.
core
.
MaskedConstant
:
return
'
{}
'
.
format
(
val
)
else
:
return
'
{0:0.3f}
'
.
format
(
val
)
table
.
columns
[
'
I
'
].
format
=
fluxformat
# Set column units and default values
...
...
@@ -744,8 +809,8 @@ def ds9RegionWriter(table, fileName):
log
.
debug
(
'
Writing ds9 region file to {0}
'
.
format
(
fileName
))
outLines
=
[]
outLines
.
append
(
'
# Region file format: DS9 version 4.0
\n
global color=green
'
\
'
font=
"
helvetica 10 normal
"
select=1 highlite=1 edit=1
'
\
outLines
.
append
(
'
# Region file format: DS9 version 4.0
\n
global color=green
'
'
font=
"
helvetica 10 normal
"
select=1 highlite=1 edit=1
'
'
move=1 delete=1 include=1 fixed=0 source
\n
fk5
\n
'
)
# Make sure all columns have the correct units
...
...
@@ -761,20 +826,17 @@ def ds9RegionWriter(table, fileName):
if
row
[
'
Type
'
].
lower
()
==
'
gaussian
'
:
a
=
row
[
'
MajorAxis
'
]
/
3600.0
# deg
b
=
row
[
'
MinorAxis
'
]
/
3600.0
# deg
pa
=
row
[
'
Orientation
'
]
# deg
ree
pa
=
row
[
'
Orientation
'
]
# deg
# ds9 can't handle 1-D Gaussians, so make sure they are 2-D
if
a
<
1.0
/
3600.0
:
a
=
1.0
/
3600.0
# deg
if
b
<
1.0
/
3600.0
:
b
=
1.0
/
3600.0
# deg
stype
=
'
GAUSSIAN
'
region
=
'
ellipse({0}, {1}, {2}, {3}, {4}) # text={{{5}}}
\n
'
.
format
(
ra
,
dec
,
a
,
b
,
pa
+
90.0
,
name
)
region
=
'
ellipse({0}, {1}, {2}, {3}, {4}) # text={{{5}}}
\n
'
.
format
(
ra
,
dec
,
a
,
b
,
pa
+
90.0
,
name
)
else
:
stype
=
'
POINT
'
region
=
'
point({0}, {1}) # point=cross width=2 text={{{2}}}
\n
'
.
format
(
ra
,
dec
,
name
)
region
=
'
point({0}, {1}) # point=cross width=2 text={{{2}}}
\n
'
.
format
(
ra
,
dec
,
name
)
outLines
.
append
(
region
)
regionFile
.
writelines
(
outLines
)
...
...
@@ -854,7 +916,6 @@ def casaRegionWriter(table, fileName):
for
row
in
table
:
ra
=
row
[
'
Ra
'
]
dec
=
row
[
'
Dec
'
]
name
=
row
[
'
Name
'
]
if
row
[
'
Type
'
].
lower
()
==
'
gaussian
'
:
a
=
row
[
'
MajorAxis
'
]
/
3600.0
# degree
...
...
@@ -932,10 +993,9 @@ def factorDirectionsWriter(table, fileName):
gRA
=
Angle
(
0.0
)
gDec
=
Angle
(
0.0
)
outLines
.
append
(
'
{0} {1},{2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}
'
'
{13} {14}
\n
'
.
format
(
patchName
,
gRA
.
to_string
(
unit
=
'
hourangle
'
,
sep
=
'
hms
'
),
gDec
.
to_string
(
sep
=
'
dms
'
),
'
empty
'
,
'
empty
'
,
0
,
0
,
0
,
'
LD
'
,
'
empty
'
,
'
empty
'
,
'
empty
'
,
False
,
size
,
flux
))
'
{13} {14}
\n
'
.
format
(
patchName
,
gRA
.
to_string
(
unit
=
'
hourangle
'
,
sep
=
'
hms
'
),
gDec
.
to_string
(
sep
=
'
dms
'
),
'
empty
'
,
'
empty
'
,
0
,
0
,
0
,
'
LD
'
,
'
empty
'
,
'
empty
'
,
'
empty
'
,
False
,
size
,
flux
))
regionFile
.
writelines
(
outLines
)
regionFile
.
close
()
...
...
@@ -951,7 +1011,7 @@ def broadcastTable(fileName):
Name of sky model file to broadcast
"""
from
astropy.vo.samp
import
SAMPHubServer
,
SAMPIntegratedClient
,
SAMPHubError
from
astropy.vo.samp
import
SAMPIntegratedClient
import
urlparse
client
=
SAMPIntegratedClient
()
...
...
@@ -1068,8 +1128,6 @@ def convertExternalTable(table, columnMapping, fluxUnits='mJy'):
log
.
debug
(
'
Converting RA...
'
)
RARaw
=
table
[
'
Ra
'
].
data
.
tolist
()
RACol
=
Column
(
name
=
'
Ra
'
,
data
=
RA2Angle
(
RARaw
))
def
raformat
(
val
):
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
hourangle
'
,
sep
=
'
:
'
)
RACol
.
format
=
raformat
RAIndx
=
table
.
keys
().
index
(
'
Ra
'
)
table
.
remove_column
(
'
Ra
'
)
...
...
@@ -1078,8 +1136,6 @@ def convertExternalTable(table, columnMapping, fluxUnits='mJy'):
log
.
debug
(
'
Converting Dec...
'
)
DecRaw
=
table
[
'
Dec
'
].
data
.
tolist
()
DecCol
=
Column
(
name
=
'
Dec
'
,
data
=
Dec2Angle
(
DecRaw
))
def
decformat
(
val
):
return
Angle
(
val
,
unit
=
'
degree
'
).
to_string
(
unit
=
'
degree
'
,
sep
=
'
.
'
)
DecCol
.
format
=
decformat
DecIndx
=
table
.
keys
().
index
(
'
Dec
'
)
table
.
remove_column
(
'
Dec
'
)
...
...
@@ -1120,8 +1176,6 @@ def convertExternalTable(table, columnMapping, fluxUnits='mJy'):
table
.
add_column
(
col
)
# Set column units and default values
def
fluxformat
(
val
):
return
'
{0:0.3f}
'
.
format
(
val
)
for
i
,
colName
in
enumerate
(
table
.
colnames
):
log
.
debug
(
"
Setting units for column
'
{0}
'
to {1}
"
.
format
(
colName
,
allowedColumnUnits
[
colName
.
lower
()]))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment