Search code examples
pythonpython-3.xsyntaxyt

SyntaxError: invalid syntax for yt module


I am trying to understand the issue that I am having, but I cannot fully get why I am getting these errors, especially since this error states what I think is a false positive. I know that it has something to do with the line: for file in glob.glob('puredef_hdf5_chk_000000')but I am unsure what it might be.

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

Solution

  • You're missing a :

    for file in glob.glob('placeholder'): # Make sure you add the ':'
        ... # And indent
    

    Also, the contents inside a for loop needs to be indented one tab

    Try this:

    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'])
        ######################################################