Skip to content

Commit

Permalink
new inversion plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernandez Vilanova, Lucas committed Jul 31, 2024
1 parent e2a1c17 commit 1fe2518
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
75 changes: 75 additions & 0 deletions aiida_flexpart/calculations/inversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
from aiida import orm, common, engine
from aiida.plugins import DataFactory
import yaml

NetCDF = DataFactory('netcdf.data')


class Inversion(engine.CalcJob):
@classmethod
def define(cls, spec):
"""Define inputs and outputs of the calculation."""
# yapf: disable
super().define(spec)

#INPUTS metadata
spec.inputs['metadata']['options']['resources'].default = {
'num_machines': 1,
'num_mpiprocs_per_machine': 1,
}
spec.input('metadata.options.custom_scheduler_commands', valid_type=str, default='')
spec.input('metadata.options.withmpi', valid_type=bool, default=False)
spec.input('metadata.options.output_filename', valid_type=str, default='aiida.out', required=True)
#spec.input('metadata.options.parser_name', valid_type=str, default='collect.sens')

#Inputs
spec.input_namespace('remotes', valid_type = NetCDF, required=True)
spec.input_namespace('observations', valid_type = NetCDF, required=True)

spec.input('inv_params',valid_type = orm.Dict, required = True,
help = 'File containing inversion settings, either as R source file or yaml')
spec.input('start_date',valid_type = orm.Str, required = True,
help = 'Start date (yyyy-mm-dd)')
spec.input('end_date',valid_type = orm.Str, required = True,
help = 'End date (yyyy-mm-dd)')
spec.input('chunk',valid_type = orm.Str, required = True,
help = "Options are 'year' and 'month'. Default is 'year'")
spec.input('chunk_w',valid_type = orm.Str, required = True,
help = """Width of the individual inversion chunk. These can be wider than
the chunking itself to allow for running average fluxes.,
Possible values are 'year' and '3year' for 'chunk.by=year' and,
'month' and '3month' for 'chunk.by=month'. Default is 'year'
""")

#exit codes
spec.outputs.dynamic = True

def prepare_for_submission(self, folder):

codeinfo = common.CodeInfo()
codeinfo.cmdline_params = [
'-f',
'inversion_settings.yaml',
'-s',
self.inputs.start_date.value,
'-e',
self.inputs.end_date.value,
'-c',
self.inputs.chunk.value,
'-w',
self.inputs.chunk_w.value,
]
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
calcinfo = common.CalcInfo()
calcinfo.codes_info = [codeinfo]
calcinfo.retrieve_list = ['aiida.out']

return calcinfo
15 changes: 9 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "aiida_flexpart"

[project]
name = "aiida-flexpart"
version = "0.1.3"
version = "0.1.4"
readme = "README.md"
license = {file = 'LICENSE'}
description = "AiiDA plugin for the FLEXPART code (simulation of atmospheric transport processes)."
Expand All @@ -21,13 +21,14 @@ classifiers = [
"Programming Language :: Python :: 3",

]
requires-python = ">=3.9"
requires-python = ">=3.8"
dependencies = [
"aiida-core>=1.6.5,<3.0.0",
"six",
"psycopg2-binary<2.9",
"voluptuous",
"jinja2",
"netCDF4"
]

[[project.authors]]
Expand All @@ -51,25 +52,27 @@ docs = [
"sphinx-rtd-theme",
]

[project.entry-points."aiida.data"]
"netcdf.data" = "aiida_flexpart.data.nc_data:NetCdfData"

[project.entry-points."aiida.calculations"]
"flexpart.cosmo" = "aiida_flexpart.calculations.flexpart_cosmo:FlexpartCosmoCalculation"
"flexpart.ifs" = "aiida_flexpart.calculations.flexpart_ifs:FlexpartIfsCalculation"
"flexpart.post" = "aiida_flexpart.calculations.flexpart_post:PostProcessingCalculation"
"collect.sensitivities" = "aiida_flexpart.calculations.collect_sens:CollectSensitivitiesCalculation"
"collect.sensitivities" = "aiida_flexpart.calculations.collect_sens:CollectSensCalculation"
"inversion.calc" = "aiida_flexpart.calculations.inversion:Inversion"

[project.entry-points."aiida.parsers"]
"flexpart.cosmo" = "aiida_flexpart.parsers.flexpart_cosmo:FlexpartCosmoParser"
"flexpart.ifs" = "aiida_flexpart.parsers.flexpart_ifs:FlexpartIfsParser"
"flexpart.post" = "aiida_flexpart.parsers.flexpart_post:FlexpartPostParser"
"collect.sens" = "aiida_flexpart.parsers.collect_sens:CollectSensParser"

[project.entry-points."aiida.workflows"]
"flexpart.multi_dates" = "aiida_flexpart.workflows.multi_dates_workflow:FlexpartMultipleDatesWorkflow"
"flexpart.multi_workflow" = "aiida_flexpart.workflows.parent_workflow:ParentWorkflow"
"inspect.workflow" = "aiida_flexpart.workflows.inspect:InspectWorkflow"

[project.entry-points."aiida.data"]
"netcdf.data" = "aiida_flexpart.data.nc_data:NetCdfData"


[tool.pylint.format]
max-line-length = 125
Expand Down

0 comments on commit 1fe2518

Please sign in to comment.