Changeset 3867 for trunk/LMDZ.MARS/util


Ignore:
Timestamp:
Jul 24, 2025, 3:43:18 PM (3 weeks ago)
Author:
jbclement
Message:

Mars PCM:
Small usage improvements for the script "display_netcdf.py".
JBC

Location:
trunk/LMDZ.MARS/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.MARS/util/display_netcdf.py

    r3851 r3867  
    173173
    174174
    175 def attach_format_coord(ax, mat, x, y, is_pcolormesh=True, data_crs=ccrs.PlateCarree()):
     175def attach_format_coord(ax, mat, x, y, x_dim, y_dim, varname, is_pcolormesh=True, data_crs=ccrs.PlateCarree()):
    176176    """
    177177    Attach a format_coord function to the axes to display x, y, and value at cursor.
     
    185185    else:
    186186        raise ValueError(f"Unsupported mat shape {mat.shape}")
     187
    187188    # Edges or extents
    188189    if is_pcolormesh:
     
    194195    # Detect if ax is a GeoAxes with a projection we can invert
    195196    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    )
    197202
    198203    def format_coord(xp, yp):
    199         # If GeoAxes, invert back to geographic lon/lat
    200         if use_geo:
     204        # Geographic transform if appropriate
     205        if geo_axes:
    201206            try:
    202207                lonp, latp = data_crs.transform_point(xp, yp, src_crs=proj)
     
    215220            row = int((yi - y0) / (y1 - y0) * ny)
    216221
    217         # Within bounds?
     222        # Build the label
     223        label_xy = f"{x_dim}={xi:.3g}, {y_dim}={yi:.3g}"
    218224        if 0 <= row < ny and 0 <= col < nx:
    219225            if mat.ndim == 2:
    220226                v = mat[row, col]
    221                 return f"lon={xi:.3g}, lat={yi:.3g}, val={v:.3g}"
     227                return f"{label_xy}, {varname}={v:.3g}"
    222228            else:
    223229                vals = mat[row, col]
    224230                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 coords
    227         return f"lon={xi:.3g}, lat={yi:.3g}"
     231                return f"{label_xy}, {varname}=({txt})"
     232        else:
     233            return label_xy
    228234
    229235    ax.format_coord = format_coord
     
    277283        uniq_lons = np.unique(lon2d.ravel())
    278284        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)
    280286
    281287        # Optionally overlay MOLA topography
     
    497503        prompt = (
    498504                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"
    502508                "Choose: "
    503509        )
     
    577583        )
    578584        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)
    580586        overlay_topography(ax, transform=proj, levels=10) # Overlay MOLA topography
    581587        cbar = fig.colorbar(cf, ax=ax, pad=0.02)
     
    651657        fig, ax = plt.subplots(figsize=(8, 6))
    652658        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)
    654660        cbar = fig.colorbar(im, ax=ax, pad=0.02)
    655661        cbar.set_label(varname)
     
    658664        ax.set_title(f"{varname} ({y_dim} vs {x_dim})")
    659665        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)
    668675        if output_path:
    669676            fig.savefig(output_path, bbox_inches='tight')
     
    708715        print("\nAvailable variables:")
    709716        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 == "":
    713720            print("Exiting.")
    714721            break
     
    722729        print(f"\nVariable '{varname}' has dimensions:")
    723730        for dim, size in zip(dims, shape):
    724             print(f"  > {dim}: size {size}")
     731            print(f"  - {dim} (size {size})")
    725732        print()
    726733
  • trunk/LMDZ.MARS/util/display_netcdf.yml

    r3854 r3867  
    3030  - deprecated=1.2.18=pyhd8ed1ab_0
    3131  - double-conversion=3.3.1=h5888daf_0
    32   - ffmpeg=7.1.1=gpl_h127656b_906
     32  - ffmpeg=7.1.1=gpl_hea4b676_907
    3333  - font-ttf-dejavu-sans-mono=2.37=hab24e00_0
    3434  - font-ttf-inconsolata=3.000=h77eed37_0
     
    4242  - fribidi=1.0.10=h36c2ea0_0
    4343  - frozenlist=1.7.0=py312h447239a_0
    44   - gdk-pixbuf=2.42.12=hb9ae30d_0
     44  - gdk-pixbuf=2.42.12=h7b179bb_1
    4545  - geos=3.13.1=h97f6797_0
    46   - gettext=0.25.1=h5888daf_0
    47   - gettext-tools=0.25.1=h5888daf_0
     46  - gettext=0.25.1=h3f43e3d_1
     47  - gettext-tools=0.25.1=h3f43e3d_1
    4848  - gl2ps=1.4.2=hae5d5c5_1
    4949  - gmp=6.3.0=hac33072_2
    5050  - graphite2=1.3.14=h5888daf_0
    51   - harfbuzz=11.2.1=h3beb420_0
     51  - harfbuzz=11.3.2=hbb57e21_0
    5252  - hdf4=4.2.15=h2a13503_7
    53   - hdf5=1.14.6=nompi_h6e4c0c1_102
     53  - hdf5=1.14.6=nompi_h6e4c0c1_103
    5454  - icu=75.1=he02047a_0
    5555  - idna=3.10=pyhd8ed1ab_1
     
    6363  - lerc=4.0.0=h0aef613_1
    6464  - level-zero=1.23.1=h84d6215_0
    65   - libabseil=20250127.1=cxx17_hbbce691_0
     65  - libabseil=20250512.1=cxx17_hba17884_0
    6666  - libaec=1.1.4=h3f801dc_0
    67   - libasprintf=0.25.1=h8e693c7_0
    68   - libasprintf-devel=0.25.1=h8e693c7_0
    69   - libass=0.17.3=h52826cd_2
     67  - libasprintf=0.25.1=h3f43e3d_1
     68  - libasprintf-devel=0.25.1=h3f43e3d_1
     69  - libass=0.17.4=h96ad9f0_0
    7070  - libblas=3.9.0=32_h59b9bed_openblas
    7171  - libbrotlicommon=1.1.0=hb9d3cd8_3
     
    9191  - libgcc-ng=15.1.0=h69a702a_3
    9292  - libgcrypt-lib=1.11.1=hb9d3cd8_0
    93   - libgettextpo=0.25.1=h5888daf_0
    94   - libgettextpo-devel=0.25.1=h5888daf_0
     93  - libgettextpo=0.25.1=h3f43e3d_1
     94  - libgettextpo-devel=0.25.1=h3f43e3d_1
    9595  - libgfortran=15.1.0=h69a702a_3
    9696  - libgfortran5=15.1.0=hcea5267_3
     
    101101  - libgomp=15.1.0=h767d61c_3
    102102  - libgpg-error=1.55=h3f2d84a_0
    103   - libhwloc=2.11.2=default_h3d81e11_1002
     103  - libhwloc=2.12.1=default_h3d81e11_1000
    104104  - libiconv=1.18=h4ce23a2_1
    105105  - libjpeg-turbo=3.1.0=hb9d3cd8_0
     
    114114  - libopenblas=0.3.30=pthreads_h94d23a6_0
    115115  - libopengl=1.7.0=ha4b6fd6_2
    116   - libopenvino=2025.0.0=hdc3f47d_3
    117   - libopenvino-auto-batch-plugin=2025.0.0=h4d9b6c2_3
    118   - libopenvino-auto-plugin=2025.0.0=h4d9b6c2_3
    119   - libopenvino-hetero-plugin=2025.0.0=h981d57b_3
    120   - libopenvino-intel-cpu-plugin=2025.0.0=hdc3f47d_3
    121   - libopenvino-intel-gpu-plugin=2025.0.0=hdc3f47d_3
    122   - libopenvino-intel-npu-plugin=2025.0.0=hdc3f47d_3
    123   - libopenvino-ir-frontend=2025.0.0=h981d57b_3
    124   - libopenvino-onnx-frontend=2025.0.0=h0e684df_3
    125   - libopenvino-paddle-frontend=2025.0.0=h0e684df_3
    126   - libopenvino-pytorch-frontend=2025.0.0=h5888daf_3
    127   - libopenvino-tensorflow-frontend=2025.0.0=h684f15b_3
    128   - libopenvino-tensorflow-lite-frontend=2025.0.0=h5888daf_3
     116  - 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
    129129  - libopus=1.5.2=hd0c01bc_0
    130130  - libpciaccess=0.18=hb9d3cd8_0
    131131  - libpng=1.6.50=h943b412_0
    132132  - libpq=17.5=h27ae623_0
    133   - libprotobuf=5.29.3=h501fc15_1
     133  - libprotobuf=6.31.1=h9ef548d_1
    134134  - librsvg=2.58.4=he92a37e_3
    135135  - libsndfile=1.2.2=hc60ed4a_1
    136   - libsqlite=3.50.2=hee844dc_2
     136  - libsqlite=3.50.3=hee844dc_1
    137137  - libssh2=1.11.1=hcf80075_0
    138138  - libstdcxx=15.1.0=h8f9b012_3
     
    154154  - libxkbcommon=1.10.0=h65c71a3_0
    155155  - libxml2=2.13.8=h4bc477f_0
    156   - libxslt=1.1.39=h76b75d6_0
     156  - libxslt=1.1.43=h7a3aeb2_0
    157157  - libzip=1.11.2=h6991a6a_0
    158158  - libzlib=1.3.1=hb9d3cd8_2
     
    181181  - pillow=11.3.0=py312h80c1187_0
    182182  - pip=25.1.1=pyh8b19718_0
    183   - pixman=0.46.2=h29eaf8c_0
     183  - pixman=0.46.4=h537e5f6_0
    184184  - proj=9.6.2=h0054346_0
    185185  - propcache=0.3.1=py312h178313f_0
     
    204204  - setuptools=80.9.0=pyhff2d567_0
    205205  - shapely=2.1.1=py312h21f5128_0
    206   - six=1.17.0=pyhd8ed1ab_0
    207   - snappy=1.2.1=h8bd8927_1
    208   - sqlite=3.50.2=heff268d_2
     206  - six=1.17.0=pyhe01879c_1
     207  - snappy=1.2.2=h03e3b7b_0
     208  - sqlite=3.50.3=heff268d_1
    209209  - svt-av1=3.0.2=h5888daf_0
    210   - tbb=2022.1.0=h4ce085d_0
     210  - tbb=2022.2.0=hb60516a_0
    211211  - tk=8.6.13=noxft_hd72426e_102
    212212  - tornado=6.5.1=py312h66e93f0_0
Note: See TracChangeset for help on using the changeset viewer.