I’d like to write some Python code that works with sets of run numbers, doing things like taking the union or intersection of sets, iterating over them, or loading them into a Workspace Group. The sets of runs will in general be too large to load at once into Mantid until I specifically choose to do so. I could probably implement something like this with a subclass of Python’s set object, but before I do, does anything like this exist in Mantid already that could help me?
Also, at some point I’ll need a human-readable notation for the sets of runs, e.g. “123456-999;125000;125750-6000”. Does any existing algorithm in Mantid (or other part of Mantid) use a notation like this, that I could also adopt myself for consistency?
Any comments or suggestions gratefully received!
Mantid has a filefinder for locating runs with strings like you have given. This is a C++ method that is exposed to Python. See if you can get
FileFinder.findRuns(run_string) to work for you:
from mantid.api import FileFinder
from typing import List
runs: List[int] = FileFinder.findRuns(runs_str)
Note this will separate with
, rather than
Tell me if you need any help or have more questions!
That’s really helpful, thanks! I’ll use the same format in anything I do. Does this syntax have any extensions (in any API call not just FileFinder) for skipping over all but every kth run, or applying a default grouping file when loaded, or anything like that? Also, if I make a set of runs somehow, is it possible for Mantid to generate a string like this, e.g. if I add runs individually, can it look for continuous run ranges and use the dash character in its response?
In general, I’ve so far found Mantid overall generally lacks capabilities for doing anything like this with large run ranges, but some of the individual technique APIs do offer some ability to work with run ranges. Is there any longer term plan to unify everything here?
I’m not sure about skipping run numbers. I’d like to point out that the Load algorithm can take :,± for run ranges and will group or sum these workspaces: Loading Data
Also, IntArrayProperty seem to do the reverse of what you’ve asked, so I’ll tell you if I can find something that turns run numbers into ranges. IntArrayProperty turn ranges into run numbers:
import mantid.kernel as mk