I'm writing a function for region growing on an irregular grid: Start in a seed bin, find the neighboring bins, and include them in the set of returned bin indices if a certain requirement is fulfilled. I would like for the requirement to be arbitrary, e.g., '> 2', '>= 2', '== 2', etc.. So the syntax would be:
myregion = get_region(bin_coordinates, bin_values, seed_bin, '> 2')
and the region of neighboring bins, whose values are greater than 2 will be returned.
Essentially I'm looking for the same functionality as in the pandas library, where the following is possible when querying a HDF store:
store.select('dfq',where="A>0 or C>0")
I could of course write some sort of parser with if/else statements to translate '> 2' into code, but I was wondering if there is a more elegant way?