Skip to content

Commit d69e6f6

Browse files
Dana SinghDana Singh
authored andcommitted
#60 Fix variable names and clean up
1 parent 4097401 commit d69e6f6

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

app/remap-pp-components/bin/remap-pp-components

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -214,44 +214,49 @@ def search_files(product,var,source,freq,current_chunk,begin):
214214

215215
return files
216216

217-
######### REWRITE
218217
def get_variables(comp_info, product):
219-
if product == "static" :
218+
"""
219+
Retrieve variables listed for a component
220+
Params:
221+
comp_info: information about requested component
222+
product: temporal, ts, or av
223+
"""
224+
if product == "static":
220225
if comp_info.get("static") is not None:
221-
for ah in comp_info.get("static"): #source, variables OR offline_diagnostics, variables
222-
if ah.get("variables") is not None:
223-
v = ah.get("variables")
226+
for static_info in comp_info.get("static"):
227+
if static_info.get("variables") is not None:
228+
v = static_info.get("variables")
224229
else:
225230
v = "all"
226231
else:
227232
raise ValueError(f"Product is set to static but no static sources/variables defined for {comp_info.get('type')}")
228233
else:
229-
for ah in comp_info.get("sources"): #history_file,variables
230-
if ah.get("variables"):
231-
v = ah.get("variables")
234+
for src_info in comp_info.get("sources"): #history_file,variables
235+
if src_info.get("variables"):
236+
v = src_info.get("variables")
232237
else:
233238
v = "all"
234239

235240
return v
236241

237242
def get_sources(comp_info, product):
243+
"""
244+
Retrieve source name for a component
245+
Params:
246+
comp_info: information about requested component
247+
product: temporal, ts, or av
248+
"""
238249
sources = []
239250
if "static" in product:
240-
for ah in comp_info.get("static"):
241-
sources.append(ah.get("source"))
251+
for static_info in comp_info.get("static"):
252+
sources.append(static_info.get("source"))
242253
else:
243-
for ah in comp_info.get("sources"):
244-
sources.append(ah.get("history_file"))
254+
for src_info in comp_info.get("sources"):
255+
sources.append(src_info.get("history_file"))
245256

246257
return sources
247258

248259
def get_freq(comp_info, product):
249-
# if "static" in product:
250-
# for ah in comp_info.get("static"):
251-
# if "freq" not in ah.keys():
252-
# freq = glob.glob("*")
253-
# else:
254-
# for k in comp_info.keys():
255260
if "freq" not in comp_info.keys():
256261
freq = glob.glob("*")
257262
else:
@@ -310,19 +315,12 @@ def remap():
310315
print(" ens_mem: None")
311316
copy_tool = os.getenv('COPY_TOOL')
312317

313-
# # Read rose config files (for now)
314-
# config_dir = os.getcwd()
315-
# print(f"rose configuration directory: {config_dir}")
316-
# config = mrc.load(f"{config_dir}/rose-app-run.conf")
317-
318-
##
319318
# Path to yaml configuration
320319
exp_dir = Path(__file__).resolve().parents[3]
321320
path_to_yamlconfig = os.path.join(exp_dir, yaml_config)
322321
# Load and read yaml configuration
323322
with open(path_to_yamlconfig,'r') as yml:
324323
yml_info = yaml.safe_load(yml)
325-
##
326324

327325
# Verify the input and output directories
328326
verify_dirs(input_dir, output_dir)
@@ -335,8 +333,8 @@ def remap():
335333
comps = components.split()
336334
for comp in comps:
337335
comp = comp.strip('""')
338-
##
339-
#make sure component or source is in yaml file?
336+
337+
# Make sure component/source is in the yaml configuration file
340338
for comp_info in yml_info["postprocess"]["components"]:
341339
components = comp_info.get("type")
342340

@@ -348,17 +346,17 @@ def remap():
348346
logger.warning('f"WARNING: component {comp} does not exist in yaml config')
349347
continue
350348

351-
#if static but no static defined, skip...or raise error?
349+
#if static but no static defined, skip
352350
if product == "static":
353351
if comp_info.get("static") is None:
354-
continue
352+
logger.warning('Static component requested but not defined')
353+
continue
355354

356-
### VARIABLE INFORMATION
357-
#variables defined in yaml
355+
## VARIABLE INFORMATION
358356
# Save variables if defined
359357
v = get_variables(comp_info, product)
360358

361-
### GRID INOFRMATION
359+
## Loop through grid
362360
# Set grid type if component has xyInterp defined or not
363361
grid = []
364362
if "xyInterp" not in comp_info.keys():
@@ -376,9 +374,8 @@ def remap():
376374
else:
377375
os.chdir(f"{input_dir}/{g}")
378376

379-
##sources
377+
## Loop through sources
380378
sources = get_sources(comp_info, product)
381-
print(sources)
382379
for s in sources:
383380
if ens_mem is not None:
384381
source_dir = os.path.join(input_dir, g, ens_mem, s)
@@ -389,7 +386,7 @@ def remap():
389386
continue
390387
os.chdir(source_dir)
391388

392-
###FREQ STUFF
389+
## Loop through freq
393390
freq = get_freq(comp_info, product) ###might have to be a list
394391

395392
for f in freq:
@@ -398,7 +395,7 @@ def remap():
398395
else:
399396
os.chdir(f"{input_dir}/{g}/{s}/{f}")
400397

401-
##chunk stuff
398+
## Loop through chunk
402399
chunk = get_chunk(comp_info, product) ## might have to be a list ...
403400
for c in chunk:
404401
if c != current_chunk:
@@ -407,7 +404,6 @@ def remap():
407404
os.chdir(f"{input_dir}/{g}/{ens_mem}/{s}/{f}/{c}")
408405
else:
409406
os.chdir(f"{input_dir}/{g}/{s}/{f}/{c}")
410-
##directory stuff???
411407

412408
# Create directory
413409
# ts output is written to final location, av is not.

0 commit comments

Comments
 (0)