Skip to content

Commit 62d628d

Browse files
authored
Merge pull request #31 from andycasey/main
Add component_default special function for mwmVisit/mwmStar products
2 parents 950538a + bcaeade commit 62d628d

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

python/sdss_access/path/path.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ def extract(self, name, example):
334334
template = re.sub('@pad_fieldid[|]', '{fieldid}', template)
335335
if re.search('@plateid6[|]', template):
336336
template = re.sub('@plateid6[|]', '{plateid:0>6}', template)
337+
if re.search('@component_default[|]', template):
338+
template = re.sub('@component_default[|]', '{component_default}', template)
339+
if re.search('@catalogid_groups[|]', template):
340+
template = re.sub('@catalogid_groups[|]', '{catalogid_groups}', template)
337341

338342
# check if template has any brackets
339343
haskwargs = re.search('[{}]', template)
@@ -1215,6 +1219,59 @@ def healpixgrp(self, filetype, **kwargs):
12151219
subdir = "{:d}".format(healpix // 1000)
12161220
return subdir
12171221

1222+
def catalogid_groups(self, filetype, **kwargs):
1223+
'''
1224+
Return a folder structure to group data together based on their catalog
1225+
identifier so that we don't have too many files in any one folder.
1226+
1227+
Parameters
1228+
----------
1229+
filetype : str
1230+
File type parameter.
1231+
catalogid : int or str
1232+
SDSS-V catalog identifier
1233+
1234+
Returns
1235+
-------
1236+
catalogid_group : str
1237+
A set of folders.
1238+
'''
1239+
catalogid = int(kwargs['catalogid'])
1240+
return f"{catalogid % 10000:.0f}/{catalogid % 100:.0f}"
1241+
1242+
def component_default(self, filetype, **kwargs):
1243+
''' Return the component name, if given.
1244+
1245+
The component designates a stellar or planetary body following the
1246+
Washington Multiplicity Catalog, which was adopted by the XXIV meeting
1247+
of the International Astronomical Union. When no component is given,
1248+
the star is assumed to be without a discernible companion. When a
1249+
component is given it follows the system (Hessman et al., arXiv:1012.0707):
1250+
1251+
– the brightest component is called “A”, whether it is initially resolved
1252+
into sub-components or not;
1253+
– subsequent distinct components not contained within “A” are labeled “B”,
1254+
“C”, etc.;
1255+
– sub-components are designated by the concatenation of on or more suffixes
1256+
with the primary label, starting with lowercase letters for the 2nd
1257+
hierarchical level and then with numbers for the 3rd.
1258+
1259+
Parameters
1260+
----------
1261+
filetype : str
1262+
File type parameter. This argument is not used here, but is required for
1263+
all special functions in the `sdss_access` product.
1264+
component : str [optional]
1265+
The component name as given by the fields.
1266+
1267+
Returns
1268+
-------
1269+
component : str
1270+
The component name if given, otherwise a blank string.
1271+
'''
1272+
# the (..) or '' resolves None to ''
1273+
return str(kwargs.get('component', '') or '')
1274+
12181275
def apgprefix(self, filetype, **kwargs):
12191276
''' Returns APOGEE prefix using telescope/instrument.
12201277

tests/path/test_path.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ def test_healpixgrp(self, path, key, val, exp):
9797
out = path.healpixgrp('', **{key: val})
9898
assert out == exp
9999

100+
@pytest.mark.parametrize('key, val, exp',
101+
[('catalogid', '213948712937684123', '123/23'),
102+
('catalogid', 213948712937684123, '123/23')])
103+
def test_catalogid_groups(self, path, key, val, exp):
104+
out = path.catalogid_groups('', **{key: val})
105+
assert out == exp
106+
107+
108+
@pytest.mark.parametrize('key, val, exp',
109+
[('component', None, ''),
110+
('component', 'A', 'A'),
111+
('component', 'B', 'B'),
112+
('component', 'Ca', 'Ca'),
113+
# If component not given, return ''
114+
('some_other_kwd', 'any_value', ''),
115+
# This convention is against WMC, but the path
116+
# definition will be forgiving and resolve to string.
117+
('component', 1, '1'),
118+
('component', 0, '0')])
119+
def test_component_default(self, path, key, val, exp):
120+
out = path.component_default('', **{key: val})
121+
assert out == exp
122+
100123
def test_envvar_expansion(self, path):
101124
name = 'mangacube'
102125
assert '$MANGA_SPECTRO_REDUX' in path.templates[name]

0 commit comments

Comments
 (0)