Skip to content

Commit

Permalink
Updates to cgyro scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcandy committed Dec 5, 2024
1 parent fc6e565 commit f3a247e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cgyro/bin/cgyro_json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def opts():
description="CGYRO localdump utility",
epilog=textwrap.dedent(mytext))

parser.add_argument('-dir',
parser.add_argument('-e',
help="working directory (default: cwd)",
type=str,
default='.')

args=parser.parse_args()

return args.dir
return args.e

mydir = opts()

Expand Down
47 changes: 33 additions & 14 deletions cgyro/bin/cgyrodb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ from cgyro.data import cgyrodata

pd.set_option('display.max_rows', None)

ignore = 'eslshared'

# Command line option parser
def opts():

Expand All @@ -27,20 +29,32 @@ def opts():
description="CGYRO database utility",
epilog=textwrap.dedent(mytext))

parser.add_argument('-mode',
help='Mode switch (data,update)',
type=str,
default='data')
parser.add_argument('-ref',
help='Refresh directories',
action='store_true')
parser.add_argument('-json',
help='Generate IMAS and localdump files',
action='store_true')
parser.add_argument('-db',
help='Load the DB and print',
action='store_true')
parser.add_argument('-flux',
help='Add flux to DB',
action='store_true')

args=parser.parse_args()

return args.mode
return args.ref,args.json,args.db,args.flux

mode = opts()
ref,json,db,doflux = opts()

meta = {}

def gendict(sim,mode):
if (not ref) and (not json) and (not db):
print('Type "cgyrodb -h" for help')
sys.exit()

def gendict(sim,doflux):

mydict = {}

Expand All @@ -60,7 +74,7 @@ def gendict(sim,mode):
mydict['a/Ln1'] = 0.0
mydict['a/Lt1'] = 0.0

if mode == 'flux':
if doflux:
sim.getflux()
y = np.sum(sim.ky_flux,axis=(2,3))
for ispec in range(sim.n_species):
Expand All @@ -73,25 +87,30 @@ def gendict(sim,mode):

return mydict

ignore = 'eslshared'

# First locate all directories
y = []
for root,xd,xf in os.walk('./'):
if xd == []:
if ignore not in root:
y.append(root)

if mode == 'update':
if ref:
# Run through directories and update
for mdir in y:
print('Updating '+mdir)
print('Refreshing '+mdir)
os.system('cgyro -t '+mdir)
else:

if json:
# Run through directories and update
for mdir in y:
print('Dumping '+mdir)
os.system('cgyro_json -e '+mdir)

if db:
# Create master dictionary "meta"
for mdir in tqdm(y):
sim = cgyrodata(mdir+'/',silent=True)
meta[mdir]=gendict(sim,mode)
meta[mdir]=gendict(sim,doflux)

df = pd.DataFrame(meta)
dfpart = df.T[['n_n','n_radial','n_theta','q','s','kappa','a/Ln0','a/Lt0','a/Ln1','a/Lt1','nuee']]
Expand Down
1 change: 1 addition & 0 deletions f2py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ matplotlib
fortranformat
scikit-image
build
pandas

0 comments on commit f3a247e

Please sign in to comment.