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

Issue 219 no2 #240

Open
wants to merge 3 commits 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
65 changes: 56 additions & 9 deletions gammacat/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,44 @@ def get_reference_id(self):

For now, we always use the last one listed.
"""
return self.reference_ids[-1]
if (len(self.reference_ids) == 0):
return None
else:
return self.reference_ids[-1]

class SEDConfigSource:

def __init__(self, data):
self.data = data

def get_catalog_reference_id(self):
return self.data['catalog']['reference_id']

def get_catalog_file_id(self):
return self.data['catalog']['file_id']

class SEDConfig:
schema = load_yaml(gammacat_info.base_dir / 'input/schemas/gamma_cat_sed.schema.yaml')

def __init__(self, data, path):
self.data = data
self.path = path

@classmethod
def read(cls):
path = gammacat_info.base_dir / 'input/gammacat/gamma_cat_sed.yaml'
data = load_yaml(path)
return cls(data=data, path=path)

@property
def source_ids(self):
return [_['source_id'] for _ in self.data]

def get_source_by_id(self, source_id):
idx = self.source_ids.index(source_id)
return SEDConfigSource(data=self.data[idx])

#TODO: Add validate function for gamma_cat_sed.yaml

class DatasetConfig:
"""
Expand Down Expand Up @@ -542,7 +578,6 @@ def __init__(self, *, out_path, source_ids):
self.out_path = out_path
self.source_ids = source_ids


class CatalogMaker:
"""Make gamma-cat source catalog (from the data collection)."""

Expand Down Expand Up @@ -572,7 +607,7 @@ def run(self):
def read_source_data(self, source_ids):
"""Gather data into Python data structures."""
input_data = InputData.read()

# TODO: find a better way to load this
resource_index = GammaCatResourceIndex.from_list(
load_json(self.config.out_path / 'gammacat-datasets.json')
Expand All @@ -582,15 +617,27 @@ def read_source_data(self, source_ids):
for source_id in source_ids:
basic_source_info = input_data.sources.get_source_by_id(source_id)
log.info('Processing : {}'.format(basic_source_info))
try:
config = input_data.gammacat_dataset_config.get_source_by_id(source_id)
reference_id = config.get_reference_id()
except IndexError:
reference_id = None
reference_id_dataset = DatasetConfig.read().get_source_by_id(source_id).get_reference_id()
reference_id_sed = SEDConfig.read().get_source_by_id(source_id).get_catalog_reference_id()
if (reference_id_sed == None):
sed = SED(table=Table(), resource=None)
else:
file_id_sed = SEDConfig.read().get_source_by_id(source_id).get_catalog_file_id()
if (file_id_sed == -1):
query = 'type == "sed" and source_id == {} and reference_id == {!r}'.format(source_id, reference_id_sed)
ri = resource_index.query(query)
print(ri.resources[0])
filename = ri.resources[0].location
sed = SED.read(filename=filename)
else:
query = 'type == "sed" and source_id == {} and reference_id == {!r} and file_id == {}'.format(source_id, reference_id_sed, file_id_sed)
ri = resource_index.query(query)
filename = ri.resources[0].location
sed = SED.read(filename=filename)

# TODO: right now this implies, that a GammaCatSource object can only
# handle the information from one dataset, maybe this should be changed
dataset = input_data.datasets.get_dataset_by_reference_id(reference_id)
dataset = input_data.datasets.get_dataset_by_reference_id(reference_id_dataset)
dataset_source_info = dataset.get_source_by_id(source_id)

query = 'type == "sed" and source_id == {} and reference_id == {!r}'.format(source_id, reference_id)
Expand Down
Loading