SyntaxError: invalid syntax for yt module
SyntaxError: invalid syntax for yt module
我试图了解我遇到的问题,但我无法完全理解为什么会出现这些错误,特别是因为这个错误表明我认为是误报。我知道它与以下行有关:for file in glob.glob('puredef_hdf5_chk_000000')
但我不确定它可能是什么。
import yt
import glob
for file in glob.glob('puredef_hdf5_chk_000000')
ds=yt.load(file)
#########################################
slc= yt.ProjectionPlot(ds,'theta','density')
slc= yt.SlicePlot(0.25,p_size=15.0,col="Pink")
slc.set_cmap('density',('Blues'))
slc.annotate_particles(0.25,p_size=12.0,col='Red')
slc.save('tr')
#########################################
# This
#slc = yt.SlicePlot(ds,"theta", ["density"])
#slc.set_cmap("density","Blues")
#slc.annotate_particles(0.25, p_size=12.0, col="Red")
#slc.save('tr')
##########################################
p = yt.ProjectionPlot(ds,"theta","density",center='m',width=(10, 'Mpc'))
p.annotate_particles((10,'Mpc'))
p.save('tr')
############################################################
#p = yt.ParticlePlot(ds, 'particle_position_x', 'particle_position_y', 'particle_dens')
#or
#p = yt.ParticlePlot(ds, 'particle_position_cylindrical_radius', 'particle_position_cylindrical_theta', 'particle_dens')
# Above is for axi-symmetric
#p.set_ylim(-2.5e10,3.5e10)
#p.set_xlim(1e10,3.5e10)
#p.set_zlim('particle_dens', 1e1, 1e13) #fixed the density axis
#p.save()
######################################################
#ad = ds.all_data()
#print(ad['particle_position_y'])
######################################################
runfile('C:/Users/rocke/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/richard/new 1.py', wdir='C:/Users/rocke/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/richard')
File "C:\Users\rocke\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\richard\new 1.py", line 4
for file in glob.glob('puredef_hdf5_chk_000000')
^
SyntaxError: invalid syntax
您缺少 :
for file in glob.glob('placeholder'): # Make sure you add the ':'
... # And indent
此外,for
循环中的内容需要缩进一个制表符
试试这个:
import yt
import glob
for file in glob.glob('puredef_hdf5_chk_000000')
ds=yt.load(file)
#########################################
slc= yt.ProjectionPlot(ds,'theta','density')
slc= yt.SlicePlot(0.25,p_size=15.0,col="Pink")
slc.set_cmap('density',('Blues'))
slc.annotate_particles(0.25,p_size=12.0,col='Red')
slc.save('tr')
#########################################
# This
#slc = yt.SlicePlot(ds,"theta", ["density"])
#slc.set_cmap("density","Blues")
#slc.annotate_particles(0.25, p_size=12.0, col="Red")
#slc.save('tr')
##########################################
p = yt.ProjectionPlot(ds,"theta","density",center='m',width=(10, 'Mpc'))
p.annotate_particles((10,'Mpc'))
p.save('tr')
############################################################
#p = yt.ParticlePlot(ds, 'particle_position_x', 'particle_position_y', 'particle_dens')
#or
#p = yt.ParticlePlot(ds, 'particle_position_cylindrical_radius', 'particle_position_cylindrical_theta', 'particle_dens')
# Above is for axi-symmetric
#p.set_ylim(-2.5e10,3.5e10)
#p.set_xlim(1e10,3.5e10)
#p.set_zlim('particle_dens', 1e1, 1e13) #fixed the density axis
#p.save()
######################################################
#ad = ds.all_data()
#print(ad['particle_position_y'])
######################################################
yt : [WARNING ] 2020-07-11 16:27:32,912 Extending theta dimension to 2PI + left edge.
yt : [INFO ] 2020-07-11 16:27:32,927 Parameters: current_time = 0.0
yt : [INFO ] 2020-07-11 16:27:32,928 Parameters: domain_dimensions = [2 2 0]
yt : [INFO ] 2020-07-11 16:27:32,929 Parameters: domain_left_edge = [ 0.0000e+00 -6.5536e+09 0.0000e+00]
yt : [INFO ] 2020-07-11 16:27:32,931 Parameters: domain_right_edge = [6.55360000e+09 6.55360000e+09 6.28318531e+00]
yt : [INFO ] 2020-07-11 16:27:32,932 Parameters: cosmological_simulation = 0.0
yt : [INFO ] 2020-07-11 16:27:32,939 Allocating for 8.800e+01 particles (index particle type 'all')
yt : [INFO ] 2020-07-11 16:27:32,941 Identified 9.000e+00 octs
Traceback (most recent call last):
File "C:\Users\rocke\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\richard\new 1.py", line 8, in <module>
slc= yt.ProjectionPlot(ds,'theta','density')
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\visualization\plot_window.py", line 1464, in __init__
validate_mesh_fields(test_data_source, fields)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\visualization\plot_window.py", line 132, in validate_mesh_fields
canonical_fields = data_source._determine_fields(fields)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\data_objects\data_containers.py", line 1165, in _determine_fields
finfo = self.ds._get_field_info("unknown", fname)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\data_objects\static_output.py", line 798, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
YTFieldNotFound: Could not find field '('all', 'density')' in puredef_hdf5_chk_000000.
按照您的方式我似乎遇到了新的错误,但它现在正在读取我的数据文件。我以前没有见过这个错误,因为它是 yt 模块独有的。
我试图了解我遇到的问题,但我无法完全理解为什么会出现这些错误,特别是因为这个错误表明我认为是误报。我知道它与以下行有关:for file in glob.glob('puredef_hdf5_chk_000000')
但我不确定它可能是什么。
import yt
import glob
for file in glob.glob('puredef_hdf5_chk_000000')
ds=yt.load(file)
#########################################
slc= yt.ProjectionPlot(ds,'theta','density')
slc= yt.SlicePlot(0.25,p_size=15.0,col="Pink")
slc.set_cmap('density',('Blues'))
slc.annotate_particles(0.25,p_size=12.0,col='Red')
slc.save('tr')
#########################################
# This
#slc = yt.SlicePlot(ds,"theta", ["density"])
#slc.set_cmap("density","Blues")
#slc.annotate_particles(0.25, p_size=12.0, col="Red")
#slc.save('tr')
##########################################
p = yt.ProjectionPlot(ds,"theta","density",center='m',width=(10, 'Mpc'))
p.annotate_particles((10,'Mpc'))
p.save('tr')
############################################################
#p = yt.ParticlePlot(ds, 'particle_position_x', 'particle_position_y', 'particle_dens')
#or
#p = yt.ParticlePlot(ds, 'particle_position_cylindrical_radius', 'particle_position_cylindrical_theta', 'particle_dens')
# Above is for axi-symmetric
#p.set_ylim(-2.5e10,3.5e10)
#p.set_xlim(1e10,3.5e10)
#p.set_zlim('particle_dens', 1e1, 1e13) #fixed the density axis
#p.save()
######################################################
#ad = ds.all_data()
#print(ad['particle_position_y'])
######################################################
runfile('C:/Users/rocke/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/richard/new 1.py', wdir='C:/Users/rocke/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/richard')
File "C:\Users\rocke\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\richard\new 1.py", line 4
for file in glob.glob('puredef_hdf5_chk_000000')
^
SyntaxError: invalid syntax
您缺少 :
for file in glob.glob('placeholder'): # Make sure you add the ':'
... # And indent
此外,for
循环中的内容需要缩进一个制表符
试试这个:
import yt
import glob
for file in glob.glob('puredef_hdf5_chk_000000')
ds=yt.load(file)
#########################################
slc= yt.ProjectionPlot(ds,'theta','density')
slc= yt.SlicePlot(0.25,p_size=15.0,col="Pink")
slc.set_cmap('density',('Blues'))
slc.annotate_particles(0.25,p_size=12.0,col='Red')
slc.save('tr')
#########################################
# This
#slc = yt.SlicePlot(ds,"theta", ["density"])
#slc.set_cmap("density","Blues")
#slc.annotate_particles(0.25, p_size=12.0, col="Red")
#slc.save('tr')
##########################################
p = yt.ProjectionPlot(ds,"theta","density",center='m',width=(10, 'Mpc'))
p.annotate_particles((10,'Mpc'))
p.save('tr')
############################################################
#p = yt.ParticlePlot(ds, 'particle_position_x', 'particle_position_y', 'particle_dens')
#or
#p = yt.ParticlePlot(ds, 'particle_position_cylindrical_radius', 'particle_position_cylindrical_theta', 'particle_dens')
# Above is for axi-symmetric
#p.set_ylim(-2.5e10,3.5e10)
#p.set_xlim(1e10,3.5e10)
#p.set_zlim('particle_dens', 1e1, 1e13) #fixed the density axis
#p.save()
######################################################
#ad = ds.all_data()
#print(ad['particle_position_y'])
######################################################
yt : [WARNING ] 2020-07-11 16:27:32,912 Extending theta dimension to 2PI + left edge.
yt : [INFO ] 2020-07-11 16:27:32,927 Parameters: current_time = 0.0
yt : [INFO ] 2020-07-11 16:27:32,928 Parameters: domain_dimensions = [2 2 0]
yt : [INFO ] 2020-07-11 16:27:32,929 Parameters: domain_left_edge = [ 0.0000e+00 -6.5536e+09 0.0000e+00]
yt : [INFO ] 2020-07-11 16:27:32,931 Parameters: domain_right_edge = [6.55360000e+09 6.55360000e+09 6.28318531e+00]
yt : [INFO ] 2020-07-11 16:27:32,932 Parameters: cosmological_simulation = 0.0
yt : [INFO ] 2020-07-11 16:27:32,939 Allocating for 8.800e+01 particles (index particle type 'all')
yt : [INFO ] 2020-07-11 16:27:32,941 Identified 9.000e+00 octs
Traceback (most recent call last):
File "C:\Users\rocke\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\richard\new 1.py", line 8, in <module>
slc= yt.ProjectionPlot(ds,'theta','density')
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\visualization\plot_window.py", line 1464, in __init__
validate_mesh_fields(test_data_source, fields)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\visualization\plot_window.py", line 132, in validate_mesh_fields
canonical_fields = data_source._determine_fields(fields)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\data_objects\data_containers.py", line 1165, in _determine_fields
finfo = self.ds._get_field_info("unknown", fname)
File "C:\Users\rocke\anaconda3\lib\site-packages\yt\data_objects\static_output.py", line 798, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
YTFieldNotFound: Could not find field '('all', 'density')' in puredef_hdf5_chk_000000.
按照您的方式我似乎遇到了新的错误,但它现在正在读取我的数据文件。我以前没有见过这个错误,因为它是 yt 模块独有的。