Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
2.3 kB
1
Indexable
import netCDF4 as nc

# Open a NetCDF file
file_path = '/p/work1/hersheya/archive-test/eastmed_u/202407/coamps_ncom_eastmed_u_1_2024070200_00230000.nc'
dataset = nc.Dataset(file_path, 'r')

# Iterate over all variables and print their scale_factor and add_offset
for var_name in dataset.variables:
    var = dataset.variables[var_name]
    scale_factor = var.getncattr('scale_factor') if 'scale_factor' in var.ncattrs() else 'Not available'
    add_offset = var.getncattr('add_offset') if 'add_offset' in var.ncattrs() else 'Not available'
    print(f'Variable: {var_name}, Scale Factor: {scale_factor}, Add Offset: {add_offset}')

# Close the dataset
dataset.close()






#Output
Variable: lon, Scale Factor: Not available, Add Offset: Not available
Variable: lat, Scale Factor: Not available, Add Offset: Not available
Variable: depth, Scale Factor: Not available, Add Offset: Not available
Variable: time, Scale Factor: Not available, Add Offset: Not available
Variable: tau, Scale Factor: Not available, Add Offset: Not available
Variable: watdep, Scale Factor: 0.09155552834272385, Add Offset: 3000.0
Variable: surf_el, Scale Factor: 0.0015259254723787308, Add Offset: 0.0
Variable: water_baro_u, Scale Factor: 0.07629627734422684, Add Offset: 0.0
Variable: water_baro_v, Scale Factor: 0.07629627734422684, Add Offset: 0.0
Variable: water_u, Scale Factor: 0.00027466658502817154, Add Offset: 0.0
Variable: water_v, Scale Factor: 0.00027466658502817154, Add Offset: 0.0
Variable: water_w, Scale Factor: 3.0518509447574615e-05, Add Offset: 0.0
Variable: salinity, Scale Factor: 0.0008239997550845146, Add Offset: 18.0
Variable: water_temp, Scale Factor: 0.0006561479531228542, Add Offset: 16.5
Variable: surf_atm_press, Scale Factor: 0.003814813680946827, Add Offset: 975.0
Variable: surf_wnd_stress_gridx, Scale Factor: 0.00030518509447574615, Add Offset: 0.0
Variable: surf_wnd_stress_gridy, Scale Factor: 0.00030518509447574615, Add Offset: 0.0
Variable: surf_roughness, Scale Factor: 1.5259254723787308e-05, Add Offset: 0.5
Variable: surf_temp_flux, Scale Factor: 9.15555276037594e-08, Add Offset: 0.0
Variable: surf_solar_flux, Scale Factor: 1.5259255192745513e-08, Add Offset: 0.0005000000237487257
Leave a Comment