Skip to content

Commit

Permalink
inversion workflow dates change
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernandez Vilanova, Lucas committed Sep 26, 2024
1 parent b9416b4 commit 0b2142e
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions aiida_flexpart/workflows/inversion_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@
from datetime import datetime
from dateutil.relativedelta import relativedelta

def make_date_range(start:datetime, end:datetime, months:int, offset:int)->dict:
def make_date_range(start:datetime,
end:datetime,
chunk:str,
chunk_w:str)->dict:

step = 1*(chunk=='month')+12*(chunk=='year')
dates = {}
x = start - relativedelta(months=offset)
end += relativedelta(months=offset)
while x < end:
dates[datetime.strftime(x,'%Y-%m-%d')] = datetime.strftime(x+relativedelta(months=months),'%Y-%m-%d')
x += relativedelta(months=months)
while start < end:
dates[datetime.strftime(start-relativedelta(months=step*(chunk!=chunk_w)),'%Y-%m-%d')
] = datetime.strftime(start+relativedelta(months=step+step*(chunk!=chunk_w)),'%Y-%m-%d')
start += relativedelta(months=step)
return dates

def split_chunk(start,end,chunk):

if chunk =='year':
return make_date_range(start, end, 12,0)
elif chunk == '3year':
return make_date_range(start, end, 12,12)
elif chunk == 'month':
return make_date_range(start, end, 1,0)
else:
return make_date_range(start, end, 3,1)


InversionCalculation = plugins.CalculationFactory("inversion.calc")
NetCDF = plugins.DataFactory('netcdf.data')

Expand Down Expand Up @@ -83,7 +75,7 @@ def run_inv(self):

start = datetime.strptime(self.inputs.date_range.value[:10], '%Y-%m-%d')
end = datetime.strptime(self.inputs.date_range.value[12:], '%Y-%m-%d')
dates = split_chunk(start, end, self.inputs.chunk_w)
dates = make_date_range(start, end, self.inputs.chunk, self.inputs.chunk_w)

for s,e in dates.items():
self.ctx.inv_params_dict.update({'dtm_start':s,
Expand Down

0 comments on commit 0b2142e

Please sign in to comment.