Skip to content

Commit

Permalink
Merge pull request #79 from SgmAstro/findfile
Browse files Browse the repository at this point in the history
Findfile
  • Loading branch information
michaelJwilson committed Feb 2, 2022
2 parents a7a9ffd + 925a01b commit e8334de
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions findfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import glob
import datetime
import numpy as np

from astropy.table import Table, vstack
from delta8_limits import d8_limits
Expand All @@ -26,12 +27,14 @@ def gather_cat(fpaths):
return tables


def findfile(ftype, dryrun=False, prefix='', field=None, utier='{utier}', survey='gama'):
def findfile(ftype, dryrun=False, prefix='', field=None, utier='{utier}', survey='gama', realz=0):
if dryrun:
dryrun = '_dryrun'
else:
dryrun = ''

realz = str(realz)

gold_dir = os.environ['GOLD_DIR']
rand_dir = os.environ['RANDOMS_DIR']

Expand All @@ -50,10 +53,21 @@ def findfile(ftype, dryrun=False, prefix='', field=None, utier='{utier}', survey
parts = file_types[ftype]
fpath = parts['dir'] + '{}_{}{}.fits'.format(parts['id'], parts['ftype'], dryrun)

else:
file_types = {'ddp_n8_d0': {'dir': gold_dir, 'id': f'{survey}_gold', 'ftype': 'ddp_n8_d0_{}'.format(utier)}}
else:
file_types = {'ddp_n8_d0': {'dir': gold_dir, 'id': f'{survey}_gold', 'ftype': 'ddp_n8_d0_{}'.format(utier)},\
'ddp_n8_d0_vmax': {'dir': gold_dir, 'id': f'{survey}_gold', 'ftype': 'ddp_n8_d0_{}_vmax'.format(utier)},\
'ddp_n8_d0_lumfn': {'dir': gold_dir, 'id': f'{survey}_gold', 'ftype': 'ddp_n8_d0_{}_lumfn'.format(utier)},\
'randoms': {'dir': rand_dir, 'id': 'randoms', 'ftype': realz},\
'randoms_n8': {'dir': rand_dir, 'id': 'randoms_N8', 'ftype': realz},\
'randoms_bd': {'dir': rand_dir, 'id': 'randoms_bd', 'ftype': realz},\
'randoms_ddp1': {'dir': rand_dir, 'id': 'randoms_ddp1', 'ftype': realz},\
'randoms_ddp1_n8': {'dir': rand_dir, 'id': 'randoms_ddp1_N8', 'ftype': realz},\
'randoms_ddp1_bd': {'dir': rand_dir, 'id': 'randoms_ddp1_bd', 'ftype': realz},\
'randoms_ddp1_bd_n8': {'dir': rand_dir, 'id': 'randoms_ddp1_bd_ddp_n8', 'ftype': realz},\
'randoms_bd_ddp_n8': {'dir': rand_dir, 'id': 'randoms_bd_ddp_n8', 'ftype': realz}
}

parts = file_types[ftype]

fpath = f'' + parts['dir'] + '{}_{}_{}{}.fits'.format(parts['id'], field, parts['ftype'], dryrun)

return fpath
Expand All @@ -70,8 +84,20 @@ def file_check(dryrun=None):
fpaths = [findfile(xx, dryrun=False, prefix='', field=None) for xx in supported]

for field in fields:
fpaths.append(findfile('randoms', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_n8', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_bd', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_ddp1', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_ddp1_n8', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_ddp1_bd', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_ddp1_bd_n8', dryrun=False, prefix='', field=field))
fpaths.append(findfile('randoms_bd_ddp_n8', dryrun=False, prefix='', field=field))

for ii, _ in enumerate(d8_limits):
fpaths.append(findfile('ddp_n8_d0', dryrun=False, prefix='', field=field, utier=ii))
fpaths.append(findfile('ddp_n8_d0', dryrun=False, prefix='', field=field, utier=ii))
fpaths.append(findfile('ddp_n8_d0_vmax', dryrun=False, prefix='', field=field, utier=ii))
fpaths.append(findfile('ddp_n8_d0_lumfn', dryrun=False, prefix='', field=field, utier=ii))


print('\n\n---- SUPPORTED FPATHS ----\n')

Expand All @@ -92,7 +118,7 @@ def file_check(dryrun=None):
unsupported = [x for x in all_paths if (x not in fpaths and 'dryrun' not in x)]

print('\n\n---- UNSUPPORTED FPATHS ----\n')

for fp in unsupported:
if os.path.isfile(fp):
mtime = os.path.getmtime(fp)
Expand All @@ -102,13 +128,12 @@ def file_check(dryrun=None):

print('{}\t\t{}\t{}'.format(fp.ljust(100), os.path.isfile(fp), mtime))

# print('\n\n---- Multiple fields ----\n')

print('\n\n---- Multiple fields ----\n')

# return np.all([os.path.isfile(fp) for fp in fpaths])
return ~np.all([os.path.isfile(fp) for fp in all_paths])


if __name__ == '__main__':
file_check()
failure = file_check()

print('\n\nDone.\n\n')
print('\n\nSuccess: {}\n\n'.format(~failure))

0 comments on commit e8334de

Please sign in to comment.