Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MGPro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NJU Geophy
MGPro
Commits
eaf621d4
Commit
eaf621d4
authored
Jul 02, 2019
by
Mijian Xu
😷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add dt2xa, dt2ya
parent
671b53c9
Pipeline
#740
passed with stage
in 1 minute and 47 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
12 deletions
+86
-12
mgpro/client.py
mgpro/client.py
+49
-1
mgpro/mgpro.py
mgpro/mgpro.py
+36
-10
setup.py
setup.py
+1
-1
No files found.
mgpro/client.py
View file @
eaf621d4
...
...
@@ -16,9 +16,12 @@ class Client(Cmd):
self
.
prompt
=
'MGPro>'
self
.
aliases
=
{
'c'
:
self
.
do_continuation
,
'g'
:
self
.
do_gradient
,
'p'
:
self
.
do_plot
,
'q'
:
self
.
do_quit
,
'r'
:
self
.
do_read
,
'w'
:
self
.
do_write
,
'x'
:
self
.
do_dt2xa
,
'y'
:
self
.
do_dt2ya
,
'z'
:
self
.
do_dt2za
,
'h'
:
self
.
do_help
}
self
.
result
=
None
...
...
@@ -93,9 +96,46 @@ horizontal gradient in azimuth of 0, 45, 90 or 135 or module of horizontal gradi
self
.
result
=
self
.
mg
.
gradient
(
arg
)
def
do_dt2za
(
self
,
arg
):
if
len
(
arg
.
split
())
!=
2
:
'''
dt2za (z): Vertical magnetization
Syntax: dt2za i0 d0
i0: Magnetic dip of the region
d0: Magnetic declination of the region
'''
if
len
(
arg
.
split
())
==
2
:
i0
,
d0
=
[
float
(
value
)
for
value
in
arg
.
split
()]
self
.
result
=
self
.
mg
.
dt2za
(
i0
,
d0
)
else
:
print
(
'Two argumrnts required'
)
def
do_dt2xa
(
self
,
arg
):
'''
dt2xa (x): Horizontal magnetization along x direction
Syntax: dt2xa i0 d0
i0: Magnetic dip of the region
d0: Magnetic declination of the region
'''
if
len
(
arg
.
split
())
==
2
:
i0
,
d0
=
[
float
(
value
)
for
value
in
arg
.
split
()]
self
.
result
=
self
.
mg
.
dt2xa
(
i0
,
d0
)
else
:
print
(
'Two argumrnts required'
)
def
do_dt2ya
(
self
,
arg
):
'''
dt2xa (y): Horizontal magnetization along y direction
Syntax: dt2ya i0 d0
i0: Magnetic dip of the region
d0: Magnetic declination of the region
'''
if
len
(
arg
.
split
())
==
2
:
i0
,
d0
=
[
float
(
value
)
for
value
in
arg
.
split
()]
self
.
result
=
self
.
mg
.
dt2ya
(
i0
,
d0
)
else
:
print
(
'Two argumrnts required'
)
def
do_write
(
self
,
arg
):
'''
...
...
@@ -125,6 +165,14 @@ Syntax: write filename [\'lalo\']
print
(
'{}'
.
format
(
e
))
return
def
do_plot
(
self
,
arg
):
'''
plot (p): Preview the result.
Syntax: plot
'''
self
.
mg
.
pltmap
(
self
.
result
)
def
completedefault
(
self
,
*
args
):
readline
.
set_completer_delims
(
'
\t\n
;'
)
readline
.
parse_and_bind
(
"tab: complete"
)
...
...
mgpro/mgpro.py
View file @
eaf621d4
import
numpy
as
np
from
mgpro
import
expand
from
mgpro.proj
import
*
# from mgpro import expand
import
expand
# from mgpro.proj import *
from
proj
import
*
import
matplotlib.pyplot
as
plt
import
matplotlib.colors
as
colors
from
scipy.fftpack
import
fft2
,
fftshift
,
ifft2
,
ifftshift
from
scipy.interpolate
import
griddata
import
argparse
np
.
warnings
.
filterwarnings
(
'ignore'
)
def
msg
():
return
'''
...
...
@@ -42,6 +45,12 @@ def xyz2grd(raw_data, dx, dy, xy_limit=None):
grid_data
=
griddata
(
data
[:,
0
:
2
],
data
[:,
2
],
(
ymesh
,
xmesh
))
return
xrange
,
yrange
,
grid_data
def
direction_cos
(
i0
,
d0
):
P0
=
np
.
cos
(
np
.
deg2rad
(
i0
))
*
np
.
cos
(
np
.
deg2rad
(
d0
))
Q0
=
np
.
cos
(
np
.
deg2rad
(
i0
))
*
np
.
sin
(
np
.
deg2rad
(
d0
))
R0
=
np
.
sin
(
np
.
deg2rad
(
i0
))
return
P0
,
Q0
,
R0
def
norm_uv
(
data
,
dx
,
dy
):
(
len_row
,
len_col
)
=
data
.
shape
...
...
@@ -125,15 +134,33 @@ class mgmat(object):
return
grad
def
dt2za
(
self
,
i0
,
d0
):
P0
=
np
.
cos
(
np
.
deg2rad
(
i0
))
*
np
.
cos
(
np
.
deg2rad
(
d0
))
Q0
=
np
.
cos
(
np
.
deg2rad
(
i0
))
*
np
.
sin
(
np
.
deg2rad
(
d0
))
R0
=
np
.
sin
(
np
.
deg2rad
(
i0
))
P0
,
Q0
,
R0
=
direction_cos
(
i0
,
d0
)
u
,
v
=
norm_uv
(
self
.
data_sf
,
self
.
dx
,
self
.
dy
)
phi
=
np
.
sqrt
(
u
**
2
+
v
**
2
)
/
((
P0
*
u
+
Q0
*
v
)
*
1j
+
R0
*
np
.
sqrt
(
u
**
2
+
v
**
2
))
phi
[
np
.
where
(
np
.
isnan
(
phi
))]
=
0
+
0j
result
=
np
.
real
(
ifft2
(
ifftshift
(
phi
*
self
.
data_sf
)))[
self
.
row_begin
:
self
.
row_end
+
1
,
self
.
col_begin
:
self
.
col_end
+
1
]
return
result
def
pltmap
(
self
,
fig
,
data
,
breakpoint
=
None
):
def
dt2xa
(
self
,
i0
,
d0
):
P0
,
Q0
,
R0
=
direction_cos
(
i0
,
d0
)
u
,
v
=
norm_uv
(
self
.
data_sf
,
self
.
dx
,
self
.
dy
)
trans_func
=
u
*
1j
/
((
P0
*
u
+
Q0
*
v
)
*
1j
+
R0
*
np
.
sqrt
(
u
**
2
+
v
**
2
))
trans_func
[
np
.
where
(
np
.
isnan
(
trans_func
))]
=
0
+
0j
result
=
np
.
real
(
ifft2
(
ifftshift
(
trans_func
*
self
.
data_sf
)))[
self
.
row_begin
:
self
.
row_end
+
1
,
self
.
col_begin
:
self
.
col_end
+
1
]
return
result
def
dt2ya
(
self
,
i0
,
d0
):
P0
,
Q0
,
R0
=
direction_cos
(
i0
,
d0
)
u
,
v
=
norm_uv
(
self
.
data_sf
,
self
.
dx
,
self
.
dy
)
trans_func
=
v
*
1j
/
((
P0
*
u
+
Q0
*
v
)
*
1j
+
R0
*
np
.
sqrt
(
u
**
2
+
v
**
2
))
trans_func
[
np
.
where
(
np
.
isnan
(
trans_func
))]
=
0
+
0j
result
=
np
.
real
(
ifft2
(
ifftshift
(
trans_func
*
self
.
data_sf
)))[
self
.
row_begin
:
self
.
row_end
+
1
,
self
.
col_begin
:
self
.
col_end
+
1
]
return
result
def
pltmap
(
self
,
data
,
breakpoint
=
None
):
fig
=
plt
.
figure
()
f_width
=
fig
.
get_figwidth
()
f_height
=
fig
.
get_figheight
()
frac_w
=
min
([
f_height
,
f_width
])
/
max
([
f_height
,
f_width
])
...
...
@@ -141,12 +168,13 @@ class mgmat(object):
real_width
*=
frac_w
fig
.
clf
()
ax_raw
=
fig
.
gca
()
pcm
=
ax_raw
.
pcolor
(
data
,
cmap
=
'jet'
)
pcm
=
ax_raw
.
imshow
(
data
,
cmap
=
'jet'
,
extent
=
[
self
.
x
[
0
],
self
.
x
[
-
1
],
self
.
y
[
0
],
self
.
y
[
-
1
]]
)
# ax_raw.figure.canvas.draw()
cb
=
fig
.
colorbar
(
pcm
,
extend
=
'both'
)
# ax_raw.set_position([.1, .125, real_width, real_height], which='original')
# cb.ax.set_position([.8, .1, real_height/6.27, real_height])
fig
.
canvas
.
draw
()
plt
.
show
()
def
savetxt
(
self
,
filename
,
result
,
to_latlon
=
False
):
points
=
np
.
zeros
([
result
.
size
,
3
])
...
...
@@ -164,6 +192,4 @@ class mgmat(object):
if
__name__
==
'__main__'
:
mg
=
mgmat
(
'/Users/xumj/Codes/MGPro/example/mag_proj.dat'
,
2000
,
2000
)
mg
.
dt2za
(
46
,
-
1
)
# exec()
mg
.
pltmap
(
mg
.
dt2ya
(
46
,
-
1
))
setup.py
View file @
eaf621d4
...
...
@@ -5,7 +5,7 @@ packages = find_packages()
with
open
(
"README.md"
,
"r"
)
as
fh
:
long_description
=
fh
.
read
()
VERSION
=
"0.1.
4
"
VERSION
=
"0.1.
5
"
setup
(
name
=
'mgpro'
,
version
=
VERSION
,
author
=
'Mijian Xu'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment