Skip to content
Snippets Groups Projects
Commit 0d669f5d authored by kgao's avatar kgao
Browse files

Added time_offset variable and fixed time variable

Mixed up time and time_offset
time now seconds since epoch
parent c0418f94
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,6 @@ def writeDimensions(ncFile):
ncFile.createDimension('time', None)
ncFile.createDimension('strlen', 256)
print(ncFile)
return ncFile
def createVariables(ncFile, firstStamp, chunksizes, zlib):
......@@ -37,19 +35,22 @@ def createVariables(ncFile, firstStamp, chunksizes, zlib):
bts = firstStamp.strftime('%Y-%m-%d 00:00:00Z')
#time long name
tln = 'time offset from midnight UTC'
tln = 'time offset from base_time'
#time units
tu = 'seconds since ' + firstStamp.strftime('%Y-%m-%d 00:00:00Z')
coordinates = {
#fields: type, dimension, fille, positive, valid_min, std_name, longname, units, valid_max, cf_role, axis
#fields: type, dimension, fill, valid_min, std_name, longname, units, valid_max, cf_role, axis
'lon': [np.float32, None, float(-999), '-180L', 'longitude', None, 'degrees_east', '180L', None],
'lat': [np.float32, None, float(-999), '-90L', 'latitude', None, 'degrees_north', '90L', None],
'alt': [np.float32, None, float(-999), None, 'height', 'vertical distance', 'm', None, None],
'base_time': [np.float32, None, float(-999), None, 'time', btln, btu, None, None],
'time': [np.float32, 'time', float(-999), None, 'time', tln, tu, None, None],
'station_name': ['c', 'strlen', '-', None, None, 'station name', None, None, 'timeseries_id']
'time_offset': [np.float32, 'time', float(-999), None, 'time', tln, tu, None, None],
'station_name': ['c', 'strlen', '-', None, None, 'station name', None, None, 'timeseries_id'],
'time': [np.float32, 'time', float(-999), None, None, "Time offset from epoch", "seconds since 1970-01-01 00:00:00Z", None, None, None]
}
for key in coordinates:
......@@ -57,7 +58,7 @@ def createVariables(ncFile, firstStamp, chunksizes, zlib):
if(attr[1]):
if attr[1] == 'strlen':
if chunksizes[0] > 256:
if (chunksizes) and chunksizes[0] > 256:
variable = ncFile.createVariable(key, attr[0], dimensions=(attr[1]), fill_value=attr[2], zlib=zlib, chunksizes=[256])
else:
......@@ -165,7 +166,8 @@ def writeVars(ncFile, frame):
fileVar = ncFile.variables
fileVar['base_time'].assignValue(baseTimeValue)
fileVar['time'][:] = timeNumpy
fileVar['time_offset'][:] = timeNumpy
fileVar['time'][:] = timeNumpy + baseTimeValue
#write coordinate var values to file
#alt might not be right, need to verify
......@@ -200,7 +202,11 @@ def writeVars(ncFile, frame):
# @param output filename - filename of the netcdf file
def createGiantNetCDF(start, end, inputFiles, outputName, zlib, chunkSize, no_empty):
chunksizes = [chunkSize]
if(chunkSize):
chunksizes = [chunkSize]
else:
chunksizes = None
frame = getData(inputFiles, no_empty)
......@@ -288,7 +294,6 @@ def main():
level=levels[min(3, args.verbosity)]
logging.basicConfig(level=level)
print(args)
if(args.start_time and args.end_time):
createGiantNetCDF(args.start_time, args.end_time, args.input_files, args.output[0], args.zlib, args.chunk_size, args.no_empty)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment