Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the hardcoded propID variable to version dependent propID. #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions opsimsummary/opsim_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _get_propIDs(tableNames, engine, opsimversion, subset,

Parameters
----------
tableNames :
tableNames :

engine :

Expand All @@ -529,7 +529,7 @@ def _get_propIDs(tableNames, engine, opsimversion, subset,
propDict = OpSimOutput.get_propIDDict(proposals, opsimversion=opsimversion)

# Seq of propIDs consistent with subset
_propIDs = OpSimOutput.propIDVals(subset, propDict, proposals)
_propIDs = OpSimOutput.get_propIDVals(subset, proposals, opsimversion)

# If propIDs and subset were both provided, override subset propIDs
propIDs = OpSimOutput._overrideSubsetPropID(user_propIDs, _propIDs)
Expand Down Expand Up @@ -604,7 +604,7 @@ def dropDuplicates(df, propIDDict, opsimversion):
@classmethod
def _fromOpSimHDF(cls, hdfName, subset='combined',
tableNames=('Summary', 'Proposal'),
propIDs=None):
propIDs=None, opsimversion='lsstv4'):
"""
Construct an instance of a subset of the OpSim
Output from a serialization in the format of hdf
Expand Down Expand Up @@ -637,7 +637,8 @@ def _fromOpSimHDF(cls, hdfName, subset='combined',
propDict = cls.get_propIDDict(proposal)
print('read in proposal')
print(subset, propDict)
_propIDs = cls.propIDVals(subset, propDict, proposals)
_propIDs = cls.get_propIDVals(subset, proposals, opsimversion)
# _propIDs = cls.propIDVals(subset, propDict, proposals)
except:
print('Proposal not read')
pass
Expand Down Expand Up @@ -676,7 +677,7 @@ def propIds(self):
if self._propID is not None:
return self._propID
elif self.subset is not None and self.propIDDict is not None:
return self.propIDVals(self.subset, self.propIDDict, self.proposalTable)
return self.get_propIDVals(self.subset, self.proposalTable, self.opsimVars)

def _writeOpSimHDF(self, hdfName):
"""
Expand Down Expand Up @@ -809,6 +810,51 @@ def get_opsimVariablesForVersion(opsimversion='lsstv3'):
raise NotImplementedError('`get_propIDDict` is not implemented for this `opsimversion`')
return x

@staticmethod
def get_propIDVals(subset, proposalTable, opsimversion):
"""
Parameters
----------
subset : string
{'wfd'|'ddf'|'combined'|'_all'|'unique_all'}
proposalTable : `pd.DataFrame`
representation of the proposal table
opsimversion : string
The version of a supported OpSim version. Must be one
of {'lsstv3'|'lsstv4'|'sstf'}

Returns
-------
List of propId Values corresponding to the chosen subset
"""
if subset is None:
raise ValueError('subset arg in propIDVals cannot be None')

_opsimvars = OpSimOutput.get_opsimVariablesForVersion(opsimversion)
_propIDName = _opsimvars['propIDName']

if subset.lower() in ('ddf', 'wfd'):
x = [propIDDict[subset.lower()]]
elif subset.lower() == 'combined':
x = [propIDDict['ddf'], propIDDict['wfd']]
elif subset.lower() in ('_all', 'unique_all'):
if proposalTable is not None:
x = proposalTable[_propIDName].values
else:
return None
else:
raise NotImplementedError('value of subset Not recognized')

# unroll lists
l = list()
for elem in x:
if isinstance(elem, collections.Iterable):
for e in elem:
l.append(e)
else:
l.append(elem)
return l

@staticmethod
def propIDVals(subset, propIDDict, proposalTable):
"""
Expand All @@ -827,6 +873,7 @@ def propIDVals(subset, propIDDict, proposalTable):
-------
list of propID values (integers) associated with the subset
"""
print("This static method propIDVals is DEPRECATED")
if subset is None:
raise ValueError('subset arg in propIDVals cannot be None')

Expand Down
2 changes: 1 addition & 1 deletion opsimsummary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = "1.25.0"
__VERSION__ = "1.25.2"