envtoolkit.nc¶
Module that handles functions relative to NetCDF files
Functions
copy_ncstruct (fin, fout) |
Copy the internal structure of a NetCDF file. |
extract_date (fin[, timevar_name, units, …]) |
Converts the time array of a NetCDF file into a date. |
-
envtoolkit.nc.
copy_ncstruct
(fin, fout)[source]¶ Copy the internal structure of a NetCDF file.
It copies the dimension names, variable names and attributes from a file to another file.
Parameters: - fin (netCDF4.Dataset) – Source file
- fout (netCDF4.Dataset) – Destination file
Note
The file contents are not copied! Only the structure of the file
from netCDF4 import Dataset import envtoolkit.nc fin = Dataset("source_file.nc", "r") fout = Dataset("dest_file.nc", "w") # copy the dimensions/variables/attributes of # the source file into the dest file envtoolkit.nc.copy_ncstruct(fin, fout) # Fill in the variable of the destination file # closing the files fin.close() fout.close()
Parameters: - fin (netCDF4.Dataset) – the source file
- fout (netCDF4.Dataset) – the destination file
-
envtoolkit.nc.
extract_date
(fin, timevar_name='time', units=None, calendar='gregorian', timeoff=0)[source]¶ Converts the time array of a NetCDF file into a date.
Parameters: - fin (netCDF4.Dataset) – the NetCDF file
- timevar_name (str) – the name of the time variable
- units (str) – the time units (used only if no time units in the the file)
- calendar (str) – the time calendar (used only if no time units in the the file)
- timeoff (float) – A time offset that is added to the time array
Returns: an array of
datetime.datetime
objectReturn type: numpy.array