Difference between revisions of "CyberShake output data headers"
Line 36: | Line 36: | ||
=== Sample C code === | === Sample C code === | ||
+ | Below is sample C code to read and | ||
=== Sample Python code === | === Sample Python code === |
Revision as of 21:37, 10 October 2017
This page details the header formats for various kinds of CyberShake output data files. These headers have been used in CyberShake since Run ID 1310.
Contents
Seismogram header
The seismogram header is 56 bytes, and is defined (in C) as follows:
struct seisheader { char version[8]; char site_name[8]; //in case we think of something later char padding[8]; int source_id; int rupture_id; int rup_var_id; float dt; int nt; int comps; float det_max_freq; float stoch_max_freq; };
- Version: The current version is 12.10.
- Site name: The name of the CyberShake site.
- Padding: Empty space in case we have a use for it later.
- Source ID: The source ID of the event this seismogram is for.
- Rupture ID: The rupture ID of the event this seismogram is for.
- Rup Var ID: The rupture variation ID of the event this seismogram is for.
- DT: the timestep size used in the seismogram.
- NT: the number of timesteps in the seismogram.
- Comps: This tracks the components in the seismogram. There are three flags, one for each component (X=1, Y=2, Z=4), and the flags are ANDed together to produce the value here.
- Det_max_freq: the maximum frequency of the deterministic part of the seismogram. This was 0.5 for studies before 15.4, and 1.0 for 15.4, 15.12, and 17.3.
- Stoch_max_freq: the maximum frequency of the stochastic part of the seismogram. For studies with no stochastic component this is -1; for studies 1.4 and 15.12 it is 10.0.
This header precedes every two-component seismogram.
Sample C code
Below is sample C code to read and
Sample Python code
This is a Python script to read in and print the header information.
#!/usr/bin/env python2 import sys import struct if len(sys.argv)<2: print "Usage: %s <input seismogram>" % sys.argv[0] sys.exit(1) seismogram = sys.argv[1] with open(seismogram, "rb") as fp_in: header_str = fp_in.read(56) version = header_str[0:8] if version[0:5]!="12.10": print "Error: version does not match expected string '12.10', aborting." sys.exit(2) site = header_str[8:16] source_id = struct.unpack('i', header_str[24:28]) rupture_id = struct.unpack('i', header_str[28:32]) rup_var_id = struct.unpack('i', header_str[32:36]) dt = struct.unpack('f', header_str[36:40]) nt = struct.unpack('i', header_str[40:44]) comps = struct.unpack('i', header_str[44:48]) x_flag = y_flag = z_flag = False if (comps & 1)==1: x_flag = True if (comps & 2)==2: y_flag = True if (comps & 4)==4: z_flag = True det_max_freq = struct.unpack('f', header_str[48:52])[0] stoch_max_freq = struct.unpack('f', header_str[52:56])[0] print "Version = %s" % version print "Site = %s" % site print "Source ID = %d" % source_id print "Rupture ID = %d" % rupture_id print "Rupture Variation ID = %d" % rup_var_id print "DT = %f" % dt print "NT = %d" % nt print "X component? %d" % x_flag print "Y component? %d" % y_flag print "Z component? %d" % z_flag print "Maximum deterministic frequency = %f" % det_max_freq print "Maximum stochastic frequency = %f" % stoch_max_freq fp_in.close()
PSA header
The format for the PSA header is exactly the same as the seismogram header, given above.
RotD header
The format for the RotD header is exactly the same as the seismogram and PSA headers, given above. However, after the above header, there is an additional value, defined as:
int num_periods;
This value contains the number of periods which are to follow, making it easier to parse.
Duration header
The format for the duration header is exactly the same as the seismogram, PSA, and RotD headers, given above.