- if plotVerbose or config.PYLAB_VERBOSE or config.TEXT_VERBOSE :
- print "Temperature ", T
-
-@splittableKwargsFunction((T_analyze, 'T', 'convert_to_K'),
- (T_plot, 'T'))
-def T_load_analyze_tweaked(tweak_file, convert_to_K=C_to_K, textVerboseFile=None, **kwargs) :
- "Load all the T array files from a tweak file and return a single array"
- T_analyze_kwargs,T_plot_kwargs = \
- T_load_analyze_tweaked._splitargs(T_load_analyze_tweaked, kwargs)
- Ts = []
- for line in file(tweak_file, 'r') :
- parsed = line.split()
- path = parsed[0].split('\n')[0]
- if textVerboseFile != None :
- print >> textVerboseFile, "Reading data from %s" % (path)
- # read the data
- data = T_load(path)
- Ts.extend(data)
- T_analyze(Ts, convert_to_K=convert_to_K)
- return numpy.array(Ts, dtype=numpy.float)
-
-# commandline interface functions
-import scipy.io, sys
-
-def read_data(ifile):
- "ifile can be a filename string or open (seekable) file object"
- if ifile == None : ifile = sys.stdin
- unlabeled_data=scipy.io.read_array(ifile)
- return unlabeled_data
-
-if __name__ == '__main__' :
- # command line interface
- from optparse import OptionParser
-
- usage_string = ('%prog <input-file>\n'
- '2008, W. Trevor King.\n'
- '\n'
- 'There are two operation modes, one to analyze a single T (temperature) file,\n'
- 'and one to analyze tweak files.\n'
- '\n'
- 'Single file mode (the default) :\n'
- 'Reads in single column ASCII file of temperatures and... prints them back out.\n'
- 'No need to do this, but the option is available for consistency with the other\n'
- 'calibcant modules.\n'
- '\n'
- 'Tweak file mode:\n'
- 'Runs the same analysis as in single file mode for each T file in\n'
- 'a tweak file. Each line in the tweak file specifies a single T file.\n'
- 'A T file contains a sequence of 32 bit floats representing temperature in K.\n'
- )
- parser = OptionParser(usage=usage_string, version='%prog 0.1')
- parser.add_option('-C', '--celsius', dest='celsius',
- help='Use Celsius input temperatures instead of Kelvin (default %default)\n',
- action='store_true', default=False)
- parser.add_option('-o', '--output-file', dest='ofilename',
- help='write output to FILE (default stdout)',
- type='string', metavar='FILE')
- parser.add_option('-c', '--comma-out', dest='comma_out', action='store_true',
- help='Output comma-seperated values (default %default)',
- default=False)
- parser.add_option('-t', '--tweak-mode', dest='tweakmode', action='store_true',
- help='Run in tweak-file mode',
- default=False)
- parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
- help='Print lots of debugging information',
- default=False)
-
- options,args = parser.parse_args()
- parser.destroy()
- assert len(args) >= 1, "Need an input file"
-
- ifilename = args[0]
-
- if options.ofilename != None :
- ofile = file(options.ofilename, 'w')
- else :
- ofile = sys.stdout
- if options.verbose == True :
- vfile = sys.stderr
- else :
- vfile = None
- config.TEXT_VERBOSE = options.verbose
- config.PYLAB_VERBOSE = False
- config.GNUPLOT_VERBOSE = False
- if options.celsius :
- convert_to_K = C_to_K
- else :
- convert_to_K = K_to_K
-
- if options.tweakmode == False :
- data = read_data(ifilename)
- Ts = T_analyze(data, convert_to_K)
- else : # tweak file mode
- Ts = T_load_analyze_tweaked(ifilename, convert_to_K, textVerboseFile=vfile)
-
- if options.comma_out :
- sep = ','
- else :
- sep = '\n'
- common.write_array(ofile, Ts, sep)
-
- if options.ofilename != None :
- ofile.close()
+ if temperature_config['units'] == _Celsius:
+ return _C2K(T)
+ else:
+ return T
+
+def T_save(filename, group='/', raw_T=None, temperature_config=None,
+ processed_T=None):
+ with _h5py.File(filename, 'a') as f:
+ cwg = _h5_create_group(f, group)
+ if raw_T is not None:
+ try:
+ del cwg['raw']
+ except KeyError:
+ pass
+ cwg['raw'] = raw_T
+ if temperature_config is not None:
+ config_cwg = _h5_create_group(cwg, 'config')
+ storage = _HDF5_Storage()
+ storage.save(config=temperature_config, group=config_cwg)
+ if processed_T is not None:
+ try:
+ del cwg['processed']
+ except KeyError:
+ pass
+ cwg['processed'] = processed_T
+
+def T_load(filename, group='/'):
+ assert group.endswith('/')
+ raw_T = processed_T = None
+ with _h5py.File(filename, 'a') as f:
+ try:
+ raw_T = f[group+'raw'][...]
+ except KeyError:
+ pass
+ temperature_config = _TemperatureConfig(storage=_HDF5_Storage(
+ filename=filename, group=group+'config/'))
+ try:
+ processed_T = f[group+'processed'][...]
+ except KeyError:
+ pass
+ temperature_config.load()
+ return (raw_T, temperature_config, processed_T)
+
+def T_plot(raw_T=None, processed_T=None):
+ if not _matplotlib:
+ raise _matplotlib_import_error
+ figure = _matplotlib_pyplot.figure()
+ timestamp = _time.strftime('%H%M%S')
+ if raw_T is None:
+ if processed_T is None:
+ return # nothing to plot
+ axes1 = None
+ axes2 = figure.add_subplot(1, 1, 1)
+ elif processed_T is None:
+ axes1 = figure.add_subplot(1, 1, 1)
+ axes2 = None
+ else:
+ axes1 = figure.add_subplot(2, 1, 1)
+ axes2 = figure.add_subplot(2, 1, 2)
+ if axes1:
+ axes1.set_title('Raw Temperatures %s' % timestamp)
+ axes1.plot(raw_T, label='raw')
+ if axes2:
+ axes2.set_title('Processed Temperatures %s' % timestamp)
+ axes2.plot(processed_T, label='processed')
+ if hasattr(figure, 'show'):
+ figure.show()