@@ -258,14 +258,32 @@ def check_bipole(inp, name):
258258
259259 def chck_dipole (inp , name ):
260260 r"""Check inp for shape and type."""
261- # Check x
261+ # Check x, y, and z
262262 inp_x = _check_var (inp [0 ], float , 1 , name + '-x' )
263-
264- # Check y and ensure it has same dimension as x
265- inp_y = _check_var (inp [1 ], float , 1 , name + '-y' , inp_x .shape )
266-
267- # Check z
268- inp_z = _check_var (inp [2 ], float , 1 , name + '-z' , (1 ,), inp_x .shape )
263+ inp_y = _check_var (inp [1 ], float , 1 , name + '-y' )
264+ inp_z = _check_var (inp [2 ], float , 1 , name + '-z' )
265+
266+ # Expand x or y coordinate if necessary.
267+ if inp_x .size != inp_y .size :
268+ if inp_x .size == 1 :
269+ inp_x = np .repeat (inp_x , inp_y .size )
270+ elif inp_y .size == 1 :
271+ inp_y = np .repeat (inp_y , inp_x .size )
272+ else :
273+ raise ValueError (
274+ f"Parameters { name } -x and { name } -y must be of same size "
275+ "or be a single value; provided: "
276+ f"{ inp_x .shape } ; { inp_y .shape } ."
277+ )
278+
279+ # If x/y=1, but z not => expand
280+ if inp_z .size > 1 and inp_x .size == 1 :
281+ inp_x = np .repeat (inp_x , inp_z .size )
282+ inp_y = np .repeat (inp_y , inp_z .size )
283+
284+ # If x/y!=1 and z!=1, check!
285+ else :
286+ _check_shape (inp_z , name + '-z' , (1 ,), inp_x .shape )
269287
270288 # Check if all depths are the same, if so replace by one value
271289 if np .all (np .isclose (inp_z - inp_z [0 ], 0 )):
@@ -287,18 +305,32 @@ def chck_dipole(inp, name):
287305 out = chck_dipole (inp , name )
288306
289307 # Check azimuth and dip
290- inp_a = _check_var (inp [3 ], float , 1 , 'azimuth' , (1 ,), out [0 ].shape )
291- inp_d = _check_var (inp [4 ], float , 1 , 'dip' , (1 ,), out [0 ].shape )
308+ inp_a = _check_var (inp [3 ], float , 1 , 'azimuth' )
309+ inp_d = _check_var (inp [4 ], float , 1 , 'dip' )
310+
311+ # Expand x/y coordinate or azm/dip if necessary.
312+ # THINK ABOUT IT!
313+ for inp_ad , ad_name in ([inp_a , 'azimuth' ], [inp_d , 'dip' ]):
314+ if inp_ad .size != 1 and out [0 ].shape != inp_ad .shape :
315+ if out [0 ].size == 1 :
316+ out [0 ] = np .repeat (out [0 ], inp_ad .size )
317+ out [1 ] = np .repeat (out [1 ], inp_ad .size )
318+ else :
319+ raise ValueError (
320+ f"Parameter { name } -x and { name } -y must be of same size "
321+ "or be a single value; provided: "
322+ f"{ inp_x .shape } ; { inp_y .shape } ."
323+ )
292324
293325 # How many different depths
294326 nz = out [2 ].size
295327
296328 # Expand azimuth and dip to match number of depths
297329 if nz > 1 :
298330 if inp_a .size == 1 :
299- inp_a = np .ones ( nz )* inp_a
331+ inp_a = np .repeat ( inp_a , nz )
300332 if inp_d .size == 1 :
301- inp_d = np .ones ( nz )* inp_d
333+ inp_d = np .repeat ( inp_d , nz )
302334
303335 out = [* out , inp_a , inp_d ]
304336
@@ -310,11 +342,19 @@ def chck_dipole(inp, name):
310342 # If one pole has a single depth, but the other has various
311343 # depths, we have to repeat the single depth, as we will have
312344 # to loop over them.
313- if out0 [2 ].size != out1 [2 ].size :
314- if out0 [2 ].size == 1 :
315- out0 [2 ] = np .repeat (out0 [2 ], out1 [2 ].size )
316- else :
317- out1 [2 ] = np .repeat (out1 [2 ], out0 [2 ].size )
345+ for i in range (3 ):
346+ if out0 [i ].size != out1 [i ].size :
347+ if out0 [i ].size == 1 :
348+ out0 [i ] = np .repeat (out0 [i ], out1 [i ].size )
349+ elif out1 [i ].size == 1 :
350+ out1 [i ] = np .repeat (out1 [i ], out0 [i ].size )
351+ else :
352+ raise ValueError ("TODO" )
353+
354+ # Think about it. Same as above, but for the coordinates.
355+ # 1. Test that x0, x1 have same dimension
356+ # 2. If x0.shape != 1 and z0.shape != 1: check
357+ # 3. if z.shape > x0.shape -> expand
318358
319359 # Check if inp is a dipole instead of a bipole
320360 # (This is a problem, as we would could not define the angles then.)
0 commit comments