Skip to content

Commit 1216308

Browse files
committed
to_rec_array works
1 parent cebbaee commit 1216308

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

mtpy/modeling/simpeg/data_3d.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,40 @@ def __init__(self, dataframe, **kwargs):
4141
"z_xy": {"simpeg": "zyx", "z+": "z_xy"},
4242
"z_yx": {"simpeg": "zxy", "z+": "z_yx"},
4343
"z_yy": {"simpeg": "zxx", "z+": "z_yy"},
44-
"t_zx": {"simpeg": "zzy", "z+": "z_zx"},
45-
"t_zy": {"simpeg": "zzx", "z+": "z_zy"},
44+
"t_zx": {"simpeg": "tzy", "z+": "t_zx"},
45+
"t_zy": {"simpeg": "tzx", "z+": "t_zy"},
4646
}
4747

48+
self._component_list = list(self.component_map.keys())
49+
50+
self._rec_columns = {
51+
"frequency": "freq",
52+
"east": "x",
53+
"north": "y",
54+
"elevation": "z",
55+
}
56+
self._rec_columns.update(
57+
dict(
58+
[
59+
(key, self.component_map[key]["simpeg"])
60+
for key in self._component_list
61+
]
62+
)
63+
)
64+
65+
self._rec_dtypes = [
66+
("freq", float),
67+
("x", float),
68+
("y", float),
69+
("z", float),
70+
("zxx", complex),
71+
("zxy", complex),
72+
("zyx", complex),
73+
("zyy", complex),
74+
("tzx", complex),
75+
("tzy", complex),
76+
]
77+
4878
self.include_elevation = False
4979
self.topography = None # should be a geotiff or asc file
5080
self.geographic_coordinates = True
@@ -55,8 +85,6 @@ def __init__(self, dataframe, **kwargs):
5585
self.invert_t_zx = True
5686
self.invert_t_zy = True
5787

58-
self._component_list = list(self.component_map.keys())
59-
6088
@property
6189
def station_locations(self):
6290
"""
@@ -77,7 +105,7 @@ def station_locations(self):
77105
np.zeros(station_df.elevation.size),
78106
]
79107

80-
def frequecies(self):
108+
def frequencies(self):
81109
"""unique frequencies from the dataframe"""
82110

83111
return 1.0 / self.dataframe.period.unique()
@@ -180,21 +208,13 @@ def get_survey(self, index):
180208
def to_rec_array(self):
181209

182210
df = self.dataframe[
183-
["period", "east", "north", "elevation"] + self.component_map
211+
["period", "east", "north", "elevation"] + self._component_list
184212
]
185213

186-
df["freq"] = 1.0 / df.period
214+
df.loc[:, "frequency"] = 1.0 / df.period.to_numpy()
187215
df = df.drop(columns="period")
216+
new_column_names = [self._rec_columns[col] for col in df.columns]
217+
df.columns = new_column_names
218+
df = df[[col[0] for col in self._rec_dtypes]]
188219

189-
df.rename(
190-
columns={"east": "x", "north": "y", "elevation": "z"}.update(
191-
dict(
192-
[
193-
(key, self.component_map[key]["simpeg"])
194-
for key in self._component_list
195-
]
196-
)
197-
)
198-
)
199-
200-
return df.to_recarray()
220+
return df.to_records(index=False, column_dtypes=dict(self._rec_dtypes))

tests/modeling/simpeg/test_simpeg_3d_data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from mtpy_data import PROFILE_LIST
1616
from mtpy.modeling.simpeg.data_3d import Simpeg3DData
17-
from mtpy.modeling.simpeg.recipes.inversion_2d import Simpeg2D
17+
from simpeg.electromagnetics.natural_source.survey import Data
1818

1919
# =============================================================================
2020

@@ -56,6 +56,9 @@ def test_station_locations(self):
5656
)
5757
)
5858

59+
def test_to_rec_array(self):
60+
survey_data = Data.fromRecArray(self.simpeg_data.to_rec_array())
61+
5962
# def test_station_locations_no_elevation(self):
6063
# self.simpeg_data.include_elevation = False
6164
# with self.subTest("shape"):

0 commit comments

Comments
 (0)