def _get_label(measurement_serial): return\ '-'.join("{}_{}".format(make_label(key), make_label(value)) for key, value in index_tree.as_unnested_dict( measurement_serial.parameter_set.items()))\ .replace('{', '')\ .replace('}', '')\ .replace("'", "")
def field_values(self): """...""" try: name_phenomenon = self.phenomenon.name except AttributeError: name_phenomenon = make_name(self.phenomenon, separator="-") return\ dict( circuit=OrderedDict(( ("animal", self.provenance_model.animal), ("age", self.provenance_model.age), ("brain_region", self.provenance_model.brain_region), ("uri", self.provenance_model.uri), ("references", self.references), ("date_release", self.provenance_model.date_release), ("authors", '; '.join( "{}. {}".format(i+1, a) for i, a in enumerate(self.provenance_model.authors))))), author=self.author, phenomenon=name_phenomenon, label=make_label(self.label, separator='-'), title=make_name(self.label, separator='-'), abstract=self.abstract, introduction=self.introduction, methods=self.methods, results=self.results, content=self.content, discussion=self.discussion)
def get_output_location(self, report, path_output_folder=None, output_subfolder=None, with_time_stamp=True): """ Where should the report be saved. Create the folder if it does not exist. """ path_parent =\ path_output_folder if path_output_folder\ else self.path_output_folder if not os.path.exists(path_parent): os.makedirs(path_parent) path_report_folder =\ os.path.join( path_parent, make_label(report.label)) if with_time_stamp: if isinstance(with_time_stamp, str): path_report_folder =\ os.path.join( path_report_folder, with_time_stamp) else: daytime =\ timestamp() path_report_folder =\ os.path.join( path_report_folder, daytime.day, daytime.time) if output_subfolder is not None: path_report_folder =\ os.path.join( path_report_folder, output_subfolder) if not os.path.exists(path_report_folder): os.makedirs(path_report_folder) return path_report_folder
class DocElem(WithFields, AIBase): """...""" title = Field(""" Title of this document element. """) label = LambdaField( """ A single word tag for this document element. """, lambda self: make_label(self.title)) @field def parent(self): """ Parent `DocElem` that contains this one. """ raise FieldIsRequired @field def children(self): """ A sequence of `DocElem`s that are contained in this one. """ return tuple() def save(self, record, path): """Save this `DocElem`""" try: save_super = super().save except AttributeError: return path return save_super(record, Path(path).joinpath(self.label)) def __call__(self, adapter, model, *args, **kwargs): """...""" try: get_record = super().__call__ except AttributeError: return Record(title=self.title, label=self.label) return get_record(adapter, model, *args, **kwargs).assign(title=self.title, label=self.label)
def label(self): """ A single word label. """ return make_label(self.title)
def _get_label(x): try: return x.label except AttributeError: return make_label(x) return None
def test_post(): """ Reporter should be able to post a report with sections. """ provenance =\ CircuitProvenance( label="Test", authors=3*[Author.anonymous], date_release="XXXXXXXX", uri="UnknownLocation", animal="UnkownAnimal", age="UnknownAge", brain_region="UnknownBrainArea") def _section(label, subsections=NA): """ Each section will generate it's own 'CircuitAnalysisReport` instance, just as we will implement `Report.sections` as a list of independent reports. """ figure, axes =\ golden_figure(14, 12) xs = np.linspace(0., 1., 100) ys = np.cumsum(np.random.uniform(size=100)) measurement =\ pd.DataFrame({"x": xs, "y": ys}).set_index(["x"]) plt.plot(xs, ys) return\ CircuitAnalysisReport( author=Author.anonymous, phenomenon="{}".format(label), abstract=""" Abstract {} """.format(label), introduction=""" Introduce {} """.format(label), methods=""" Methods {} """.format(label), measurement=measurement, figures={ "random_walk_{}".format(label): Figure( figure, caption=""" Each random walk step size is uniformly drawn from [0, 1). The individual steps are added up cummulatively to obtain the location of the walk at a given time. """.format(label))}, results=""" Results {} """.format(label), discussion=""" Discussion {} """.format(label), references={"{}".format(label): "https://www.example.org/{}".format(label)}, sections=subsections, provenance_model=provenance) report_main =\ CircuitAnalysisReport( author=Author.anonymous, phenomenon="Composition", abstract="Main abstract", introduction="Main introduction", methods="Main methods", sections=[_section(make_label(phenomenon, separator='-')) for phenomenon in ("Cell Density by Layer", "Inhibitory Fractions by Layer", "Mtype Cell Density by Layer", "Fiber Density by Layer", "Marker Density by Cortical Depth", "Cell Density by Cortical Depth")], results="Main results", discussion="Main discussion", references={"main": "https://www.example.org"}, provenance_model=provenance) reporter =\ CheetahReporter( path_output_folder=os.path.join(os.getcwd(), "random_walks")) path_report =\ reporter.post(report_main) return\ Record( provenance=provenance, report=report_main, reporter=reporter, path_report=path_report)