Last active
November 29, 2020 02:35
-
-
Save chrisroat/e7bdf5f8f2a478da4a9fc14792b443ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datajoint as dj | |
schema = dj.schema('test_aggr') | |
# An acquisition has several rounds that come in independently over days. | |
# The preprocessing and processing can proceed independently for each round. | |
# But there is an analysis done once all preprocessing is done, and | |
# another analysis done once all processing is done. | |
# This can be accomplished, in a brittle manner, by creating artificial | |
# <Stage>Done entities by manually specifying the primary key. | |
@schema | |
class Acquisition(dj.Manual): | |
definition = """ | |
name: varchar(30) | |
--- | |
num_rounds: int | |
""" | |
@schema | |
class AcquisitionRound(dj.Manual): | |
definition = """ | |
-> Acquisition | |
round: int | |
""" | |
@schema | |
class PreprocessParams(dj.Manual): | |
definition = """ | |
preprocess_params: varchar(30) | |
""" | |
@schema | |
class PreprocessRound(dj.Computed): | |
definition = """ | |
-> AcquisitionRound | |
-> PreprocessParams | |
""" | |
def make(self, key): | |
self.insert1(key) | |
@schema | |
class PreprocessDone(dj.Computed): | |
# Brittle entity that needs to "know" all upstream *Params | |
# Can this be done via an aggregating over the "round" piece | |
# of the PreprocessRound primary key? | |
definition = """ | |
-> Acquisition | |
-> PreprocessParams | |
""" | |
class PreprocessDoneRound(dj.Part): | |
definition = """ | |
-> PreprocessDone | |
-> PreprocessRound | |
""" | |
def make(self, key): | |
num_acq = (Acquisition & key).fetch1('num_rounds') | |
rnds = (PreprocessRound & key).fetch('round') | |
if num_acq == len(rnds): | |
self.insert1(key) | |
self.PreprocessDoneRound.insert([{**key, 'round': r} for r in rnds]) | |
@schema | |
class PreprocessAnalysis(dj.Computed): | |
definition = """ | |
-> PreprocessDone | |
""" | |
def make(self, key): | |
self.insert1(key) | |
@schema | |
class ProcessParams(dj.Manual): | |
definition = """ | |
process_params: varchar(30) | |
""" | |
@schema | |
class ProcessRound(dj.Computed): | |
definition = """ | |
-> PreprocessRound | |
-> ProcessParams | |
""" | |
def make(self, key): | |
self.insert1(key) | |
@schema | |
class ProcessDone(dj.Computed): | |
# Brittle entity that needs to "know" all upstream *Params | |
# Can this be done via an aggregating over the "round" piece | |
# of the ProcessRound primary key? | |
definition = """ | |
-> Acquisition | |
-> PreprocessParams | |
-> ProcessParams | |
""" | |
class ProcessDoneRound(dj.Part): | |
definition = """ | |
-> ProcessDone | |
-> ProcessRound | |
""" | |
def make(self, key): | |
num_acq = (Acquisition & key).fetch1('num_rounds') | |
rnds = (ProcessRound & key).fetch('round') | |
if num_acq == len(rnds): | |
self.insert1(key) | |
self.ProcessDoneRound.insert([{**key, 'round': r} for r in rnds]) | |
@schema | |
class ProcessAnalysis(dj.Computed): | |
definition = """ | |
-> ProcessDone | |
""" | |
def make(self, key): | |
self.insert1(key) | |
num_rounds = 5 | |
Acquisition.insert1({'name': 'foo', 'num_rounds': num_rounds}) | |
AcquisitionRound.insert([{'name': 'foo', 'round': r} for r in range(num_rounds)]) | |
PreprocessParams.insert1({'preprocess_params': 'bar'}) | |
ProcessParams.insert1({'process_params': 'baz'}) | |
PreprocessRound.populate() | |
PreprocessDone.populate() | |
PreprocessAnalysis.populate() | |
ProcessRound.populate() | |
ProcessDone.populate() | |
ProcessAnalysis.populate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment