From 6cea8e0dcef411e7f441e820b777de72fd554d65 Mon Sep 17 00:00:00 2001 From: Sean-Morrison Date: Wed, 6 Nov 2024 12:17:43 -0600 Subject: [PATCH] restore tilegrp --- python/sdss_access/path/path.py | 36 ++++++++++++++++++++++++++++----- tests/path/test_sdss5.py | 7 +++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/python/sdss_access/path/path.py b/python/sdss_access/path/path.py index 83e67d1..3a60cc7 100644 --- a/python/sdss_access/path/path.py +++ b/python/sdss_access/path/path.py @@ -325,15 +325,15 @@ def extract(self, name, example): # handle special functions; perform a drop in replacement if re.match('@spectrodir[|]', template): template = re.sub('@spectrodir[|]', os.environ['BOSS_SPECTRO_REDUX'], template) - elif re.search('@platedir[|]', template): + if re.search('@platedir[|]', template): template = re.sub('@platedir[|]', r'(.*)/{plateid:0>6}', template) - elif re.search('@definitiondir[|]', template): + if re.search('@definitiondir[|]', template): template = re.sub('@definitiondir[|]', '{designid:0>6}', template) - elif re.search('@apgprefix[|]', template): + if re.search('@apgprefix[|]', template): template = re.sub('@apgprefix[|]', '{prefix}', template) - elif re.search('@healpixgrp[|]', template): + if re.search('@healpixgrp[|]', template): template = re.sub('@healpixgrp[|]', '{healpixgrp}', template) - elif re.search('@configgrp[|]', template): + if re.search('@configgrp[|]', template): template = re.sub('@configgrp[|]', '{configgrp}', template) if re.search('@isplate[|]', template): template = re.sub('@isplate[|]', '{isplate}', template) @@ -359,6 +359,8 @@ def extract(self, name, example): template = re.sub('@cat_id_groups[|]', '{cat_id_groups}', template) if re.search('@sdss_id_groups[|]', template): template = re.sub('@sdss_id_groups[|]', '{sdss_id_groups}', template) + if re.search('@tilegrp[|]', template): + template = re.sub('@tilegrp[|]', '{tilegrp}', template) # check if template has any brackets haskwargs = re.search('[{}]', template) @@ -1738,5 +1740,29 @@ def fieldgrp(self, filetype, **kwargs): return '{:0>3d}XXX'.format(int(fieldid) // 1000) return fieldid + def tilegrp(self, filetype, **kwargs): + ''' Returns LVM tile id group subdirectory + + Parameters + ---------- + filetype : str + File type parameter. + tileid : int or str + LVM Tile ID number. Will be converted to int internally. + + Returns + ------- + tileidgrp : str + Tile ID group directory in the format ``NNNNXX``. + + ''' + + tileid = kwargs.get('tileid', None) + if not tileid: + return '0000XX' + elif '*' in str(tileid): + return '{0}XX'.format(tileid) + return '{:0>4d}XX'.format(int(tileid) // 1000) + class AccessError(Exception): pass diff --git a/tests/path/test_sdss5.py b/tests/path/test_sdss5.py index 16d2347..baf05bd 100644 --- a/tests/path/test_sdss5.py +++ b/tests/path/test_sdss5.py @@ -70,11 +70,14 @@ def test_apogee_paths(self, path, name, special, keys, exp): ('spAll_epoch','@epochflag',{'run2d':'v6_2_0'}, 'v6_2_0/summary/epoch/spAll-v6_2_0-epoch.fits'), ('spAll_coadd','@spcoaddgrp',{'run2d':'v6_2_0','coadd':'allepoch'}, - 'v6_2_0/summary/allepoch/spAll-v6_2_0-allepoch.fits')], + 'v6_2_0/summary/allepoch/spAll-v6_2_0-allepoch.fits'), + ('lvm_frame', '@tilegrp', {'drpver': 'master', 'mjd': 60235, + 'tileid': 1055360, 'kind': 'CFrame', 'expnum': 6817}, + '1055XX/1055360/60235/lvmCFrame-00006817.fits')], ids=['configgrp', 'apgprefix-apo', 'apgprefix-lco', 'apgprefix-ins', 'isplate-v6_0_4','pad_fieldid-5','pad_fieldid-6', 'frame-pad', 'frame-nopadp', 'pad_fieldid-*','spcoaddfolder', 'sptypefolder', - 'fieldgrp','spcoaddobs','epochflag','spcoaddgrp']) + 'fieldgrp','spcoaddobs','epochflag','spcoaddgrp','lvm-tileid']) def test_special_function(self, path, name, special, keys, exp): assert special in path.templates[name] full = os.path.normpath(path.full(name, **keys))