
# processing video LEGI wave flume
# application to soliton gas analysis
# Thibault Leduque 2021
# Hervé Michallet 2022
#

# from IPython import get_ipython   # clear all variables !!
# get_ipython().magic('reset -sf')
%reset -f

import numpy as np
import netCDF4

import matplotlib.pyplot as plt
import h5py
# import scipy.fft as scfft
import os
# import numpy.matlib as npm
# from scipy.stats import skew

##%% choose data file


# path='C://Users//leduque8th//Documents//Resultat'
# path='Z://project//watu//2021//21CANAL//Resultat'
# path='D:\watu\canal\data_video'
path='D:\sogood\canal\data_video'
os.chdir(path)
cwd=os.getcwd()

#-------Parametres Physique-------#
L00 = 33.73 # longueur canal (m)

g=9.81


## Load Data / uncomment condition to select


Nom_Dossier='2024-10-15T14.19.06' # manip soliton gas
freq=50
h00=0.183
exp_type='manip solitons'
precision='Vr=1cm/s random'
Vr0=0.01 # (m/s)
AA0=0.45*h00   # soliton amplitude (m)
csol=np.sqrt(g*(h00+AA0))           # Rayleigh
beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
excu= 4*AA0/beta/h00   # wave paddle excursion
print('wave paddle excursion (m):         ',excu)
Trs0=excu/Vr0     # mean soliton repetition period (s)
print('mean soliton repetition period (s):',Trs0)
aa0=0      # sinus amplitude (m)
T00=0     # sinus period (s)
t0=0        # useless time duration to remove at the beginning of the record (s)
fich_gene='X_GB02_h0183mm_gaz615s_100_82mm.dat'

# Nom_Dossier='2024-10-15T14.44.12' # manip sinus
# freq=50
# h00=0.183   # water depth (m)
# exp_type='manip sinus'
# precision='strong forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.03      # sinus amplitude (m)
# T00=1.72     # sinus period (s)
# t0=12        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1314.dat'

# Nom_Dossier='2024-10-15T13.53.56' # manip sinus
# freq=50
# h00=0.190   # water depth (m)
# exp_type='manip sinus'
# precision='weak forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.01      # sinus amplitude (m)
# T00=1.72     # sinus period (s)
# t0=5        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1313.dat'

# Nom_Dossier='2024-10-15T13.41.29' # manip interaction 3 solitons 0.65
# freq=50
# h00=0.19
# exp_type='manip 3 solitons'
# precision='Vr=1.cm/s 3 solitons interaction'
# Vr0=0.01 # (m/s)
# AA0=0.65*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0190mm_gaz136s_100_124mm.dat'

# Nom_Dossier='2023-10-27T18.59.27' # manip interaction 2 solitons 0.65
# freq=50
# h00=0.17
# exp_type='manip 2 solitons'
# precision='Vr=1.43cm/s 2 solitons interaction'
# Vr0=0.0143 # (m/s)
# AA0=0.65*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz57s_70_111mm.dat'

# Nom_Dossier='2023-10-27T18.29.05' # manip interaction 2 solitons 0.65
# freq=50
# h00=0.17
# exp_type='manip 2 solitons'
# precision='Vr=1.43cm/s 2 solitons interaction'
# Vr0=0.0143 # (m/s)
# AA0=0.65*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz57s_70_111mm.dat'

# Nom_Dossier='2023-10-27T18.11.58' # manip interaction 2 solitons 0.5
# freq=50
# h00=0.17
# exp_type='manip 2 solitons'
# precision='Vr=1.cm/s 2 solitons interaction'
# Vr0=0.01 # (m/s)
# AA0=0.5*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz68s_100_85mm.dat'

# Nom_Dossier='2023-10-27T17.49.10' # manip interaction 2 solitons 0.7
# freq=50
# h00=0.17
# exp_type='manip 2 solitons'
# precision='Vr=1.67cm/s 2 solitons interaction'
# Vr0=0.0167 # (m/s)
# AA0=0.7*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz51s_60_119mm.dat'

# Nom_Dossier='2023-10-27T17.08.41' # manip interaction 2 solitons 0.6
#########  PB processing !!
# freq=50
# h00=0.17
# exp_type='manip 2 solitons'
# precision='Vr=1.11cm/s 2 solitons interaction'
# Vr0=0.0111 # (m/s)
# AA0=0.6*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz69s_90_102mm.dat'


# Nom_Dossier='2023-10-17T14.32.49' # manip soliton gas
# freq=50
# h00=0.176
# exp_type='manip solitons'
# precision='Vr=1cm/s random'
# Vr0=0.01 # (m/s)
# AA0=0.6*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0176mm_gaz916s_100_106mm.dat'

# Nom_Dossier='2023-10-17T14.12.35' # manip sinus
# freq=50
# h00=0.178   # water depth (m)
# exp_type='manip sinus'
# precision='medium forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.01      # sinus amplitude (m)
# T00=2.2279     # sinus period (s)
# t0=40        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1309.dat'

# Nom_Dossier='2023-10-17T13.57.01' # manip sinus
# freq=50
# h00=0.178   # water depth (m)
# exp_type='manip sinus'
# precision='weak forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.008      # sinus amplitude (m)
# T00=2.2279     # sinus period (s)
# t0=15        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1308.dat'

# Nom_Dossier='2023-10-17T13.41.36' # manip interaction 2 solitons 0.6
# freq=50
# h00=0.178
# exp_type='manip 2 solitons'
# precision='Vr=2cm/s 2 solitons interaction'
# Vr0=0.02 # (m/s)
# AA0=0.6*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0178mm_gaz45s_50_107mm.dat'

# Nom_Dossier='2023-10-17T10.36.08' # manip interaction 2 solitons 0.6
# freq=50
# h00=0.197
# exp_type='manip 2 solitons'
# precision='Vr=2cm/s 2 solitons interaction'
# Vr0=0.02 # (m/s)
# AA0=0.6*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0197mm_gaz45s_50_118mm.dat'


# Nom_Dossier='2022-11-21T16.50.55' # manip soliton gas
# freq=50
# h00=0.17
# exp_type='manip solitons'
# precision='Vr=1cm/s random'
# Vr0=0.01 # (m/s)
# AA0=0.6*h00   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_GB02_h0170mm_gaz615s_100_102mm.dat'

# Nom_Dossier='2022-11-21T16.30.17' # manip sinus
# freq=50
# h00=0.17   # water depth (m)
# exp_type='manip sinus'
# precision='strong forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.025      # sinus amplitude (m)
# T00=2.2279     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1305.dat'

# Nom_Dossier='2022-11-21T15.57.27' # manip sinus
# freq=50
# h00=0.17   # water depth (m)
# exp_type='manip sinus'
# precision='weak forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.005      # sinus amplitude (m)
# T00=1.5260     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1304.dat'

# Nom_Dossier='2022-11-18T18.12.07' # manip sinus
# freq=50
# h00=0.17   # water depth (m)
# exp_type='manip sinus'
# precision='relatively strong forcing'
# AA0=0   # soliton amplitude (m)
# Vr0=0 # (m/s) pour un cycle de 60s
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.015      # sinus amplitude (m)
# T00=2.2279     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)
# fich_gene='X_1301.dat'

# Nom_Dossier='2022-11-18T17.04.30' # manip 1 epsilon=0.5 sur 60s
# freq=50
# h00=0.17   # water depth (m)
# exp_type='manip solitons'
# precision='1 seul soliton '
# AA0=h00*0.5   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# Vr0=excu/60 # (m/s) pour un cycle de 60s
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=0        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2021-05-31T16.09.47' # manip 1 epsilon=0.65 
# freq=50
# h00=0.2   # water depth (m)
# exp_type='manip solitons'
# precision='1 seul soliton '
# AA0=h00*0.65   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# Vr0=excu/60 # (m/s) pour un cycle de 60s
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=50        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2021-05-31T16.39.18' # manip solitons Vr=3.3cm/s M2R Thibault Leduque
# freq=50
# h00=0.2
# exp_type='manip solitons'
# precision='Vr=3.3cm/s M2R Thibault Leduque'
# Vr0=0.033 # (m/s)
# AA0=0.06   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2021-06-23T13.20.15' # manip solitons Vr=0.5cm/s Thibault
# freq=50
# h00=0.2
# exp_type='manip solitons'
# precision='Vr=0.5cm/s M2R Thibault Leduque'
# Vr0=0.005 # (m/s)
# AA0=0.06   # soliton amplitude (m)
# csol=np.sqrt(g*(h00+AA0))           # Rayleigh
# beta=np.sqrt(3*AA0/h00**2/(AA0+h00))  # Rayleigh
# excu= 4*AA0/beta/h00   # wave paddle excursion
# print('wave paddle excursion (m):         ',excu)
# Trs0=excu/Vr0     # mean soliton repetition period (s)
# print('mean soliton repetition period (s):',Trs0)
# aa0=0      # sinus amplitude (m)
# T00=0     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2021-06-30T15.06.19' # manip sinus Thibault
# freq=50
# h00=0.2
# exp_type='manip sinus'
# precision='relatively strong forcing, M2R Thibault Leduque'
# Vr0=0     # (m/s)
# AA0=0     # soliton amplitude (m)
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.022      # sinus amplitude (m)
# T00=(69.28-52.84)/7     # sinus period (s)
# t0=10        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2018-07-05T16.25.28' # manip Ivan sinus
# freq=20
# h00=0.2
# exp_type='manip sinus'
# precision='moderate forcing, PhD Ivan Redor'
# Vr0=0     # (m/s)
# AA0=0     # soliton amplitude (m)
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.01      # sinus amplitude (m)
# T00=1/0.2915     # sinus period (s)
# t0=130        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='2018-04-10T11.29.43' # manip Ivan PRL
# freq=20
# h00=0.117
# exp_type='manip sinus'
# precision='moderate forcing, PhD Ivan Redor, see Redor et al. PRL 2019'
# Vr0=0     # (m/s)
# AA0=0     # soliton amplitude (m)
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.015      # sinus amplitude (m)
# T00=1/0.6     # sinus period (s)
# t0=120        # useless time duration to remove at the beginning of the record (s)

# Nom_Dossier='effetboitefinie' # manip Ivan sinus petite amplitude
# path='D:\watu'
# os.chdir(path)
# freq=20
# h00=0.2
# exp_type='manip sinus'
# precision='weak forcing, PhD Ivan Redor'
# Vr0=0     # (m/s)
# AA0=0     # soliton amplitude (m)
# Trs0=0     # mean soliton repetition period (s)
# aa0=0.004      # sinus amplitude (m)
# T00=1.9939     # sinus period (s)
# t0=50        # useless time duration to remove at the beginning of the record (s)


# chargement du fichier matlab
DATA_H=h5py.File(Nom_Dossier+'//H.mat')
etam=np.array(DATA_H.get('H')).transpose()
etam=-etam/1000    # surface elevation above rest level (m)

##Parametres
xx00=9.54     #Abcisse du premier point de mesure: longueur entre le batteur et la vitre de la camera_1

#-------Parametres cameras-------#

dx0=0.08     # Resolution Spatiale= 8cm


iNt=int(t0*freq) # 1er point

# size of video record
Nx, Nt=np.shape(etam)
etam=etam[:,iNt:Nt]

Nx, Nt=np.shape(etam)
# print(Nt)

#%% 
path='D:\sogood\canal'
os.chdir(path)
cwd=os.getcwd()

# ncfile = netCDF4.Dataset('data_video/new3.nc',mode='w',format='NETCDF4_CLASSIC')
ncfile = netCDF4.Dataset('data_video/'+Nom_Dossier+'.nc',mode='w',format='NETCDF4_CLASSIC')
print(ncfile)

  # %%
ncfile.title='LEGI wave flume video data'
print(ncfile.title)

ncfile.subtitle=exp_type
ncfile.details=precision
print(ncfile.subtitle)
print(ncfile)
print(ncfile.details)

h0_dim = ncfile.createDimension('h0', 1) 
h0 = ncfile.createVariable('h0', np.float32, ('h0'))
h0.units = 'm'
h0.long_name = 'water depth'
h0[:] = h00

L0_dim = ncfile.createDimension('L0', 1) 
L0 = ncfile.createVariable('L0', np.float32, ('L0'))
L0.units = 'm'
L0.long_name = 'flume length'
L0[:] = L00

x0_dim = ncfile.createDimension('x0', 1) 
x0 = ncfile.createVariable('x0', np.float32, ('x0'))
x0.units = 'm'
x0.long_name = 'distance to wave-maker mean position of the 1st video recorded location'
x0[:] = xx00

dx_dim = ncfile.createDimension('dx', 1) 
dx = ncfile.createVariable('dx', np.float32, ('dx'))
dx.units = 'm'
dx.long_name = 'video record spatial resolution'
dx[:] = dx0

fps_dim = ncfile.createDimension('fps', 1) 
fps = ncfile.createVariable('fps', np.float32, ('fps'))
fps.units = 'Hz'
fps.long_name = 'sampling frequency of the video record'
fps[:] = freq

aa_dim = ncfile.createDimension('aa', 1) 
aa = ncfile.createVariable('aa', np.float32, ('aa'))
aa.units = 'm'
aa.long_name = 'sinus amplitude '
aa[:] = aa0

Tsin_dim = ncfile.createDimension('Tsin', 1) 
Tsin = ncfile.createVariable('Tsin', np.float32, ('Tsin'))
Tsin.units = 's'
Tsin.long_name = 'sinus period'
Tsin[:] = T00

AA_dim = ncfile.createDimension('AA', 1) 
AA = ncfile.createVariable('AA', np.float32, ('AA'))
AA.units = 'm'
AA.long_name = 'soliton amplitude'
AA[:] = AA0

Vr_dim = ncfile.createDimension('Vr', 1) 
Vr = ncfile.createVariable('Vr', np.float32, ('Vr'))
Vr.units = 'm/s'
Vr.long_name = 'wave paddle backward motion speed'
Vr[:] = Vr0

Trs_dim = ncfile.createDimension('Trs', 1) 
Trs = ncfile.createVariable('Trs', np.float32, ('Trs'))
Trs.units = 's'
Trs.long_name = 'mean soliton repetition period'
Trs[:] = Trs0

X_dim = ncfile.createDimension('X', Nx) # distance to wave-maker axis
X = ncfile.createVariable('X', np.float32, ('X'))
X.units = 'm'
X.long_name = 'distance to wave-maker mean position of video recorded locations'
X[:] = np.linspace(xx00, Nx*dx0+xx00, Nx)   # vecteur distance au batteur

time_dim = ncfile.createDimension('time', Nt) 
time = ncfile.createVariable('time', np.float64, ('time'))
time.units = 's'
time.long_name = 'time'
time[:] = np.linspace(0, Nt/freq, Nt)      # vecteur temps
# time_dim = ncfile.createDimension('time', None) # unlimited axis (can be appended to).

for dim in ncfile.dimensions.items():
  print(dim)

eta = ncfile.createVariable('eta',np.float64,('X','time')) # 
eta.units = 'm' 
eta.standard_name = 'elevation' # is this a CF standard name?
print(eta)
print("-- Some pre-defined attributes for variable eta:")
print("eta.dimensions:", eta.dimensions)
print("eta.shape:", eta.shape)
print("eta.dtype:", eta.dtype)
print("eta.ndim:", eta.ndim)
eta[:,:] = etam # surface elevation above rest level (m)
print("-- Wrote data, eta.shape is now ", eta.shape)
print("-- Min/Max values:", eta[:,:].min(), eta[:,:].max())

#%% first print the Dataset object to see what we've got
print(ncfile)
# close the Dataset.
ncfile.close(); print('Dataset is closed!')


#
#
#
#%%
# etatam=np.array('eta')
# plt.plot(np.array('time'),etatam[1,:])

#
#
#

