Can someone help me with the Python code to read the .mat file generated from Visual SFM? You can download the .mat file from the link:
https://github.com/cvlab-epfl/tf-lift/tree/master/example
You can get a .mat file in the zip in the link and the file is what I am asking for help.
It seems to be an ASCII file. I do not know how to read the data in the file.
I tried to load the data in the .mat file with scipy.io.loadmat() but an error occurred as:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
raise ValueError('Unknown mat file type, version %s, %s' % ret)
ValueError: Unknown mat file type, version 20, 0
Can someone help me to load the data in the file with Python code?
Thanks for your help and replies sincerely.
If you mean this VisualSFM (http://ccwu.me/vsfm/doc.html), then the .mat file isn't a MATLAB .mat file, but a 'match' file.
From the website:
[name].sift stores all the detected SIFT features, and [name].mat stores the feature matches.
It seems there is C++ code for reading this file (http://ccwu.me/vsfm/MatchFile.zip) which you could use to write a python parser.
Additionally, it seems like there is a python socket interface to VSFM, which may allow you to do what you want https://github.com/nrhine1/vsfm_util
Related
I am trying to read some Canadian census data from Statistics Canada
(the XML option for the "Canada, provinces and territories" geograpic level). I see that the xml file is in the SDMX format and that there is a structure file provided, but I cannot figure out how to read the data from the xml file.
It seems there are 2 options in Python, pandasdmx and sdmx1, both of which say they can read local files. When I try
import sdmx
datafile = '~/Documents/Python/Generic_98-401-X2016059.xml'
canada = sdmx.read_sdmx(datafile)
It appears to read the first 903 lines and then produces the following:
Traceback (most recent call last):
File "/home/username/.local/lib/python3.10/site-packages/sdmx/reader/xml.py", line 238, in read_message
raise NotImplementedError(element.tag, event) from None
NotImplementedError: ('{http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message}GenericData', 'start')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/username/.local/lib/python3.10/site-packages/sdmx/reader/__init__.py", line 126, in read_sdmx
return reader().read_message(obj, **kwargs)
File "/home/username/.local/lib/python3.10/site-packages/sdmx/reader/xml.py", line 259, in read_message
raise XMLParseError from exc
sdmx.exceptions.XMLParseError: NotImplementedError: ('{http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message}GenericData', 'start')
Is this happening because I've not loaded the structure of the sdmx file (Structure_98-401-X2016059.xml in the zip file from the StatsCan link above)? If so, how do I go about loading that and telling sdmx to use that when reading datafile?
The documentation for sdmx and pandasdmx only show examples of loading files from online providers and not from local files, so I'm stuck. I have limited familiarity with python so any help is much appreciated.
For reference, I can read the file in R using the instructions from the rsdmx github. I would like to be able to do the same/similar in Python.
Thanks in advance.
From a cursory inspection of the documentation, it seems that Statistics Canada is not one of the sources that is included by default. There is however an sdmx.add_source function. I suggest you try that (before loading the data).
As per the sdmx1 developer, StatsCan is using the older, unsupported version of the SDMX (v. 2.0). The current version is 2.1 and rsdmx1 only supports this (support is also going towards the upcoming v.3).
I'm trying to programmatically access information in google sheet files on Google Colab, but because I'm working in a shared drive, the usual method of just giving the sheet name doesn't work (it only looks in my personal drive; this is a known bug.)
From the command line on one computer (Mac 10.13.6 High Sierra, Python 3.8.5), if I type
more exp4.gsheet
I see what looks like a python dictionary which includes the full url and doc_id for the sheet. I want to extract that dictionary so I can open the gsheet using its doc_id. I can also open the file using
f = open("exp4.gsheet","r")
f.readline()
And I get that same string.
However, when I switch into a Colab notebook, or onto my work computer (Mac 10.15.7 Catalina, Python 3.8.8), I get "exp4.gsheet: Operation not supported" on the command line and the following error from python.
>>> f = open("exp4.gsheet",)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 45] Operation not supported: 'exp4.gsheet'
Does anybody know a workaround for this, or some other way to load a gsheet if I just give it a file path within drive? Thanks
I am trying to stitch several hyperspectral tiles together using gdal. The raw files are in ENVI .bin/.hdr format.
I have used gdal to build a virtual raster for each scene, and then used gdal_merge to create the new combined file. I am using the OSGeo4W shell.
gdalbuildvrt -srcnodata 0 -input_file_list list.txt tiles.vrt
gdal_merge -o tile_mosaic.bin tiles.vrt
I have successfully output the files in .tif and .bil format, but I then need to convert the files, which takes a long time due to the file sizes (>200 GB per scene). I need to have it in .bin or .lan format to use with spectral python (SPy). When I try to merge to these formats, I get traceback messages stating:
File "C:\OSGEO4~1\bin\gdal_merge.py", line 611, in <module>
sys.exit(main())
File "C:\OSGEO4~1\bin\gdal_merge.py", line 478, in main
frmt = GetOutputDriverFor(out_file)
File "C:\OSGEO4~1\bin\gdal_merge.py", line 90, in GetOutputDriverFor
raise Exception("Cannot guess driver for %s" % filename)
Exception: Cannot guess driver for tile_mosaic.lan
I'm fairly new to python and coding in general. Any help would be greatly appreciated!
Try setting the output file format explicitly using the of tag. For example:
gdal_merge -of LAN -o tile_mosaic.lan tiles.vrt
For reference on the LAN raster driver in GDAL: https://gdal.org/drivers/raster/lan.html
New to scipy but not to python. Trying to import a .sav file to scipy so I can do some basic work on it. But, each time I try to import the file using scipy.io.readsav(), python throws an error:
Traceback (most recent call last):
File "<ipython-input-7-743be643d8a1>", line 1, in <module>
dataset = io.readsav("c:/users/me/desktop/survey.sav")
File "C:\Users\me\Anaconda3\lib\site-packages\scipy\io\idl.py", line 726, in readsav
raise Exception("Invalid SIGNATURE: %s" % signature)
Exception: Invalid SIGNATURE: b'$F'
Any idea what's happening? I can open the file in R and manipulate the data, but I'd like to do it in Python. Running Anaconda on Windows.
scipy.io.readsav() reads IDL SAVE files. You have tagged this question spss, so I assume you are trying to read an SPSS file. The format of an SPSS .sav file is not the same as the format of an IDL SAVE file.
Look on pypi for savReaderWriter for Python code to read and write sav files.
I am trying to call python code from excel using
wb = xw.Book.caller()
If file path is in English, it works. However, if the path has other language, it raise below Error popup
---------------------------
Error
---------------------------
C:\Anaconda2\lib\site-packages\xlwings\main.py:2692: UnicodeWarning: Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
throw = (os.path.normpath(os.path.realpath(impl.fullname.lower())) != os.path.normpath(fullname.lower()))
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "test.py", line 13, in plot_chart
wb = xw.Book.caller()
File "C:\Anaconda2\lib\site-packages\xlwings\main.py", line 545, in caller
return cls(impl=app.books.open(fullname).impl)
File "C:\Anaconda2\lib\site-packages\xlwings\main.py", line 2695, in open
"Cannot open two workbooks named '%s', even if they are saved in different locations." % name
ValueError: Cannot open two workbooks named 'test.xlsm', even if they are saved in different locations.
Guess this has something to do with unicode problem. I did not have this kind of problem with previous version. (e.g. 0.6 or 0.7) This is new problem after I updated to version 0.9.2.
Thank you for any help
p.s. I am using Python 2.7
xlwings version 0.9.3 solve above problem. Self closing the question.