Skip to content

Commit

Permalink
Change to main pyroSAR
Browse files Browse the repository at this point in the history
  • Loading branch information
gr4n0t4 committed Aug 24, 2022
1 parent 48ba78c commit ec5a16b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
14 changes: 10 additions & 4 deletions ERS_NRB/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_config(config_file, section_name='GENERAL'):
if k.endswith('date'):
v = parser_sec.get_datetime(k)
if k == 'acq_mode':
assert v in ['IMM', 'IMP', 'APP']
assert v in ['IMM', 'IMP', 'APP', 'IMS', 'WSM']
if k == 'work_dir':
assert os.path.isdir(v), "Parameter '{}': '{}' must be an existing directory".format(k, v)
if k.endswith('_dir') and not k == 'work_dir':
Expand Down Expand Up @@ -132,7 +132,9 @@ def geocode_conf(config):
"""
return {'spacing': {'IMM': 10, # TODO Completly guess
'IMP': 10, # TODO Completly guess
'APP': 20}[config['acq_mode']], # TODO Completly guess
'APP': 20, # TODO Completly guess
'IMS': 20, # TODO Completly guess
'WSM': 20,}[config['acq_mode']], # TODO Completly guess
'scaling': 'linear',
'groupsize': 1,
'allow_RES_OSV': True,
Expand All @@ -148,10 +150,14 @@ def geocode_conf(config):
'cleanup': False,
'rlks': {'IMM': 5, # TODO Completly guess
'IMP': 6, # TODO Completly guess
'APP': 3}[config['acq_mode']], # TODO Completly guess
'APP': 3, # TODO Completly guess
'IMS': 6, # TODO Completly guess
'WSM': 3}[config['acq_mode']], # TODO Completly guess
'azlks': {'IMM': 1, # TODO Completly guess
'IMP': 6, # TODO Completly guess
'APP': 1}[config['acq_mode']]} # TODO Completly guess
'APP': 1, # TODO Completly guess
'IMS': 1, # TODO Completly guess
'WSM': 1}[config['acq_mode']]} # TODO Completly guess


def gdal_conf(config):
Expand Down
31 changes: 12 additions & 19 deletions ERS_NRB/metadata/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from datetime import datetime
import numpy as np
from pyroSAR import identify
from pyroSAR.snap.auxil import parse_recipe
from pyroSAR.ERS.mapping import ANGLES_RESOLUTION
from spatialist import Raster
from spatialist.ancillary import finder
from spatialist.vector import wkt2vector, bbox
from spatialist.raster import rasterize
from ERS_NRB.metadata.mapping import NRB_PATTERN, RES_MAP, ORB_MAP
from ERS_NRB.metadata.mapping import NRB_PATTERN, ORB_MAP


def get_prod_meta(product_id, tif, src_scenes, src_dir):
def get_prod_meta(product_id, tif, src_scenes):
"""
Returns a metadata dictionary, which is generated from the ID of a product scene using a regular expression pattern
and from a measurement GeoTIFF file of the same product scene using spatialist's Raster class.
Expand All @@ -26,9 +26,6 @@ def get_prod_meta(product_id, tif, src_scenes, src_dir):
The paths to a measurement GeoTIFF file of the product scene.
src_scenes: list[str]
A list of paths pointing to the source scenes of the product.
src_dir: str
A paths pointing to the SNAP processed datasets of the product.
Returns
-------
dict
Expand Down Expand Up @@ -403,16 +400,12 @@ def meta_dict(config, target, src_scenes, src_files, proc_time):

product_id = os.path.basename(target)
tif = finder(target, ['[hv]{2}-g-lin.tif$'], regex=True)[0]
prod_meta = get_prod_meta(product_id=product_id, tif=tif, src_scenes=src_scenes,
# src_dir=os.path.dirname(src_files[0]))
src_dir=None)
prod_meta = get_prod_meta(product_id=product_id, tif=tif, src_scenes=src_scenes)

src_sid = {}
src_xml = {}
for i in range(len(src_scenes)):
uid, sid = get_uid_sid(filepath=src_scenes[i])
src_sid[uid] = sid
# src_xml[uid] = etree_from_sid(sid=sid)

src0 = list(src_sid.keys())[0] # first key/first file
sid0 = src_sid[src0]
Expand Down Expand Up @@ -471,9 +464,9 @@ def meta_dict(config, target, src_scenes, src_files, proc_time):
# meta['common']['platformShortName'] = 'ERS'
# meta['common']['platformFullname'] = '{}{}'.format(meta['common']['platformShortName'].lower(),
# meta['common']['platformIdentifier'].lower())
meta['common']['platformReference'] = {'ERS1': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=575', # TODO Wrong
'ERS2': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=576',
'ENVISAT': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=576'}[meta['common']['platformFullname']]
meta['common']['platformReference'] = {'ERS1': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=220',
'ERS2': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=221',
'ENVISAT': 'http://database.eohandbook.com/database/missionsummary.aspx?missionID=2'}[meta['common']['platformFullname']]
meta['common']['polarisationChannels'] = sid0.polarizations
meta['common']['polarisationMode'] = prod_meta['pols']
meta['common']['radarBand'] = 'C'
Expand Down Expand Up @@ -512,10 +505,10 @@ def meta_dict(config, target, src_scenes, src_files, proc_time):
meta['prod']['filterType'] = None
meta['prod']['filterWindowSizeCol'] = None
meta['prod']['filterWindowSizeLine'] = None
meta['prod']['geoCorrAccuracyEasternBias'] = None
meta['prod']['geoCorrAccuracyEasternSTDev'] = None
meta['prod']['geoCorrAccuracyNorthernBias'] = None
meta['prod']['geoCorrAccuracyNorthernSTDev'] = None
meta['prod']['geoCorrAccuracyAzimuthBias'] = '0'
meta['prod']['geoCorrAccuracyAzimuthSTDev'] = ANGLES_RESOLUTION[sid0.sensor][sid0.acquisition_mode]['std_dev']
meta['prod']['geoCorrAccuracyRangeBias'] = '0'
meta['prod']['geoCorrAccuracyRangeSTDev'] = ANGLES_RESOLUTION[sid0.sensor][sid0.acquisition_mode]['std_dev']
meta['prod']['geoCorrAccuracy_rRMSE'] = None
meta['prod']['geoCorrAccuracyReference'] = 'TBD'
meta['prod']['geoCorrAccuracyType'] = 'slant-range'
Expand Down Expand Up @@ -603,7 +596,7 @@ def meta_dict(config, target, src_scenes, src_files, proc_time):
# meta['source'][uid]['azimuthPixelSpacing'] = str(sum(list(tmp_out.values())) / len(list(tmp_out.values())))
meta['source'][uid]['azimuthResolution'] = src_sid[uid].meta['azimuthResolution']
meta['source'][uid]['dataGeometry'] = src_sid[uid].meta['image_geometry']
meta['source'][uid]['doi'] = 'https://sentinel.esa.int/documents/247904/1877131/Sentinel-1-Product-Specification'
meta['source'][uid]['doi'] = 'TBD'
meta['source'][uid]['faradayMeanRotationAngle'] = None
meta['source'][uid]['faradayRotationReference'] = None
meta['source'][uid]['filename'] = src_sid[uid].file
Expand Down
1 change: 1 addition & 0 deletions ERS_NRB/metadata/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@
'unit': None,
'role': 'noise-power',
'title': 'Noise Power HV'}}

5 changes: 3 additions & 2 deletions ERS_NRB/metadata/stacparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def product_json(meta, target, tifs):
item.properties['card4l:geometric_accuracy_type'] = meta['prod']['geoCorrAccuracyType']
item.properties['card4l:column_spacing'] = meta['prod']['columnSpacing']
item.properties['card4l:row_spacing'] = meta['prod']['rowSpacing']
for x in ['Northern', 'Eastern']:
for x in ['Azimuth', 'Range']:
key = ['geoCorrAccuracy{}{}'.format(x, y) for y in ['STDev', 'Bias']]
stddev = float(meta['prod'][key[0]]) if meta['prod'][key[0]] is not None else None
bias = float(meta['prod'][key[1]]) if meta['prod'][key[1]] is not None else None
Expand Down Expand Up @@ -212,7 +212,8 @@ def product_json(meta, target, tifs):
key = re.search('-[a-z]{2}(?:-[a-z]{2}|).tif', tif).group()

if key in ['-dm.tif', '-id.tif']:
ras_bands_base = {'nodata': 255,
ras_bands_base = {"unit": "mask",
'nodata': 255,
'data_type': 'uint8',
'bits_per_sample': 8}
raster_bands = []
Expand Down
2 changes: 1 addition & 1 deletion ERS_NRB/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def main(config_file, section_name):
scenesENVI = finder(config['scene_dir'], [r'^ASA.*\.N1'], regex=True, recursive=True)

scenes = scenesERS + scenesENVI

print(f"scenes: {scenes}")
if not os.path.isfile(config['db_file']):
config['db_file'] = os.path.join(config['work_dir'], config['db_file'])

Expand Down
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ aoi_geometry = /home/rnoguera/development/work_asar_app/mount.geojson
mindate = 1990-12-31
maxdate = 2022-01-01

# OPTIONS: IMM | IMP | APP
# OPTIONS: IMM | IMP | APP | IMS | WSM
acq_mode = IMP

# NOTE: [work_dir] and [scene_dir] must be full paths to existing directories
Expand All @@ -45,6 +45,6 @@ db_file = scenes.db
# OPTIONS: Copernicus 10m EEA DEM | Copernicus 30m Global DEM II | Copernicus 90m Global DEM II | GETASSE30
# NOTE: Water Body Masks are not available for GETASSE30 and will therefore not be included in the product data mask.
dem_type = Copernicus 30m Global DEM II

# dem_type = Copernicus 10m EEA DEM
# Temporarily changes GDAL_NUM_THREADS during processing. Will be reset after processing has finished.
gdal_threads = 4
4 changes: 2 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies:
- sphinxcontrib-bibtex>=2.2
- nbsphinx
- sphinx_rtd_theme
- pip:
- pyroSAR @ git+https://github.com/SAR-ARD/pyroSAR.git
- pyroSAR>=0.18.0

4 changes: 1 addition & 3 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ dependencies:
- pip
- pystac
- scipy
- pip:
- spatialist @ git+https://github.com/johntruckenbrodt/spatialist.git
- pyroSAR @ git+https://github.com/SAR-ARD/pyroSAR.git
- pyroSAR>=0.18.0

0 comments on commit ec5a16b

Please sign in to comment.