Skip to content

Commit

Permalink
Merge pull request #140 from sami2py/enh-netcdf-output
Browse files Browse the repository at this point in the history
attributes update for netcdf
  • Loading branch information
jklenzing committed May 20, 2021
2 parents 68c0a03 + 1f1d973 commit 743c924
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [next version] - 2021-04-05
- Updated Variable and datasest attributes for netcdf export
- Added default drift fourier coefficient array accessable from run model
- Using minimum test version of numpy in accordance with NEP 29
- Removed the sami2py-1.00.namelist and version.txt files from run_name
Expand Down
40 changes: 30 additions & 10 deletions sami2py/_core_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def __init__(self, tag, lon, year, day, outn=False, test=False):
zalt : (2D ndarray)
Altitude (km)
deni : (4D ndarray)
Ion density by species (cm^-3)
Ion density for each species (cm^-3)
vsi : (4D ndarray)
Ion Velocity by species (m/s)
Ion Velocity for each species (cm/s)
ti : (4D ndarray)
Ion Temperature by species (K)
Ion Temperature for each species (K)
te : (3D ndarray)
Electron Temperature (K)
Examples
Expand Down Expand Up @@ -238,20 +238,34 @@ def _load_model(self):
vsi = np.reshape(vsi, (nz, nf, ni, nt), order="F")
ti = np.reshape(ti, (nz, nf, ni, nt), order="F")
te = np.reshape(te, (nz, nf, nt), order="F")
self.data = xr.Dataset({'deni': (['z', 'f', 'ion', 'ut'], deni),
'vsi': (['z', 'f', 'ion', 'ut'], vsi),
'ti': (['z', 'f', 'ion', 'ut'], ti),
'te': (['z', 'f', 'ut'], te),
'slt': (['ut'], self.slt)},
self.data = xr.Dataset({'deni': (['z', 'f', 'ion', 'ut'], deni,
{'units': 'N/cc',
'long_name': 'ion density'}),
'vsi': (['z', 'f', 'ion', 'ut'], vsi,
{'units': 'cm/s',
'long_name': 'ion velocity'}),
'ti': (['z', 'f', 'ion', 'ut'], ti,
{'units': 'K',
'long_name': 'ion temperature'}),
'te': (['z', 'f', 'ut'], te,
{'units': 'K',
'long_name': 'electron temperature'}),
'slt': (['ut'], self.slt,
{'units': 'hrs',
'long_name': 'solar local time'})},
coords={'glat': (['z', 'f'], glat),
'glon': (['z', 'f'], glon),
'zalt': (['z', 'f'], zalt),
'ut': self.ut})
if self.outn:
denn = np.reshape(denn, (nz, nf, ni, nt), order="F")
self.data['denn'] = (('z', 'f', 'ion', 'ut'), denn)
self.data['denn'] = (('z', 'f', 'ion', 'ut'), denn,
{'units': 'N/cc',
'long_name': 'neutral density'})
u4 = np.reshape(u4, (nz, nf, nt), order="F")
self.data['u4'] = (('z', 'f', 'ut'), u4)
self.data['u4'] = (('z', 'f', 'ut'), u4,
{'units': 'm/s',
'long_name': 'neutral wind velocity'})

if self.MetaData['ExB model'] == 'Fourier Series':
exb = return_fourier(self.data['slt'],
Expand Down Expand Up @@ -376,6 +390,12 @@ def to_netcdf(self, path=''):
"""saves core data as a netcdf file"""
if path == '':
path = 'sami2py_output.nc'
attrs = self.MetaData
attrs['fmtout'] = str(attrs['fmtout'])
if attrs['ExB model'] == 'Fourier Series':
attrs['Fourier Coeffs'] = str(attrs['Fourier Coeffs'])

self.data.attrs = attrs
self.data.to_netcdf(path=path, format='NETCDF4')

def plot_lat_alt(self, time_step=0, species=1):
Expand Down

0 comments on commit 743c924

Please sign in to comment.