SAR-ARD / s1ard

Sentinel-1 ARD Prototype Processor
MIT License
23 stars 6 forks source link

fixed handling of empty list of neighbors during SLC processing #186

Closed abradley60 closed 3 months ago

abradley60 commented 3 months ago

Process not running with an SLC. Neighbors should be initiated as a list as when it is called on line 202 in the snap.geocode function; a list is expected neighbors=neighbors[i]

The following error will result processing a SLC:

2024-03-13 00:31:05 INFO     Traceback (most recent call last):
  File "/opt/conda/envs/nrb_env/bin/s1_nrb", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/S1_NRB/cli.py", line 60, in cli
    S1_NRB.process(config_file=config_file, section_name=section, debug=debug, **extra)
  File "/opt/conda/envs/nrb_env/lib/python3.12/site-packages/S1_NRB/processor.py", line 202, in main
    dem=fname_dem, neighbors=neighbors[i],
                             ~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable
johntruckenbrodt commented 3 months ago

Hi @abradley60 thanks a lot for pointing this out. However, your fix doesn't fully solve the problem because of this loop: https://github.com/SAR-ARD/S1_NRB/blob/5312d5d8b1af836580cbde770288409b5ddeeeaa/S1_NRB/processor.py#L147 If your list of neighbors only contains one item (neighbors = [None]), the neighbors[i] selection in this loop will fail if the list of scenes contains more than one item.
I think this should fix it (without previous declaration of neighbors):

    if config['product'] == 'GRD':
        print('###### [    SAR] collecting GRD neighbors')
        neighbors = []
        for scene in scenes:
            neighbors.append(search.collect_neighbors(archive=archive, scene=scene))
    else:
        neighbors = [None for scene in scenes]

Could you update your PR with this?

abradley60 commented 3 months ago

Hi @johntruckenbrodt . Good point! I have only been working with a single scene. Fix for the loop has been implemented.

johntruckenbrodt commented 3 months ago

great! Thanks again @abradley60