Git Product home page Git Product logo

Comments (2)

kujaku11 avatar kujaku11 commented on September 15, 2024

@CedricPatzer Could you provide an example of the header where it fails?

Also, are you using MTData.from_modem()? If not try that.

from mtpy import MTData

md = MTData()
md.from_modem(modem_data_filename)

from mtpy-v2.

VicenteYanez avatar VicenteYanez commented on September 15, 2024

Hello

I am having a similar issue as @CedricPatzer. I have tested with two ModEM files, one file of my own and one that I downloaded from the old repo of mtpy (https://github.com/MTgeophysics/mtpy/blob/develop/examples/data/ModEM_files/ModEM_Data.dat).

My version of MTpy is 2.0.6

import mtpy
from mtpy import MTData

datafile = 'datos3.dat'
#datafile = 'ModEM_Data.dat'

md = MTData()
md.from_modem(datafile)

With my modem file (datos3.dat) I get the following error

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[9], line 8
      5 datafile = 'datos3.dat'
      7 md = MTData()
----> 8 md.from_modem(datafile)

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/core/mt_data.py:917](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/core/mt_data.py#line=916), in MTData.from_modem(self, data_filename, file_type, **kwargs)
    905 """
    906 read in a modem data file
    907 
   (...)
    914 
    915 """
    916 modem_data = Data(**kwargs)
--> 917 mdf = modem_data.read_data_file(data_filename)
    918 if file_type in ["data"]:
    919     mdf.dataframe["survey"] = "data"

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:1141](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=1140), in Data.read_data_file(self, data_fn)
   1138     dlines = dfid.readlines()
   1140 # read header information
-> 1141 n_periods, n_stations = self._read_header(
   1142 [line for line in dlines if ">" in line or "#" in line]
   1143 )
   1145 # create a list of dictionaries to make into a pandas dataframe
   1146 entries = []

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:939](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=938), in Data._read_header(self, header_lines)
    936             n_stations = int(hline[1:].strip().split()[1])
    938 for head_line, inv_mode in zip(header_list, inv_list):
--> 939     self._parse_header_line(head_line, inv_mode)
    941 self._get_inv_mode(inv_list)
    943 return n_periods, n_stations

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:978](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=977), in Data._parse_header_line(self, header_line, mode)
    976 if len(item_list) == 2:
    977     key = item_list[0]
--> 978     value = item_list[1].replace("%", "").split()[0]
    979     if key in ["error_value", "data_rotation"]:
    980         try:

IndexError: list index out of range

and with ModEM_Data.dat I get

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 8
      5 #datafile = 'datos3.dat'
      7 md = MTData()
----> 8 md.from_modem(datafile)

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/core/mt_data.py:917](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/core/mt_data.py#line=916), in MTData.from_modem(self, data_filename, file_type, **kwargs)
    905 """
    906 read in a modem data file
    907 
   (...)
    914 
    915 """
    916 modem_data = Data(**kwargs)
--> 917 mdf = modem_data.read_data_file(data_filename)
    918 if file_type in ["data"]:
    919     mdf.dataframe["survey"] = "data"

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:1141](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=1140), in Data.read_data_file(self, data_fn)
   1138     dlines = dfid.readlines()
   1140 # read header information
-> 1141 n_periods, n_stations = self._read_header(
   1142 [line for line in dlines if ">" in line or "#" in line]
   1143 )
   1145 # create a list of dictionaries to make into a pandas dataframe
   1146 entries = []

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:939](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=938), in Data._read_header(self, header_lines)
    936             n_stations = int(hline[1:].strip().split()[1])
    938 for head_line, inv_mode in zip(header_list, inv_list):
--> 939     self._parse_header_line(head_line, inv_mode)
    941 self._get_inv_mode(inv_list)
    943 return n_periods, n_stations

File [~/projects/test_pymt/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py:1016](http://localhost:8888/lab/tree/envs/lib/python3.12/site-packages/mtpy/modeling/modem/data.py#line=1015), in Data._parse_header_line(self, header_line, mode)
   1010     setattr(obj, item_dict["error_value"], value)
   1012 if "deg" in item:
   1013     setattr(
   1014         self,
   1015         item_dict["data_rotation"],
-> 1016         float(item.split("_")[0]),
   1017     )

ValueError: could not convert string to float: ' data rotated 0.0'

from mtpy-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.