url: Utils for data locators

URL module

class silx.io.url.DataUrl(path=None, file_path=None, data_path=None, data_slice=None, scheme=None)[source]

Non-mutable object to parse a string representing a resource data locator.

It supports:

  • path to file and path inside file to the data
  • data slicing
  • fabio or silx access to the data
  • absolute and relative file access
>>> # fabio access using absolute path
>>> DataUrl("fabio:///data/image.edf?slice=2")
>>> DataUrl("fabio:///C:/data/image.edf?slice=2")
>>> # silx access using absolute path
>>> DataUrl("silx:///data/image.h5?path=/data/dataset&slice=1,5")
>>> DataUrl("silx:///data/image.edf?path=/scan_0/detector/data")
>>> DataUrl("silx:///C:/data/image.edf?path=/scan_0/detector/data")
>>> # `path=` can be omited if there is no other query keys
>>> DataUrl("silx:///data/image.h5?/data/dataset")
>>> # is the same as
>>> DataUrl("silx:///data/image.h5?path=/data/dataset")
>>> # `::` can be used instead of `?` which can be useful with shell in
>>> # command lines
>>> DataUrl("silx:///data/image.h5::/data/dataset")
>>> # is the same as
>>> DataUrl("silx:///data/image.h5?/data/dataset")
>>> # Relative path access
>>> DataUrl("silx:./image.h5")
>>> DataUrl("fabio:./image.edf")
>>> DataUrl("silx:image.h5")
>>> DataUrl("fabio:image.edf")
>>> # Is also support parsing of file access for convenience
>>> DataUrl("./foo/bar/image.edf")
>>> DataUrl("C:/data/")
Parameters:
  • path (str) – Path representing a link to a data. If specified, other arguments are not used.
  • file_path (str) – Link to the file containing the the data. None if there is no data selection.
  • data_path (str) – Data selection applyed to the data file selected. None if there is no data selection.
  • data_slice (Tuple[int,slice,Ellipse]) – Slicing applyed of the selected data. None if no slicing applyed.
  • scheme (Union[str,None]) – Scheme of the URL. “silx”, “fabio” is supported. Other strings can be provided, but is_valid() will be false.
is_valid()[source]

Returns true if the URL is valid. Else attributes can be None.

Return type:bool
path()[source]

Returns the string representing the URL.

Return type:str
is_absolute()[source]

Returns true if the file path is an absolute path.

Return type:bool
file_path()[source]

Returns the path to the file containing the data.

Return type:str
data_path()[source]

Returns the path inside the file to the data.

Return type:str
data_slice()[source]

Returns the slicing applyed to the data.

It is a tuple containing numbers, slice or ellipses.

Return type:Tuple[int, slice, Ellipse]
scheme()[source]

Returns the scheme. It can be None if no scheme is specified.

Return type:Union[str, None]