Skip to content

Commit

Permalink
added modes-project script
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Oct 1, 2023
1 parent 96475bb commit 06b88ac
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
5 changes: 4 additions & 1 deletion plugins/milk-extra-src/linalgebra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ set(INCLUDEFILES
SingularValueDecomp_mkU.h
)


set(SCRIPTS
scripts/milk-modes-project
)



Expand Down Expand Up @@ -145,3 +147,4 @@ message("---------------------------------------")

install(TARGETS ${LIBNAME} DESTINATION lib)
install(FILES ${INCLUDEFILES} DESTINATION include/${SRCNAME})
install(PROGRAMS ${SCRIPTS} DESTINATION bin)
3 changes: 2 additions & 1 deletion plugins/milk-extra-src/linalgebra/SGEMM.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static CLICMDARGDEF farg[] =
{
CLIARG_IMG,
".matB",
"output matrix B",
"input matrix B",
"matA",
CLIARG_VISIBLE_DEFAULT,
(void **) &inmatB,
Expand Down Expand Up @@ -132,6 +132,7 @@ static CLICMDDATA CLIcmddata =
static errno_t help_function()
{
printf("CPU or GPU matrix-matrix multiplication\n");
printf("Single precision only\n");

return RETURN_SUCCESS;
}
Expand Down
66 changes: 66 additions & 0 deletions plugins/milk-extra-src/linalgebra/scripts/milk-modes-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

MSdescr="Linear projection of modesA onto space defined by modesB"

MSextdescr="Project modesA (image cube) onto modesB (image cube)
Neither modesA nor modesB are assumed to be orthogonal
Main steps:
- Perform PCA on modesB to build an orthonormal basis B
- Decompose modesA according to basis B (decomposition coefficients are mcoeff)
- Use mcoeff and basis B to reconstruct projection of modesA onto modesB
- Compute the residual of the reconstruction = modesA - reconstruction
Output:
- projection
- reconstruction
"

source milk-script-std-config

RequiredCommands=( milk-all )
RequiredFiles=()
RequiredDirs=()


MSarg+=( "inmodesA:string:input modes to be decomposed" )
MSarg+=( "inmodesB:string:modes onto which to decompose" )
MSarg+=( "SVDlim:float:SVD limit" )
MSarg+=( "outimrec:string:reconstruction (projection)" )
MSarg+=( "outimres:string:residual" )

GPUindex="-1"
MSopt+=( "g:gpu:setgpu:GPU[int]:GPU index, -1 for CPU" )
function setgpu() {
GPUindex="$1"
}


source milk-argparse


immA="${inputMSargARRAY[0]}"
immB="${inputMSargARRAY[1]}"
svdlim="${inputMSargARRAY[2]}"
outimrec="${inputMSargARRAY[3]}"
outimres="${inputMSargARRAY[4]}"

milk-all << EOF
loadfits "$immA" modesA
loadfits "$immB" modesB
linalg.compSVD .GPUdevice ${GPUindex}
linalg.compSVD modesB svdU svdS svdV ${svdlim}
listim
linalg.sgemm .GPUdevice ${GPUindex}
linalg.sgemm .transpA 1
linalg.sgemm modesA svdU mcoeff
linalg.sgemm .transpA 0
linalg.sgemm .transpB 1
linalg.sgemm svdU mcoeff imrec
saveFITS imrec "$outimrec"
imres=modesA-imrec
saveFITS imres "$outimres"
exitCLI
EOF


2 changes: 1 addition & 1 deletion scripts/milk-images-merge
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ while IFS= read -r filename; do
echo "loadfits \"${filename}\" inimmerge${i}" >> $SF
echo "immerge mergedim inimmerge${i} mergedim1 ${mergeaxis}" >> $SF
echo "rm mergedim" >> $SF
echo "mv mergedim1 mergedim" >> $SF
echo "mv mergedim1 mergedim" >> $SF
fi
((i=i+1))
initmerge=1
Expand Down

0 comments on commit 06b88ac

Please sign in to comment.