Changeset 3867 for trunk/LMDZ.MARS/util
- Timestamp:
- Jul 24, 2025, 3:43:18 PM (3 weeks ago)
- Location:
- trunk/LMDZ.MARS/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/display_netcdf.py
r3851 r3867 173 173 174 174 175 def attach_format_coord(ax, mat, x, y, is_pcolormesh=True, data_crs=ccrs.PlateCarree()):175 def attach_format_coord(ax, mat, x, y, x_dim, y_dim, varname, is_pcolormesh=True, data_crs=ccrs.PlateCarree()): 176 176 """ 177 177 Attach a format_coord function to the axes to display x, y, and value at cursor. … … 185 185 else: 186 186 raise ValueError(f"Unsupported mat shape {mat.shape}") 187 187 188 # Edges or extents 188 189 if is_pcolormesh: … … 194 195 # Detect if ax is a GeoAxes with a projection we can invert 195 196 proj = getattr(ax, 'projection', None) 196 use_geo = isinstance(proj, ccrs.Projection) 197 geo_axes = ( 198 isinstance(proj, ccrs.Projection) 199 and x_dim.lower() in LON_DIMS 200 and y_dim.lower() in LAT_DIMS 201 ) 197 202 198 203 def format_coord(xp, yp): 199 # If GeoAxes, invert back to geographic lon/lat200 if use_geo:204 # Geographic transform if appropriate 205 if geo_axes: 201 206 try: 202 207 lonp, latp = data_crs.transform_point(xp, yp, src_crs=proj) … … 215 220 row = int((yi - y0) / (y1 - y0) * ny) 216 221 217 # Within bounds? 222 # Build the label 223 label_xy = f"{x_dim}={xi:.3g}, {y_dim}={yi:.3g}" 218 224 if 0 <= row < ny and 0 <= col < nx: 219 225 if mat.ndim == 2: 220 226 v = mat[row, col] 221 return f" lon={xi:.3g}, lat={yi:.3g}, val={v:.3g}"227 return f"{label_xy}, {varname}={v:.3g}" 222 228 else: 223 229 vals = mat[row, col] 224 230 txt = ", ".join(f"{vv:.3g}" for vv in vals[:3]) 225 return f" lon={xi:.3g}, lat={yi:.3g}, val=({txt})"226 # Out of bounds: still show coords227 return f"lon={xi:.3g}, lat={yi:.3g}"231 return f"{label_xy}, {varname}=({txt})" 232 else: 233 return label_xy 228 234 229 235 ax.format_coord = format_coord … … 277 283 uniq_lons = np.unique(lon2d.ravel()) 278 284 uniq_lats = np.unique(lat2d.ravel()) 279 attach_format_coord(ax, data2d, uniq_lons, uniq_lats, is_pcolormesh=True)285 attach_format_coord(ax, data2d, uniq_lons, uniq_lats, 'lon', 'lat', varname, is_pcolormesh=True) 280 286 281 287 # Optionally overlay MOLA topography … … 497 503 prompt = ( 498 504 f"Available options for '{dim}' (size {size}):\n" 499 f" -'1–{size}' to pick that index\n"500 " -'a' to average over this dimension\n"501 " -'e' or Enter to take all values\n"505 f" > '1–{size}' to pick that index\n" 506 " > 'a' to average over this dimension\n" 507 " > 'e' or Enter to take all values\n" 502 508 "Choose: " 503 509 ) … … 577 583 ) 578 584 cf = ax.pcolormesh(lon2d, lat2d, grid, shading='auto', cmap=colormap, transform=ccrs.PlateCarree()) 579 attach_format_coord(ax, grid, uniq_lons, uniq_lats, is_pcolormesh=True)585 attach_format_coord(ax, grid, uniq_lons, uniq_lats, 'lon', 'lat', varname, is_pcolormesh=True) 580 586 overlay_topography(ax, transform=proj, levels=10) # Overlay MOLA topography 581 587 cbar = fig.colorbar(cf, ax=ax, pad=0.02) … … 651 657 fig, ax = plt.subplots(figsize=(8, 6)) 652 658 im = ax.pcolormesh(x_coords, y_coords, plot_data, shading='auto', cmap=colormap) 653 attach_format_coord(ax, plot_data, x_coords, y_coords, is_pcolormesh=True)659 attach_format_coord(ax, plot_data, x_coords, y_coords, x_dim, y_dim, varname, is_pcolormesh=True) 654 660 cbar = fig.colorbar(im, ax=ax, pad=0.02) 655 661 cbar.set_label(varname) … … 658 664 ax.set_title(f"{varname} ({y_dim} vs {x_dim})") 659 665 ax.grid(True) 660 # Prompt for polar-stereo views if interactive 661 if sys.stdin.isatty() and input("Display polar-stereo views? [y = yes, anything else = no]: ").strip().lower() == "y": 662 units = getattr(dataset.variables[varname], "units", None) 663 plot_polar_views(x_coords, y_coords, plot_data, colormap, varname, units) 664 # Prompt for 3D globe view if interactive 665 if sys.stdin.isatty() and input("Display 3D globe view? [y = yes, anything else = no]: ").strip().lower() == "y": 666 units = getattr(dataset.variables[varname], "units", None) 667 plot_3D_globe(x_coords, y_coords, plot_data, colormap, varname, units) 666 if {x_dim, y_dim} & set(LAT_DIMS) and {x_dim, y_dim} & set(LON_DIMS): 667 # Prompt for polar-stereo views if interactive 668 if sys.stdin.isatty() and input("Display polar-stereo views? [y = yes, anything else = no]: ").strip().lower() == "y": 669 units = getattr(dataset.variables[varname], "units", None) 670 plot_polar_views(x_coords, y_coords, plot_data, colormap, varname, units) 671 # Prompt for 3D globe view if interactive 672 if sys.stdin.isatty() and input("Display 3D globe view? [y = yes, anything else = no]: ").strip().lower() == "y": 673 units = getattr(dataset.variables[varname], "units", None) 674 plot_3D_globe(x_coords, y_coords, plot_data, colormap, varname, units) 668 675 if output_path: 669 676 fig.savefig(output_path, bbox_inches='tight') … … 708 715 print("\nAvailable variables:") 709 716 for name in var_list: 710 print(f" -{name}")711 varname = input("\nEnter variable name to plot (or 'q'to quit): ").strip()712 if varname .lower() in ("q", "quit", "exit"):717 print(f" > {name}") 718 varname = input("\nEnter variable name to plot (or Enter to quit): ").strip() 719 if varname == "": 713 720 print("Exiting.") 714 721 break … … 722 729 print(f"\nVariable '{varname}' has dimensions:") 723 730 for dim, size in zip(dims, shape): 724 print(f" > {dim}: size {size}")731 print(f" - {dim} (size {size})") 725 732 print() 726 733 -
trunk/LMDZ.MARS/util/display_netcdf.yml
r3854 r3867 30 30 - deprecated=1.2.18=pyhd8ed1ab_0 31 31 - double-conversion=3.3.1=h5888daf_0 32 - ffmpeg=7.1.1=gpl_h 127656b_90632 - ffmpeg=7.1.1=gpl_hea4b676_907 33 33 - font-ttf-dejavu-sans-mono=2.37=hab24e00_0 34 34 - font-ttf-inconsolata=3.000=h77eed37_0 … … 42 42 - fribidi=1.0.10=h36c2ea0_0 43 43 - frozenlist=1.7.0=py312h447239a_0 44 - gdk-pixbuf=2.42.12=h b9ae30d_044 - gdk-pixbuf=2.42.12=h7b179bb_1 45 45 - geos=3.13.1=h97f6797_0 46 - gettext=0.25.1=h 5888daf_047 - gettext-tools=0.25.1=h 5888daf_046 - gettext=0.25.1=h3f43e3d_1 47 - gettext-tools=0.25.1=h3f43e3d_1 48 48 - gl2ps=1.4.2=hae5d5c5_1 49 49 - gmp=6.3.0=hac33072_2 50 50 - graphite2=1.3.14=h5888daf_0 51 - harfbuzz=11. 2.1=h3beb420_051 - harfbuzz=11.3.2=hbb57e21_0 52 52 - hdf4=4.2.15=h2a13503_7 53 - hdf5=1.14.6=nompi_h6e4c0c1_10 253 - hdf5=1.14.6=nompi_h6e4c0c1_103 54 54 - icu=75.1=he02047a_0 55 55 - idna=3.10=pyhd8ed1ab_1 … … 63 63 - lerc=4.0.0=h0aef613_1 64 64 - level-zero=1.23.1=h84d6215_0 65 - libabseil=20250 127.1=cxx17_hbbce691_065 - libabseil=20250512.1=cxx17_hba17884_0 66 66 - libaec=1.1.4=h3f801dc_0 67 - libasprintf=0.25.1=h 8e693c7_068 - libasprintf-devel=0.25.1=h 8e693c7_069 - libass=0.17. 3=h52826cd_267 - libasprintf=0.25.1=h3f43e3d_1 68 - libasprintf-devel=0.25.1=h3f43e3d_1 69 - libass=0.17.4=h96ad9f0_0 70 70 - libblas=3.9.0=32_h59b9bed_openblas 71 71 - libbrotlicommon=1.1.0=hb9d3cd8_3 … … 91 91 - libgcc-ng=15.1.0=h69a702a_3 92 92 - libgcrypt-lib=1.11.1=hb9d3cd8_0 93 - libgettextpo=0.25.1=h 5888daf_094 - libgettextpo-devel=0.25.1=h 5888daf_093 - libgettextpo=0.25.1=h3f43e3d_1 94 - libgettextpo-devel=0.25.1=h3f43e3d_1 95 95 - libgfortran=15.1.0=h69a702a_3 96 96 - libgfortran5=15.1.0=hcea5267_3 … … 101 101 - libgomp=15.1.0=h767d61c_3 102 102 - libgpg-error=1.55=h3f2d84a_0 103 - libhwloc=2.1 1.2=default_h3d81e11_1002103 - libhwloc=2.12.1=default_h3d81e11_1000 104 104 - libiconv=1.18=h4ce23a2_1 105 105 - libjpeg-turbo=3.1.0=hb9d3cd8_0 … … 114 114 - libopenblas=0.3.30=pthreads_h94d23a6_0 115 115 - libopengl=1.7.0=ha4b6fd6_2 116 - libopenvino=2025. 0.0=hdc3f47d_3117 - libopenvino-auto-batch-plugin=2025. 0.0=h4d9b6c2_3118 - libopenvino-auto-plugin=2025. 0.0=h4d9b6c2_3119 - libopenvino-hetero-plugin=2025. 0.0=h981d57b_3120 - libopenvino-intel-cpu-plugin=2025. 0.0=hdc3f47d_3121 - libopenvino-intel-gpu-plugin=2025. 0.0=hdc3f47d_3122 - libopenvino-intel-npu-plugin=2025. 0.0=hdc3f47d_3123 - libopenvino-ir-frontend=2025. 0.0=h981d57b_3124 - libopenvino-onnx-frontend=2025. 0.0=h0e684df_3125 - libopenvino-paddle-frontend=2025. 0.0=h0e684df_3126 - libopenvino-pytorch-frontend=2025. 0.0=h5888daf_3127 - libopenvino-tensorflow-frontend=2025. 0.0=h684f15b_3128 - libopenvino-tensorflow-lite-frontend=2025. 0.0=h5888daf_3116 - libopenvino=2025.2.0=hb617929_1 117 - libopenvino-auto-batch-plugin=2025.2.0=hed573e4_1 118 - libopenvino-auto-plugin=2025.2.0=hed573e4_1 119 - libopenvino-hetero-plugin=2025.2.0=hd41364c_1 120 - libopenvino-intel-cpu-plugin=2025.2.0=hb617929_1 121 - libopenvino-intel-gpu-plugin=2025.2.0=hb617929_1 122 - libopenvino-intel-npu-plugin=2025.2.0=hb617929_1 123 - libopenvino-ir-frontend=2025.2.0=hd41364c_1 124 - libopenvino-onnx-frontend=2025.2.0=h1862bb8_1 125 - libopenvino-paddle-frontend=2025.2.0=h1862bb8_1 126 - libopenvino-pytorch-frontend=2025.2.0=hecca717_1 127 - libopenvino-tensorflow-frontend=2025.2.0=h0767aad_1 128 - libopenvino-tensorflow-lite-frontend=2025.2.0=hecca717_1 129 129 - libopus=1.5.2=hd0c01bc_0 130 130 - libpciaccess=0.18=hb9d3cd8_0 131 131 - libpng=1.6.50=h943b412_0 132 132 - libpq=17.5=h27ae623_0 133 - libprotobuf= 5.29.3=h501fc15_1133 - libprotobuf=6.31.1=h9ef548d_1 134 134 - librsvg=2.58.4=he92a37e_3 135 135 - libsndfile=1.2.2=hc60ed4a_1 136 - libsqlite=3.50. 2=hee844dc_2136 - libsqlite=3.50.3=hee844dc_1 137 137 - libssh2=1.11.1=hcf80075_0 138 138 - libstdcxx=15.1.0=h8f9b012_3 … … 154 154 - libxkbcommon=1.10.0=h65c71a3_0 155 155 - libxml2=2.13.8=h4bc477f_0 156 - libxslt=1.1. 39=h76b75d6_0156 - libxslt=1.1.43=h7a3aeb2_0 157 157 - libzip=1.11.2=h6991a6a_0 158 158 - libzlib=1.3.1=hb9d3cd8_2 … … 181 181 - pillow=11.3.0=py312h80c1187_0 182 182 - pip=25.1.1=pyh8b19718_0 183 - pixman=0.46. 2=h29eaf8c_0183 - pixman=0.46.4=h537e5f6_0 184 184 - proj=9.6.2=h0054346_0 185 185 - propcache=0.3.1=py312h178313f_0 … … 204 204 - setuptools=80.9.0=pyhff2d567_0 205 205 - shapely=2.1.1=py312h21f5128_0 206 - six=1.17.0=pyh d8ed1ab_0207 - snappy=1.2. 1=h8bd8927_1208 - sqlite=3.50. 2=heff268d_2206 - six=1.17.0=pyhe01879c_1 207 - snappy=1.2.2=h03e3b7b_0 208 - sqlite=3.50.3=heff268d_1 209 209 - svt-av1=3.0.2=h5888daf_0 210 - tbb=2022. 1.0=h4ce085d_0210 - tbb=2022.2.0=hb60516a_0 211 211 - tk=8.6.13=noxft_hd72426e_102 212 212 - tornado=6.5.1=py312h66e93f0_0
Note: See TracChangeset
for help on using the changeset viewer.