Changeset 3681


Ignore:
Timestamp:
Mar 12, 2025, 11:06:49 AM (3 months ago)
Author:
jbclement
Message:

PEM:
Small improvements for the python script to display variables in a NetCDF file.
JBC

Location:
trunk/LMDZ.MARS
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.MARS/changelog.txt

    r3648 r3681  
    47764776== 26/02/2025 == JBC
    47774777Skipping non-numeric variables in the analysis of NetCDF files.
     4778
     4779== 12/03/2025 == JBC
     4780Small improvements for the python script to display variables in a NetCDF file.
  • trunk/LMDZ.MARS/util/display_netcdf.py

    r3459 r3681  
    2424    # Add '/' if the match is a directory
    2525    matches = [match + '/' if os.path.isdir(match) else match for match in matches]
    26    
    2726    try:
    2827        return matches[state]
     
    8180    # If the variable has a time dimension, ask for the time index
    8281    if 'Time' in dimensions:
    83         time_index = int(input(f"Enter the time index (0 to {variable.shape[0] - 1}): "))
     82        if variable.shape[0] == 1:
     83            time_index = 0
     84        else:
     85            time_index = int(input(f"Enter the time index (0 to {variable.shape[0] - 1}): "))
    8486    else:
    8587        time_index = None
     
    103105   
    104106    # Plot the selected variable
    105     plt.figure(figsize=(10,6))
    106     plt.contourf(longitude,latitude,data_slice,cmap='viridis')
     107    plt.figure(figsize = (10,6))
     108    plt.contourf(longitude,latitude,data_slice,cmap = 'jet')
    107109    plt.colorbar(label=f"{variable_name.capitalize()} (units)") # Adjust units based on your data
    108110    plt.xlabel('Longitude (degrees)')
Note: See TracChangeset for help on using the changeset viewer.