コード例 #1
0
ファイル: segyreader.py プロジェクト: thecassion/PH5
 def read_trace_header (self) :
     buf = self.read_buf (180)
     if not buf : return {}
     t = segy_h.Trace (self.endianess)
     
     ret = {}
     container = t.parse (buf)
     
     keys = segy_h.Trace ().__keys__
     for k in keys :
         what = "container.{0}".format (k)
         ret[k] = eval (what)
     
     return ret
コード例 #2
0
ファイル: dumpsgy.py プロジェクト: thecassion/PH5
def print_trace_header(container):
    keys = segy_h.Trace().__keys__
    tt = 0
    print "---------- Trace Header ----------"
    for k in keys:
        what = "container.{0}".format(k)
        #print repr (what)
        try:
            if tt == 9999: raise
            s = SIZEOF[k] / 8
            foffset = "{0:<3} - {1:>3}".format(tt, tt + s - 1)
            tt += s
        except:
            tt = 9999
            foffset = "{0:<3} - {1:>3}".format('_', '_')

        print "{2} {0:<20}\t---\t{1}".format(k, eval(what), foffset)
コード例 #3
0
ファイル: dumpsgy.py プロジェクト: thecassion/PH5
def read_trace_header():
    buf = FH.read(180)
    t = segy_h.Trace(ENDIAN)

    return t.parse(buf)
コード例 #4
0
    def set_trace_header(self):
        '''
           Set values in trace header.
        '''
        tra = {}
        self.trace_header = segy_h.Trace()
        #
        ###   Get time correction
        #
        cor_low, cor_high, sort_start_time = self._cor()
        #   Calculate start time based on calculated drift
        corrected_start_time = self.cut_start_epoch + (cor_low / 1000.0)

        cl, sl = scale_16(cor_low)
        if sl > 1:
            cor_low = MAX_16
        elif sl < 1:
            cor_low = MIN_16

        ch, sh = scale_16(cor_high)
        if sh > 1:
            cor_high = MAX_16
        elif sh < 1:
            cor_high = MIN_16

        #   Set time correction
        tra['totalStatic'] = cor_low

        tra['lineSeq'] = self.seq
        #   das_t['event_number'] is the FFID or recording window
        tra['event_number'] = self.das_t['event_number_i']
        tra['channel_number'] = self.seq
        #tra['channel_number'] = self.array_t['channel_number_i']
        #   Set the traceID to the channel, 15 => Z, 16 => N, 17 => E
        #   Fallback is to set it to 1 => seismic data
        try:
            try:
                #   This should be the orientation
                comp = self.receiver_t['orientation/description_s'][0]
                tra['traceID'] = COMP2TID[comp]
            except:
                tra['traceID'] = CHAN2TID[self.array_t['channel_number_i']]
        except:
            #   Changed for Mark Goldman, Aug 2011
            tra['traceID'] = 1

        length_points = int(self.length_points)
        if length_points < MAX_16:
            tra['sampleLength'] = length_points
        #   Non-standard sample length
        elif self.break_standard == True:
            #   Set sample length to zero as a flag its non-standard
            tra['sampleLength'] = 0
        else:
            tra['sampleLength'] = int(MAX_16)

        sample_rate = float(int(self.sample_rate))
        if sample_rate > 30.0:
            #   In usec
            tra['deltaSample'] = int((1.0 / sample_rate) * 1000000.0)
        else:
            tra['deltaSample'] = 1

        tra['gainType'] = 1
        tra['gainConst'] = int(self.response_t['gain/value_i'])

        twfUnits = self.response_t['bit_weight/units_s'].strip()
        try:
            mult = COUNTMULT[twfUnits]
        except:
            mult = 1.

        try:
            tra['traceWeightingFactor'] = int(
                math.log(self.response_t['bit_weight/value_d'] / mult, 2) +
                0.5)
        except ValueError:
            tra['traceWeightingFactor'] = 1.
        #print twfUnits, self.response_t['bit_weight/value_d'], tra['traceWeightingFactor']

        #m_secs = int (math.modf (corrected_start_time)[0] * 1000.0)
        ttuple = time.gmtime(corrected_start_time)
        tra['year'] = ttuple[0]
        tra['day'] = ttuple[7]
        tra['hour'] = ttuple[3]
        tra['minute'] = ttuple[4]
        tra['second'] = ttuple[5]
        tra['timeBasisCode'] = 4  #   UTC

        #   Limit size of phoneFirstTrace to 65535 maximum
        try:
            pft, spft = scale_u16(int(self.array_t['id_s']))
            if spft != 1:
                tra['phoneFirstTrace'] = pft
            else:
                tra['phoneFirstTrace'] = int(self.array_t['id_s'])
        except:
            tra['phoneFirstTrace'] = 0

        #
        ###   Set receiver location here
        #
        try:
            re, es = scale_32(self.array_t['location/Z/value_d'])
            tra['recElevation'] = re
            tra['elevationScale'] = es
            #multiplier = units_stub (string.strip (self.array_t['location/Z/units_s']), 'decimeters')
            #tra['recElevation'] = int (float (self.array_t['location/Z/value_d']) * multiplier)
            #tra['elevationScale'] = -10
        except:
            tra['recElevation'] = 0
            tra['elevationScale'] = 0

        if self.utm == True:
            try:
                Y, X, Z = geod2utm(
                    None,  #   Zone goes here
                    "WGS84",
                    self.array_t['location/Y/value_d'],
                    self.array_t['location/X/value_d'],
                    self.array_t['location/Z/value_d'])
                #print 'X: ', X, 'Y: ', Y, 'Z:', Z
                s, vx, vy = pick_values_32(X, Y)

                tra['coordScale'] = s
                tra['recLongOrX'] = vx
                tra['recLatOrY'] = vy
                tra['coordUnits'] = 1  #   meters
            except:
                tra['coordScale'] = 0
                tra['recLongOrX'] = 0
                tra['recLatOrY'] = 0
                tra['coordUnits'] = 0
        else:
            try:
                s, vx, vy = pick_values_32(self.array_t['location/X/value_d'],
                                           self.array_t['location/Y/value_d'])
                tra['coordScale'] = s
                tra['recLongOrX'] = vx
                tra['recLatOrY'] = vy
                u = self.array_t['location/X/units_s'].strip()
                if LOCUNITS.has_key(u):
                    tra['coordUnits'] = LOCUNITS[u]
                else:
                    tra['coordUnits'] = 0
            except:
                tra['coordScale'] = 0
                tra['recLongOrX'] = 0
                tra['recLatOrY'] = 0
                tra['coordUnits'] = 0

        #
        ###   Event location
        #
        if self.event_t:
            try:
                tra['energySourcePt'] = int(self.event_t['id_s'])
                #sys.stderr.write ("Shot: {0:d}\n".format (int (self.event_t['id_s'])))
            except Exception, e:
                tra['energySourcePt'] = 0
                #sys.stderr.write ("Error: {0:s} Shot ID: {1:s}\n".format (e, self.event_t['id_s']))

            #   Set source location here
            try:
                sz, ez, rz = pick_values_32(self.event_t['location/Z/value_d'],
                                            self.array_t['location/Z/value_d'])
                tra['sourceSurfaceElevation'] = ez
                if tra['recElevation'] != rz:
                    tra['recElevation'] = rz
                    tra['elevationScale'] = sz

                #multiplier = units_stub (string.strip (self.event_t['location/Z/units_s']), 'decimeters')
                #tra['sourceSurfaceElevation'] = int (float (self.event_t['location/Z/value_d']) * multiplier)
                #tra['sourceDepth'] = int (float (self.event_t['depth/value_d']) * multiplier)
            except:
                tra['sourceSurfaceElevation'] = 0
                tra['sourceDepth'] = 0

            if self.utm:
                try:
                    Y, X, Z = geod2utm(
                        None,  #   Zone goes here
                        "WGS84",
                        self.event_t['location/Y/value_d'],
                        self.event_t['location/X/value_d'],
                        self.event_t['location/Z/value_d'])

                    s, vx, vy = pick_values_32(X, Y)
                    tra['sourceLongOrX'] = vx
                    tra['sourceLatOrY'] = vy

                except:
                    tra['sourceLongOrX'] = 0
                    tra['sourceLatOrY'] = 0

            else:
                try:
                    s, vx, vy = pick_values_32(
                        self.event_t['location/X/value_d'],
                        self.event_t['location/Y/value_d'])
                    tra['sourceLongOrX'] = vx
                    tra['sourceLatOrY'] = vy
                except:
                    tra['sourceLongOrX'] = 0
                    tra['sourceLatOrY'] = 0
コード例 #5
0
    def set_trace_header(self):
        '''
           Set values in trace header.
        '''
        tra = {}
        self.trace_header = segy_h.Trace()

        #   Get time correction
        cor_low, cor_high, sort_start_time = self._cor()
        if cor_low < -MAX_16 or cor_low > MAX_16:
            #print cor_low
            cor_low = int(MAX_16)

        tra['totalStatic'] = cor_low

        tra['lineSeq'] = self.seq
        #   das_t['event_number'] is the FFID or recording window
        tra['event_number'] = self.das_t['event_number_i']
        tra['channel_number'] = self.seq
        #tra['channel_number'] = self.array_t['channel_number_i']
        #   Set the traceID to the channel, 15 => Z, 16 => N, 17 => E
        #   Fallback is to set it to 1 => seismic data
        try:
            tra['traceID'] = CHAN2TID[self.array_t['channel_number_i']]
        except:
            #   Changed for Mark Goldman, Aug 2011
            tra['traceID'] = 1

        length_points = int(self.length_points)
        if length_points < MAX_16:
            tra['sampleLength'] = length_points
        #   Non-standard sample length
        elif self.break_standard == True:
            tra['sampleLength'] = 0
        else:
            tra['sampleLength'] = int(MAX_16)

        sample_rate = float(int(self.sample_rate))
        if sample_rate > 30.0:
            tra['deltaSample'] = int((1.0 / sample_rate) * 1000000.0)
        else:
            tra['deltaSample'] = 1

        tra['gainType'] = 1
        tra['gainConst'] = int(self.response_t['gain/value_i'])

        corrected_start_time = self.cut_start_epoch + (cor_low / 1000.0)
        #m_secs = int (math.modf (corrected_start_time)[0] * 1000.0)
        ttuple = time.gmtime(corrected_start_time)
        tra['year'] = ttuple[0]
        tra['day'] = ttuple[7]
        tra['hour'] = ttuple[3]
        tra['minute'] = ttuple[4]
        tra['second'] = ttuple[5]
        tra['timeBasisCode'] = 4  #   UTC

        twfUnits = self.response_t['bit_weight/units_s'].strip()
        try:
            mult = COUNTMULT[twfUnits]
        except:
            mult = 1.

        try:
            tra['traceWeightingFactor'] = int(
                math.log(self.response_t['bit_weight/value_d'] / mult, 2) +
                0.5)
        except ValueError:
            tra['traceWeightingFactor'] = 1.

        #print twfUnits, self.response_t['bit_weight/value_d'], tra['traceWeightingFactor']
        #   Limit size of phoneFirstTrace to 65535 maximum
        tra['phoneFirstTrace'] = 0xFFFF & int(self.array_t['id_s'])

        #   Set receiver location here
        try:
            multiplier = units_stub(
                string.strip(self.array_t['location/Z/units_s']), 'decimeters')
            tra['recElevation'] = int(
                float(self.array_t['location/Z/value_d']) * multiplier)
            tra['elevationScale'] = -10
        except:
            tra['recElevation'] = 0
            tra['elevationScale'] = 0

        if self.utm == True:
            try:
                Y, X, Z = geod2utm(
                    None,  #   Zone goes here
                    "WGS84",
                    self.array_t['location/Y/value_d'],
                    self.array_t['location/X/value_d'],
                    self.array_t['location/Z/value_d'])
                #print 'X: ', X, 'Y: ', Y, 'Z:', Z
                tra['coordScale'] = -10
                tra['recLongOrX'] = int((X * 10.0) + 0.5)
                tra['recLatOrY'] = int((Y * 10.0) + 0.5)
                tra['coordUnits'] = 1  #   meters
            except:
                tra['coordScale'] = 0
                tra['recLongOrX'] = 0
                tra['recLatOrY'] = 0
                tra['coordUnits'] = 0
        else:
            try:
                tra['coordScale'] = -10000
                tra['recLongOrX'] = int((self.array_t['location/X/value_d'] *
                                         10000.0) + 0.5)
                tra['recLatOrY'] = int((self.array_t['location/Y/value_d'] *
                                        10000.0) + 0.5)
                tra['coordUnits'] = 3
            except:
                tra['coordScale'] = 0
                tra['recLongOrX'] = 0
                tra['recLatOrY'] = 0
                tra['coordUnits'] = 0

        if self.event_t:
            try:
                tra['energySourcePt'] = int(self.event_t['id_s'])
                #sys.stderr.write ("Shot: {0:d}\n".format (int (self.event_t['id_s'])))
            except Exception, e:
                tra['energySourcePt'] = 0
                #sys.stderr.write ("Error: {0:s} Shot ID: {1:s}\n".format (e, self.event_t['id_s']))

            #   Set source location here
            try:
                multiplier = units_stub(
                    string.strip(self.event_t['location/Z/units_s']),
                    'decimeters')
                tra['sourceSurfaceElevation'] = int(
                    float(self.event_t['location/Z/value_d']) * multiplier)
                tra['sourceDepth'] = int(
                    float(self.event_t['depth/value_d']) * multiplier)
            except:
                tra['sourceSurfaceElevation'] = 0
                tra['sourceDepth'] = 0

            if self.utm:
                try:
                    Y, X, Z = geod2utm(
                        None,  #   Zone goes here
                        "WGS84",
                        self.event_t['location/Y/value_d'],
                        self.event_t['location/X/value_d'],
                        self.event_t['location/Z/value_d'])

                    tra['sourceLongOrX'] = int((X * 10.0) + 0.5)
                    tra['sourceLatOrY'] = int((Y * 10.0) + 0.5)
                except:
                    tra['sourceLongOrX'] = 0
                    tra['sourceLatOrY'] = 0

            else:
                try:
                    tra['sourceLongOrX'] = int(
                        (self.event_t['location/X/value_d'] * 10000.0) + 0.5)
                    tra['sourceLatOrY'] = int(
                        (self.event_t['location/Y/value_d'] * 10000.0) + 0.5)
                except:
                    tra['sourceLongOrX'] = 0
                    tra['sourceLatOrY'] = 0