Python Forum
how to open dx file in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to open dx file in Python
#1
Would anyone tell me how to open a dx file in Python? I got stuck here. Thanks a bunch.
Reply
#2
There are some docs/howtos/wiki you can find easily, like : https://griddataformats.readthedocs....ts/OpenDX.html
Reply
#3
Would you please send the full link again?Thanks. :)
Reply
#4
https://griddataformats.readthedocs.io/
And the link in the other post is https://griddataformats.readthedocs.io/e...penDX.html
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
That's great. Thanks a lot.
I did use "from gridData import Grid". but got error mesg saying: "No module named 'gridData'". What else should I do to import Grid? Thanks again.
Reply
#6
You need to install it first
https://github.com/MDAnalysis/GridDataFormats
From what I see it is available via pip from PyPI
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Sorry to bother you again. I got ParseError as following:
g = Grid("ray.dx")

---------------------------------------------------------------------------
DXParseError Traceback (most recent call last)
<ipython-input-2-0a1918c382cd> in <module>()
----> 1 g = Grid("ray.dx")

~/anaconda3/lib/python3.7/site-packages/gridData/core.py in __init__(self, grid, edges, origin, delta, metadata, interpolation_spline_order)
115
116 if type(grid) is str:
--> 117 self.load(grid)
118 elif not (grid is None or edges is None):
119 # set up from histogramdd-type data

~/anaconda3/lib/python3.7/site-packages/gridData/core.py in load(self, filename, file_format)
300 """
301 loader = self._get_loader(filename, file_format=file_format)
--> 302 loader(filename)
303
304 def _load_python(self, filename):

~/anaconda3/lib/python3.7/site-packages/gridData/core.py in _load_dx(self, filename)
319 """Initializes Grid from a OpenDX file."""
320 dx = OpenDX.field(0)
--> 321 dx.read(filename)
322 grid, edges = dx.histogramdd()
323 self.__init__(grid=grid, edges=edges, metadata=self.metadata)

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in read(self, file)
486 DXfield = self
487 p = DXParser(file)
--> 488 p.parse(DXfield)
489
490 def add(self,component,DXobj):

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in parse(self, DXfield)
672 self.tokens = [] # token buffer
673 with open(self.filename,'r') as self.dxfile:
--> 674 self.use_parser('general') # parse the whole file and populate self.objects
675
676 # assemble field from objects

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in use_parser(self, parsername)
930 """Set parsername as the current parser and apply it."""
931 self.__parser = self.parsers[parsername]
--> 932 self.__parser()
933 def set_parser(self,parsername):
934 """Set parsername as the current parser."""

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in __general(self)
721 raise DXParseError('Unknown level-1 construct at '+str(tok))
722
--> 723 self.apply_parser() # hand over to new parser
724 # (possibly been set further down the hierarchy!)
725

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in apply_parser(self)
936 def apply_parser(self):
937 """Apply the current parser to the token stream."""
--> 938 self.__parser()
939
940 def __tokenize(self,string):

~/anaconda3/lib/python3.7/site-packages/gridData/OpenDX.py in __array(self)
895 value = self.__consume().value()
896 else:
--> 897 raise DXParseError('array: '+str(tok)+' not recognized.')
898
899 def __field(self):

DXParseError: array: <token BARESTRING,shape> not recognized.
Reply
#8
are you sure this is OpenDX file?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
aha, openDX can be installed using "sudo apt-get install dx". so simple. I found it somewhere.
Yes, it is openDX file. I think the format is different tho. Anyway, the window pops up.
Thanks, buran. Really appreciate your help. And shivkumar123 also.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 314 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,087 Dec-14-2023, 08:03 AM
Last Post: shanoger
  How can i combine these two functions so i only open the file once? cubangt 4 852 Aug-14-2023, 05:04 PM
Last Post: snippsat
  I cannot able open a file in python ? ted 5 3,286 Feb-11-2023, 02:38 AM
Last Post: ted
  testing an open file Skaperen 7 1,357 Dec-20-2022, 02:19 AM
Last Post: Skaperen
  I get an FileNotFouerror while try to open(file,"rt"). My goal is to replace str decoded 1 1,400 May-06-2022, 01:44 PM
Last Post: Larz60+
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 6,020 Jan-07-2022, 04:55 PM
Last Post: bowlofred
  Open an excel file Newbie1114 1 2,330 Jun-16-2021, 09:11 PM
Last Post: Gribouillis
  How to open MIDI-file and get events in a list? philipbergwerf 7 4,958 May-29-2021, 08:24 AM
Last Post: j.crater
  Error on open of file created with tempfile.TemporaryDirectory() Brian177 4 6,258 Apr-05-2021, 07:12 PM
Last Post: Brian177

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020