-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgather_images.py
More file actions
45 lines (31 loc) · 1.57 KB
/
gather_images.py
File metadata and controls
45 lines (31 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pathlib import Path
from shutil import copy
import pickle
import os
"""Sort the output of pacs_model_batch.py into succeeded/failed/unresolved folders."""
#succeeded: PSF subtraction not consistent with noise but model residuals are
#failed: PSF subtraction and model residuals both inconsistent with noise
#unresolved: PSF subtraction consistent with noise (no disc fit performed)
rootdir = '../batch_results/'
#first make sure the required folders exist
for dir in ['succeeded', 'failed']:
for subdir in ['images', 'chains', 'corner']:
os.makedirs(f'{rootdir}/sorted/{dir}/{subdir}/', exist_ok = True)
os.makedirs(f'{rootdir}/sorted/unresolved/images/', exist_ok = True)
for path in Path(rootdir).rglob('*params.pickle'):
full_path = path.resolve()
print(full_path)
with open(str(full_path), 'rb') as input:
dict = pickle.load(input)
name = full_path.parents[0].name
obsid = full_path.parents[1].name
imgname = full_path.parents[0] / 'image_model.png'
chainsname = full_path.parents[0] / 'chains.pdf'
cornername = full_path.parents[0] / 'corner.pdf'
if dict['resolved']:
subdir = 'succeeded' if dict['model_consistent'] else 'failed'
copy(imgname, f'{rootdir}/sorted/{subdir}/images/{obsid} - {name}.png')
copy(chainsname, f'{rootdir}/sorted/{subdir}/chains/{obsid} - {name}.pdf')
copy(cornername, f'{rootdir}/sorted/{subdir}/corner/{obsid} - {name}.pdf')
else:
copy(imgname, f'{rootdir}/sorted/unresolved/images/{obsid} - {name}.png')