Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding DataFrames output to SeisHeaderInfo #35

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,6 +16,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
Documenter = "0.27"
DocumenterTools = "0.1"
DataFrames = "1"
julia = "1"

[extras]
Expand Down
111 changes: 60 additions & 51 deletions src/ReadWrite/SeisHeaderInfo.jl
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
1 change: 1 addition & 0 deletions src/SeisMain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module SeisMain
using Printf
using Statistics
using Distributed
using DataFrames
include("ReadWrite/ReadWrite.jl")
include("Utils/Utils.jl")
end
Loading