3 from schema
import NoiseSpectrum
8 def dumps(spectra, indent=4):
10 Dump the spectra to a JSON string 12 spectra = [s._asdict()
for s
in spectra]
13 return json.dumps(spectra, indent=indent)
17 Return a list of NoiseSpectrum objects from the JSON text 19 spectra = json.loads(text)
20 return [NoiseSpectrum(**s)
for s
in spectra]
23 def dump(filename, spectra):
25 Save a list of wirecell.sigproc.noise.NoiseSpectrum objects to a 26 file of the given name. 28 File is saved depending on extension. .json, .json.bz2 and 29 .json.gz are supported. 31 text =
dumps(spectra,indent=4)
32 if filename.endswith(
".json"):
35 if filename.endswith(
".json.bz2"):
37 bz2.BZ2File(filename,
'w').
write(text)
39 if filename.endswith(
".json.gz"):
41 gzip.open(filename,
"wb").
write(text)
43 raise ValueError(
"unknown file format: %s" % filename)
47 Return a list of wirecell.sigproc.noise.NoiseSpectrum objects 48 loaded from the given file. 50 File is loaded depending on extension. .json, .json.bz2 and 51 .json.gz are supported. 53 if filename.endswith(
".json"):
56 if filename.endswith(
".json.bz2"):
58 return loads(bz2.BZ2File(filename,
'r').read()) 60 if filename.endswith(
".json.gz"):
62 return loads(gzip.open(filename,
"rb").
read())
64 raise ValueError(
"unknown file format: %s" % filename)
def dumps(spectra, indent=4)
def dump(filename, spectra)
int open(const char *, int)
Opens a file descriptor.
size_t write(int, const char *, size_t)
Writes count bytes from buf to the filedescriptor fd.
int read(int, char *, size_t)
Read bytes from a file descriptor.