AlanLoh / nenupy

NenuFAR python package
MIT License
10 stars 6 forks source link

New methods for scheduling #69

Closed louisbondonneau closed 5 months ago

louisbondonneau commented 8 months ago

After creating an optimized schedule with Nenupy and the genetic algorithm I still have gaps between my observation blocks. It would be great to have a method for extending the blocks on what is observable... (I MP you a nootbook for example on Slack)

Capture d’écran 2024-03-08 à 10 26 19
AlanLoh commented 7 months ago

Hey Louis,

Great suggestion -as we have already discussed in private-. I've added a new method Schedule.extend_scheduled_observations() to extend the scheduled observation blocks.

There is also a new argument ObsBlock(..., max_extended_duration=<dt>) if it is set to None (default), nothing is done. But if you give a duration, the algorithm will automatically try to increase the block duration.

As always, it's not bug-free guaranteed, so tell me if it suits your needs and if you see anything that should be corrected.

Here is a simple example:

from nenupy.schedule import (
    Schedule,
    ObsBlock,
    ESTarget,
    Constraints,
    ElevationCnst,
)
from astropy.time import Time, TimeDelta
import astropy.units as u

schedule = Schedule(
    time_min=Time('2024-04-10 00:00:00'),
    time_max=Time('2024-04-12 00:00:00'),
    dt=TimeDelta(10*60, format='sec')
)

schedule.plot(days_per_line=2, grid=False)

# Define ObsBlocks ---> note the new argument `max_extended_duration `
casa = ObsBlock(
    name='Cas A',
    program='es00',
    target=ESTarget.fromName('Vir A'),
    duration=TimeDelta(60*60, format='sec'),
    max_extended_duration=TimeDelta(5*3600, format='sec')
)
cyga = ObsBlock(
    name='Cyg A',
    program='es00',
    target=ESTarget.fromName('Cyg A'),
    duration=TimeDelta(60*60, format='sec'),
    max_extended_duration=TimeDelta(10*3600, format='sec'),
    constraints=Constraints(ElevationCnst(20))
)

my_observations = casa*2 + cyga*3

schedule.insert(my_observations)

schedule.book( optimize=False )

schedule.plot(days_per_line=2, grid=False)

schedule.extend_scheduled_observations(relative_score_threshold=0.4)

schedule.plot(days_per_line=2, grid=False)