@@ -78,119 +78,66 @@ def test_meca_spec_single_focalmecha_file():
78
78
return fig
79
79
80
80
81
- @pytest .mark .mpl_image_compare
82
- def test_meca_spec_dict_list ():
81
+ @pytest .mark .mpl_image_compare (filename = "test_meca_spec_multiple_focalmecha.png" )
82
+ @pytest .mark .parametrize (
83
+ "inputtype" , ["dict_mecha" , "dict_mecha_mixed" , "dataframe" , "array2d" ]
84
+ )
85
+ def test_meca_spec_multiple_focalmecha (inputtype ):
83
86
"""
84
- Test supplying a dictionary containing a list of focal mechanism to the
85
- spec parameter.
87
+ Test passing multiple focal mechanisms to the spec parameter.
86
88
"""
87
- fig = Figure ()
88
- # supply focal mechanisms as a dict of lists
89
- focal_mechanisms = {
90
- "strike" : [330 , 350 ],
91
- "dip" : [30 , 50 ],
92
- "rake" : [90 , 90 ],
93
- "magnitude" : [3 , 2 ],
94
- }
95
- fig .meca (
96
- spec = focal_mechanisms ,
97
- longitude = [- 123.5 , - 124.5 ],
98
- latitude = [47.5 , 48.5 ],
99
- depth = [12.0 , 11.0 ],
100
- region = [- 125 , - 122 , 47 , 49 ],
101
- scale = "2c" ,
102
- projection = "M8c" ,
103
- frame = True ,
104
- )
105
- return fig
106
-
107
-
108
- @pytest .mark .mpl_image_compare
109
- def test_meca_spec_dataframe ():
110
- """
111
- Test supplying a pandas.DataFrame containing focal mechanisms and locations
112
- to the spec parameter.
113
- """
114
-
115
- fig = Figure ()
116
- # supply focal mechanisms to meca as a dataframe
117
- focal_mechanisms = {
118
- "strike" : [324 , 353 ],
119
- "dip" : [20.6 , 40 ],
120
- "rake" : [83 , 90 ],
121
- "magnitude" : [3.4 , 2.9 ],
122
- "longitude" : [- 124 , - 124.4 ],
123
- "latitude" : [48.1 , 48.2 ],
124
- "depth" : [12 , 11.0 ],
125
- }
126
- fig .meca (
127
- spec = pd .DataFrame (data = focal_mechanisms ),
128
- region = [- 125 , - 122 , 47 , 49 ],
129
- scale = "2c" ,
130
- projection = "M14c" ,
131
- )
132
- return fig
133
-
134
-
135
- @pytest .mark .mpl_image_compare
136
- def test_meca_spec_2d_array ():
137
- """
138
- Test supplying a 2-D numpy array containing focal mechanisms and locations
139
- to the spec parameter.
140
- """
141
- fig = Figure ()
142
- # supply focal mechanisms to meca as a 2-D numpy array, here we are using
143
- # the GCMT convention but the focal mechanism parameters may be
144
- # specified any of the available conventions. Since we are not using a
145
- # dict or dataframe the convention and component should be specified.
146
-
147
- # longitude, latitude, depth, strike1, rake1, strike2, dip2, rake2,
148
- # mantissa, exponent, plot_longitude, plot_latitude
149
- focal_mechanisms = np .array (
150
- [
151
- [- 127.40 , 40.87 , 12 , 170 , 20 , - 110 , 11 , 71 , - 83 , 5.1 , 23 , 0 , 0 ],
152
- [- 127.50 , 40.88 , 12.0 , 168 , 40 , - 115 , 20 , 54 , - 70 , 4.0 , 23 , 0 , 0 ],
153
- ]
154
- )
155
- fig .meca (
156
- spec = focal_mechanisms ,
157
- convention = "gcmt" ,
158
- region = [- 128 , - 127 , 40 , 41 ],
159
- scale = "2c" ,
160
- projection = "M14c" ,
161
- )
162
- return fig
163
-
89
+ if inputtype == "dict_mecha" :
90
+ args = {
91
+ "spec" : {
92
+ "strike" : [330 , 350 ],
93
+ "dip" : [30 , 50 ],
94
+ "rake" : [90 , 90 ],
95
+ "magnitude" : [3 , 2 ],
96
+ },
97
+ "longitude" : [- 123.5 , - 124.5 ],
98
+ "latitude" : [47.5 , 48.5 ],
99
+ "depth" : [12.0 , 11.0 ],
100
+ }
101
+ elif inputtype == "dict_mecha_mixed" :
102
+ args = {
103
+ "spec" : {
104
+ "strike" : [330 , 350 ],
105
+ "dip" : [30 , 50 ],
106
+ "rake" : [90 , 90 ],
107
+ "magnitude" : [3 , 2 ],
108
+ },
109
+ "longitude" : np .array ([- 123.5 , - 124.5 ]),
110
+ "latitude" : [47.5 , 48.5 ],
111
+ "depth" : [12 , 11 ],
112
+ }
113
+ elif inputtype == "dataframe" :
114
+ args = {
115
+ "spec" : pd .DataFrame (
116
+ data = {
117
+ "strike" : [330 , 350 ],
118
+ "dip" : [30 , 50 ],
119
+ "rake" : [90 , 90 ],
120
+ "magnitude" : [3 , 2 ],
121
+ "longitude" : [- 123.5 , - 124.5 ],
122
+ "latitude" : [47.5 , 48.5 ],
123
+ "depth" : [12.0 , 11.0 ],
124
+ },
125
+ )
126
+ }
127
+ elif inputtype == "array2d" :
128
+ args = {
129
+ "spec" : np .array (
130
+ [
131
+ [- 123.5 , 47.5 , 12.0 , 330 , 30 , 90 , 3 ],
132
+ [- 124.5 , 48.5 , 11.0 , 350 , 50 , 90 , 2 ],
133
+ ]
134
+ ),
135
+ "convention" : "aki" ,
136
+ }
164
137
165
- @pytest .mark .mpl_image_compare
166
- def test_meca_loc_array ():
167
- """
168
- Test supplying lists and np.ndarrays as the event location (longitude,
169
- latitude, and depth).
170
- """
171
138
fig = Figure ()
172
- # specify focal mechanisms
173
- focal_mechanisms = {
174
- "strike" : [327 , 350 ],
175
- "dip" : [41 , 50 ],
176
- "rake" : [68 , 90 ],
177
- "magnitude" : [3 , 2 ],
178
- }
179
- # longitude, latitude, and depth may be specified as an int, float,
180
- # list, or 1-D numpy array
181
- longitude = np .array ([- 123.3 , - 124.4 ])
182
- latitude = np .array ([48.4 , 48.2 ])
183
- depth = [12.0 , 11.0 ] # to test mixed data types as inputs
184
- scale = "2c"
185
- fig .meca (
186
- focal_mechanisms ,
187
- scale ,
188
- longitude = longitude ,
189
- latitude = latitude ,
190
- depth = depth ,
191
- region = [- 125 , - 122 , 47 , 49 ],
192
- projection = "M14c" ,
193
- )
139
+ fig .basemap (region = [- 125 , - 122 , 47 , 49 ], projection = "M8c" , frame = True )
140
+ fig .meca (scale = "2c" , ** args )
194
141
return fig
195
142
196
143
0 commit comments