Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernandez Vilanova, Lucas committed May 6, 2024
1 parent 21e3ea0 commit da02e46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
9 changes: 1 addition & 8 deletions aiida_flexpart/parsers/collect_sens.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,13 @@ def parse(self, **kwargs):
self.logger.error("Found files '{}', expected to find '{}'".format(
files_retrieved, files_expected))
return self.exit_codes.ERROR_MISSING_OUTPUT_FILES

nc_file_names = [i for i in files_retrieved if '.nc' in i]
with tempfile.TemporaryDirectory() as td:
self.retrieved.copy_tree(Path(td))
for i in nc_file_names:
output_nc = NetCDF(Path(td)/i)
self.out(i,output_nc)

# add output file
self.logger.info(f"Parsing '{output_filename}'")
with self.retrieved.open(output_filename, 'r') as handle:
content = handle.read()
output_node = SinglefileData(file=handle)
if 'CONGRATULATIONS' not in content:
if 'Writing' not in content:
self.out('output_file', output_node)
return ExitCode(1)

Expand Down
9 changes: 1 addition & 8 deletions aiida_flexpart/parsers/flexpart_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ def parse(self, **kwargs):
self.logger.error(
f"Found files '{files_retrieved}', expected to find '{files_expected}'"
)
return self.exit_codes.ERROR_MISSING_OUTPUT_FILES

nc_file_names = [i for i in files_retrieved if '.nc' in i]
with tempfile.TemporaryDirectory() as td:
self.retrieved.copy_tree(Path(td))
for i in nc_file_names:
output_nc = NetCDF(Path(td)/i)
self.out(i,output_nc)
return self.exit_codes.ERROR_MISSING_OUTPUT_FILES

# add output file
self.logger.info(f"Parsing '{output_filename}'")
Expand Down
27 changes: 13 additions & 14 deletions aiida_flexpart/workflows/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
NetCDF = DataFactory("netcdf.data")

def check(nc_file):
"""
Checks if there is a netcdf file stored with the same name,
if so, it checks the created date, if that is a match then returns
False.
"""
qb = orm.QueryBuilder()
qb.append(
NetCDF,
Expand Down Expand Up @@ -35,26 +40,20 @@ class InspectWorkflow(WorkChain):
@classmethod
def define(cls, spec):
super().define(spec)
spec.input('remotes',valid_type=orm.RemoteData,required=False)
spec.input_namespace('remotes_cs', valid_type=orm.RemoteStashFolderData, required=False)
spec.input_namespace('remotes',valid_type=orm.RemoteData,required=False)
spec.outputs.dynamic = True
spec.outline(
cls.inspect,
cls.save_file,
cls.results,
)

def inspect(self):
self.ctx.list_files = []
if 'remotes' in self.inputs:
for i in self.inputs.remotes.listdir()[:10]:
if '.nc' in i:
self.ctx.list_files.append(i)

def save_file(self):
for i in self.ctx.list_files:
self.report(f'processing {i}')
store(i,self.inputs.remotes)

self.ctx.list_files = []
for v in self.inputs.remotes.values():
for i in v.listdir():
if '.nc' in i:
self.ctx.list_files.append(i)
store(i,v)

def results(self):
self.out('result', self.ctx.list_files)

0 comments on commit da02e46

Please sign in to comment.