Skip to content

Commit

Permalink
Added random selector to fitting process
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel3834 committed Oct 26, 2024
1 parent 27a744b commit 5f436e4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mop/management/commands/fit_need_events_PSPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datetime
import os
import logging
import numpy as np

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -100,6 +101,16 @@ def run_fit(mulens, cores=0, verbose=False):
logger.error('Job failed: '+mulens.name)
return False

def select_random_events(target_list, max_nevents):
"""
Function to select a random set of max_nevents from the list provided
"""
rng = np.random.default_rng()
target_list = rng.shuffle(target_list)
selected_targets = target_list[0:max_nevents]

return selected_targets

class Command(BaseCommand):
help = 'Fit events with PSPL and parallax, then ingest fit parameters in the db'

Expand Down Expand Up @@ -128,7 +139,7 @@ def handle(self, *args, **options):
+ repr(options['run_every']) + 'hrs ago')
target_list = list(set(ts))
if len(target_list) > max_nevents:
target_list = target_list[0:max_nevents]
target_list = select_random_events(target_list, max_nevents)
logger.info('FIT_NEED_EVENTS: Capped number of models to fit at ' + str(max_nevents))

utilities.checkpoint()
Expand Down

0 comments on commit 5f436e4

Please sign in to comment.