Auxiliary functionality

do_execute

small helper function to assess whether a GAMMA command shall be executed.

ISPPar

Reader for ISP parameter files of the GAMMA software package

Namespace

GAMMA file name handler.

par2hdr

Create an ENVI HDR file from a GAMMA PAR file

process

wrapper function to execute GAMMA commands via module subprocess

slc_corners

extract the corner coordinates of a SAR scene

Spacing

compute multilooking factors and pixel spacings from an ISPPar object for a defined ground range target pixel spacing

UTM

convert a gamma parameter file corner coordinate from EQA to UTM

class pyroSAR.gamma.auxil.ISPPar(filename)[source]

Bases: object

Reader for ISP parameter files of the GAMMA software package

This class allows to read all information from files in GAMMA’s parameter file format. Each key-value pair is parsed and added as attribute. For instance if the parameter file contains the pair ‘sensor: TSX-1’ an attribute named ‘sensor’ with the value ‘TSX-1’ will be available.

The values are converted to native Python types, while unit identifiers like ‘dB’ or ‘Hz’ are removed. Please see the GAMMA reference manual for further information on the actual file format.

Parameters:

filename (str) – the GAMMA parameter file

Examples

>>> from pyroSAR.gamma import ISPPar
>>> with ISPPar('S1A__IW___A_20141115T181801_VH_grd.par') as par:
...     print(par) # print an overview of all available metadata
...     print(par.keys) # print all parameter names
...     for key, value in par.envidict().items():
...         print('{0}: {1}'.format(key, value)) # print the ENVI HDR compliant metadata
keys

the names of all parameters

Type:

list

envidict(nodata=None)[source]

export relevant metadata to an ENVI HDR file compliant format

Parameters:

nodata (int, float or None) – a no data value to write to the HDR file via attribute ‘data ignore value’

Returns:

a dictionary containing attributes translated to ENVI HDR naming

Return type:

dict

class pyroSAR.gamma.auxil.Namespace(directory, basename)[source]

Bases: object

GAMMA file name handler. This improves managing the many files names handled when processing with GAMMA.

Parameters:

Examples

>>> n = Namespace(directory='/path', basename='S1A__IW___A_20180829T170631')
>>> print(n.pix_geo)
'-'
>>> n.appreciate(['pix_geo'])
>>> print(n.pix_geo)
'/path/S1A__IW___A_20180829T170631_pix_geo'
appreciate(keys)[source]
Parameters:

keys (list[str])

depreciate(keys)[source]
Parameters:

keys (list[str])

get(key)[source]
getall()[source]
isappreciated(key)[source]
isfile(key)[source]
isregistered(key)[source]
select(selection)[source]
class pyroSAR.gamma.auxil.Spacing(par, spacing='automatic')[source]

Bases: object

compute multilooking factors and pixel spacings from an ISPPar object for a defined ground range target pixel spacing

Parameters:
  • par (str or ISPPar) – the ISP parameter file

  • spacing (int or float) – the target pixel spacing in ground range

class pyroSAR.gamma.auxil.UTM(parfile)[source]

Bases: object

convert a gamma parameter file corner coordinate from EQA to UTM

Parameters:

parfile (str) – the GAMMA parameter file to read the coordinate from

Example

>>> from pyroSAR.gamma import UTM
>>> print(UTM('gamma.par').zone)
pyroSAR.gamma.auxil.do_execute(par, ids, exist_ok)[source]

small helper function to assess whether a GAMMA command shall be executed.

Parameters:
  • par (dict) – a dictionary containing all arguments for the command

  • ids (list[str]) – the IDs of the output files

  • exist_ok (bool) – allow existing output files?

Returns:

execute the command because (a) not all output files exist or (b) existing files are not allowed

Return type:

bool

pyroSAR.gamma.auxil.par2hdr(parfile, hdrfile, modifications=None, nodata=None)[source]

Create an ENVI HDR file from a GAMMA PAR file

Parameters:
  • parfile (str) – the GAMMA parfile

  • hdrfile (str) – the ENVI HDR file

  • modifications (dict or None) – a dictionary containing value deviations to write to the HDR file

  • nodata (int, float or None) – a no data value to write to the HDR file via attribute ‘data ignore value’

Examples

>>> from pyroSAR.gamma.auxil import par2hdr
>>> par2hdr('dem_seg.par', 'inc.hdr')
# write a HDR file for byte data based on a parfile of float data
>>> par2hdr('dem_seg.par', 'ls_map.hdr', modifications={'data_type': 1})
pyroSAR.gamma.auxil.process(cmd, outdir=None, logfile=None, logpath=None, inlist=None, void=True, shellscript=None)[source]

wrapper function to execute GAMMA commands via module subprocess

Parameters:
  • cmd (list[str]) – the command line arguments

  • outdir (str) – the directory to execute the command in

  • logfile (str) – a file to write the command log to; overrides parameter logpath

  • logpath (str) – a directory to write logfiles to; the file will be named {GAMMA command}.log, e.g. gc_map.log; is overridden by parameter logfile

  • inlist (list) – a list of values, which is passed as interactive inputs via stdin

  • void (bool) – return the stdout and stderr messages?

  • shellscript (str) – a file to write the GAMMA commands to in shell format

Returns:

the stdout and stderr messages if void is False, otherwise None

Return type:

tuple of str or None

pyroSAR.gamma.auxil.slc_corners(parfile)[source]

extract the corner coordinates of a SAR scene

Parameters:

parfile (str) – the GAMMA parameter file to read coordinates from

Returns:

a dictionary with keys xmin, xmax, ymin, ymax

Return type:

dict of float