
    >.i                        S r SSKrSSKrSSKJr  SSKrSSKrSSK	J
r  S r\S:X  Ga$  \R                  " SS9r\R!                  SS	S
9  \R#                  5       r\R&                  R)                  5       r\" S5      \-  r\\ S3-  r\R/                  5       (       d  \" S\ 35        \R2                  " S5        \" S\R5                  5        S35        \R6                  " \SS9rS\R:                  ;  a  \" S5        S\S'   O&\R<                  " \S   SS9R?                  S5      \S'   \R5                  5        S3r \\ S3-  r!\" \\ \!5        gg)u-  
Visualize OpenStreetMap road features for a state,
colored directly by their 'layer' attribute value.

✅ Features:
 - Colors each road by its layer value (-2 .. +3)
 - Uses diverging color map (blue→green→red)
 - Handles missing values gracefully (layer=0 default)
 - Saves PNG to state folder
    N)Pathc                 D   [         R                  " SS9u  p4U R                  SSSUSSSS	S
S.S9  UR                  USSS9  UR	                  S5        [         R
                  " 5         [         R                  " USSS9  [        SU 35        [         R                  " U5        g)z(Plot roads colored by their layer value.)   
   )figsizelayerRdYlBu_rg333333?TzOSM Layer Valueverticalgffffff?g{Gz?)labelorientationshrinkpad)columncmap	linewidthaxlegendlegend_kwds   r   )fontsizer   offi,  tight)dpibbox_inchesu!   💾 Saved colored layer map to: N)	pltsubplotsplot	set_titleaxistight_layoutsavefigprintclose)roadstitle	save_pathfigr   s        2/data2/heatmap/scripts/visualize_layer_by_value.pyplot_layer_mapr)      s    ll8,GC 
JJ&%	
   LLL,GGENKK	s8	-i[
9:IIcN    __main__z7Visualize roads colored by their OSM 'layer' attribute.)descriptionstatezState name (e.g., alabama).)helpOSM_State_Filesz_roads_projected.gpkgu   ❌ File not found:    u   📦 Loading roads for z...roads_projected)r   r   u7   ⚠️ No 'layer' column found — defaulting all to 0.coerce)errorsz Road Network by OSM Layerz_road_layers.png)"__doc__argparsesyspathlibr   	geopandasgpdpandaspdmatplotlib.pyplotpyplotr   r)   __name__ArgumentParserparseradd_argument
parse_argsargsr-   lowerbase_dir
roads_pathexistsr"   exit
capitalize	read_filer$   columns
to_numericfillnar%   
output_png r*   r(   <module>rP      sl  	  
    4 z$$MF &CDDJJE%&.Hug%:;;J$ZL12	#E$4$4$6#7s
;<MM*,=>E emm#GHguW~hGNNqQg!""<=Eug%566J5%,7 r*   