Custom Interferometric Datasets#

In this tutorial, we will walk through how to customize your own datasets in FanInSAR.

Although we have provided several commonly used interferometric datasets, many datasets are still not yet implemented. We plan to add more in future releases, but you also have the option to implement your own dataset class.

Fortunately, FanInSAR offers a simple and flexible interface for creating new interferometric dataset classes. By inheriting from the base class InterferogramDataset and implementing a few essential methods, you can easily define a custom dataset.

Below is a basic example demonstrating how to implement a dataset class for HyP3 Sentinel-1 data:

from faninsar import Pairs
from faninsar.datasets import InterferogramDataset
from faninsar.constants import Sentinel1

import numpy as np
import pandas as pd

from pathlib import Path
class HyP3S1(InterferogramDataset, Sentinel1):
    """A dataset manages the data of HyP3 Sentinel-1 product.

    `Hyp3 <https://hyp3-docs.asf.alaska.edu/>`_ is a service for processing
    Synthetic Aperture Radar (SAR) imagery. This class is used to manage the
    data of Hyp3 product.
    """

    pattern_unw = "*unw_phase.tif"
    pattern_coh = "*corr.tif"

    @classmethod
    def parse_pairs(cls, paths: list[Path]) -> Pairs:
        """Parse the Pairs from the paths of the interferogram."""
        names = [Path(f).name for f in paths]
        pair_names = ["_".join(i.split("_")[1:3]) for i in names]
        return Pairs.from_names(pair_names)

    @classmethod
    def parse_datetime(cls, paths: list[Path]) -> pd.DatetimeIndex:
        """Parse the datetime of the interferogram to generate DatetimeIndex object."""
        names = [Path(f).name for f in paths]
        pair_names = ["_".join(i.split("_")[1:3]) for i in names]
        date_names = np.unique([i.split("_") for i in pair_names])
        return pd.DatetimeIndex(date_names)
  • pattern_unw and pattern_coh are two patterns used to locate the unwrapped interferogram and coherence files, respectively.

  • The parse_pairs method extracts the image pair information from the interferogram file path.

  • The parse_datetime method parses the date information from the interferogram file path.

  • In this example, the custom dataset class inherits from both InterferogramDataset and Sentinel1. The Sentinel1 class provides properties such as wavelength and frequency specific to Sentinel-1 data.

This example provides a simple implementation that should cover most common use cases. You can extend it by adding more methods and attributes as needed. You may also explore the source code of each dataset class by clicking [source] links under each class here to gain deeper insights and inspiration for your own implementation.