7070from geoh5py .shared .entity_type import EntityType
7171from geoh5py .shared .exceptions import Geoh5FileClosedError
7272from geoh5py .shared .utils import (
73- DEFAULT_PAGE_BUF_SIZE ,
73+ DEFAULT_PAGE_SIZE ,
7474 ClassIdentifierEnum ,
7575 as_str_if_utf8_bytes ,
7676 clear_array_attributes ,
@@ -115,6 +115,7 @@ class Workspace(AbstractContextManager):
115115 :param name: Name of the project.
116116 :param repack: Repack the *geoh5* file after closing.
117117 :param version: Version of the project.
118+ :param page_size: Page size of the h5 file, in bytes.
118119 """
119120
120121 _active_ref : ClassVar [ReferenceType [Workspace ]] | type (None ) = type (None ) # type: ignore
@@ -136,6 +137,7 @@ def __init__(
136137 name : str = "GEOSCIENCE" ,
137138 repack : bool = False ,
138139 version : float = 2.1 ,
140+ page_size : int = DEFAULT_PAGE_SIZE ,
139141 ):
140142 self ._root : RootGroup
141143 self ._data : dict [uuid .UUID , ReferenceType [data .Data ]] = {}
@@ -152,7 +154,7 @@ def __init__(
152154 self ._repack : bool = repack
153155 self ._types : dict [uuid .UUID , ReferenceType [EntityType ]] = {}
154156 self ._version : float = version
155-
157+ self . _page_size : int = validate_page_size ( page_size )
156158 self ._h5file = self .validate_h5file_input (h5file )
157159
158160 self .open (mode = mode )
@@ -1298,18 +1300,33 @@ def _open_h5(self, mode) -> h5py.File:
12981300 def _create_h5 (self ) -> h5py .File :
12991301 """
13001302 Generate a new geoh5 file with core structure.
1303+
1304+ Default mode for ANALYST uses:
1305+ - Page size (fs_page_size) of 65536 bytes.
1306+ - Page buffer (page_buf_size) is able to hold 256 pages.
1307+ - Library version (libver) fixed with (lower, upper) bound.
13011308 """
13021309 self ._geoh5 = h5py .File (
13031310 self .h5file ,
13041311 "x" ,
13051312 fs_strategy = "page" ,
1306- page_buf_size = DEFAULT_PAGE_BUF_SIZE ,
1313+ page_buf_size = self ._page_size * 256 ,
1314+ fs_page_size = self ._page_size ,
13071315 libver = ("v110" , "v114" ),
13081316 )
13091317 H5Writer .init_geoh5 (self ._geoh5 , self )
13101318
13111319 return self ._geoh5
13121320
1321+ @property
1322+ def page_size (self ) -> int :
1323+ """
1324+ HDF5 page size.
1325+
1326+ Must be a multiple of 2, greater than or equal 512.
1327+ """
1328+ return self ._page_size
1329+
13131330 def promote (self , value : Any ) -> Any :
13141331 """
13151332 Promote uuid to entity as it is or in a nested structure.
@@ -1605,3 +1622,20 @@ def active_workspace(workspace: Workspace):
16051622 previous_active = previous_active_ref ()
16061623 if previous_active is not None :
16071624 previous_active .activate () # pylint: disable=no-member
1625+
1626+
1627+ def validate_page_size (value : int ) -> int :
1628+ """
1629+ Check if a page size is valid value. Raise an error if not valid,
1630+ else return the value as-is.
1631+
1632+ :param value: A positive integer multiple of 2, >=512.
1633+ :return: Page size value, same as :param value:
1634+ """
1635+ if not isinstance (value , int ):
1636+ raise TypeError ("Page size must be an integer." )
1637+
1638+ if value < 512 or value % 2 != 0 :
1639+ raise ValueError ("Page size must be an integer multiple of 2, and >=512." )
1640+
1641+ return value
0 commit comments