dr-rodriguez / DSII_LocalGroupDB

The Local Group Galaxy Database
4 stars 2 forks source link

Write function to generate curation #26

Open dr-rodriguez opened 4 years ago

dr-rodriguez commented 4 years ago

Given a reference, have a function that can be run to provide a curation dictionary. This would search all possible parameters for that reference and if it finds some, would write a curation dictionary containing this. Long term we may want to implement a sorted list of references, but for a first pass a single reference is enough.

The curation dictionary can then be saved in the standard way to a file and we may want to consider this as a delta applied to an existing curation, both of which can be handled by a utility function.

dr-rodriguez commented 4 years ago

@eteq This is now implemented and it was actually not too difficult to do it recursively. Currently, a single reference is used per parameter, though, which we may want to revisit.

You can use the db.generate_curation method as follows:

from galcat.core import *
db = Database(references_file='data_references.json')
# Simple case:
curation = db.generate_curation('Ref_1')
# Adding to an existing curation (ie, overwritting):
curation = db.generate_curation('Ref_2', existing_curation=curation) 
# Creating from a list:
curation = db.generate_curation(['Ref_1', 'Ref_2'])

The last case works by recursively calling itself with a reversed list, resulting in Ref_1 being prioritized over Ref_2 if any cases are found. Since only a single reference is saved per parameter this is currently somewhat limited, but can still be useful.

Curation dictionaries can be saved with the write_curation() function and read from a JSON with the hidden function _read_curation()