macaodha / batdetect2

Other
48 stars 9 forks source link

Pass time expansion factor in API #9

Closed Jeff37 closed 1 year ago

Jeff37 commented 1 year ago

This question is pretty much the same as in issue #5 but for script integration to call the batdetect2 python API. Can I pass a time expansion factor argument to process_file function?

Process a whole file

results = api.process_file(AUDIO_FILE)

My attempts did not work, however I can add time_exp_fact argument in

audio = api.load_audio(AUDIO_FILE, time_exp_fact = 10)

I believe it makes sense to add this argument in process_file() or should I work differently? Thx!

mbsantiago commented 1 year ago

Hi @Jeff37. I agree it is confusing that the process_* and load_audio functions have a different interfaces. Since the process_* functions take in so many parameters we decided to group them together into a singe dict argument called config. The load_audio function does not have this issue, thus we went with the more explicit approach of adding each as a named keyword argument. There might be a refactor of this down the line but for now I'll add better documentation on how to use the config parameter. If you want to use a different config I suggest you do the following:

config = api.get_config(
    time_expansion=10,
    # other things you might want to change about the config
)
results = api.process_file(AUDIO_FILE, config=config)

There is also a bit of inconsistency in the naming of the time expansion factor. time_expansion is used in the process_* functions but the load_audio function uses time_exp_fact, and time_expansion_factor in the CLI. Will also refactor this soon.

Hope this snippet helps. I'll also add the docs soon. Let me know if you have any other questions.

Jeff37 commented 1 year ago

Thx @mbsantiago for the snippet. This is indeed changing the result of api.process_file(). I'm slowly getting inside of the code...