Skip to content

Commit

Permalink
add a skeleton MeasurementSets module
Browse files Browse the repository at this point in the history
for now it only allows you to create a measurement set with default
keywords and columns
  • Loading branch information
mweastwood committed Mar 5, 2018
1 parent 79c95b4 commit 92d82c5
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 2 deletions.
4 changes: 2 additions & 2 deletions deps/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CXX = g++
LDLIBS = -lcasa_casa -lcasa_tables -lcasa_measures
LDLIBS = -lcasa_casa -lcasa_tables -lcasa_measures -lcasa_ms
LDFLAGS = -Wl,-rpath,\$$ORIGIN -Wl,--no-undefined

MODULES = tables measures
MODULES = tables measures measurement-sets
OBJ = $(addsuffix /module.o, $(MODULES))

.PHONY: all clean $(MODULES)
Expand Down
20 changes: 20 additions & 0 deletions deps/src/measurement-sets/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CXX = g++
CXXFLAGS = -c -std=c++0x -Wall -Werror -fpic -Wno-return-type-c-linkage

SRC = $(wildcard *.cpp)
OBJ = $(SRC:.cpp=.o)

.PHONY: all clean

all: module.o

module.o: $(OBJ)
$(LD) -r $(OBJ) -o module.o

%.o: %.cpp
$(CXX) $(CXXFLAGS) -o $@ $<

clean:
-rm -f $(OBJ)
-rm -f module.o

28 changes: 28 additions & 0 deletions deps/src/measurement-sets/measurement-sets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2015-2017 Michael Eastwood
//
// 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/>.

#include <casacore/tables/Tables.h>
#include <casacore/ms/MeasurementSets.h>
using namespace casacore;

extern "C" {
Table* new_measurement_set_create(char* path) {
SetupNewTable maker(path, MS::requiredTableDesc(), Table::NewNoReplace);
MeasurementSet* ms = new MeasurementSet(maker);
ms->createDefaultSubtables(Table::New);
return ms;
}
}

1 change: 1 addition & 0 deletions src/CasaCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module CasaCore

include("Tables.jl")
include("Measures.jl")
include("MeasurementSets.jl")

end

31 changes: 31 additions & 0 deletions src/MeasurementSets.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2015-2017 Michael Eastwood
#
# 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/>.

"The `MeasurementSets` module is used to interact with CasaCore measurement sets."
module MeasurementSets

using ..Tables

const libcasacorewrapper = normpath(joinpath(@__DIR__, "..", "deps", "src",
"libcasacorewrapper.so"))

function __init__()
isfile(libcasacorewrapper) || error("Run Pkg.build(\"CasaCore\")")
end

include("measurement-sets/measurement-sets.jl")

end

25 changes: 25 additions & 0 deletions src/measurement-sets/measurement-sets.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2015-2017 Michael Eastwood
#
# 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/>.

function create(path)
path = Tables.table_fix_path(path)
if isfile(path) || isdir(path)
Tables.table_exists_error()
end
ptr = ccall((:new_measurement_set_create, libcasacorewrapper), Ptr{Tables.CasaCoreTable},
(Ptr{Cchar},), path)
Table(path, Tables.readwrite, ptr)
end

59 changes: 59 additions & 0 deletions test/measurement-sets.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2015-2017 Michael Eastwood
#
# 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/>.

@testset "Measurement Sets" begin

@testset "creation" begin
path = tempname()*".ms"
ms = MeasurementSets.create(path)
@test Tables.column_exists(ms, "UVW")
@test Tables.column_exists(ms, "FLAG")
@test Tables.column_exists(ms, "FLAG_CATEGORY")
@test Tables.column_exists(ms, "WEIGHT")
@test Tables.column_exists(ms, "SIGMA")
@test Tables.column_exists(ms, "ANTENNA1")
@test Tables.column_exists(ms, "ANTENNA2")
@test Tables.column_exists(ms, "ARRAY_ID")
@test Tables.column_exists(ms, "DATA_DESC_ID")
@test Tables.column_exists(ms, "EXPOSURE")
@test Tables.column_exists(ms, "FEED1")
@test Tables.column_exists(ms, "FEED2")
@test Tables.column_exists(ms, "FIELD_ID")
@test Tables.column_exists(ms, "FLAG_ROW")
@test Tables.column_exists(ms, "INTERVAL")
@test Tables.column_exists(ms, "OBSERVATION_ID")
@test Tables.column_exists(ms, "PROCESSOR_ID")
@test Tables.column_exists(ms, "SCAN_NUMBER")
@test Tables.column_exists(ms, "STATE_ID")
@test Tables.column_exists(ms, "TIME")
@test Tables.column_exists(ms, "TIME_CENTROID")
@test ms[kw"MS_VERSION"] === Float32(2)
@test Tables.keyword_exists(ms, kw"ANTENNA")
@test Tables.keyword_exists(ms, kw"DATA_DESCRIPTION")
@test Tables.keyword_exists(ms, kw"FEED")
@test Tables.keyword_exists(ms, kw"FLAG_CMD")
@test Tables.keyword_exists(ms, kw"FIELD")
@test Tables.keyword_exists(ms, kw"HISTORY")
@test Tables.keyword_exists(ms, kw"OBSERVATION")
@test Tables.keyword_exists(ms, kw"POINTING")
@test Tables.keyword_exists(ms, kw"POLARIZATION")
@test Tables.keyword_exists(ms, kw"PROCESSOR")
@test Tables.keyword_exists(ms, kw"SPECTRAL_WINDOW")
@test Tables.keyword_exists(ms, kw"STATE")
Tables.delete(ms)
end

end

2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using CasaCore.Tables
using CasaCore.Measures
using CasaCore.MeasurementSets
using Unitful
using Base.Test

Expand All @@ -23,5 +24,6 @@ srand(123)
@testset "CasaCore Tests" begin
include("tables.jl")
include("measures.jl")
include("measurement-sets.jl")
end

0 comments on commit 92d82c5

Please sign in to comment.