Beispiel #1
0
    def start(self, doc):
        doc = dict(doc)
        doc["analysis_stage"] = "meta"
        super().start(doc)
        self.filenames = [
            pfmt.format(self.start_template, base_folder=bf).replace(".", ",")
            for bf in self.base_folders
        ]

        for filename in self.filenames:
            fn = clean_template(pfmt.format(filename, ext=".yaml"))
            print(f"Saving file to {fn}")
            os.makedirs(os.path.dirname(fn), exist_ok=True)
            dump_yml(fn, doc)
Beispiel #2
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for two_d_var in [
                k for k, v in self.dep_shapes.items() if len(v) == 2
        ]:
            for filename in self.filenames:
                fit2d_save(
                    np.flipud(doc["data"][two_d_var]),
                    clean_template(pfmt.format(filename, ext="")),
                )
                np.save(
                    clean_template(pfmt.format(filename, ext="_mask.npy")),
                    doc["data"][two_d_var],
                )
Beispiel #3
0
    def descriptor(self, doc):
        self.in_dep_shapes = {
            n: doc["data_keys"][n]["shape"]
            for n in self.dim_names
        }
        self.dep_shapes = {
            n: doc["data_keys"][n]["shape"]
            for n in set(self.dim_names) ^ set(doc["data_keys"])
        }

        # Use independent vars to create the filename
        independent_var_string = "_"
        for dim in sorted(self.dim_names):
            # Only use scalar data in filenames
            if len(self.in_dep_shapes[dim]) == 0:
                independent_var_string += "{name}_{data}_{units}_".format(
                    name=dim,
                    data=
                    f"{{event[data][{dim}]:1.{doc['data_keys'][dim]['precision']}f}}",
                    # TODO: fill in the sig figs
                    units=f"{doc['data_keys'][dim].get('units', 'arb')}",
                )

        self.descriptor_templates[doc["uid"]] = pfmt.format(
            self.start_template,
            descriptor=doc,
            __independent_vars__=independent_var_string,
        )

        return super().descriptor(doc)
Beispiel #4
0
    def event(self, doc):
        doc = super().event(doc)

        for filename in self.filenames:
            doc["data"]["calibration"].save(
                clean_template(pfmt.format(filename, ext=".poni"))
            )
Beispiel #5
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for two_d_var in [
            k for k, v in self.dep_shapes.items() if len(v) == 2
        ]:
            for filename in self.filenames:
                fit2d_save(
                    np.flipud(doc["data"][two_d_var]),
                    clean_template(pfmt.format(filename, ext="")),
                )
                np.save(
                    clean_template(pfmt.format(filename, ext="_mask.npy")),
                    doc["data"][two_d_var],
                )
Beispiel #6
0
    def descriptor(self, doc):
        self.in_dep_shapes = {
            n: doc["data_keys"][n]["shape"] for n in self.dim_names
        }
        self.dep_shapes = {
            n: doc["data_keys"][n]["shape"]
            for n in set(self.dim_names) ^ set(doc["data_keys"])
        }

        # Use independent vars to create the filename
        independent_var_string = "_"
        for dim in sorted(self.dim_names):
            # Only use scalar data in filenames
            if len(self.in_dep_shapes[dim]) == 0:
                independent_var_string += "{name}_{data}_{units}_".format(
                    name=dim,
                    data=f"{{event[data][{dim}]:1.{doc['data_keys'][dim]['precision']}f}}",
                    # TODO: fill in the sig figs
                    units=f"{doc['data_keys'][dim].get('units', 'arb')}",
                )

        self.descriptor_templates[doc["uid"]] = pfmt.format(
            self.start_template,
            descriptor=doc,
            __independent_vars__=independent_var_string,
        )

        return super().descriptor(doc)
Beispiel #7
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for two_d_var in [
                k for k, v in self.dep_shapes.items() if len(v) == 2
        ]:
            for filename in self.filenames:
                imsave(
                    clean_template(
                        pfmt.format(filename, ext=f"_{two_d_var}.tiff")),
                    doc["data"][two_d_var],
                )
Beispiel #8
0
 def event(self, doc):
     self.filenames = [
         pfmt.format(
             self.descriptor_templates[doc["descriptor"]],
             event=doc,
             base_folder=bf,
         ).replace(".", ",").replace("__", "_") for bf in self.base_folders
     ]
     # Note that formally there are more steps to the formatting, but we
     #  should have the folder by now
     for filename in self.filenames:
         print(f"Saving file to {filename}")
         os.makedirs(os.path.dirname(filename), exist_ok=True)
     return super().event(doc)
Beispiel #9
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for two_d_var in [
            k for k, v in self.dep_shapes.items() if len(v) == 2
        ]:
            for filename in self.filenames:
                imsave(
                    clean_template(
                        pfmt.format(filename, ext=f"_{two_d_var}.tiff")
                    ),
                    doc["data"][two_d_var],
                )
Beispiel #10
0
 def event(self, doc):
     self.filenames = [
         pfmt.format(
             self.descriptor_templates[doc["descriptor"]],
             event=doc,
             base_folder=bf,
         )
         .replace(".", ",")
         .replace("__", "_")
         for bf in self.base_folders
     ]
     # Note that formally there are more steps to the formatting, but we
     #  should have the folder by now
     for filename in self.filenames:
         print(f"Saving file to {filename}")
         os.makedirs(os.path.dirname(filename), exist_ok=True)
     return super().event(doc)
Beispiel #11
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for one_d_ind_var in [
            k for k, v in self.in_dep_shapes.items() if len(v) == 1
        ]:
            for one_d_dep_var in [
                k for k, v in self.dep_shapes.items() if len(v) == 1
            ]:
                for filename in self.filenames:
                    pdf_saver(
                        doc["data"][one_d_ind_var],
                        doc["data"][one_d_dep_var],
                        doc["data"]["config"],
                        clean_template(
                            pfmt.format(filename, ext=f".{one_d_dep_var}")
                        ),
                    )
Beispiel #12
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for one_d_ind_var in [
            k for k, v in self.in_dep_shapes.items() if len(v) == 1
        ]:
            for one_d_dep_var in [
                k for k, v in self.dep_shapes.items() if len(v) == 1
            ]:
                for filename in self.filenames:
                    save_output(
                        doc["data"][one_d_ind_var],
                        doc["data"][one_d_dep_var],
                        clean_template(
                            pfmt.format(
                                filename,
                                ext=f"_{one_d_dep_var}_{one_d_ind_var}",
                            )
                        ),
                        {"tth": "2theta", "q": "Q"}.get(one_d_ind_var),
                    )
Beispiel #13
0
    def event(self, doc):
        # fill the document
        doc = super().event(doc)

        for one_d_ind_var in [
                k for k, v in self.in_dep_shapes.items() if len(v) == 1
        ]:
            for one_d_dep_var in [
                    k for k, v in self.dep_shapes.items() if len(v) == 1
            ]:
                for filename in self.filenames:
                    save_output(
                        doc["data"][one_d_ind_var],
                        doc["data"][one_d_dep_var],
                        clean_template(
                            pfmt.format(
                                filename,
                                ext=f"_{one_d_dep_var}_{one_d_ind_var}",
                            )),
                        {
                            "tth": "2theta",
                            "q": "Q"
                        }.get(one_d_ind_var),
                    )