Extract data from*.vtu file - python

I am trying to extract some data arrays from a *.vtu file
import numpy
import vtk.vtk
from vtk import vtkUnstructuredGridReader
from vtk.util import numpy_support as VN
reader = vtkUnstructuredGridReader()
reader.SetFileName("heterogeneousbox-00041.vtu")
reader.ReadAllVectorsOn()
reader.ReadAllScalarsOn()
reader.Update()
data = reader.GetOutput()
GasSaturation = data.GetPointData().GetScalars("Sn")
print(type(GasSaturation))
but I get this error: ModuleNotFoundError: No module named 'vtk'
PS: I am using pycharm and python3.8 as interpreter!
Thanks in advance

Related

ModuleNotFoundError: No module named 'xlxswriter'

Language: Python 3.8.3
I faced this error when I was importing my xlxs file ModuleNotFoundError: No module named 'xlxswriter'
import xlxswriter
import pandas as pd
from pandas import DataFrame
path = ('mypath.xlxs')
xl = pd.ExcelFile(path)
print(xl.sheet_names)
How can I fix this?
Instead of typing xlsx, type xlsx like this:
import xlsxwriter
import pandas as pd
from pandas import DataFrame
path = ('mypath.xlsx')
xl = pd.ExcelFile(path)
print(xl.sheet_names)
It'll work.
The module name is xlsxwriter not xlxswriter, so replace that line with:
import xlsxwriter

Why cant my reader import the basereader from the file?

i am trying to run a file "reader_microphone.py" with some of its line below
import pyaudio
import numpy
import wave
from reader import basereader
class MicrophoneReader(BaseReader):
default_chunksize = 8192
default_format = pyaudio.paInt16
default_channels = 2
default_rate = 44100
default_seconds = 0
i am getting this error-
from reader import basereader
ImportError: cannot import name 'basereader' from 'reader' (C:\ProgramData\Anaconda3\lib\reader.py)
and welcome to StackOverflow.
There is no basereader reference in the reader package. You can take a look at the package's documentation here, to try and see what's the object you are looking for.

Error opening '*.wav': File contains data in an unknown format

I'm trying to run the following code:
import os
import librosa
import IPython.display as ipd
import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile
import warnings
warnings.filterwarnings("ignore")
train_audio_path = 'train/audio/'
samples, sample_rate = librosa.load(train_audio_path+'yes/0a7c2a8d_nohash_0.wav', sr = 16000)
But get two errors:
Error opening 'train/audio/yes/0a7c2a8d_nohash_0.wav': File contains data in an unknown format
and
NoBackendError:
I've tried downloading ffmpeg and gstreamer to fix the second error but no luck. I'm not sure what to do about the first error as I have imported libraries that should be able to handle .wav files.
Thank you for your help in advance.

Unable to read a text file into jupyter notebook on mac

I downloaded this dataset and stored it in a folder called AutomobileDataset.
I cross checked the working directory using:
import pandas as pd
import numpy as np
import os
os.chdir("/Users/madan/Desktop/ML/Datasets/AutomobileDataset")
os.getcwd()
Output:
'/Users/madan/Desktop/ML/Datasets/AutomobileDataset'
Then I tried reading the file using pandas:
import pandas as pd
import numpy as np
import os
os.chdir("/Users/madan/Desktop/ML/Datasets/AutomobileDataset")
os.getcwd()
automobile_data = pd.read_csv("AutomobileDataset.txt", sep = ',',
header = None, na_values = '?')
automobile_data.head()
Output:
---------------------------------------------------------------------------
ParserError: Error tokenizing data. C error: Expected 1 fields in line 2, saw 26
Someone please help me with this, I don't know where I am making a mistake.
Can try this!
import os
# Read in a plain text file
with open(os.path.join("c:user/xxx/xx", "xxx.txt"), "r") as f:
text = f.read()
print(text)

Can not save file using the below python code. Error: numpy.ndarray object has no attribute 'save'

import os
import sys
import numpy as np
import scipy
import pylab
import pymorph
import mahotas
import matplotlib.pyplot as plt
import Image
from scipy import ndimage
from pymorph import regmax
from PIL import Image
path='all_images'
for file in os.listdir(path):
current = os.path.join(path, file)
extension = os.path.splitext(current)[-1]
fileType = extension.upper()
print(current)
if os.path.isfile(current):
img = mahotas.imread(current)
imgf = ndimage.gaussian_filter(img, 8)
pylab.gray()
imgf.save('dnaa.gif')
Can not save file using the below python code. Error: numpy.ndarray object has no attribute 'save'. Can anyone help how to save file using pylab. I guss the last line of the code has some issue.
Use mahotas.imsave('dnaa.gif', imgf) instead. The NumPy array you get from gaussian_filter doesn't have save functionality built in.

Categories