edwardoughton / itmlogic

Longley-Rice Irregular Terrain Model (itmlogic)
https://itmlogic.readthedocs.io/en/latest/?badge=latest
Other
55 stars 21 forks source link

UnboundLocalError in a acat function #69

Closed aleksandrovivan closed 1 year ago

aleksandrovivan commented 1 year ago

I've been trying to run the code of p2p.py example in Google Colab (as well as Anaconda, through Jupiter) but I encountered the UnboundLocalError when running itmlogic_p2p():

/usr/local/lib/python3.8/dist-packages/itmlogic/ascat.py in ascat(d, prop) 17 r2 = r2 * prop['he'][1] 18 ---> 19 if r1 < 0.2 and r2 < 0.2: 20 prop['ascat1'] = 1001 21

UnboundLocalError: local variable 'r1' referenced before assignment/usr/local/lib/python3.8/dist-packages/itmlogic/ascat.py in ascat(d, prop) 17 r2 = r2 * prop['he'][1] 18 ---> 19 if r1 < 0.2 and r2 < 0.2: 20 prop['ascat1'] = 1001 21

UnboundLocalError: local variable 'r1' referenced before assignment/usr/local/lib/python3.8/dist-packages/itmlogic/ascat.py in ascat(d, prop) 17 r2 = r2 * prop['he'][1] 18 ---> 19 if r1 < 0.2 and r2 < 0.2: 20 prop['ascat1'] = 1001 21

UnboundLocalError: local variable 'r1' referenced before assignment

The only difference of substance is that I'm using ASTGTMV003_N51W001_dem.tif instead of ASTGTM2_N51W001_dem.tif, since only the v3 is now available online (though it is claimed that "the same gridding and tile structure as V1 and V2, with 30-meter postings and 1 x 1 degree tiles" in v3).

tomalrussell commented 1 year ago

Hi @aleksandrovivan thanks for the error report.

I can't reproduce the problem locally - with the latest itmlogic code and the v3 ASTER DEM switched in, I can run okay:

> python scripts/p2p.py
Distance is 77.57231025439202km
len(measured_terrain_profile) 599
len(original_surface_profile_m) 157
Line of sight path
Diffraction is the dominant mode
Estimated quantiles of basic transmission loss (db)
Free space value 102.63079048306626 db
Confidence levels 50, 90, 10
Completed run

Can you check which version of itmlogic you're trying to run? The relevant block of code in itmlogic/scatter_attenuation/ascat.py has r1 where it should be.

We've generally tested and run code from a source checkout of this repository - there was an old itmlogic on pypi, and I've just released v1.1 which is our last tagged release.

Could you try pip install itmlogic==1.1 and then test your script again? OR download/clone this repository and pip install -e . from within the source directory.

aleksandrovivan commented 1 year ago

Thank you tomalrussell for the quick response!

The issue was indeed all about the version of itmlogic that I was using (it was 0.1). It runs smoothly now.