示例#1
0
 class Meta(DataModel.Meta):
     store_id = "Project"
     file_filters = [
         ("PyXRD Project files",
          get_case_insensitive_glob("*.pyxrd", "*.zpd")),
     ]
     import_filters = [
         ("Sybilla XML files", get_case_insensitive_glob("*.xml")),
     ]
示例#2
0
 class Meta(DataModel.Meta):
     properties = [
         PropIntel(name="name",
                   label="Name",
                   data_type=unicode,
                   is_column=True,
                   storable=True,
                   has_widget=True),
         PropIntel(name="value",
                   label="Value",
                   data_type=float,
                   is_column=True,
                   storable=True,
                   has_widget=True,
                   widget_type='float_entry',
                   refinable=True),
         PropIntel(name="enabled",
                   label="Enabled",
                   data_type=bool,
                   is_column=True,
                   storable=True,
                   has_widget=True),
         PropIntel(name="driven_by_other",
                   label="Driven by other",
                   data_type=bool,
                   is_column=True,
                   storable=False,
                   has_widget=False)
     ]
     store_id = "AtomRelation"
     file_filters = [
         ("Atom relation", get_case_insensitive_glob("*.atr")),
     ]
     allowed_relations = {}
示例#3
0
 class Meta(AbstractPhase.Meta):
     store_id = "RawPatternPhase"
     file_filters = [
         ("Phase file", get_case_insensitive_glob("*.PHS")),
     ]
     rp_filters = xrd_parsers.get_import_file_filters()
     rp_export_filters = xrd_parsers.get_export_file_filters()
示例#4
0
class JSONPhaseParser(JSONParser):

    description = "Phase file *.PHS"
    extensions = get_case_insensitive_glob("*.PHS")
    mimetypes = ["application/octet-stream", "application/zip"]

    pass  #end of class
示例#5
0
class JSONGoniometerParser(JSONParser):

    description = "Goniometer file *.GON"
    extensions = get_case_insensitive_glob("*.GON")
    mimetypes = ["application/octet-stream", "application/zip"]

    pass  #end of class
示例#6
0
class JSONAtomTypeParser(JSONParser):
    """
        Atomic scattering factors JSON file parser
    """

    description = "Atom types JSON file *.ZTL"
    extensions = get_case_insensitive_glob("*.ZTL")
    mimetypes = ["application/octet-stream", "application/zip"]

    __file_mode__ = "rb"

    @classmethod
    def _parse_header(cls, filename, fp, data_objects=None, close=False):
        return data_objects # just pass it on, nothing to do

    @classmethod
    def write(cls, filename, items, props):
        """
            Saves multiple AtomTypes to a single (JSON) file.
        """
        with zipfile.ZipFile(filename, 'w', compression=COMPRESSION) as zfile:
            for i, atom_type in enumerate(items):
                zfile.writestr("%d###%s" % (i, atom_type.uuid), atom_type.dump_object())

    pass # end of class
示例#7
0
 class Meta(AbstractPhase.Meta):
     properties = [
         PropIntel(name="display_color", data_type=str, label="Display color", is_column=True, has_widget=True, widget_type='color', storable=True),
         PropIntel(name="raw_pattern", label="Raw pattern", data_type=object, is_column=True, storable=True, has_widget=True, widget_type="xy_list_view"),
     ]
     store_id = "RawPatternPhase"
     file_filters = [
         ("Phase file", get_case_insensitive_glob("*.PHS")),
     ]
     rp_filters = xrd_parsers.get_import_file_filters()
     rp_export_filters = xrd_parsers.get_export_file_filters()
示例#8
0
文件: models.py 项目: tomcat333/PyXRD
 class Meta(DataModel.Meta):
     store_id = "Atom"
     properties = [ # TODO add labels
         PropIntel(name="name", data_type=unicode, **PropIntel.ST_WID_COL),
         PropIntel(name="default_z", data_type=float, **PropIntel.ST_WID_COL),
         PropIntel(name="z", data_type=float, **PropIntel.WID_COL),
         PropIntel(name="pn", data_type=float, **PropIntel.ST_WID_COL),
         PropIntel(name="atom_type", data_type=object, **PropIntel.WID_COL),
         PropIntel(name="stretch_values", data_type=bool),
     ]
     layer_filters = [
         ("Layer file", get_case_insensitive_glob("*.lyr")),
     ]
示例#9
0
文件: phase.py 项目: Python3pkg/PyXRD
 class Meta(AbstractPhase.Meta):
     properties = [
         PropIntel(name="based_on", data_type=object, label="Based on phase", is_column=True, has_widget=True, widget_type='custom'),
         PropIntel(name="sigma_star", data_type=float, label="σ* [°]", math_label="$\sigma^*$ [°]", is_column=True, has_widget=True, storable=True, refinable=True, minimum=0.0, maximum=90.0, inh_name="inherit_sigma_star", stor_name="_sigma_star", inh_from="based_on"),
         PropIntel(name="display_color", data_type=str, label="Display color", is_column=True, has_widget=True, widget_type='color', storable=True, inh_name="inherit_display_color", stor_name="_display_color", inh_from="based_on"),
         PropIntel(name="inherit_sigma_star", data_type=bool, label="Inh. sigma star", is_column=True, has_widget=True, storable=True),
         PropIntel(name="inherit_display_color", data_type=bool, label="Inh. display color", is_column=True, has_widget=True, storable=True),
         PropIntel(name="inherit_CSDS_distribution", data_type=bool, label="Inh. mean CSDS", is_column=True, has_widget=True, storable=True),
         PropIntel(name="CSDS_distribution", data_type=object, label="CSDS Distribution", is_column=True, has_widget=True, storable=True, refinable=True, widget_type="custom", inh_name="inherit_CSDS_distribution", stor_name="_CSDS_distribution", inh_from="based_on"),
         PropIntel(name="probabilities", data_type=object, label="Probabilities", is_column=True, has_widget=True, storable=True, refinable=True, widget_type="custom"),
         PropIntel(name="components", data_type=object, label="Components", is_column=True, has_widget=True, storable=True, refinable=True, widget_type="custom", class_type=Component),
     ]
     store_id = "Phase"
     file_filters = [
         ("Phase file", get_case_insensitive_glob("*.PHS")),
     ]
示例#10
0
class JSONProjectParser(JSONParser):

    description = "Project file *.PYXRD"
    extensions = get_case_insensitive_glob("*.PYXRD")
    mimetypes = ["application/octet-stream", "application/zip"]

    @classmethod
    def _parse_data(cls, filename, fp, data_objects=None, close=True):
        project = super(JSONProjectParser,
                        cls)._parse_data(filename,
                                         fp,
                                         data_objects=data_objects,
                                         close=close)
        project.filename = filename
        return project

    pass  #end of class
示例#11
0
class SybillaProjectParser(XMLParserMixin, BaseParser):

    description = "Sybilla XML files"
    extensions = get_case_insensitive_glob("*.XML")
    mimetypes = ["application/xml", "text/xml"]

    @classmethod
    def parse(cls, fp, data_objects=None, close=True):
        """
            This method parses the file and return a list of DataObjects
            with both header and data properties filled in accordingly.
            The filename argument is always required. If no file object is passed
            as keyword argument, it only serves as a label. Otherwise a new file
            object is created.
            File objects are closed unless close is set to False.
            Existing DataObjects can be passed as well and will then 
            be used instead of creating new ones.
        """
        filename, fp, close = cls._get_file(fp, close=close)
        data_objects = create_project_from_sybilla_xml(filename)
        if close: fp.close()
        return data_objects

    pass  #end of class
示例#12
0
class ATLAtomTypeParser(CSVBaseParser):
    """
        Atomic scattering factors CSV file parser
    """

    namespace = "atl"
    description = "Atom types CSV file"
    extensions = get_case_insensitive_glob("*.ATL")

    default_fmt_params = {
        "delimiter": ',',
        "doublequote": True,
        "escapechar": None,
        "quotechar": "\"",
        "quoting": csv.QUOTE_MINIMAL,
        "skipinitialspace": True,
        "strict": False
    }

    @classmethod
    def _parse_header(cls,
                      filename,
                      fp,
                      data_objects=None,
                      close=False,
                      **fmt_params):
        try:
            fmt_params = dict(cls.default_fmt_params, **fmt_params)

            # Goto start of file
            fp.seek(0)

            # Get base filename:
            basename = u(os.path.basename(filename))

            # Read in the first and last data line and put the file cursor back
            # at its original position
            header = cls.parse_raw_line(fp.readline().strip(), str)
            replace = ["a%d" % i for i in range(1, 6)
                       ] + ["b%d" % i for i in range(1, 6)] + [
                           "c",
                       ]
            header = [
                "par_%s" % val if val in replace else val for val in header
            ]
            data_start_pos = fp.tell()
            line_count, _ = cls.get_last_line(fp)
            fp.seek(data_start_pos)

            # Adapt DataObject list
            data_objects = cls._adapt_data_object_list(data_objects,
                                                       num_samples=line_count)

            # Fill in header info:
            for i in xrange(line_count):
                data_objects[i].update(filename=basename, header=header)
        finally:
            if close: fp.close()
        return data_objects

    @classmethod
    def _parse_data(cls,
                    filename,
                    fp,
                    data_objects=None,
                    close=False,
                    **fmt_params):
        if fp is not None:
            for row, data_object in zip(csv.reader(fp, **fmt_params),
                                        data_objects):
                if row:
                    for key, val in zip(data_object.header, row):
                        setattr(data_object, key, val)
                    data_object.is_json = False

        if close: fp.close()
        return data_objects

    @classmethod
    def parse(cls, filename, fp, data_objects=None, close=True, **fmt_params):
        """
            Files are sniffed for the used csv dialect, but an optional set of
            formatting parameters can be passed that will override the sniffed
            parameters.
        """
        filename, fp, close = cls._get_file(filename, fp, close=close)

        # Guess dialect
        fmt_params = cls.sniff(fp, **fmt_params)

        # Parse header
        data_objects = cls.parse_header(filename,
                                        fp,
                                        data_objects=data_objects,
                                        **fmt_params)

        # Parse data
        data_objects = cls.parse_data(filename,
                                      fp,
                                      data_objects=data_objects,
                                      **fmt_params)

        if close: fp.close()
        return data_objects

    @classmethod
    def write(cls, filename, items, props):
        """
            Writes the header to the first line, and will write x, y1, ..., yn
            rows for each column inside the x and ys arguments.
            Header argument should not include a newline, and can be a string or
            any iterable containing strings.
        """
        atl_writer = csv.writer(open(filename, 'wb'),
                                delimiter=',',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL)
        atl_writer.writerow([name for prop, name in props])
        for item in items:
            prop_row = []
            for prop, name in props:
                prop_row.append(getattr(item, prop))
            atl_writer.writerow(prop_row)

    pass  # end of class
示例#13
0
文件: models.py 项目: openafox/PyXRD
 class Meta(DataModel.Meta):
     properties = [
         PropIntel(name="name",
                   label="Name",
                   data_type=str,
                   **PropIntel.ST_WID),
         PropIntel(name="date",
                   label="Date",
                   data_type=str,
                   **PropIntel.ST_WID),
         PropIntel(name="description",
                   label="Description",
                   data_type=str,
                   widget_type="text_view",
                   **PropIntel.ST_WID),
         PropIntel(name="author",
                   label="Author",
                   data_type=str,
                   **PropIntel.ST_WID),
         OptionPropIntel(name="layout_mode",
                         label="Layout mode",
                         data_type=str,
                         options=settings.DEFAULT_LAYOUTS,
                         **PropIntel.ST_WID),
         PropIntel(name="display_marker_color",
                   label="Color",
                   data_type=str,
                   widget_type="color",
                   **PropIntel.ST_WID),
         PropIntel(name="display_marker_top_offset",
                   label="Offset from base",
                   data_type=float,
                   widget_type="float_entry",
                   **PropIntel.ST_WID),
         PropIntel(name="display_marker_angle",
                   label="Angle",
                   data_type=float,
                   widget_type="float_entry",
                   **PropIntel.ST_WID),
         OptionPropIntel(name="display_marker_align",
                         label="Label alignment",
                         data_type=str,
                         options=settings.MARKER_ALIGNS,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_marker_base",
                         label="Base connection",
                         data_type=int,
                         options=settings.MARKER_BASES,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_marker_top",
                         label="Top connection",
                         data_type=int,
                         options=settings.MARKER_TOPS,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_marker_style",
                         label="Line style",
                         data_type=str,
                         options=settings.MARKER_STYLES,
                         **PropIntel.ST_WID),
         PropIntel(name="display_calc_color",
                   label="Calculated color",
                   data_type=str,
                   widget_type="color",
                   **PropIntel.ST_WID),
         PropIntel(name="display_exp_color",
                   label="Experimental color",
                   data_type=str,
                   widget_type="color",
                   **PropIntel.ST_WID),
         PropIntel(name="display_calc_lw",
                   label="Calculated linewidth",
                   data_type=int,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="display_exp_lw",
                   label="Experimental linewidth",
                   data_type=int,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         OptionPropIntel(name="display_calc_ls",
                         label="Calculated linestyle",
                         data_type=str,
                         options=settings.PATTERN_LINE_STYLES,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_exp_ls",
                         label="Experimental linestyle",
                         data_type=str,
                         options=settings.PATTERN_LINE_STYLES,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_calc_marker",
                         label="Calculated line marker",
                         data_type=str,
                         options=settings.PATTERN_MARKERS,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="display_exp_marker",
                         label="Experimental line marker",
                         data_type=str,
                         options=settings.PATTERN_MARKERS,
                         **PropIntel.ST_WID),
         PropIntel(name="display_plot_offset",
                   label="Pattern offset",
                   data_type=float,
                   widget_type="float_entry",
                   **PropIntel.ST_WID),
         PropIntel(name="display_group_by",
                   label="Group patterns by",
                   data_type=int,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="display_label_pos",
                   label="Default label position",
                   data_type=float,
                   widget_type="float_entry",
                   **PropIntel.ST_WID),
         OptionPropIntel(name="axes_xlimit",
                         label="X limit",
                         data_type=int,
                         options=settings.AXES_XLIMITS,
                         **PropIntel.ST_WID),
         PropIntel(name="axes_xmin",
                   label="min. [°2T]",
                   data_type=float,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="axes_xmax",
                   label="max. [°2T]",
                   data_type=float,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="axes_xstretch",
                   label="Stretch X-axis to fit window",
                   data_type=bool,
                   **PropIntel.ST_WID),
         PropIntel(name="axes_dspacing",
                   label="Show d-spacing in x-axis",
                   data_type=bool,
                   **PropIntel.ST_WID),
         OptionPropIntel(name="axes_ynormalize",
                         label="Y scaling",
                         data_type=int,
                         options=settings.AXES_YNORMALIZERS,
                         **PropIntel.ST_WID),
         OptionPropIntel(name="axes_ylimit",
                         label="Y limit",
                         data_type=int,
                         options=settings.AXES_YLIMITS,
                         **PropIntel.ST_WID),
         PropIntel(name="axes_ymin",
                   label="min. [counts]",
                   data_type=float,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="axes_ymax",
                   label="max. [counts]",
                   data_type=float,
                   widget_type="spin",
                   **PropIntel.ST_WID),
         PropIntel(name="axes_yvisible",
                   label="Y-axis visible",
                   data_type=bool,
                   **PropIntel.ST_WID),
         PropIntel(name="specimens",
                   label="Specimens",
                   data_type=object,
                   widget_type="object_list_view",
                   class_type=Specimen,
                   **PropIntel.ST_WID),
         PropIntel(name="phases",
                   data_type=object,
                   class_type=Phase,
                   **PropIntel.ST),
         PropIntel(name="mixtures",
                   data_type=object,
                   class_type=Mixture,
                   **PropIntel.ST),
         PropIntel(name="atom_types",
                   data_type=object,
                   class_type=AtomType,
                   **PropIntel.ST),
         PropIntel(name="needs_saving", data_type=bool),
     ]
     store_id = "Project"
     file_filters = [
         ("PyXRD Project files",
          get_case_insensitive_glob("*.pyxrd", "*.zpd")),
     ]
     import_filters = [
         ("Sybilla XML files", get_case_insensitive_glob("*.xml")),
     ]
示例#14
0
 class Meta(AbstractPhase.Meta):
     store_id = "Phase"
     file_filters = [
         ("Phase file", get_case_insensitive_glob("*.PHS")),
     ]
示例#15
0
文件: models.py 项目: fbocches/PyXRD
 class Meta(DataModel.Meta):
     store_id = "Atom"
     layer_filters = [
         ("Layer file", get_case_insensitive_glob("*.lyr")),
     ]
示例#16
0
 class Meta(DataModel.Meta):
     store_id = "AtomRelation"
     file_filters = [
         ("Atom relation", get_case_insensitive_glob("*.atr")),
     ]
     allowed_relations = {}