-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimkscript
executable file
·126 lines (104 loc) · 5.31 KB
/
imkscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/bash
# https://github.com/holgerbrandl/kscript/blob/master/docs/user_guide.md#create-interpreters-for-custom-dsls
# https://github.com/holgerbrandl/kscript/blob/master/test/resources/custom_dsl/mydsl
# https://stackoverflow.com/questions/12855000/bash-redirecting-eof-into-variable
set -e
function _get_version {
POM_XML="$1"
PACKAGE="$2"
PATTERN='/*[local-name()="project"]/*[local-name()="properties"]/*[local-name()="%s.version"]/text()'
QUERY="$(printf $PATTERN $PACKAGE)"
VERSION="$(xmllint --xpath ${QUERY} ${POM_XML})"
echo $VERSION
exit 0
}
POM_SCIJAVA_VERSION="${POM_SCIJAVA_VERSION:-pom-scijava-27.0.1}"
POM_SCIJAVA_URL="https://raw.githubusercontent.com/scijava/pom-scijava/${POM_SCIJAVA_VERSION}/pom.xml"
CACHE_DIR="$HOME/.cache/imkscript"
mkdir -p "${CACHE_DIR}/pom-scijava"
POM_SCIJAVA_POM="${CACHE_DIR}/pom-scijava/${POM_SCIJAVA_VERSION}"
if [ -f "${POM_SCIJAVA_POM}" ]; then
: # echo POM_SCIJAVA_POM exists at "$POM_SCIJAVA_POM"
else
wget -O "${POM_SCIJAVA_POM}" "${POM_SCIJAVA_URL}"
fi
# TODO for now, use hard coded default versions until pom-scijava is more up-to-date
IMGLIB2_VERSION="${IMGLIB2_VERSION:-5.8.0}" #$(_get_version ${POM_SCIJAVA_POM} imglib2)}"
IMKLIB_VERSION="${IMKLIB_VERSION:-0.1.2-SNAPSHOT}"
# BIGDATAVIEWER_CORE_VERSION="${BIGDATAVIEWER_CORE_VERSION:-$(_get_version ${POM_SCIJAVA_POM} bigdataviewer-core)}"
# BIGDATAVIEWER_VISTOOLS_VERSION="${BIGDATAVIEWER_VISTOOLS_VERSION:-$(_get_version ${POM_SCIJAVA_POM} bigdataviewer-vistools)}"
BIGDATAVIEWER_CORE_VERSION="${BIGDATAVIEWER_CORE_VERSION:-7.0.0}"
BIGDATAVIEWER_VISTOOLS_VERSION="${BIGDATAVIEWER_VISTOOLS_VERSION:-1.0.0-beta-17}"
IMAGEJ_VERSION="${IMAGEJ_VERSION:-$(_get_version ${POM_SCIJAVA_POM} imagej)}"
SCIJAVA_COMMON_VERSION="${SCIJAVA_COMMON_VERSION:-$(_get_version ${POM_SCIJAVA_POM} scijava-common)}"
SIMPLIFIED_IO_VERSION="${SIMPLIFIED_IO_VERSION:-1.0.1}"
N5_VERSION="${N5_VERSION:-2.1.0}"
N5_IMGLIB2_VERSION="${N5_IMGLIB2_VERSION:-3.4.1}"
N5_HDF5_VERSION="${N5_HDF5_VERSION:-1.0.4}"
CUSTOM_KSCRIPT_PREAMBLE="$(cat <<EOF
@file:MavenRepository("scijava.public", "https://maven.scijava.org/content/groups/public")
@file:DependsOn("net.imglib2:imglib2:${IMGLIB2_VERSION}")
@file:DependsOn("net.imglib2:imklib:${IMKLIB_VERSION}")
@file:DependsOn("net.imagej:imagej:${IMAGEJ_VERSION}")
@file:DependsOn("sc.fiji:bigdataviewer-vistools:${BIGDATAVIEWER_VISTOOLS_VERSION}")
@file:DependsOn("sc.fiji:bigdataviewer-core:${BIGDATAVIEWER_CORE_VERSION}")
@file:DependsOn("org.scijava:scijava-common:${SCIJAVA_COMMON_VERSION}")
@file:DependsOn("sc.fiji:simplified-io:${SIMPLIFIED_IO_VERSION}")
@file:DependsOn("org.janelia.saalfeldlab:n5:${N5_VERSION}")
@file:DependsOn("org.janelia.saalfeldlab:n5-imglib2:${N5_IMGLIB2_VERSION}")
@file:DependsOn("org.janelia.saalfeldlab:n5-hdf5:${N5_HDF5_VERSION}")
@file:DependsOn("info.picocli:picocli:4.0.4")
import bdv.util.BdvFunctions
import bdv.util.BdvOptions
import net.imagej.ImageJ
import net.imglib2.RandomAccessibleInterval
import net.imglib2.converter.Converters
import net.imglib2.img.array.ArrayImgs
import net.imglib2.type.NativeType
import net.imglib2.type.numeric.ARGBType
import net.imglib2.type.numeric.integer.ByteType
import net.imglib2.type.numeric.integer.IntType
import net.imglib2.type.numeric.integer.LongType
import net.imglib2.type.numeric.integer.ShortType
import net.imglib2.type.numeric.integer.UnsignedByteType
import net.imglib2.type.numeric.integer.UnsignedIntType
import net.imglib2.type.numeric.integer.UnsignedLongType
import net.imglib2.type.numeric.integer.UnsignedShortType
import net.imglib2.type.numeric.real.DoubleType
import net.imglib2.type.numeric.real.FloatType
import net.imglib2.view.Views
import net.imglib2.imklib.extensions.*
import org.janelia.saalfeldlab.n5.DataType
import org.janelia.saalfeldlab.n5.N5FSReader
import org.janelia.saalfeldlab.n5.N5FSWriter
import org.janelia.saalfeldlab.n5.N5Reader
import org.janelia.saalfeldlab.n5.N5Writer
import org.janelia.saalfeldlab.n5.hdf5.N5HDF5Reader
import org.janelia.saalfeldlab.n5.hdf5.N5HDF5Writer
import org.janelia.saalfeldlab.n5.imglib2.N5Utils
import sc.fiji.simplifiedio.SimplifiedIO
typealias SIO = SimplifiedIO
typealias RAI<T> = RandomAccessibleInterval<T>
java.lang.Thread
.currentThread()
.setContextClassLoader(java.lang.invoke.MethodHandles.lookup().lookupClass().getClassLoader())
fun n5open(container: N5Reader, dataset: String): RAI<out NativeType<*>>? {
return when(container.getDatasetAttributes(dataset).dataType) {
DataType.UINT8 -> N5Utils.open<UnsignedByteType>(container, dataset)
DataType.UINT16 -> N5Utils.open<UnsignedShortType>(container, dataset)
DataType.UINT32 -> N5Utils.open<UnsignedIntType>(container, dataset)
DataType.UINT64 -> N5Utils.open<UnsignedLongType>(container, dataset)
DataType.INT8 -> N5Utils.open<ByteType>(container, dataset)
DataType.INT16 -> N5Utils.open<ShortType>(container, dataset)
DataType.INT32 -> N5Utils.open<IntType>(container, dataset)
DataType.INT64 -> N5Utils.open<LongType>(container, dataset)
DataType.FLOAT32 -> N5Utils.open<FloatType>(container, dataset)
DataType.FLOAT64 -> N5Utils.open<DoubleType>(container, dataset)
else -> null
}
}
EOF
)"
# uncomment to log pre
# echo -e "$CUSTOM_KSCRIPT_PREAMBLE"
CUSTOM_KSCRIPT_PREAMBLE=$CUSTOM_KSCRIPT_PREAMBLE exec kscript $@