Testing Filters

Let’s run a simple HelloWorld filter:

class HelloWorld(dk.Filter):
    OUTPUT_TAGS = [
        {
            'name': 'hello_world',
            'description': 'hello!',
        },
    ]

    def run(self, locus):
        print('Hello Locus ', locus.locus_id)
        locus.tag('hello_world')

Run the filter on a randomly chosen real Locus from the database:

run_filter(f, locus=None, verbose=False)

Test a Filter.

Parameters
  • f – Filter object or class

  • locus – LocusDataAPI, locus_id, or None

  • verbose – if True, print detailed log

eg:

# Execute HelloWorld filter on a random locus
report = dk.run_filter(HelloWorld)

# `run_filter()` returns a report of what the filter did. Take a look at it:
print(report)

Run the filter on multiple Loci:

run_many(f, locus_ids=None, n=100, verbose=False, keep_results=True)

Run a filter on many Loci.

Locus IDs may be passed in as locus_ids or will be chosen randomly.

Response format:

{
  'n': <number of times filter ran>
  'results': <dict mapping alert id to result of run_filter()>
  't_50_percentile': <50th percentile of filter execution time>
  't_90_percentile': <90th percentile of filter execution time>
  't_95_percentile': <95th percentile of filter execution time>
  't_99_percentile': <99th percentile of filter execution time>
}
Parameters
  • f – Python Filter object or class

  • locus_ids – list of locus_id, or None

  • n – if locus_ids is None, this many random Locus IDs will be used.

  • verbose

  • keep_results – if False, results are discarded and not returned

Returns

dict

eg:

report = run_many(HelloWorld, n=100)

Constructing Locus Objects

You can construct your own Locus objects for testing:

import antares.devkit as dk

ra, dec = 88.2744186, -5.0010774
locus_dict = {
    'locus_id': 'locus1',
    'ra': ra,
    'dec': dec,
    'properties': {
        'num_alerts': 2,
        'num_mag_values': 2,
    },
    'tags': [],
    'watch_list_ids': [],
    'watch_object_ids': [],
    'catalog_objects': dk.search_catalogs(ra, dec),
    'alerts': [
        {
            'alert_id': 'alert1',
            'locus_id': 'locus1',
            'mjd': 58794.272488399874,
            'properties': {
                'ant_mag': 15.1,
            },
        },
        {
            'alert_id': 'alert2',
            'locus_id': 'locus1',
            'mjd': 58799.50587960007,
            'properties': {
                'ant_mag': 15.2,
            }
        },
    ],
}

locus = dk.locus_from_dict(locus_dict)

dk.run_filter(HelloWorld, locus)