-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from AtilaSaraiva/seisHeaderInfo
Adding DataFrames output to SeisHeaderInfo
- Loading branch information
Showing
3 changed files
with
63 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ authors = ["fercarozzi <[email protected]>"] | |
version = "0.1.2" | ||
|
||
[deps] | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8" | ||
|
@@ -15,6 +16,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | |
[compat] | ||
Documenter = "0.27" | ||
DocumenterTools = "0.1" | ||
DataFrames = "1" | ||
julia = "1" | ||
|
||
[extras] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,76 @@ | ||
""" | ||
SeisHeaderInfo(filename;<keyword arguments>) | ||
SeisHeaderInfo(filename;<keyword arguments>) | ||
Print Seis header information to screen. The input is the name of the data file | ||
# Arguments | ||
- `ntrace=100000` : Number of traces to analyze | ||
- `ntrace=nothing` : Number of traces to analyze | ||
*Credits: AS, 2015* | ||
""" | ||
function SeisHeaderInfo(filename;ntrace=100000) | ||
function SeisHeaderInfo(filename::String;ntrace::Union{Integer,Nothing}=nothing) | ||
|
||
key = fieldnames(Header) | ||
nhead = length(key) | ||
filename_headers = ParseHeaderName(filename) | ||
stream = open(filename_headers) | ||
NX = GetNumTraces(filename) | ||
h = GrabHeader(stream,1) | ||
println("Displaying information for ", filename," (",NX," traces):") | ||
min_h = zeros(Float32,length(key)) | ||
max_h = zeros(Float32,length(key)) | ||
mean_h = zeros(Float32,length(key)) | ||
key = fieldnames(Header) | ||
nhead = length(key) | ||
filename_headers = ParseHeaderName(filename) | ||
stream = open(filename_headers) | ||
NX = GetNumTraces(filename) | ||
newNTrace = isnothing(ntrace) ? NX : ntrace | ||
h = GrabHeader(stream,1) | ||
println("Displaying information for ", filename," (",NX," traces):") | ||
min_h = zeros(Float32,length(key)) | ||
max_h = zeros(Float32,length(key)) | ||
mean_h = zeros(Float32,length(key)) | ||
|
||
for ikey=1:length(key) | ||
min_h[ikey] = convert(Float32,getfield(h,key[ikey])) | ||
max_h[ikey] = convert(Float32,getfield(h,key[ikey])) | ||
mean_h[ikey] += convert(Float32,getfield(h,key[ikey])) | ||
end | ||
for ikey=1:length(key) | ||
min_h[ikey] = convert(Float32,getfield(h,key[ikey])) | ||
max_h[ikey] = convert(Float32,getfield(h,key[ikey])) | ||
mean_h[ikey] += convert(Float32,getfield(h,key[ikey])) | ||
end | ||
|
||
itrace = 2 | ||
while itrace <= NX | ||
nx = NX - itrace + 1 | ||
ntrace = nx > ntrace ? ntrace : nx | ||
position = 4*nhead*(itrace-1) | ||
seek(stream,position) | ||
h1 = read!(stream,Array{Header32Bits}(undef,nhead*ntrace)) | ||
h1 = reshape(h1,nhead,convert(Int,ntrace)) | ||
for ikey = 1 : length(key) | ||
keytype = eval(Meta.parse("typeof(SeisMain.InitSeisHeader().$(string(key[ikey])))")) | ||
h2 = reinterpret(keytype,vec(h1[ikey,:])) | ||
a = minimum(h2) | ||
b = maximum(h2) | ||
c = mean(h2) | ||
if (a < min_h[ikey]) | ||
min_h[ikey] = a | ||
end | ||
if (b > max_h[ikey]) | ||
max_h[ikey] = b | ||
end | ||
mean_h[ikey] += c*ntrace | ||
end | ||
itrace += ntrace | ||
end | ||
itrace = 2 | ||
while itrace <= NX | ||
nx = NX - itrace + 1 | ||
newNTrace = nx > newNTrace ? newNTrace : nx | ||
position = 4*nhead*(itrace-1) | ||
seek(stream,position) | ||
h1 = read!(stream,Array{Header32Bits}(undef,nhead*newNTrace)) | ||
h1 = reshape(h1,nhead,convert(Int,newNTrace)) | ||
for ikey = 1 : length(key) | ||
keytype = eval(Meta.parse("typeof(SeisMain.InitSeisHeader().$(string(key[ikey])))")) | ||
h2 = reinterpret(keytype,vec(h1[ikey,:])) | ||
a = minimum(h2) | ||
b = maximum(h2) | ||
c = mean(h2) | ||
if (a < min_h[ikey]) | ||
min_h[ikey] = a | ||
end | ||
if (b > max_h[ikey]) | ||
max_h[ikey] = b | ||
end | ||
mean_h[ikey] += c*newNTrace | ||
end | ||
itrace += newNTrace | ||
end | ||
|
||
for ikey=1:length(key) | ||
mean_h[ikey] /= NX | ||
end | ||
close(stream) | ||
println(" Key Minimum Maximum Mean"); | ||
println("=============================================================") | ||
for ikey=1:length(key) | ||
@printf("%10s %11.3f %11.3f %11.3f\n",string(key[ikey]),min_h[ikey],max_h[ikey],mean_h[ikey]) | ||
end | ||
for ikey=1:length(key) | ||
mean_h[ikey] /= NX | ||
end | ||
close(stream) | ||
println(" Key Minimum Maximum Mean"); | ||
println("=============================================================") | ||
for ikey=1:length(key) | ||
@printf("%10s %11.3f %11.3f %11.3f\n",string(key[ikey]),min_h[ikey],max_h[ikey],mean_h[ikey]) | ||
end | ||
|
||
df = DataFrame() | ||
|
||
df.Keys = key |> collect | ||
df.Minimum = min_h | ||
df.Mean = mean_h | ||
df.Maximum = max_h | ||
|
||
return df | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters