@@ -205,10 +205,10 @@ def get_n_stations(self):
205
205
if self .dataframe is not None :
206
206
return (
207
207
self .dataframe .loc [
208
- (self .dataframe .zxx != 0 )
209
- | (self .dataframe .zxy != 0 )
210
- | (self .dataframe .zyx != 0 )
211
- | (self .dataframe .zyy != 0 ),
208
+ (self .dataframe .z_xx != 0 )
209
+ | (self .dataframe .z_xy != 0 )
210
+ | (self .dataframe .z_yx != 0 )
211
+ | (self .dataframe .z_yy != 0 ),
212
212
"station" ,
213
213
]
214
214
.unique ()
@@ -256,7 +256,7 @@ def write_data_file(self, **kwargs):
256
256
# -----Write data file--------------------------------------------------
257
257
n_stations = self .get_n_stations ()
258
258
n_periods = self .period .size
259
- station_locations = self .dataframe . station_locations .copy ()
259
+ station_locations = self .station_locations .copy ()
260
260
261
261
lines = []
262
262
data_lines = []
@@ -266,56 +266,62 @@ def write_data_file(self, **kwargs):
266
266
267
267
# write N-S locations
268
268
lines .append ("Station_Location: N-S \n " )
269
- for ii in range (n_stations / self .n_z + 1 ):
270
- for ll in range (self .n_z ):
271
- index = ii * self .n_z + ll
272
- try :
273
- lines .append (
274
- f"{ station_locations .model_north [index ]:+.4e} "
275
- )
276
- except IndexError :
277
- pass
278
- lines .append ("\n " )
269
+ for ii in range (n_stations ):# / self.n_z + 1
270
+ # for ll in range(self.n_z):
271
+ # index = ii * self.n_z + ll
272
+ try :
273
+ lines .append (
274
+ f"{ station_locations .model_north [ii ]:+.4e} "
275
+ )
276
+ except IndexError :
277
+ pass
278
+ if ii % 8 == 7 :
279
+ lines .append ("\n " )
280
+ lines .append ("\n " )
279
281
280
282
# write E-W locations
281
283
lines .append ("Station_Location: E-W \n " )
282
- for ii in range (n_stations / self .n_z + 1 ):
283
- for ll in range (self .n_z ):
284
- index = ii * self .n_z + ll
285
- try :
286
- lines .append (
287
- f"{ station_locations .model_east [index ]:+.4e} "
288
- )
289
- except IndexError :
290
- pass
291
- lines .append ("\n " )
284
+ for ii in range (n_stations ):# / self.n_z + 1
285
+ # for ll in range(self.n_z):
286
+ # index = ii * self.n_z + ll
287
+ try :
288
+ lines .append (
289
+ f"{ station_locations .model_east [ii ]:+.4e} "
290
+ )
291
+ except IndexError :
292
+ pass
293
+
294
+ if ii % 8 == 7 :
295
+ lines .append ("\n " )
296
+ lines .append ("\n " )
292
297
293
298
# write impedance tensor components
294
299
for ii , p1 in enumerate (self .period ):
295
- pdf = self .get_period_df (p1 )
300
+ # pdf = self.get_period_df(p1)
301
+ pdf = self .dataframe [self .dataframe ['period' ]== p1 ]
296
302
data_lines .append (f"DATA_Period: { p1 :3.6f} \n " )
297
303
error_lines .append (f"ERROR_Period: { p1 :3.6f} \n " )
298
304
error_map_lines .append (f"ERMAP_Period: { p1 :3.6f} \n " )
299
305
for row in pdf .itertuples ():
300
306
data_lines .append (
301
- f"{ row .zxx .real * zconv :+.4e} "
302
- f"{ row .zxx .imag * zconv :+.4e} "
303
- f"{ row .zxy .real * zconv :+.4e} "
304
- f"{ row .zxy .imag * zconv :+.4e} "
305
- f"{ row .zyx .real * zconv :+.4e} "
306
- f"{ row .zyx .imag * zconv :+.4e} "
307
- f"{ row .zyy .real * zconv :+.4e} "
308
- f"{ row .zyy .imag * zconv :+.4e} \n "
307
+ f"{ row .z_xx .real * zconv :+.4e} "
308
+ f"{ row .z_xx .imag * zconv :+.4e} "
309
+ f"{ row .z_xy .real * zconv :+.4e} "
310
+ f"{ row .z_xy .imag * zconv :+.4e} "
311
+ f"{ row .z_yx .real * zconv :+.4e} "
312
+ f"{ row .z_yx .imag * zconv :+.4e} "
313
+ f"{ row .z_yy .real * zconv :+.4e} "
314
+ f"{ row .z_yy .imag * zconv :+.4e} \n "
309
315
)
310
316
error_lines .append (
311
- f"{ row .zxx .real * self .z_error :+.4e} "
312
- f"{ row .zxx .imag * self .z_error :+.4e} "
313
- f"{ row .zxy .real * self .z_error :+.4e} "
314
- f"{ row .zxy .imag * self .z_error :+.4e} "
315
- f"{ row .zyx .real * self .z_error :+.4e} "
316
- f"{ row .zyx .imag * self .z_error :+.4e} "
317
- f"{ row .zyy .real * self .z_error :+.4e} "
318
- f"{ row .zyy .imag * self .z_error :+.4e} "
317
+ f"{ row .z_xx .real * self .z_error :+.4e} "
318
+ f"{ row .z_xx .imag * self .z_error :+.4e} "
319
+ f"{ row .z_xy .real * self .z_error :+.4e} "
320
+ f"{ row .z_xy .imag * self .z_error :+.4e} "
321
+ f"{ row .z_yx .real * self .z_error :+.4e} "
322
+ f"{ row .z_yx .imag * self .z_error :+.4e} "
323
+ f"{ row .z_yy .real * self .z_error :+.4e} "
324
+ f"{ row .z_yy .imag * self .z_error :+.4e} "
319
325
)
320
326
321
327
error_map_lines .append (
@@ -326,11 +332,13 @@ def write_data_file(self, **kwargs):
326
332
f"{ self .z_error_map [2 ]:+.4e} "
327
333
f"{ self .z_error_map [2 ]:+.4e} "
328
334
f"{ self .z_error_map [3 ]:+.4e} "
329
- f"{ self .z_error_map [3 ]:+.4e} "
335
+ f"{ self .z_error_map [3 ]:+.4e} \n "
330
336
)
331
337
332
338
with open (self .data_filename , "w" ) as fid :
333
- fid .write ("" .join (lines , data_lines , error_lines , error_map_lines ))
339
+ for dlist in [lines , data_lines , error_lines , error_map_lines ]:
340
+ for line in dlist :
341
+ fid .write (line )
334
342
335
343
self .logger .info (f"Wrote WS3DINV file to { self .data_filename } " )
336
344
return self .data_filename
0 commit comments