とらりもんHOME  Index  Search  Changes  Login

netCDF

How to deal with netCDF data on Ubuntu Linux

2022/10/09, 2020/12/09 Kenlo Nasahara

Install netCDF library

sudo apt install python3-netcdf libnetcdf-dev netcdf-bin

Exercise with solar spectrum data (TSIS-1 Hybrid Solar Reference Spectrum)

$ wget https://lasp.colorado.edu/lisird/resources/lasp/hsrs/hybrid_reference_spectrum_p005nm_resolution_c2021-03-04_with_unc.nc
(then you get the netCDF file)

$ ncdump hybrid_reference_spectrum_p005nm_resolution_c2020-09-21_with_unc.nc | less
(then you can look inside the netCDF file)

$ ipython3
import netCDF4
import numpy as np
import matplotlib.pyplot as plt
fn="hybrid_reference_spectrum_p005nm_resolution_c2020-09-21_with_unc.nc"
nc = netCDF4.Dataset(fn, 'r', format="NETCDF4")
# check structure and contents of the data
nc.dimensions
nc.variables
nc.variables.keys()
nc['SSI']
nc['Vacuum Wavelength']
nc['Wavelength_Band_Width']
nc['SSI_UNC']
type(nc['SSI'][:])
# draw a graph 
x=np.array((nc['SSI'][:], nc['Vacuum Wavelength'][:]))
plt.xlabel("wavelength / nm")
plt.ylabel("spectral irradiance / (W m-2 nm-1)")
plt.xlim([300,700])
plt.plot(x[1], x[0], lw=0.02, color="black")
plt.show()
solar_spectrum.png
Last modified:2022/10/09 14:06:30
Keyword(s):
References: