Skip to content

Image: resolve basename-only paths relative to XML#28124

Open
MaciejMax wants to merge 2 commits into
isce-framework:mainfrom
MaciejMax:image-load-xml-relative-paths
Open

Image: resolve basename-only paths relative to XML#28124
MaciejMax wants to merge 2 commits into
isce-framework:mainfrom
MaciejMax:image-load-xml-relative-paths

Conversation

@MaciejMax
Copy link
Copy Markdown

@MaciejMax MaciejMax commented May 7, 2026

Resolve basename-only image paths relative to XML metadata

Problem

ISCE image metadata XML can contain basename-only raster paths:

<property name="file_name">
  <value>example.dem.wgs84</value>
</property>
<property name="extra_file_name">
  <value>example.dem.wgs84.vrt</value>
</property>

When loading such XML by path, Image.load() currently keeps self.filename and self._extraFilename as those basename values. Downstream processing can then look for the raster and VRT in the current working directory instead of the directory containing the XML metadata.

This makes it harder to reuse one shared DEM across multiple processing work directories, because each work directory may otherwise need its own local copy or hardlink of the DEM files.

Proposed change

Add an Image.load() wrapper that delegates to Configurable.load() and then resolves basename-only image paths relative to the XML file location:

def load(self, filename, parser='xml'):
    super(Image, self).load(filename, parser=parser)
    base_dir = os.path.dirname(os.path.abspath(filename))

    # Resolve basename-only image paths relative to the XML file.
    # Relative paths that already include a directory are kept unchanged.
    if self.filename and not os.path.isabs(self.filename) and not os.path.dirname(self.filename):
        self.filename = os.path.join(base_dir, self.filename)

    if self._extraFilename and not os.path.isabs(self._extraFilename) and not os.path.dirname(self._extraFilename):
        self._extraFilename = os.path.join(base_dir, self._extraFilename)

The basename-only guard is important. Relative paths that already include directories should remain unchanged, because some internal products intentionally rely on those paths as written.

Validation

The change was validated in three ways:

  1. Loading DEM XML with basename-only file_name and extra_file_name values now resolves both paths relative to the XML location.
  2. Relative paths that already include directories are left unchanged, avoiding duplicated path prefixes.
  3. End-to-end processing works with a shared DEM referenced from outside the pair work directory, without requiring local DEM copies or hardlinks inside each work directory.

Motivation

This makes XML-relative image metadata behave in the way users generally expect: basename values inside an image metadata XML file refer to files located next to that XML file. It also reduces friction when reusing large shared rasters across many processing directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant