Skip to content

Instantly share code, notes, and snippets.

@mileslucas
Last active May 3, 2023 06:34
Show Gist options
  • Save mileslucas/f5be374deff6f398810534bd3f7fe340 to your computer and use it in GitHub Desktop.
Save mileslucas/f5be374deff6f398810534bd3f7fe340 to your computer and use it in GitHub Desktop.
quickselect scripts using ds9 interfaces
using Glob
using SAOImageDS9
function quickselect(glob_str; logscale=true)
# parse out the directory, if any
directory, globstr = splitdir(glob_str)
filelist = collect(glob(globstr, directory))
N = length(filelist)
@info "Selecting through $N files"
# connect to ds9 and set up
DS9.connect()
DS9.set("cmap magma")
if logscale
DS9.set("scale log")
else
DS9.set("scale 99.5")
end
i = 1
files_to_keep = filter(filelist) do file
@info "$i/$N [$(round((i - 1) / N * 100, digits=1)) %]" filename=file
DS9.set("file $file")
print("Keep this file? [Y/n]: ")
res = readline()
return isempty(res) || lowercase(res) == "y"
end
return files_to_keep
end
from pathlib import Path
from argparse import ArgumentParser
from pyds9 import DS9
parser = ArgumentParser()
parser.add_argument("filenames", nargs="+")
def main():
args = parser.parse_args()
ds9 = DS9()
ds9.set("cmap magma")
ds9.set("scale log")
for file in args.filenames:
path = Path(file)
ds9.set(f"file {path.absolute():s}")
res = input("Keep this file [Y/n]? ")
if res.lower() == "n":
continue
print(path)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment