Skip to content

Commit

Permalink
Inversion (#37)
Browse files Browse the repository at this point in the history
* new inversion plugin

* minor changes

* bugfix

---------

Co-authored-by: Fernandez Vilanova, Lucas <[email protected]>
  • Loading branch information
LucR31 and Fernandez Vilanova, Lucas authored Aug 14, 2024
1 parent cd4ec77 commit 2cd338c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
25 changes: 21 additions & 4 deletions aiida_flexpart/calculations/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,28 @@ def prepare_for_submission(self, folder):
codeinfo.code_uuid = self.inputs.code.uuid
codeinfo.stdout_name = self.metadata.options.output_filename
codeinfo.withmpi = self.inputs.metadata.options.withmpi

with folder.open('inversion_settings.yaml', 'w') as f:
_ = yaml.dump(self.inputs.inv_params.get_dict(), f)

# Prepare a `CalcInfo` to be returned to the engine

#create dict for yaml, add remotes by location
remote_dict = {}
for k,v in self.inputs.remotes.items():
if k.split("_")[0] in remote_dict.keys():
remote_dict[k.split("_")[0]].append(v.attributes["remote_path"]+'/'+k)
else:
remote_dict[k.split("_")[0]] = [v.attributes["remote_path"]+'/'+k]

params_dict = self.inputs.inv_params.get_dict()
for k,v in remote_dict.items():
params_dict['sites'][k].update({'ft.fls':v})

#replace _ by . in dict
params_dict = {
key.replace("_", "."): value for key, value in params_dict.items()
}

with folder.open('inversion_settings.yaml', 'w') as f:
_ = yaml.dump(params_dict, f)

calcinfo = common.CalcInfo()
calcinfo.codes_info = [codeinfo]
calcinfo.retrieve_list = ['aiida.out']
Expand Down
17 changes: 9 additions & 8 deletions aiida_flexpart/workflows/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ def check(nc_file, version):
return False
return True


def validate_history(nc_file):
return True if "history" in nc_file.attributes["global_attributes"].keys() else None


@calcfunction
def store(remote_dir, file):
with tempfile.TemporaryDirectory() as td:
Expand All @@ -53,10 +48,16 @@ def store(remote_dir, file):
nc_dimensions=nc_dimensions,
)

if validate_history(node) == None:
if "history" in node.attributes["global_attributes"].keys():
if check(node, "history"):
return node
elif "created" in node.attributes["global_attributes"].keys():
if check(node, "created"):
return node
else:
return
elif check(node, "history"):
return node




class InspectWorkflow(WorkChain):
Expand Down

0 comments on commit 2cd338c

Please sign in to comment.