Skip to content

Commit 3f7300a

Browse files
authored
Merge pull request #1128 from cbegeman/do-not-require-tseries-transport-files-if-cached-output
Check for transport output before loading input files
2 parents 019fea8 + 236c5fa commit 3f7300a

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

mpas_analysis/ocean/time_series_transport.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@ def run_task(self):
235235

236236
outFileName = f'{outputDirectory}/{self.groupSuffix}_{self.startYear:04d}-{self.endYear:04d}.nc'
237237

238+
outputExists = os.path.exists(outFileName)
239+
outputValid = outputExists
240+
if outputExists:
241+
with open_mpas_dataset(fileName=outFileName,
242+
calendar=self.calendar,
243+
timeVariableNames=None,
244+
variableList=None,
245+
startDate=startDate,
246+
endDate=endDate) as dsOut:
247+
248+
for load_year in numpy.arange(self.startYear, self.endYear + 1):
249+
for load_month in numpy.arange(1, 13):
250+
mask = numpy.logical_and(
251+
dsOut.year.values == load_year,
252+
dsOut.month.values == load_month)
253+
if numpy.count_nonzero(mask) == 0:
254+
outputValid = False
255+
break
256+
257+
if outputValid:
258+
self.logger.info(' Time series exists -- Done.')
259+
return
260+
238261
inputFiles = sorted(self.historyStreams.readpath(
239262
'timeSeriesStatsMonthlyOutput', startDate=startDate,
240263
endDate=endDate, calendar=self.calendar))
@@ -259,29 +282,6 @@ def run_task(self):
259282
'Using advection velocity.')
260283
variableList.append('timeMonthly_avg_normalVelocity')
261284

262-
outputExists = os.path.exists(outFileName)
263-
outputValid = outputExists
264-
if outputExists:
265-
with open_mpas_dataset(fileName=outFileName,
266-
calendar=self.calendar,
267-
timeVariableNames=None,
268-
variableList=None,
269-
startDate=startDate,
270-
endDate=endDate) as dsOut:
271-
272-
for inIndex in range(dsOut.sizes['Time']):
273-
274-
mask = numpy.logical_and(
275-
dsOut.year[inIndex].values == years,
276-
dsOut.month[inIndex].values == months)
277-
if numpy.count_nonzero(mask) == 0:
278-
outputValid = False
279-
break
280-
281-
if outputValid:
282-
self.logger.info(' Time series exists -- Done.')
283-
return
284-
285285
transectMaskFileName = self.masksSubtask.maskFileName
286286

287287
dsTransectMask = xarray.open_dataset(transectMaskFileName)

0 commit comments

Comments
 (0)