def from_2netcdf(infile, parameter): """ For moorings with a, and b deployments Ingest and concatenate both files """ ncfile = infile[0] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata1 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ncfile = infile[1] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata2 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ###data massaging pytime1 = util.EPICdate2udunits(ncdata1['time'], ncdata1['time2']) pytime2 = util.EPICdate2udunits(ncdata2['time'], ncdata2['time2']) dt = 1. / pytime1['interval_min'] #data is 4 times daily time_base = 'days' ### fill time gap blanktime = np.array([]) for tg in np.arange(np.max(pytime1['timeint'])+dt,np.min(pytime2['timeint']),dt): blanktime = np.hstack((blanktime,tg)) time = np.hstack((pytime1['timeint'], blanktime)) time = np.hstack((time,pytime2['timeint'])) # signal data_interp = np.interp(blanktime,[np.max(pytime1['timeint']),np.min(pytime2['timeint'])],[ncdata1[parameter][-1,0,0,0], ncdata2[parameter][0,0,0,0]]) data = np.hstack((ncdata1[parameter][:,0,0,0], data_interp)) data = np.hstack((data, ncdata2[parameter][:,0,0,0])) variance = np.var(data) #normalize print 'Variance = %s ' % (variance) x = (data - np.mean(data)) / np.sqrt(variance) variance = np.var(x) return_data = {'data': data, 'anom': x, 'dt': dt, 'time':np.array(time), 'variance':variance, 'time_base':time_base} return (return_data)
def from_2netcdf(infile, parameter): """ Uses ncreadfile_dic which returns a dictionary of all data from netcdf Assumes that there is an "a" and "b" mooring each year """ ncfile = infile[0] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata1 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ncfile = infile[1] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata2 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ###data massaging pytime1 = util.EPICdate2udunits(ncdata1['time'], ncdata1['time2']) pytime2 = util.EPICdate2udunits(ncdata2['time'], ncdata2['time2']) dt = 1. / pytime['interval_min'] #data is 4 times daily time_base = 'days' time = pytime['timeint'] #time = util.subsample(time, int(pytime.get('interval_min')) / 4) # signal data = ncdata1[parameter][:,0,0,0] variance = np.var(data) #normalize print 'Variance = %s ' % (variance) x = (data - np.mean(data)) / np.sqrt(variance) variance = np.var(x) return_data = {'data': data, 'anom': x, 'dt': dt, 'time':np.array(time), 'variance':variance, 'time_base':time_base} return (return_data)
def from_netcdf(infile, parameter, detrend=False): """ Uses ncreadfile_dic which returns a dictionary of all data from netcdf""" ncfile = infile ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ###data massaging pytime = util.EPICdate2udunits(ncdata['time'], ncdata['time2']) dt = 1. / pytime['interval_min'] #data is 4 times daily time_base = 'days' time = pytime['timeint'] #time = util.subsample(time, int(pytime.get('interval_min')) / 4) # signal data = ncdata[parameter][:, 0, 0, 0] variance = np.var(data) #test routine, set default to false if detrend: #detrend if flag is true - default false x = sp.signal.detrend(data, axis=0) else: x = data #normalize print 'Variance = %s ' % (variance) x = (x - np.mean(x)) / np.sqrt(variance) variance = np.var(x) return_data = { 'data': data, 'anom': x, 'dt': dt, 'time': np.array(time), 'variance': variance, 'time_base': time_base } return (return_data)
def from_netcdf(infile, parameter, detrend=False): """ Uses ncreadfile_dic which returns a dictionary of all data from netcdf""" ncfile = infile ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ###data massaging pytime = util.EPICdate2udunits(ncdata['time'], ncdata['time2']) dt = 1. / pytime['interval_min'] #data is 4 times daily time_base = 'days' time = pytime['timeint'] #time = util.subsample(time, int(pytime.get('interval_min')) / 4) # signal data = ncdata[parameter][:,0,0,0] variance = np.var(data) #test routine, set default to false if detrend: #detrend if flag is true - default false x = sp.signal.detrend(data, axis=0) else: x = data #normalize print 'Variance = %s ' % (variance) x = (x - np.mean(x)) / np.sqrt(variance) variance = np.var(x) return_data = {'data': data, 'anom': x, 'dt': dt, 'time':np.array(time), 'variance':variance, 'time_base':time_base} return (return_data)
def from_2netcdf(infile, parameter): """ For moorings with a, and b deployments Ingest and concatenate both files """ ncfile = infile[0] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata1 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ncfile = infile[1] ###nc readin/out nchandle = ncutil.ncopen(ncfile) params = ncutil.get_vars(nchandle) #gets all of them if not parameter in params: ### specified parameter doesn't exist return ('no param') ncdata2 = ncutil.ncreadfile_dic(nchandle, params) ncutil.ncclose(nchandle) ###data massaging pytime1 = util.EPICdate2udunits(ncdata1['time'], ncdata1['time2']) pytime2 = util.EPICdate2udunits(ncdata2['time'], ncdata2['time2']) dt = 1. / pytime1['interval_min'] #data is 4 times daily time_base = 'days' ### fill time gap blanktime = np.array([]) for tg in np.arange( np.max(pytime1['timeint']) + dt, np.min(pytime2['timeint']), dt): blanktime = np.hstack((blanktime, tg)) time = np.hstack((pytime1['timeint'], blanktime)) time = np.hstack((time, pytime2['timeint'])) # signal data_interp = np.interp( blanktime, [np.max(pytime1['timeint']), np.min(pytime2['timeint'])], [ncdata1[parameter][-1, 0, 0, 0], ncdata2[parameter][0, 0, 0, 0]]) data = np.hstack((ncdata1[parameter][:, 0, 0, 0], data_interp)) data = np.hstack((data, ncdata2[parameter][:, 0, 0, 0])) variance = np.var(data) #normalize print 'Variance = %s ' % (variance) x = (data - np.mean(data)) / np.sqrt(variance) variance = np.var(x) return_data = { 'data': data, 'anom': x, 'dt': dt, 'time': np.array(time), 'variance': variance, 'time_base': time_base } return (return_data)