Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sec23
korte
pymagglobal
Commits
54befec4
Commit
54befec4
authored
Aug 06, 2021
by
Maximilian Schanner
Browse files
Change 'master curve' to 'local curve'
parent
ecab3303
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
54befec4
Changelog
=========
2021-08-06 v0.1.5
-----------------
* Change "master curve" to "local curve" everywhere
2021-07-28 v0.1.4
-----------------
* CLI for secular variation
...
...
pymagglobal/__init__.py
View file @
54befec4
...
...
@@ -37,11 +37,11 @@ accessed, see also the `list of included models
'''
# expose only utilities and core modules
__all__
=
[
'
master
_curve'
,
'dipole_series'
,
'file2splines'
,
'field'
,
__all__
=
[
'
local
_curve'
,
'dipole_series'
,
'file2splines'
,
'field'
,
'built_in_models'
,
'coefficients'
,
'utils'
,
'secular_variation'
,
'power_spectrum'
,
'Model'
]
from
pymagglobal.core
import
master
_curve
,
dipole_series
,
file2splines
,
\
from
pymagglobal.core
import
local
_curve
,
dipole_series
,
file2splines
,
\
field
,
coefficients
,
secular_variation
,
power_spectrum
,
built_in_models
,
\
Model
from
pymagglobal
import
utils
...
...
pymagglobal/__main__.py
View file @
54befec4
...
...
@@ -66,8 +66,8 @@ map_ex_cmd = 'pymagglobal map 1700 gufm1'
mst_ex_ofn
=
'pic_mst.png'
'''Output file name for the mater curve example :py:attr:`~mst_ex_cmd`'''
mst_ex_cmd
=
'pymagglobal
master
12 12 ARCH10k.1'
'''CLI usage example for plotting a
master
curve.'''
mst_ex_cmd
=
'pymagglobal
local
12 12 ARCH10k.1'
'''CLI usage example for plotting a
local
curve.'''
_models
=
built_in_models
()
'''A dictionary of built-in models. The result of a call to `built_in_models`,
...
...
@@ -134,8 +134,8 @@ def argument_parser():
default
=
argparse
.
SUPPRESS
,
help
=
'Show this message and exit. Each of the '
'commands above has its own --help, so use e.g. '
'
master
--help to get information on how to create a '
'
master
curve.'
)
'
local
--help to get information on how to create a '
'
local
curve.'
)
parser
.
add_argument
(
'--version'
,
action
=
'version'
,
version
=
f
'pymagglobal
{
__version__
}
'
)
parser
.
add_argument
(
'--list-models'
,
help
=
'List available models and '
...
...
@@ -194,23 +194,23 @@ def argument_parser():
# the subparser for all commands
subparsers
=
parser
.
add_subparsers
(
dest
=
'command'
,
required
=
True
)
# parser for the
master
curve handling
# parser for the
local
curve handling
mst_epilog
=
f
'''Example of use: :command:`
{
mst_ex_cmd
}
`
.. image:: ./
{
mst_ex_ofn
}
'''
# sphinx-argparse requires a multi line string
mst_parser
=
subparsers
.
add_parser
(
'
master
'
,
help
=
'Create a
master
curve '
mst_parser
=
subparsers
.
add_parser
(
'
local
'
,
help
=
'Create a
local
curve '
'for a specific location.'
,
parents
=
[
base_parser
,
series_base_parser
],
epilog
=
mst_epilog
)
mst_parser
.
set_defaults
(
func
=
_commands
.
master
_curve
)
mst_parser
.
set_defaults
(
func
=
_commands
.
local
_curve
)
mst_parser
.
add_argument
(
'lat'
,
type
=
float
,
help
=
'The latitude at which to create the
master
'
help
=
'The latitude at which to create the
local
'
'curve.'
)
mst_parser
.
add_argument
(
'lon'
,
type
=
float
,
help
=
'The longitude at which to create the '
'
master
curve.'
)
'
local
curve.'
)
mst_parser
.
add_argument
(
'--type'
,
choices
=
[
'dif'
,
'nez'
],
type
=
str
,
help
=
'The type of the resulting field. '
...
...
pymagglobal/_commands.py
View file @
54befec4
...
...
@@ -121,8 +121,8 @@ def lt2yr(times):
return
-
times
*
1000
+
1950
def
master
_curve
(
args
):
'''Handle the
master
command and create a
master
curve at a given
def
local
_curve
(
args
):
'''Handle the
local
command and create a
local
curve at a given
location.
Parameters
...
...
@@ -135,13 +135,13 @@ def master_curve(args):
matplotlib.figure.Figure
If the --no-show flag is not set or a savefig output is specified,
return a matplotlib.figure.Figure object, containing a plot of the
master
curve.
local
curve.
'''
# get an array of times
times
=
args2times
(
args
)
# create a
master
curve using the core function, check is performed
# create a
local
curve using the core function, check is performed
# in args2times
curves
=
core
.
master
_curve
(
times
,
(
args
.
lat
,
args
.
lon
),
args
.
model
,
curves
=
core
.
local
_curve
(
times
,
(
args
.
lat
,
args
.
lon
),
args
.
model
,
field_type
=
args
.
type
,
check
=
False
)
# output formats for dif and nez components
fmts
=
{
'dif'
:
(
'%.2f'
,
'%2.6f'
,
'%2.6f'
,
'%1.7e'
),
...
...
@@ -160,17 +160,17 @@ def master_curve(args):
curves
[
2
]]).
T
,
fmt
=
fmts
[
args
.
type
],
delimiter
=
','
,
header
=
f
'
Master
curves at (
{
args
.
lat
}
°,
{
args
.
lon
}
°) '
header
=
f
'
Local
curves at (
{
args
.
lat
}
°,
{
args
.
lon
}
°) '
f
'for
{
args
.
model
.
name
}
\n
'
f
'
{
args
.
t_label
}
,'
f
'
{
utils
.
_labels
[
args
.
type
][
0
]
}
,'
f
'
{
utils
.
_labels
[
args
.
type
][
1
]
}
,'
f
'
{
utils
.
_labels
[
args
.
type
][
2
]
}
'
)
# if the --no-show flag is not set, plot the
master
curve
# if the --no-show flag is not set, plot the
local
curve
if
not
args
.
no_show
or
args
.
savefig
is
not
None
:
fig
=
plt
.
figure
(
figsize
=
(
10
,
7
))
fig
.
suptitle
(
f
'
Master
curves at (
{
args
.
lat
}
°,
{
args
.
lon
}
°) '
fig
.
suptitle
(
f
'
Local
curves at (
{
args
.
lat
}
°,
{
args
.
lon
}
°) '
f
'for
{
args
.
model
.
name
}
'
)
axs
=
np
.
empty
(
3
,
dtype
=
object
)
axs
[
0
]
=
fig
.
add_subplot
(
221
)
...
...
pymagglobal/core.py
View file @
54befec4
...
...
@@ -30,7 +30,7 @@ from pymagglobal.utils import nez2dif, REARTH, i2lm_l, i2lm_m, lmax2N, lm2i, \
dsh_basis
,
grad_d
,
grad_i
,
grad_f
__all__
=
[
'built_in_models'
,
'Model'
,
'
master
_curve'
,
'coefficients'
,
__all__
=
[
'built_in_models'
,
'Model'
,
'
local
_curve'
,
'coefficients'
,
'dipole_series'
,
'file2splines'
,
'field'
]
...
...
@@ -176,20 +176,20 @@ class Model(object):
return
inds
def
master
_curve
(
times
,
loc
,
splines
,
cov_splines
=
None
,
field_type
=
'dif'
,
def
local
_curve
(
times
,
loc
,
splines
,
cov_splines
=
None
,
field_type
=
'dif'
,
check
=
True
):
'''Create
master
curves from a splines object.
'''Create
local
curves from a splines object.
Parameters
----------
times : array-like
The times for which to create the
master
curve.
The times for which to create the
local
curve.
loc : tuple
lat, lon tuple of the location at which to create the
master
curve.
lat, lon tuple of the location at which to create the
local
curve.
splines : scipy.interpolate.BSpline or Model
An instance of Model or splines specifying the model.
field_type : {'dif', 'nez'}
The type of the
master
curves. May be either 'dif' (default) for
The type of the
local
curves. May be either 'dif' (default) for
declination, inclination and intensity or 'nez' for north, east, down.
cov_splines : scipy.interpolate.BSpline, optional
A BSpline interpolating the covariance matrices of the coefficients.
...
...
@@ -201,15 +201,15 @@ def master_curve(times, loc, splines, cov_splines=None, field_type='dif',
Returns
-------
ndarray
The first component
master
curve. Either declination or north,
The first component
local
curve. Either declination or north,
depending on the field_type kwarg. If cov_splines is given, a tuple
containing the component and the standard deviation is returned.
ndarray
The second component
master
curve. Either inclination or east,
The second component
local
curve. Either inclination or east,
depending on the field_type kwarg. If cov_splines is given, a tuple
containing the component and the standard deviation is returned.
ndarray
The third component
master
curve. Either intensity or down,
The third component
local
curve. Either intensity or down,
depending on the field_type kwarg. If cov_splines is given, a tuple
containing the component and the standard deviation is returned.
'''
...
...
@@ -227,13 +227,13 @@ def master_curve(times, loc, splines, cov_splines=None, field_type='dif',
n_plt
=
len
(
times
)
except
TypeError
:
n_plt
=
1
# set up
master
curve points
# set up
local
curve points
z_mst
=
np
.
zeros
((
4
,
n_plt
),
order
=
'F'
)
z_mst
[
0
]
=
90
-
loc
[
0
]
z_mst
[
1
]
=
loc
[
1
]
z_mst
[
2
]
=
REARTH
z_mst
[
3
]
=
times
# the
master
curves are just field values at a constant location
# the
local
curves are just field values at a constant location
mst_cv
=
field
(
z_mst
,
splines
,
cov_splines
=
cov_splines
,
field_type
=
field_type
)
...
...
@@ -402,7 +402,7 @@ def dipole_series(times, splines, cov_splines=None, check=True):
Parameters
----------
times : array-like
The times for which to create the
master curve
.
The times for which to create the
dipole series
.
splines : scipy.interpolate.BSpline or Model
An instance of Model or splines specifying the model.
cov_splines : scipy.interpolate.BSpline, optional
...
...
tests/test_argument_parser.py
View file @
54befec4
...
...
@@ -64,11 +64,11 @@ class ParserTestGlobal(_SetUpCls):
class
ParserTestMaster
(
_SetUpCls
):
'''Test-cases from the `
master
` sub-command'''
'''Test-cases from the `
local
` sub-command'''
def
test_
master
_exclusive_res_every
(
self
):
def
test_
local
_exclusive_res_every
(
self
):
'''Raise if both, --res and --every are specified'''
cmd
=
'pymagglobal
master
--no-show --res=20 --every=12 12 12 gufm1'
cmd
=
'pymagglobal
local
--no-show --res=20 --every=12 12 12 gufm1'
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
# Redirect stderr not to pollute output the terminal
sys
.
stderr
=
io
.
StringIO
()
...
...
Write
Preview
Supports
Markdown
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