util

Small utility functions for the ouscope library.
scope=Telescope(config='~/.config/telescope.ini')

source

Telescope.get_object_obs

 Telescope.get_object_obs (obj:str)

Find all jobs for a given object.

reqlst=scope.get_user_requests(sort='completion')
complete = [rq for rq in sorted(reqlst, key=lambda r: int(r['requesttime']), reverse=True) 
                        if Telescope.REQUESTSTATUS_TEXTS[int(rq['status'])]=='Complete']
# Get all observations of VS
VS = 'BI Her'
jlist = sorted(list(scope.get_object_obs(VS)))
print(f'Completed observations of {VS}: {len(jlist)}')

for jid, rid in tqdm(jlist):
    # print(f"R{rid}:J{jid}")
    try :
        data = scope.get_obs(scope.get_job(jid), cube=True, verbose=False)
        if data :
            fp = f'VS/{"_".join(VS.split())}'
            os.makedirs(fp, exist_ok=True)
            fn = f'{jid}'
            try :
                # print(os.path.abspath(data.name), f'{fp}/{fn}.fits')
                os.symlink(os.path.abspath(data.name), f'{fp}/{fn}.fits')
            except FileExistsError:
                pass
            # with open(f'/home/jochym/Astro/VS/{"_".join(VS.split())}/{jid}.fits', 'wb') as ff:
            #     ff.write(data.read())
        else :
            print(f'Download of J{jid} failed (no data)')
    except TimeoutError:
        print(f'Download of J{jid} failed (timeout)')
        continue
Number of users requests: 1849
Completed: 1821
Completed observations of BI Her: 192
# get all completed jobs
for rq in (pbar := tqdm(complete[:25])):
    name = rq['objectname']
    rid = int(rq['id'])
    pbar.set_postfix_str(name)
    try:
        jid = int(scope.get_request(rid)['jid'])
        data = scope.get_obs(scope.get_job(jid), cube=True, verbose=False)
        if data :
            fp = f'VS/{"_".join(name.split())}'
            os.makedirs(fp, exist_ok=True)
            fn = f'{jid}'
            try :
                os.symlink(os.path.abspath(data.name), f'{fp}/{fn}.fits')
            except FileExistsError:
                pass
        else :
            print(f'Download of J{jid} failed')
    except TimeoutError :
        print(f'Download of J{jid} failed, timeout')
        pass