:py:mod:`FELiCS.IO.Reader` ========================== .. py:module:: FELiCS.IO.Reader Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: FELiCS.IO.Reader.Reader Attributes ~~~~~~~~~~ .. autoapisummary:: FELiCS.IO.Reader.logger .. py:data:: logger .. py:class:: Reader(sourceDir: str = '', needInterpolation: bool = True, felicsMeshFilePath: Optional[str] = None, cacheData: bool = True) A class for reading and interpolating data from HDF5 files onto FELiCS meshes. This class manages the loading of data from HDF5 files, handles interpolation or direct mapping to the calculation mesh, and assigns the data to FELiCS fields. It supports caching for performance and can handle complex-valued data. :ivar _sourceDir: The source directory for data files. :vartype _sourceDir: :py:class:`str` :ivar _needInterpolation: Whether to interpolate data onto the FELiCS mesh. :vartype _needInterpolation: :py:class:`bool` :ivar _felicsMeshFilePath: Path to the FELiCS mesh file. :vartype _felicsMeshFilePath: :py:class:`str` or :py:obj:`None` :ivar _isComplex: Whether the data is complex-valued. :vartype _isComplex: :py:class:`bool` :ivar _cacheData: Whether to cache loaded data for reuse. :vartype _cacheData: :py:class:`bool` :ivar _sourceKey: Current source key (filePath, groupName). :vartype _sourceKey: :py:class:`tuple` or :py:obj:`None` :ivar _availableVars: List of available variables in the current source. :vartype _availableVars: :py:class:`list` or :py:obj:`None` :ivar _rawDataDict: Raw data dictionary from HDF5 files. :vartype _rawDataDict: :py:class:`dict` :ivar _dataForField: Processed data for fields. :vartype _dataForField: :py:class:`dict` :ivar _calcMeshCoords: Coordinates of the calculation mesh. :vartype _calcMeshCoords: :py:class:`numpy.ndarray` or :py:obj:`None` :ivar _calcMeshP1Coords: Coordinates of the P1 calculation mesh. :vartype _calcMeshP1Coords: :py:class:`numpy.ndarray` or :py:obj:`None` :ivar _mappingImportToCalc: Mapping from import to calculation mesh. :vartype _mappingImportToCalc: :py:class:`numpy.ndarray` or :py:obj:`None` :ivar _fullAxisNames: Full axis names. :vartype _fullAxisNames: :py:class:`list` or :py:obj:`None` :ivar _meshAxisNames: Mesh axis names. :vartype _meshAxisNames: :py:class:`list` or :py:obj:`None` :ivar _numDoFsCalcMeshP2: Number of DoFs for P2 calculation mesh. :vartype _numDoFsCalcMeshP2: :py:class:`int` :ivar _numDoFsCalcMeshP1: Number of DoFs for P1 calculation mesh. :vartype _numDoFsCalcMeshP1: :py:class:`int` :ivar _spacesDegrees: Degrees of spaces. :vartype _spacesDegrees: :py:class:`list` or :py:obj:`None` .. admonition:: Notes - Caching is per-file and cleared when switching sources. - Interpolation uses Delaunay triangulation for efficiency. - Retro-compatibility with previous FELiCS files with groupNames is ensured (for now). :raises FileNotFoundError: If the specified file does not exist. :raises RuntimeError: If environment is not bound or source is not set. :raises NotImplementedError: For unsupported field types like mixed function spaces. .. py:method:: meshAxisNames() Names of the full spatial dimensions: mesh + spectral. :returns: The full dimension names (e.g., ['x', 'y', 'z']). :rtype: :py:class:`list` of :py:class:`str` :raises RuntimeError: If accessed before bind_env is called. .. py:method:: fullAxisNames() Get the names of all spatial dimensions: mesh + spectral. :returns: The full dimension names (e.g., ['x', 'y', 'z']). :rtype: :py:class:`list` of :py:class:`str` :raises RuntimeError: If accessed before bind_env is called. .. py:method:: calcMeshP2Coords() Get the coordinates of the calculation mesh. :returns: Array of shape (nPoints, nDimMesh) with the coordinates of the calculation mesh. :rtype: :py:class:`numpy.ndarray` .. py:method:: calcMeshP1Coords() Get the coordinates of the P1 calculation mesh. :returns: Array of shape (nPoints, nDimMesh) with the coordinates of the P1 calculation mesh. :rtype: :py:class:`numpy.ndarray` .. py:method:: mappingImportToCalcP2() Get the mapping from import mesh to calculation mesh (P2). :returns: The mapping array if no interpolation is needed, otherwise None. :rtype: :py:class:`numpy.ndarray` or :py:obj:`None` .. admonition:: Notes .. py:method:: importMeshCoords() Get the coordinates of the import mesh based on the configuration. Three scenarios: 1. Interpolation needed, original mesh file provided: load from original mesh file. 2. Interpolation needed, no original mesh file: load from main file under group name. 3. No interpolation needed: load from FELiCS exported mesh file. :returns: Array of shape (nPoints, nDimMesh) with the coordinates of the import mesh. :rtype: :py:class:`numpy.ndarray` .. py:method:: clear_cached_properties(cachedProps: List[str] = []) -> None Remove all cached @cached_property values from this Reader instance. They will be recomputed on the next access. :param cachedProps: List of property names to clear. If empty, clears default properties. :type cachedProps: :py:class:`list` of :py:class:`str`, *optional* .. py:method:: importInField(field: Any, filePath: str, groupName: str) -> Tuple[Any, List[str]] Import data from the specified file/group into the given field. Automatically clears per-file caches when file/group changes. :param field: The FELiCS field to import data into. :type field: :py:class:`object` :param filePath: Path to the HDF5 file. :type filePath: :py:class:`str` :param groupName: Name of the group in the HDF5 file. :type groupName: :py:class:`str` :returns: (updated field, list of missing variables) :rtype: :py:class:`tuple` :raises FileNotFoundError: If the file does not exist. :raises NotImplementedError: If the field type is not supported.