Skip to content

Instantly share code, notes, and snippets.

@brianv0
Created October 20, 2015 17:50
Show Gist options
  • Select an option

  • Save brianv0/da61245b587a6766730a to your computer and use it in GitHub Desktop.

Select an option

Save brianv0/da61245b587a6766730a to your computer and use it in GitHub Desktop.
Retrieve Numeric Folders from datacat and sort them numerically
from datacat import client_from_config_file
from datacat.model import Folder
import os
client = client_from_config_file()
def is_valid_folder(child):
try:
if isinstance(child, Folder) and float(child.name):
return True
except ValueError:
pass
return False
path = "/LSST/Raw/eTravelerFiles/SLAC/boojum/boojum-01/hasInputs"
children = [c for c in client.children(path) if is_valid_folder(c)]
nkey = lambda c: float(c.name)
children.sort(key=nkey)
latest_path = children[-1].path
# Search in latest path directly
datasets = client.search(latest_path, ...)
# Search child folders of latest path
latest_children = os.path.join(latest_path, "*")
datasets = client.search(latest_children, ...)
# Recursively search starting at latest path
latest_children_recur = os.path.join(latest_path, "**")
datasets = client.search(latest_children_recur, ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment