Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise configuration handling #305

Merged
merged 32 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0140ab4
[config] renamed from _dev_config
johntruckenbrodt Apr 22, 2024
3dbcbbc
[config] removed unnecessary Storage class and variables
johntruckenbrodt Apr 22, 2024
bf534fd
[config] centralize __LOCAL__ from drivers
johntruckenbrodt Apr 22, 2024
dc0cc8e
Merge branch 'main' of https://github.com/johntruckenbrodt/pyroSAR in…
johntruckenbrodt Apr 22, 2024
336c515
minor code edits
johntruckenbrodt Apr 22, 2024
6dab018
[examine] new class SnapProperties
johntruckenbrodt Apr 23, 2024
5a45a08
[examine.ExamineSnap] deep restructuring
johntruckenbrodt Apr 23, 2024
aa558cd
[examine.SnapProperties] various improvements
johntruckenbrodt Apr 24, 2024
0d62f25
[test_examine] initial commit
johntruckenbrodt Apr 24, 2024
e785921
[examine] minor improvements
johntruckenbrodt Apr 24, 2024
05716ef
[examine] bug fixes
johntruckenbrodt Apr 24, 2024
70d1375
[examine.SnapProperties] bug fixes
johntruckenbrodt Apr 24, 2024
b30a03c
[examine] various improvements and bug fixes
johntruckenbrodt Apr 24, 2024
4d5453d
[examine.SnapProperties] bug fix
johntruckenbrodt Apr 24, 2024
6e52084
[test_examine] bug fixes
johntruckenbrodt Apr 24, 2024
4211463
[examine.SnapProperties] bug fix
johntruckenbrodt Apr 24, 2024
c273edf
[examine.ExamineSnap] new setter for auxdatapath
johntruckenbrodt Apr 24, 2024
3bc528f
[examine] removed duplicate import
johntruckenbrodt Apr 24, 2024
b1c705d
[ExamineSnap] auto-update legacy config.ini files
johntruckenbrodt Apr 24, 2024
65801e3
Merge branch 'main' of https://github.com/johntruckenbrodt/pyroSAR in…
johntruckenbrodt May 6, 2024
6a69e8d
[ExamineSnap] bug fix
johntruckenbrodt May 6, 2024
6588b44
Merge branch 'main' of https://github.com/johntruckenbrodt/pyroSAR in…
johntruckenbrodt May 6, 2024
ecd9219
Merge branch 'main' of https://github.com/johntruckenbrodt/pyroSAR in…
johntruckenbrodt May 14, 2024
489c1df
[docs] added documentation on configuration
johntruckenbrodt May 14, 2024
64da612
[examine] renamed global variable: config -> __config__
johntruckenbrodt May 15, 2024
273843a
[ExamineSnap] fixed log message
johntruckenbrodt May 15, 2024
f14fc47
[ExamineSnap] fixed bug
johntruckenbrodt May 15, 2024
e796746
[snap] updated file snap.auxdata.properties
johntruckenbrodt May 15, 2024
dead764
[snap] copy default snap.auxdta.properties to $HOME/.snap/etc
johntruckenbrodt May 15, 2024
74139fc
[examine.SnapProperties.userpath] return default if not defined
johntruckenbrodt May 15, 2024
9c3fc41
[examine.SnapProperties] improved file reading
johntruckenbrodt May 15, 2024
e7e8665
[ExamineSnap] do not raise a warning when SNAP is not installed, but …
johntruckenbrodt May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading