Skip to content

Commit

Permalink
Merge pull request #305 from johntruckenbrodt/feature/config
Browse files Browse the repository at this point in the history
revise configuration handling
  • Loading branch information
johntruckenbrodt authored May 15, 2024
2 parents 874b457 + e7e8665 commit 54c7d39
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 303 deletions.
23 changes: 23 additions & 0 deletions docs/source/general/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#############
Configuration
#############

pyroSAR stores configuration under `$HOME/.pyrosar`.
It contains a file `config.ini` which stores installation paths of SNAP and GAMMA.
The installations are first identified by running the respective `Examine*` class (e.g. :class:`~pyroSAR.examine.ExamineSnap`):

.. code-block:: python
from pyroSAR.examine import ExamineSnap
config = ExamineSnap()
SNAP configuration can also be modified with this class, either by the object properties `userpath` and `auxdatapath` or by the underlying :class:`~pyroSAR.examine.SnapProperties` object:

.. code-block:: python
config.userpath = '/path/to/snap/data'
config.snap_properties['snap.userdir'] = '/path/to/snap/data'
The values are directly written to either `snap.auxdata.properties` or `snap.properties` under `$HOME/.snap/etc`.
The content of these files will override that in the files found under `etc` in the SNAP installation folder.
Setting a parameter to `None` will comment out the value in the respective file.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ General Topics

general/installation
general/filenaming
general/configuration
general/OSV
general/DEM
general/snap
Expand Down
128 changes: 11 additions & 117 deletions pyroSAR/_dev_config.py → pyroSAR/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
###############################################################################
# pyroSAR configuration handling

# Copyright (c) 2018-2023, the pyroSAR Developers.
# Copyright (c) 2018-2024, the pyroSAR Developers.

# This file is part of the pyroSAR Project. It is subject to the
# license terms in the LICENSE.txt file found in the top-level
Expand All @@ -17,114 +17,10 @@

import configparser as ConfigParser

__LOCAL__ = ['sensor', 'projection', 'orbit', 'polarizations', 'acquisition_mode',
'start', 'stop', 'product', 'spacing', 'samples', 'lines']


class Storage(dict):
"""
Dict class with point access to store the lookups, pattern and URLs
Attributes
----------
STORAGE.LOOKUP : Storage
All lookup table merged in a Storage class instance:
* snap : SNAP process.
* attributes : Attributes for different sensors.
STORAGE.URL : dict (with point access)
All URLs for DEMs, orbit files etc.:
* dem : URL to download specific DEMs:
* strm3
* ace2
* strm3_FTP
* strm1HGT
* ace
* orbit : URL to download the orbit files:
* ers1
* ers2
* s1_poe
* s1_pres
* doris
* auxcal : URL to download the auxcal data:
* s1
* envisat
* ers
Note
----
There may be additional attributes not listed above depending of the
specific solver. Since this class is essentially a subclass of dict
with attribute accessors, one can see which attributes are available
using the `keys()` method.
"""

def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)

__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__

def __repr__(self):
if self.keys():
m = max(map(len, list(self.keys()))) + 1
return '\n'.join([k.rjust(m) + ': ' + repr(v)
for k, v in sorted(self.items())])
else:
return self.__class__.__name__ + '()'

def __dir__(self):
return list(self.keys())


# ==============================================================================
# LOOKUP
# ==============================================================================
LOOKUP = Storage(attributes={'sensor': 'TEXT',
'orbit': 'TEXT',
'acquisition_mode': 'TEXT',
'start': 'TEXT',
'stop': 'TEXT',
'product': 'TEXT',
'samples': 'INTEGER',
'lines': 'INTEGER',
'outname_base': 'TEXT PRIMARY KEY',
'scene': 'TEXT',
'hh': 'INTEGER',
'vv': 'INTEGER',
'hv': 'INTEGER',
'vh': 'INTEGER'})

# ==============================================================================
# URL
# ==============================================================================
dem = Storage(ace2='https://step.esa.int/auxdata/dem/ACE2/5M/',
ace='https://step.esa.int/auxdata/dem/ACE30/',
srtm3_FTP='xftp.jrc.it',
srtm3='https://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF',
srtm1Hgt='https://step.esa.int/auxdata/dem/SRTMGL1/', )

orbit = Storage(doris='https://step.esa.int/auxdata/orbits/Doris/vor',
ers1='https://step.esa.int/auxdata/orbits/ers_precise_orb/ERS1',
ers2='https://step.esa.int/auxdata/orbits/ers_precise_orb/ERS2',
s1_poe='https://step.esa.int/auxdata/orbits/Sentinel-1/POEORB/',
s1_res='https://step.esa.int/auxdata/orbits/Sentinel-1/RESORB/')

auxcal = Storage(s1='https://step.esa.int/auxdata/auxcal/S1/',
envisat='https://step.esa.int/auxdata/auxcal/ENVISAT/',
ers='https://step.esa.int/auxdata/auxcal/ERS/')

URL = Storage(dem=dem,
orbit=orbit,
auxcal=auxcal)

# ==============================================================================
# Merge
# ==============================================================================
STORAGE = Storage(URL=URL,
LOOKUP=LOOKUP)
__LOCAL__ = ['acquisition_mode', 'coordinates', 'cycleNumber', 'frameNumber',
'lines', 'orbit', 'orbitNumber_abs', 'orbitNumber_rel',
'polarizations', 'product', 'projection', 'samples',
'sensor', 'spacing', 'start', 'stop']


class Singleton(type):
Expand Down Expand Up @@ -220,13 +116,10 @@ def __str__(self):
.format(options,
self.parser.get(section, options),
str(type(options))))
out = 'Class : Config\n' \
'Path : {0}\n' \
'Sections : {1}\n' \
'Contents : \n{2}' \
.format(self.__GLOBAL['config'],
len(self.parser.sections()),
''.join(items))
out = f'Class : {self.__class__.__name__}\n' \
f'Path : {self.__GLOBAL["config"]}\n' \
f'Sections : {len(self.parser.sections())}\n' \
f'Contents : \n{"".join(items)}'

return out

Expand Down Expand Up @@ -257,7 +150,8 @@ def keys(self, section):

def open(self):
"""
Open the config.ini file. This method will open the config.ini file in a external standard app (text editor).
Open the config.ini file. This method will open the config.ini
file in an external standard app (text editor).
Returns
-------
Expand Down
6 changes: 1 addition & 5 deletions pyroSAR/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from osgeo.gdalconst import GA_ReadOnly

from . import S1, patterns
from .config import __LOCAL__
from .ERS import passdb_query, get_angles_resolution
from .xml_util import getNamespaces

Expand All @@ -72,11 +73,6 @@

log = logging.getLogger(__name__)

__LOCAL__ = ['acquisition_mode', 'coordinates', 'cycleNumber', 'frameNumber',
'lines', 'orbit', 'orbitNumber_abs', 'orbitNumber_rel',
'polarizations', 'product', 'projection', 'samples',
'sensor', 'spacing', 'start', 'stop']


def identify(scene):
"""
Expand Down
Loading

0 comments on commit 54c7d39

Please sign in to comment.