def parseADCPdata(data, staInfo, ID): basetime = datetime(1970, 1, 1) # Find the number of bins nz = maxList(data['"bin (count)"']) nt = len(data['"bin (count)"']) / nz # Get the depth data ele = -np.array(data['"bin_distance (m)"\n'][0:nz]) # Load in the data time = np.zeros(nt) u = np.zeros((nt, nz)) v = np.zeros((nt, nz)) T = np.zeros(nt) ii = 0 for tt in range(0, nt): dt = data['date_time'][ii] - basetime time[tt] = dt.total_seconds() / 60.0 T[tt] = data['"sea_water_temperature (C)"'][ii] for zz in range(0, nz): uu, vv = airsea.convertSpeedDirn( data['"direction_of_sea_water_velocity (degree)"'][ii], data['"sea_water_speed (cm/s)"'][ii] / 100) u[tt, zz] = uu v[tt, zz] = vv ii += 1 # Insert each variable into a list ncdict = [] # U coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':u,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Eastward Water Velocity Component',\ 'units':'m/s','coords':coords} ncdict.append({'water_u': attribs}) # V coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':v,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Northward Water Velocity Component',\ 'units':'m/s','coords':coords} ncdict.append({'water_v': attribs}) # T coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele[0],'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':T,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Sea Water Temperature',\ 'units':'degrees C','coords':coords} ncdict.append({'watertemp': attribs}) return ncdict
def parseADCPdata(data,staInfo,ID): basetime = datetime(1970,1,1) # Find the number of bins nz = maxList(data['"bin (count)"']) nt = len(data['"bin (count)"'])/nz # Get the depth data ele = -np.array(data['"bin_distance (m)"\n'][0:nz]) # Load in the data time = np.zeros(nt) u = np.zeros((nt,nz)) v = np.zeros((nt,nz)) T = np.zeros(nt) ii=0 for tt in range(0,nt): dt = data['date_time'][ii]-basetime time[tt] = dt.total_seconds()/60.0 T[tt]=data['"sea_water_temperature (C)"'][ii] for zz in range(0,nz): uu,vv=airsea.convertSpeedDirn(data['"direction_of_sea_water_velocity (degree)"'][ii],data['"sea_water_speed (cm/s)"'][ii]/100) u[tt,zz]=uu v[tt,zz]=vv ii+=1 # Insert each variable into a list ncdict = [] # U coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':u,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Eastward Water Velocity Component',\ 'units':'m/s','coords':coords} ncdict.append({'water_u':attribs}) # V coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':v,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Northward Water Velocity Component',\ 'units':'m/s','coords':coords} ncdict.append({'water_v':attribs}) # T coords = [{'Name':'longitude','Value':staInfo[ID]['lon'],'units':'degrees East'},\ {'Name':'latitude','Value':staInfo[ID]['lat'],'units':'degrees North'},\ {'Name':'elevation','Value':ele[0],'units':'metres','positive':'up'},\ {'Name':'time','Value':time,'units':'minutes since 1970-01-01 00:00:00'}] attribs = {'StationID':ID,'StationName':staInfo[ID]['name'],'Data':T,\ 'coordinates':'time, elevation, latitude, longitude','long_name':'Sea Water Temperature',\ 'units':'degrees C','coords':coords} ncdict.append({'watertemp':attribs}) return ncdict
def ishData2struct(gzfile, station_id, station_name): """ Convert the data into a useful structure array (dictionary) """ ### Input Variables #gzfile = './rawdata/722420-12923-2012.gz' #station_id = '722420-12923' #station_name = 'test' ### print 'Reading ISH gz file: %s...' % gzfile ishdata = readRawGZdata(gzfile) # Create the base structure (dictionary) station = {} station['StationName'] = station_name station['StationID'] = station_id station['Latitude'] = [] station['Longitude'] = [] station['Tair'] = { 'Data': [], 'Time': [], 'Units': 'Celsius', 'Longname': 'Air Temperature', 'Height': [], 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['Pair'] = { 'Data': [], 'Time': [], 'Units': 'hPa', 'Longname': 'Air Pressure', 'Height': [], 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['Uwind'] = { 'Data': [], 'Time': [], 'Units': 'm s-1', 'Longname': 'Eastward wind velocity component', 'Height': [], 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['Vwind'] = { 'Data': [], 'Time': [], 'Units': 'm s-1', 'Longname': 'Northward wind velocity component', 'Height': [], 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['RH'] = { 'Data': [], 'Time': [], 'Units': 'percent', 'Longname': 'Relative Humidity', 'Height': [], 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['cloud'] = { 'Data': [], 'Time': [], 'Units': 'dimensionless', 'Longname': 'Cloud cover fraction', 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } station['rain'] = { 'Data': [], 'Time': [], 'Units': 'kg m2 s-1', 'Longname': 'rain fall rate', 'TimeUnits': 'minutes since 1970-01-01 00:00:00' } # Loop through the ishdata ii = 0 basetime = datetime(1970, 1, 1) for dd in ishdata: if ii == 0: station['Latitude'] = dd['lat'] station['Longitude'] = dd['lon'] # Convert the time to a suitable time format t = datetime.strptime(dd['yyyymmdd'] + dd['hhmm'], '%Y%m%d%H%M') dt = t - basetime tobs = dt.total_seconds() / 60.0 # tobs = (t.toordinal()-basetime.toordinal())*1440.0 # Check for missing values here # Append the required data fields station['Tair']['Data'].append(dd['airtemp']) station['Tair']['Time'].append(tobs) if ii == 0: station['Tair']['Height'] = dd['ele'] station['Pair']['Data'].append(dd['airpres']) station['Pair']['Time'].append(tobs) if ii == 0: station['Pair']['Height'] = dd['ele'] if np.size(dd['windspd']) == np.size(dd['winddir']): spd = dd['windspd'] if spd >= 999: spd = np.NaN dirn = dd['winddir'] if dirn >= 999: dirn = np.NaN # Note the flip of direction to go to cartesian vectors theta = np.mod(dirn - 180, 360) [Uwind, Vwind] = airsea.convertSpeedDirn(theta, spd) station['Uwind']['Data'].append(Uwind) station['Uwind']['Time'].append(tobs) if ii == 0: station['Uwind']['Height'] = dd['ele'] station['Vwind']['Data'].append(Vwind) station['Vwind']['Time'].append(tobs) if ii == 0: station['Vwind']['Height'] = dd['ele'] rh = returnHumidity(dd) if np.size(rh) > 0: station['RH']['Data'].append(rh) station['RH']['Time'].append(tobs) if ii == 0: station['RH']['Height'] = dd['ele'] rain = returnRainfall(dd) if np.size(rain) > 0: station['rain']['Data'].append(rain) station['rain']['Time'].append(tobs) cloud = returnCloudCover(dd) if np.size(cloud) > 0: station['cloud']['Data'].append(cloud) station['cloud']['Time'].append(tobs) # Print a summary print 'File Summary:' print 'No. of Tair observations - %d' % len(station['Tair']['Data']) print 'No. of Pair observations - %d' % len(station['Pair']['Data']) print 'No. of Uwind observations - %d' % len(station['Uwind']['Data']) print 'No. of Vwind observations - %d' % len(station['Vwind']['Data']) print 'No. of RH observations - %d' % len(station['RH']['Data']) print 'No. of rain observations - %d' % len(station['rain']['Data']) print 'No. of cloud observations - %d' % len(station['cloud']['Data']) print '############# File read successfully################\n' return station
def ishData2struct(gzfile,station_id,station_name): """ Convert the data into a useful structure array (dictionary) """ ### Input Variables #gzfile = './rawdata/722420-12923-2012.gz' #station_id = '722420-12923' #station_name = 'test' ### print 'Reading ISH gz file: %s...' % gzfile ishdata = readRawGZdata(gzfile) # Create the base structure (dictionary) station={} station['StationName']=station_name station['StationID']=station_id station['Latitude']=[] station['Longitude']=[] station['Tair'] = {'Data':[],'Time':[],'Units':'Celsius','Longname':'Air Temperature','Height':[],'TimeUnits':'minutes since 1970-01-01 00:00:00'} station['Pair'] = {'Data':[],'Time':[],'Units':'hPa','Longname':'Air Pressure','Height':[],'TimeUnits':'minutes since 1970-01-01 00:00:00'} station['Uwind'] = {'Data':[],'Time':[],'Units':'m s-1','Longname':'Eastward wind velocity component','Height':[],'TimeUnits':'minutes since 1970-01-01 00:00:00'} station['Vwind'] = {'Data':[],'Time':[],'Units':'m s-1','Longname':'Northward wind velocity component','Height':[],'TimeUnits':'minutes since 1970-01-01 00:00:00'} station['RH'] = {'Data':[],'Time':[],'Units':'percent','Longname':'Relative Humidity','Height':[],'TimeUnits':'minutes since 1970-01-01 00:00:00'} station['cloud'] = {'Data':[],'Time':[],'Units':'dimensionless','Longname':'Cloud cover fraction','TimeUnits':'minutes since 1970-01-01 00:00:00'} station['rain'] = {'Data':[],'Time':[],'Units':'kg m2 s-1','Longname':'rain fall rate','TimeUnits':'minutes since 1970-01-01 00:00:00'} # Loop through the ishdata ii=0 basetime = datetime(1970,1,1) for dd in ishdata: if ii == 0: station['Latitude'] = dd['lat'] station['Longitude'] = dd['lon'] # Convert the time to a suitable time format t = datetime.strptime(dd['yyyymmdd']+dd['hhmm'],'%Y%m%d%H%M') dt = t-basetime tobs = dt.total_seconds()/60.0 # tobs = (t.toordinal()-basetime.toordinal())*1440.0 # Check for missing values here # Append the required data fields station['Tair']['Data'].append(dd['airtemp']) station['Tair']['Time'].append(tobs) if ii == 0: station['Tair']['Height'] = dd['ele'] station['Pair']['Data'].append(dd['airpres']) station['Pair']['Time'].append(tobs) if ii == 0: station['Pair']['Height'] = dd['ele'] if np.size(dd['windspd']) == np.size(dd['winddir']): spd=dd['windspd'] if spd >= 999: spd=np.NaN dirn=dd['winddir'] if dirn >= 999: dirn=np.NaN # Note the flip of direction to go to cartesian vectors theta = np.mod(dirn-180,360) [Uwind,Vwind] = airsea.convertSpeedDirn(theta,spd) station['Uwind']['Data'].append(Uwind) station['Uwind']['Time'].append(tobs) if ii == 0: station['Uwind']['Height'] = dd['ele'] station['Vwind']['Data'].append(Vwind) station['Vwind']['Time'].append(tobs) if ii == 0: station['Vwind']['Height'] = dd['ele'] rh = returnHumidity(dd) if np.size(rh) > 0: station['RH']['Data'].append(rh) station['RH']['Time'].append(tobs) if ii == 0: station['RH']['Height'] = dd['ele'] rain = returnRainfall(dd) if np.size(rain) > 0: station['rain']['Data'].append(rain) station['rain']['Time'].append(tobs) cloud = returnCloudCover(dd) if np.size(cloud) > 0: station['cloud']['Data'].append(cloud) station['cloud']['Time'].append(tobs) # Print a summary print 'File Summary:' print 'No. of Tair observations - %d' % len(station['Tair']['Data']) print 'No. of Pair observations - %d' % len(station['Pair']['Data']) print 'No. of Uwind observations - %d' % len(station['Uwind']['Data']) print 'No. of Vwind observations - %d' % len(station['Vwind']['Data']) print 'No. of RH observations - %d' % len(station['RH']['Data']) print 'No. of rain observations - %d' % len(station['rain']['Data']) print 'No. of cloud observations - %d' % len(station['cloud']['Data']) print '############# File read successfully################\n' return station