How to export a rawEDF file to my computer - python

so basically I am manipulating edf files using mne and pyedflib libraries in python. As long as I am applying many changes on my edf_file, I need to export my edf file after each modification. I tried many commands with mne and pyedflib but none of them seems to work. Does anyone have a solution please?
Any kind of help would be much appreciated!

Since you do not specify what have you tried and what you have not tried exactly I will point to the doc that it seems to fit in your case and an example directly from the lib you use.
I assume you are using the writer so here the doc for pyedflib:
EDF file writer
and you should check directly this example from the pyedflib repository to adapt to your needs:
https://github.com/holgern/pyedflib/blob/master/demo/writeEDFFile.py
I think the example in the repo should give you a good idea.

Related

Can I load .npy/.npz files from inside a python package?

I am trying to create my own python package where hopefully one day other people will be able to contribute with their own content. For the package to work it must be possible to have small data files that will be installed as part of the package. It turns out, loading data file that are part of a Python module is not easy. I managed to load very basic ASCII files using something like this:
data = pkgutil.get_data(__name__, "data/test.txt")
data=data.decode('utf-8')
rr = re.findall("[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?", data)
datanp=np.zeros(len(rr))
for k in range(len(rr)):
datanp[k]=np.float(rr[k])
I found many comments online that say you should not use commands like np.load(path_to_package) because on some systems packages might actually be stored in zip files or something. That is why I am using pkgutil.get_data() , it is apparently the more robust. Here for example they talk in great length about different ways to safely load data, but not so much how you would actually load different data types.
My question: Are there ways to load .npy files from inside a Python package?

How to convert fb2 file in to txt using Python

Hello I am struggling to convert hundreds of fb2 files to txt using Python. I find pyandoc and EbookLib but I didn't find in their functionality this option, or I didn't search carefully.
Can someone suggest me something relevant in my case ? Maybe free API, but I think there could be a library.
something relevant in my case
I did look for fb2 and FictionBook2 at PyPI and found 2 potentially useful to you: catpandoc and FB2. 1st does Cat multiple documents to the terminal. and support numerous file formats. 2nd is Python package for working with FictionBook2. For FB2 example is given how to create FB2 file, but not how to read. I do not know if it means documentation is poor or it does not have read support at all.
EDIT: After some research I found that FictionBook2 files are XML files. Example can be seen here. That being said I encourage you to first try existing FB2 tools and only if they fail to deliver desired result implement extraction by XML parsing.

Is there any parallel way of accessing Netcdf files in Python

Is there any way of doing parallel IO for Netcdf files in Python?
I understand that there is a project called PyPNetCDF, but apparently it's old, not updated and doesn't seem to work at all. Has anyone had any success with parallel IO with NetCDF in Python at all?
Any help is greatly appreciated
It's too bad PyPnetcdf is not a bit more mature. I see hard-coded paths and abandoned domain names. It doesn't look like it will take a lot to get something compiled, but then there's the issue of getting it to actually work...
in setup.py you should change the library_dirs_list and include_dirs_list to point to the places on your system where Northwestern/Argonne Parallel-NetCDF is installed and where your MPI distribution is installed.
then one will have to go through and update the way pypnetcdf calls pnetcdf. A few years back (quite a few, actually) we promoted a lot of types to larger versions.
I haven't seen good examples from either of the two python NetCDF modules, see https://github.com/Unidata/netcdf4-python/issues/345
However, if You only need to read files and they are NetCDF4 format, You should be able to use HDF5 directly -- http://docs.h5py.org/en/latest/mpi.html
because NetCDF4 is basically HDF5 with restricted data model. Probably won't work with NetCDF3.

Opening .DBF files as read-only with the dbf Python module

First of all, the dbf module is great. I've been using it with great success.
I'm trying to open a dbf file on a network share which is a read-only file system. When I try to open it like this, I get an error which says that the .dbf file is read-only.
thisTable = dbf.Table('/volumes/readOnlyVolume/thisFile.dbf')
thisTable.open()
Looking at the documentation, it looks like there's a way to open a table in read-only mode, but I can't figure it out. If you have a second, would you be able to help me out?
Thanks!
Kyle
Cool, thanks! :)
At this point, you need to specify the open mode when you call thisTable.open(), like this:
thisTable.open(mode='read-only')
or
thisTable.open(mode=dbf.READ_ONLY)
Oh, and here's the PyPI link to the module.
Assuming you're using this module, the magic incantation to open read only is:
dbf1 = Dbf()
dbf1.openFile('county.dbf', readOnly=1)
Hope that helped, if not, do add more detail to your question.

How to parse a .shp file?

I am interested in gleaning information from an ESRI .shp file.
Specifically the .shp file of a polyline feature class.
When I open the .dbf of a feature class, I get what I would expect: a table that can open in excel and contains the information from the feature class' table.
However, when I try to open a .shp file in any program (excel, textpad, etc...) all I get is a bunch of gibberish and unusual ASCII characters.
I would like to use Python (2.x) to interpret this file and get information out of it (in this case the vertices of the polyline).
I do not want to use any modules or non built-in tools, as I am genuinely interested in how this process would work and I don't want any dependencies.
Thank you for any hints or points in the right direction you can give!
Your question, basically, is "I have a file full of data stored in an arbitrary binary format. How can I use python to read such a file?"
The answer is, this link contains a description of the format of the file. Write a dissector based on the technical specification.
If you don't want to go to all the trouble of writing a parser, you should take look at pyshp, a pure Python shapefile library. I've been using it for a couple of months now, and have found it quite easy to use.
There's also a python binding to shapelib, if you search the web. But I found the pure Python solution easier to hack around with.
might be a long shot, but you should check out ctypes, and maybe use the .dll file that came with a program (if it even exists lol) that can read that type of file. in my experience, things get weird when u start digging around .dlls

Categories