MTgeophysics / mtpy-v2

Tools to work with magnetotelluric transfer functions, based on MTH5 and mt-metadata. This is an update to mtpy.
https://mtpy-v2.readthedocs.io/en/latest/index.html
MIT License
30 stars 11 forks source link

Issues with occam 2d reading data #64

Open alkirkby opened 2 weeks ago

alkirkby commented 2 weeks ago

When I read an occam data file with code below I get an error in Occam2DData

ocd = Occam2DData() ocd.read_data_file(r'U:\scratch\alisonk\MT\synthetic_data\Forward.fwd')

The problem is line , line 456 :df = df.groupby(["station", "period"]).agg("first")

Really not sure what is going on here! I have spent quite a bit of time trying to debug but no luck.

I attached the file I am trying to read, it's a forward model from Occam (but have had problems with other files) Forward.txt

Traceback (most recent call last):

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\spyder_kernels\customize\utils.py:209 in exec_encapsulate_locals exec_fun(compile(code_ast, filename, "exec"), globals)

File occam_resolution_test_setup_inv.py:12 ocd.read_data_file(r'U:\scratch\alisonk\MT\synthetic_data\Forward.fwd')

File C:\git\mtpy-v2\mtpy\modeling\occam2d\data.py:456 in read_data_file df = df.groupby(["station", "period"]).agg("first")

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\generic.py:1432 in aggregate result = op.agg()

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\apply.py:187 in agg return self.apply_str()

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\apply.py:603 in apply_str return self._apply_str(obj, func, *self.args, **self.kwargs)

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\apply.py:693 in _apply_str return f(*args, **kwargs)

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\groupby.py:3400 in first return self._agg_general(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\groupby.py:1906 in _agg_general result = self._cython_agg_general(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\groupby.py:1998 in _cython_agg_general new_mgr = data.grouped_reduce(array_func)

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\internals\managers.py:1473 in grouped_reduce applied = blk.apply(func)

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\internals\blocks.py:393 in apply result = func(self.values, **kwargs)

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\groupby.py:1973 in array_func result = self._grouper._cython_operation(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\ops.py:830 in _cython_operation return cy_op.cython_operation(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\ops.py:549 in cython_operation return self._cython_op_ndim_compat(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\ops.py:344 in _cython_op_ndim_compat return self._call_cython_op(

File ~\AppData\Local\miniforge3\envs\mtpy-v2\Lib\site-packages\pandas\core\groupby\ops.py:418 in _call_cython_op func(

File groupby.pyx:1477 in pandas._libs.groupby.__pyx_fused_cpdef

TypeError: No matching signature found

alkirkby commented 1 day ago

I have written a work-around (bit clunky but does the job). See latest branch occam2d_fixes_2. I will do a PR, @kujaku11, you might want to take a look and replace with the proper pandas functions. Or you might not :)