question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with using CRSs without EPSG code

See original GitHub issue

OS: Ubuntu 18.04

Environment Used: Anaconda environment

Library versions: pyroSAR: version 0.11.1 from conda-forge SNAP: 8.0

Objective: I wanted to reproject (to South LAEA) and apply speckle filtering to a couple of Sentinel SAR images that I have acquired. However I am unable to do so.

Code:

from pathlib import Path
from pyroSAR.snap import geocode

outdir = './outdir'
# South Lambert Equal Area Projection (ESRI:102020)
out_proj = "+proj=laea +lat_0=-90 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"

sar_zips = [ str(Path.cwd() / i) for i in Path('./data').iterdir() if i.suffix == ".zip"]
geocode(infile=sar_zips[0], outdir=outdir, t_srs=out_proj, speckleFilter="Lee")

This snippet outputs

searching for new POE files
https://qc.sentinel1.eo.esa.int/api/v1/?product_type=AUX_POEORB&sentinel1__mission=S1B&validity_start__gte=2019-08-19T07:52:49&validity_stop__lte=2019-08-21T07:52:49
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-15-10d2a2932d21> in <module>
----> 1 geocode(infile=sar_zips, outdir=outdir, t_srs=out_proj, speckleFilter="Lee")

~/anaconda3/envs/sar/lib/python3.6/site-packages/pyroSAR/snap/util.py in geocode(infile, outdir, t_srs, tr, polarizations, shapefile, scaling, geocoding_type, removeS1BorderNoise, removeS1BorderNoiseMethod, removeS1ThermalNoise, offset, allow_RES_OSV, demName, externalDEMFile, externalDEMNoDataValue, externalDEMApplyEGM, terrainFlattening, basename_extensions, test, export_extra, groupsize, cleanup, gpt_exceptions, gpt_args, returnWF, nodataValueAtSea, demResamplingMethod, imgResamplingMethod, speckleFilter, refarea)
    384 
    385     try:
--> 386         t_srs = crsConvert(t_srs, 'epsg')
    387     except TypeError:
    388         raise RuntimeError("format of parameter 't_srs' not recognized")

~/anaconda3/envs/sar/lib/python3.6/site-packages/spatialist/auxil.py in crsConvert(crsIn, crsOut)
     77         return srs.ExportToProj4()
     78     elif crsOut == 'epsg':
---> 79         srs.AutoIdentifyEPSG()
     80         return int(srs.GetAuthorityCode(None))
     81     elif crsOut == 'opengis':

~/anaconda3/envs/sar/lib/python3.6/site-packages/osgeo/osr.py in AutoIdentifyEPSG(self, *args)
    564     def AutoIdentifyEPSG(self, *args):
    565         """AutoIdentifyEPSG(SpatialReference self) -> OGRErr"""
--> 566         return _osr.SpatialReference_AutoIdentifyEPSG(self, *args)
    567 
    568 

RuntimeError: OGR Error: Unsupported SRS

Edit: I tried using osr and importing the wkt representation of South LAEA

wkt = """PROJCS["South_Pole_Lambert_Azimuthal_Equal_Area",GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",0],PARAMETER["Latitude_Of_Origin",-90],UNIT["Meter",1],AUTHORITY["EPSG","102020"]]"""
out_proj2 = osr.SpatialReference(wkt)

geocode(
    infile=sar_zips[0],
    outdir=outdir,
    t_srs=out_proj2,
    scaling="linear",
    speckleFilter="Refined Lee",
)

This worked till the Terrain Correction part, but failed for a similar reason.

searching for new POE files
https://qc.sentinel1.eo.esa.int/api/v1/?product_type=AUX_POEORB&sentinel1__mission=S1A&validity_start__gte=2020-03-16T22:55:06&validity_stop__lte=2020-03-18T22:55:06
unpacking scene
removing border noise..
border noise removal not necessary for IPF version 3.2
executing node sequences..
ThermalNoiseRemoval
Apply-Orbit-File
Calibration
Terrain-Flattening
Speckle-Filter
Terrain-Correction
Executing processing graph
No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".
 done.
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Incompatible GDAL 3.1.4 found on system. Internal GDAL 3.0.0 from distribution will be used.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
INFO: org.hsqldb.persist.Logger: dataFileCache open start
org.esa.snap.core.gpf.graph.GraphException: [NodeId: Terrain-Correction] No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".
	at org.esa.snap.core.gpf.graph.NodeContext.initTargetProduct(NodeContext.java:79)
	at org.esa.snap.core.gpf.graph.GraphContext.initNodeContext(GraphContext.java:199)
	at org.esa.snap.core.gpf.graph.GraphContext.initNodeContext(GraphContext.java:182)
	at org.esa.snap.core.gpf.graph.GraphContext.initOutput(GraphContext.java:166)
	at org.esa.snap.core.gpf.graph.GraphContext.<init>(GraphContext.java:85)
	at org.esa.snap.core.gpf.graph.GraphContext.<init>(GraphContext.java:58)
	at org.esa.snap.core.gpf.graph.GraphProcessor.executeGraph(GraphProcessor.java:118)
	at org.esa.snap.core.gpf.main.DefaultCommandLineContext.executeGraph(DefaultCommandLineContext.java:86)
	at org.esa.snap.core.gpf.main.CommandLineTool.executeGraph(CommandLineTool.java:547)
	at org.esa.snap.core.gpf.main.CommandLineTool.runGraph(CommandLineTool.java:391)
	at org.esa.snap.core.gpf.main.CommandLineTool.runGraphOrOperator(CommandLineTool.java:287)
	at org.esa.snap.core.gpf.main.CommandLineTool.run(CommandLineTool.java:188)
	at org.esa.snap.core.gpf.main.CommandLineTool.run(CommandLineTool.java:121)
	at org.esa.snap.core.gpf.main.GPT.run(GPT.java:54)
	at org.esa.snap.core.gpf.main.GPT.main(GPT.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.esa.snap.runtime.Launcher.lambda$run$0(Launcher.java:55)
	at org.esa.snap.runtime.Engine.runClientCode(Engine.java:189)
	at org.esa.snap.runtime.Launcher.run(Launcher.java:51)
	at org.esa.snap.runtime.Launcher.main(Launcher.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:84)
	at com.install4j.runtime.launcher.UnixLauncher.start(UnixLauncher.java:66)
	at install4j.org.esa.snap.runtime.Launcher1159904018.main(Unknown Source)
Caused by: org.esa.snap.core.gpf.OperatorException: No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".
	at org.esa.snap.engine_utilities.gpf.OperatorUtils.catchOperatorException(OperatorUtils.java:440)
	at org.esa.s1tbx.sar.gpf.geometric.RangeDopplerGeocodingOp.initialize(RangeDopplerGeocodingOp.java:349)
	at org.esa.snap.core.gpf.internal.OperatorContext.initializeOperator(OperatorContext.java:528)
	at org.esa.snap.core.gpf.internal.OperatorContext.getTargetProduct(OperatorContext.java:298)
	at org.esa.snap.core.gpf.Operator.getTargetProduct(Operator.java:385)
	at org.esa.snap.core.gpf.graph.NodeContext.initTargetProduct(NodeContext.java:77)
	... 29 more
Caused by: org.esa.snap.core.gpf.OperatorException: No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".
	at org.esa.s1tbx.sar.gpf.geometric.RangeDopplerGeocodingOp.createTargetProduct(RangeDopplerGeocodingOp.java:564)
	at org.esa.s1tbx.sar.gpf.geometric.RangeDopplerGeocodingOp.initialize(RangeDopplerGeocodingOp.java:306)
	... 33 more
Caused by: org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".
	at org.geotools.referencing.factory.AbstractAuthorityFactory.noSuchAuthorityCode(AbstractAuthorityFactory.java:875)
	at org.geotools.referencing.factory.epsg.DirectEpsgFactory.createCoordinateReferenceSystem(DirectEpsgFactory.java:2239)
	at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:732)
	at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:780)
	at org.geotools.referencing.factory.BufferedAuthorityFactory.createCoordinateReferenceSystem(BufferedAuthorityFactory.java:732)
	at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:780)
	at org.geotools.referencing.factory.FallbackAuthorityFactory.createCoordinateReferenceSystem(FallbackAuthorityFactory.java:625)
	at org.geotools.referencing.factory.AuthorityFactoryAdapter.createCoordinateReferenceSystem(AuthorityFactoryAdapter.java:780)
	at org.geotools.referencing.factory.ThreadedAuthorityFactory.createCoordinateReferenceSystem(ThreadedAuthorityFactory.java:636)
	at org.geotools.referencing.DefaultAuthorityFactory.createCoordinateReferenceSystem(DefaultAuthorityFactory.java:177)
	at org.geotools.referencing.CRS.decode(CRS.java:517)
	at org.esa.s1tbx.commons.CRSGeoCodingHandler.getCRS(CRSGeoCodingHandler.java:173)
	at org.esa.s1tbx.commons.CRSGeoCodingHandler.<init>(CRSGeoCodingHandler.java:55)
	at org.esa.s1tbx.sar.gpf.geometric.RangeDopplerGeocodingOp.createTargetProduct(RangeDopplerGeocodingOp.java:530)
	... 34 more

Error: [NodeId: Terrain-Correction] No code "EPSG:102020" from authority "European Petroleum Survey Group" found for object of type "CoordinateReferenceSystem".

[S1A_EW_GRDH_1SSH_20200317T225506_20200317T225606_031721_03A873_CB43_tmp5.xml] failed with return code 1
failed: ./outdir/S1A__EW___A_20200317T225506_HH_NR_Orb_TF_Spk_TC/S1A__EW___A_20200317T225506_HH_NR_Orb_TF_Spk_TC_proc.xml

How can I correctly reproject my SAR files to South LAEA using pyroSAR?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
johntruckenbrodtcommented, Jul 1, 2021

For sure, path issues always add some spice to our daily work 😜. Glad you found the error and sorry for not being able to respond sooner.

The conda package of spatlialist version 0.7 is now online. Looks like this is under control.

1reaction
johntruckenbrodtcommented, Feb 16, 2021

Hi @ashnair1, the central function for CRS handling in pyroSAR is spatialist.crsConvert, which makes use of OSR. First, the CRS input to the geocode function is converted to EPSG so that the CRS can we written in the SNAP XML workflow like this: ‘EPSG:4326’ to save space. The South LAEA CRS apparently does not have a EPSG code. However, in the following example the ESRI code is returned as EPSG code:

from osgeo import osr

crs = """PROJCS["South_Pole_Lambert_Azimuthal_Equal_Area",GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",0],PARAMETER["Latitude_Of_Origin",-90],UNIT["Meter",1],AUTHORITY["EPSG","102020"]]"""

srs = osr.SpatialReference(crs)

# convert to EPSG code
srs.AutoIdentifyEPSG()
auth = srs.GetAuthorityName(None)
code = int(srs.GetAuthorityCode(None))
string = '{}:{}'.format(auth, code)
print(string)

# re-convert EPSG code to OSR SpatialReference
# will fail because EPSG code 102020 is not recognized
srs = osr.SpatialReference()
srs.ImportFromEPSG(code)
print(srs)

I don’t know why this happens. I am sure there is a reason for it but to me it looks strange.
I have introduced a new check in crsCovert with commit johntruckenbrodt/spatialist@5e803b4 so that 102020 is not returned as EPSG code (because it is an ESRI code) but a RuntimeError is raised instead. In a next step I’ll adjust the geocode function so that the WKT representation is written to the SNAP workflow if this error occurs. I’ll keep you posted on my progress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MapServer: using a CRS for which there is no EPSG code
I would have a try by creating a fake EPSG code into the lookup table "epsg" that is located under the proj directory....
Read more >
Understanding a CRS: Proj4 and CRS codes - PyGIS
Learn how to interpret and use coordinate reference codes like proj4strings, and EPSG codes. This includes defining a CRS, creating custom projections, ...
Read more >
Coordinate Reference Systems - Spatial Data on the Web ...
The axis order rule implies that EPSG codes for geodetic CRSs like 4326 (WGS84) or 4258 (ETTRS89) can not be used to identify...
Read more >
Overview of Coordinate Reference Systems (CRS) in R
The EPSG is a structured dataset of CRS and Coordinate Transformations. It was originally compiled by the, now defunct, European Petroleum Survey Group....
Read more >
Goodbye PROJ.4! How to specify a coordinate reference ...
In R, you can also search for CRSs and EPSG codes since these are included in ... The latter represent a coordinate operation,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found