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

Error "UnboundLocalError: cannot access local variable 'travel_time' where it is not associated with a value" #14

Open
tobiashi26 opened this issue Sep 25, 2024 · 1 comment
Assignees

Comments

@tobiashi26
Copy link
Contributor

tobiashi26 commented Sep 25, 2024

Hello,

I received this error when running the pgf.calculate_geodesic_distance(write_cost_function=True) command with the example data on my local computer.

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[92], line 2
      1 # geodesic distance (not needed for GeoFlood workflow)
----> 2 pgf.calculate_geodesic_distance(write_cost_function=True)

File ~\Miniconda3\envs\pygeoflood-env\Lib\site-packages\pygeoflood\tools.py:101, in time_it.<locals>.wrapper(*args, **kwargs)
     99 start_time = time.time()
    100 method_name = func.__name__
--> 101 result = func(*args, **kwargs)
    102 end_time = time.time()
    103 duration = end_time - start_time

File ~\Miniconda3\envs\pygeoflood-env\Lib\site-packages\pygeoflood\tools.py:170, in use_config_defaults.<locals>.wrapper(self, *args, **kwargs)
    167     print(f"    {key} = {val}")
    169 # Execute the function with the final parameters
--> 170 return func(self, **final_params)

File ~\Miniconda3\envs\pygeoflood-env\Lib\site-packages\pygeoflood\pygeoflood.py:1019, in PyGeoFlood.calculate_geodesic_distance(self, custom_curvature, custom_mfd_fac, custom_outlets, custom_basins, custom_combined_skeleton, custom_filtered_dem, custom_path, write_cost_function, basin_elements, area_threshold, normalize_curvature, local_cost_min)
   1016 del curvature, combined_skeleton
   1018 # Compute the geodesic distance using Fast Marching Method
-> 1019 geodesic_distance = t.fast_marching(
   1020     fmm_start_points, basins, mfd_fac, cost_function_geodesic
   1021 )
   1023 if write_cost_function:
   1024     # set cost function name
   1025     output_cost_function_geodesic_path = self.cost_function_geodesic_path

File ~\Miniconda3\envs\pygeoflood-env\Lib\site-packages\pygeoflood\tools.py:964, in fast_marching(fmm_start_points, basins, mfd_fac, cost_function)
    962         print("Error in catchment: ", basinIndexList)
    963         print("That was not a valid number")
--> 964     geodesic_distance[maskedBasin == 1] = travel_time[maskedBasin == 1]
    965 geodesic_distance[maskedBasin == 1] = travel_time[maskedBasin == 1]
    966 geodesic_distance[geodesic_distance == np.inf] = np.nan

UnboundLocalError: cannot access local variable 'travel_time' where it is not associated with a value

The function also printed this information.

Running calculate_geodesic_distance with parameters:
    custom_curvature = None
    custom_mfd_fac = None
    custom_outlets = None
    custom_basins = None
    custom_combined_skeleton = None
    custom_filtered_dem = None
    custom_path = None
    write_cost_function = True
    basin_elements = 2
    area_threshold = 0.1
    normalize_curvature = True
    local_cost_min = None
Performing fast marching
FMM iteration 1/32: RAM usage: 15.05/15.72 GB (95.7%)
Error in calculating skfmm travel time
Error in catchment:  139.0
That was not a valid number

Thanks

@markwang0 markwang0 self-assigned this Sep 25, 2024
@markwang0
Copy link
Member

markwang0 commented Oct 2, 2024

@tobiashi26 it looks like this problem only occurs on windows, not on mac or linux. I haven't found a fix yet but will keep looking into it.

in the meantime, if you comment out these two cells in the notebook:

pgf.calculate_geodesic_distance(write_cost_function=True)
pgf.identify_channel_heads()

the notebook should run as expected and produce an inundation map. let me know if that doesn't work for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants