Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Export the results to a netcdf file
"""
from suntans_ugrid import ugrid
from netCDF4 import Dataset
# Fill in the depths with zero
#if not self.__dict__.has_key('dv'):
if dv==None:
self.dv = np.zeros((self.Nc,))
else:
self.dv = dv
if not self.__dict__.has_key('Nk'):
self.Nk = self.Nkmax*np.ones((self.Nc,))
Grid.writeNC(self,outfile)
# write the time variable
t= othertime.SecondsSince(self.time)
self.create_nc_var(outfile,'time', ugrid['time']['dimensions'], ugrid['time']['attributes'])
# Create the other variables
self.create_nc_var(outfile,'eta',('time','Nc'),{'long_name':'Sea surface elevation','units':'metres','coordinates':'time yv xv'})
self.create_nc_var(outfile,'uc',('time','Nk','Nc'),{'long_name':'Eastward water velocity component','units':'metre second-1','coordinates':'time z_r yv xv'})
self.create_nc_var(outfile,'vc',('time','Nk','Nc'),{'long_name':'Northward water velocity component','units':'metre second-1','coordinates':'time z_r yv xv'})
self.create_nc_var(outfile,'salt',('time','Nk','Nc'),{'long_name':'Salinity','units':'ppt','coordinates':'time z_r yv xv'})
self.create_nc_var(outfile,'temp',('time','Nk','Nc'),{'long_name':'Water temperature','units':'degrees C','coordinates':'time z_r yv xv'})
self.create_nc_var(outfile,'agec',('time','Nk','Nc'),{'long_name':'Age concentration','units':''})
self.create_nc_var(outfile,'agealpha',('time','Nk','Nc'),{'long_name':'Age alpha parameter','units':'seconds','coordinates':'time z_r yv xv'})
self.create_nc_var(outfile,'agesource',('Nk','Nc'),\
{'long_name':'Age source grid cell (>0 = source)',\
'units':'','coordinates':'z_r yv xv'})