Skip to content

Commit

Permalink
pylinting, mypy, removal of unnecessary imports
Browse files Browse the repository at this point in the history
  • Loading branch information
atomprobe-tc committed Dec 7, 2023
1 parent 2090418 commit ff5cfa0
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 198 deletions.
38 changes: 16 additions & 22 deletions pynxtools/dataconverter/readers/em/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,27 @@

from pynxtools.dataconverter.readers.em.concepts.nexus_concepts import NxEmAppDef

from pynxtools.dataconverter.readers.em.subparsers.nxs_mtex import NxEmNxsMTexSubParser
# from pynxtools.dataconverter.readers.em.subparsers.nxs_mtex import NxEmNxsMTexSubParser

from pynxtools.dataconverter.readers.em.subparsers.nxs_pyxem import NxEmNxsPyxemSubParser

from pynxtools.dataconverter.readers.em.utils.default_plots import NxEmDefaultPlotResolver

from pynxtools.dataconverter.readers.em.geometry.convention_mapper \
import NxEmConventionMapper
# from pynxtools.dataconverter.readers.em.geometry.convention_mapper import NxEmConventionMapper

"""
from pynxtools.dataconverter.readers.em_om.utils.generic_eln_io \
import NxEmOmGenericElnSchemaParser
from pynxtools.dataconverter.readers.em_om.utils.orix_ebsd_parser \
import NxEmOmOrixEbsdParser
from pynxtools.dataconverter.readers.em_om.utils.mtex_ebsd_parser \
import NxEmOmMtexEbsdParser
from pynxtools.dataconverter.readers.em_om.utils.zip_ebsd_parser \
import NxEmOmZipEbsdParser
from pynxtools.dataconverter.readers.em_om.utils.dream3d_ebsd_parser \
import NxEmOmDreamThreedEbsdParser
from pynxtools.dataconverter.readers.em_om.utils.em_nexus_plots \
import em_om_default_plot_generator"""
# remaining subparsers to be implemented and merged into this one
# from pynxtools.dataconverter.readers.em_om.utils.generic_eln_io \
# import NxEmOmGenericElnSchemaParser
# from pynxtools.dataconverter.readers.em_om.utils.orix_ebsd_parser \
# import NxEmOmOrixEbsdParser
# from pynxtools.dataconverter.readers.em_om.utils.mtex_ebsd_parser \
# import NxEmOmMtexEbsdParser
# from pynxtools.dataconverter.readers.em_om.utils.zip_ebsd_parser \
# import NxEmOmZipEbsdParser
# from pynxtools.dataconverter.readers.em_om.utils.dream3d_ebsd_parser \
# import NxEmOmDreamThreedEbsdParser
# from pynxtools.dataconverter.readers.em_om.utils.em_nexus_plots \
# import em_om_default_plot_generator


class EmReader(BaseReader):
Expand Down Expand Up @@ -127,7 +121,7 @@ def read(self,

# add further with resolving cases
# if file_path is an HDF5 will use hfive parser
sub_parser = "nxs_pyxem"
# sub_parser = "nxs_pyxem"
subparser = NxEmNxsPyxemSubParser(entry_id, file_paths[0])
subparser.parse(template)
# exit(1)
Expand Down
18 changes: 4 additions & 14 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_apex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@

import numpy as np
import h5py
from itertools import groupby
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from typing import Dict
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation, Orientation
from orix.vector import Vector3d

import matplotlib.pyplot as plt
from orix.quaternion import Orientation

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import \
Expand All @@ -48,8 +38,8 @@ def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.supported_version = {}
self.version = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
30 changes: 11 additions & 19 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@
#
"""(Sub-)parser mapping concepts and content from EDAX/AMETEK *.edaxh5 (APEX) files on NXem."""

import os
import glob
import re
import sys
from typing import Dict, Any, List
import numpy as np
import h5py
import yaml
import json
# import imageio.v3 as iio
from PIL import Image as pil
from typing import Dict, List

from pynxtools.dataconverter.readers.em.subparsers.hfive_concept import \
IS_GROUP, IS_REGULAR_DATASET, IS_COMPOUND_DATASET, IS_ATTRIBUTE, \
Expand Down Expand Up @@ -64,24 +56,24 @@ def __init__(self, file_path: str = ""):
# an instance of a file whose schema belongs to the H5OINA family of HDF5 container formats
# specifically using version 5
self.prfx = None
self.tmp = {}
self.tmp: Dict = {}
self.source = None
self.file_path = None
# collection of instance path
self.groups = {}
self.datasets = {}
self.attributes = {}
self.instances = {}
self.groups: Dict = {}
self.datasets: Dict = {}
self.attributes: Dict = {}
self.instances: Dict = {}
# collection of template
self.template_groups = []
self.template_datasets = []
self.template_attributes = []
self.templates = {}
self.template_groups: List = []
self.template_datasets: List = []
self.template_attributes: List = []
self.templates: Dict = {}
self.h5r = None
if file_path is not None and file_path != "":
self.file_path = file_path
else:
raise ValueError(f"{__class__.__name__} needs proper instantiation !")
raise ValueError(f"{__name__} needs proper instantiation !")

def init_named_cache(self, ckey: str):
"""Init a new cache for normalized EBSD data if not existent."""
Expand Down
23 changes: 5 additions & 18 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@
#
"""(Sub-)parser mapping concepts and content from Bruker *.h5 files on NXem."""

import os
from typing import Dict, Any, List
import numpy as np
import h5py
from itertools import groupby
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from typing import Dict
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation
from orix.vector import Vector3d

import matplotlib.pyplot as plt

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import \
EBSD_MAP_SPACEGROUP, read_strings_from_dataset, all_equal, format_euler_parameterization
from pynxtools.dataconverter.readers.em.examples.ebsd_database import \
ASSUME_PHASE_NAME_TO_SPACE_GROUP, HEXAGONAL_GRID, SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN
ASSUME_PHASE_NAME_TO_SPACE_GROUP, SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN # HEXAGONAL_GRID
from pynxtools.dataconverter.readers.em.utils.get_scan_points import \
get_scan_point_coords

Expand All @@ -49,9 +36,9 @@ class HdfFiveBrukerEspritReader(HdfFiveBaseParser):
def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.supported_version = {}
self.version = {}
self.tmp: Dict = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
#
"""Constants and utilities used when parsing concepts from HDF5 files."""

from typing import Dict

IS_GROUP = 0
IS_REGULAR_DATASET = 1
IS_COMPOUND_DATASET = 2
IS_FIELD_IN_COMPOUND_DATASET = 3
IS_ATTRIBUTE = 4
VERSION_MANAGEMENT = {"tech_partner": [],
"schema_name": [], "schema_version": [],
"writer_name": [], "writer_version": []}
VERSION_MANAGEMENT: Dict = {"tech_partner": [],
"schema_name": [], "schema_version": [],
"writer_name": [], "writer_version": []}


class Concept():
Expand Down
25 changes: 6 additions & 19 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_dreamthreed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,15 @@
#
"""(Sub-)parser mapping concepts and content from community *.dream3d files on NXem."""

import os
from typing import Dict, Any, List
import numpy as np
import h5py
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation
from orix.vector import Vector3d

import matplotlib.pyplot as plt
from typing import Dict

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import \
EBSD_MAP_SPACEGROUP, read_strings_from_dataset, all_equal, format_euler_parameterization
read_strings_from_dataset # EBSD_MAP_SPACEGROUP
from pynxtools.dataconverter.readers.em.examples.ebsd_database import \
ASSUME_PHASE_NAME_TO_SPACE_GROUP, HEXAGONAL_GRID, SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN
SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN # ASSUME_PHASE_NAME_TO_SPACE_GROUP, HEXAGONAL_GRID

# DREAM3D implements essentially a data analysis workflow with individual steps
# in the DREAM3D jargon each step is referred to as a filter, filters have well-defined
Expand Down Expand Up @@ -97,9 +84,9 @@ def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.path_registry = {}
self.supported_version = {}
self.version = {}
self.path_registry: Dict = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
20 changes: 4 additions & 16 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,16 @@
#
"""(Sub-)parser mapping concepts and content from community *.h5/*.h5ebsd files on NXem."""

import os
from typing import Dict, Any, List
import numpy as np
import h5py
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from typing import Dict
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation
from orix.vector import Vector3d

import matplotlib.pyplot as plt

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import \
EBSD_MAP_SPACEGROUP, read_strings_from_dataset, all_equal, format_euler_parameterization
from pynxtools.dataconverter.readers.em.examples.ebsd_database import \
ASSUME_PHASE_NAME_TO_SPACE_GROUP, HEXAGONAL_GRID, SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN
ASSUME_PHASE_NAME_TO_SPACE_GROUP, SQUARE_GRID, REGULAR_TILING, FLIGHT_PLAN # HEXAGONAL_GRID
from pynxtools.dataconverter.readers.em.utils.get_scan_points import \
get_scan_point_coords

Expand All @@ -49,8 +37,8 @@ def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.supported_version = {}
self.version = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
19 changes: 3 additions & 16 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_edax.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,10 @@
#
"""(Sub-)parser mapping concepts and content from EDAX/AMETEK *.oh5/*.h5 (OIM Analysis) files on NXem."""

import os
from typing import Dict, Any, List
import numpy as np
import h5py
from itertools import groupby
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from typing import Dict
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation
from orix.vector import Vector3d

import matplotlib.pyplot as plt

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import EULER_SPACE_SYMMETRY, \
Expand All @@ -48,8 +35,8 @@ def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.supported_version = {}
self.version = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
20 changes: 3 additions & 17 deletions pynxtools/dataconverter/readers/em/subparsers/hfive_emsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,9 @@
#
"""(Sub-)parser mapping concepts and content from Marc deGraeff's EMsoft *.h5 files on NXem."""

import os
from typing import Dict, Any, List
import numpy as np
import h5py
from itertools import groupby
# import imageio.v3 as iio
from PIL import Image as pil

import diffsims
import orix
from diffpy.structure import Lattice, Structure
from orix import plot
from orix.crystal_map import create_coordinate_arrays, CrystalMap, PhaseList
from orix.quaternion import Rotation
from orix.vector import Vector3d

import matplotlib.pyplot as plt
from typing import Dict

from pynxtools.dataconverter.readers.em.subparsers.hfive_base import HdfFiveBaseParser
from pynxtools.dataconverter.readers.em.utils.hfive_utils import read_strings_from_dataset
Expand All @@ -45,8 +31,8 @@ def __init__(self, file_path: str = ""):
super().__init__(file_path)
self.prfx = None
self.tmp = {}
self.supported_version = {}
self.version = {}
self.supported_version: Dict = {}
self.version: Dict = {}
self.init_support()
self.supported = False
self.check_if_supported()
Expand Down
Loading

0 comments on commit ff5cfa0

Please sign in to comment.