MaffooClock / MrRadar

A Python utility that generates a map and imagery frames from raw NEXRAD data
MIT License
0 stars 0 forks source link

Output directory is created only when explicitly specified (default exists, but is never created) #13

Closed dkowis closed 4 days ago

dkowis commented 4 days ago

Something happeend right after install. even info logged the splode.

❯ python mr_radar map KFWS
2024-11-21 11:40:41.969 | INFO     | radar_loop_generator:site_id:55 - → Site ID is 'kfws'
2024-11-21 11:40:41.969 | INFO     | map_generator:__init__:32 - → Map file will be saved as '/home/dkowis/gitwork/MrRadar/out/map.png'
2024-11-21 11:40:41.969 | INFO     | map_generator:generate:46 - Generating map...
2024-11-21 11:40:41.969 | INFO     | radar_loop_generator:_check_site_coords:241 - Retrieving coordinates for kfws...
2024-11-21 11:40:50.944 | INFO     | radar_loop_generator:site_coords:87 - Coordinates for kfws: (32.564998626708984, -97.30799865722656)
2024-11-21 11:40:50.944 | INFO     | radar_loop_generator:_check_site_coords:253 - ...done
2024-11-21 11:40:50.958 | INFO     | radar_loop_generator:_check_image_bounds:264 - Calculating image bounds for kfws...
2024-11-21 11:40:50.959 | INFO     | radar_loop_generator:_check_image_bounds:270 - ...done.  Bounds for kfws at 150 miles: [-99.87808707834431, 30.387811598191607, -94.73791023610882, 34.74143110617807]
2024-11-21 11:40:50.988 | INFO     | map_generator:_generate_topography:68 - Generating layer 1 of 6: topography...
2024-11-21 11:41:00.277 | INFO     | map_generator:_generate_topography:85 - ...done
2024-11-21 11:41:00.278 | INFO     | map_generator:_generate_borders:89 - Generating layer 2 of 6: borders...
2024-11-21 11:41:00.616 | INFO     | map_generator:_generate_borders:108 -  • added country borders
2024-11-21 11:41:00.617 | INFO     | map_generator:_generate_borders:113 -  • added state borders
2024-11-21 11:41:00.618 | INFO     | map_generator:_generate_borders:118 -  • added 129 county borders
2024-11-21 11:41:00.618 | INFO     | map_generator:_generate_borders:120 - ...done
2024-11-21 11:41:00.619 | INFO     | map_generator:_generate_highways:124 - Generating layer 3 of 6: major highways...
2024-11-21 11:41:00.849 | INFO     | map_generator:_generate_highways:133 -     Using 353 interstate MultiLineStrings
2024-11-21 11:41:01.016 | INFO     | map_generator:_generate_highways:140 - ...done
2024-11-21 11:41:01.017 | INFO     | map_generator:_generate_lakes:144 - Generating layer 4 of 6: lakes...
2024-11-21 11:41:13.737 | INFO     | map_generator:_generate_lakes:153 -    Using 160 lake MultiPolygons
2024-11-21 11:41:13.738 | INFO     | map_generator:_generate_lakes:159 - ...done
2024-11-21 11:41:13.739 | INFO     | map_generator:_generate_rivers:163 - Generating layer 5 of 6: major rivers...
2024-11-21 11:41:14.223 | INFO     | map_generator:_generate_rivers:172 -   Using 431 river MultiLineStrings
2024-11-21 11:41:14.224 | INFO     | map_generator:_generate_rivers:178 - ...done
2024-11-21 11:41:14.225 | INFO     | map_generator:_generate_cities:182 - Generating layer 6 of 6: cities...
2024-11-21 11:41:14.470 | INFO     | map_generator:_generate_cities:191 -   Queried 607 total cities
2024-11-21 11:41:14.471 | INFO     | map_generator:_generate_cities:203 -   Plotting 114 cities
2024-11-21 11:41:14.626 | INFO     | map_generator:_generate_cities:212 - ...done
/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_cultural/ne_50m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_cultural/ne_50m_admin_1_states_provinces_lines.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
2024-11-21 11:41:18.211 | INFO     | __main__:<module>:76 - 💥 KA-BOOM! 💥
    Site:        kfws
    Site Coords: (32.564998626708984, -97.30799865722656)
    Radius:      150
    BBox:        [-99.87808707834431, 30.387811598191607, -94.73791023610882, 34.74143110617807]
    Envelope:    POLYGON ((-94.73791023610882 30.387811598191607, -94.73791023610882 34.74143110617807, -99.87808707834431 34.74143110617807, -99.87808707834431 30.387811598191607, -94.73791023610882 30.387811598191607))
    File Path:   /home/dkowis/gitwork/MrRadar/out/map.png

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/dkowis/gitwork/MrRadar/mr_radar/__main__.py", line 69, in <module>
    generator.generate()
    ~~~~~~~~~~~~~~~~~~^^
  File "/home/dkowis/gitwork/MrRadar/mr_radar/map_generator.py", line 59, in generate
    self.save_image()
    ~~~~~~~~~~~~~~~^^
  File "/home/dkowis/gitwork/MrRadar/mr_radar/map_generator.py", line 63, in save_image
    super().save_image()
    ~~~~~~~~~~~~~~~~~~^^
  File "/home/dkowis/gitwork/MrRadar/mr_radar/radar_loop_generator.py", line 180, in save_image
    figure.savefig( file_path_name, bbox_inches='tight', pad_inches=0, **kwargs )
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/figure.py", line 3395, in savefig
    self.canvas.print_figure(fname, **kwargs)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/backend_bases.py", line 2204, in print_figure
    result = print_method(
        filename,
    ...<3 lines>...
        bbox_inches_restore=_bbox_inches_restore,
        **kwargs)
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/backend_bases.py", line 2054, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
                                                                 ~~~~^
        *args, **{k: v for k, v in kwargs.items() if k not in skip}))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/backends/backend_agg.py", line 496, in print_png
    self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/backends/backend_agg.py", line 445, in _print_pil
    mpl.image.imsave(
    ~~~~~~~~~~~~~~~~^
        filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/matplotlib/image.py", line 1676, in imsave
    image.save(fname, **pil_kwargs)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/dkowis/.local/share/mise/installs/python/3.13.0/lib/python3.13/site-packages/PIL/Image.py", line 2600, in save
    fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: '/home/dkowis/gitwork/MrRadar/out/map.png'
MaffooClock commented 4 days ago

My initial reaction is from the FileNotFoundError exception, which tells me the ./out directory doesn't exist.

Here's the problem: https://github.com/MaffooClock/MrRadar/blob/606dfe4cfd960829fb7c234fbf9610aea404e4e6/mr_radar/radar_loop_generator.py#L132-L142

The setter is responsible for creating that directory if it doesn't exist. But when no value is explicitly set on the command line for --path, None is assumed, and so the setter bails out before the directory is created.

Probably ought to move that directory creation to the getter since it's responsible for setting the default when a value hasn't been set previously.