@@ -1007,15 +1007,16 @@ def _compute_moc_time_series_analysismember(self):
10071007 self .historyStreams ,
10081008 'timeSeriesStatsMonthlyOutput' )
10091009
1010- mocRegion = np .zeros (len (inputFiles ))
1010+ ntimes = int (12 * (self .endYear - self .startYear + 1 ))
1011+ mocRegion = np .zeros (ntimes )
10111012 moc = None
10121013 refTopDepth = None
1013- times = np .zeros (len ( inputFiles ) )
1014- computed = np .zeros (len ( inputFiles ) , bool )
1014+ times = np .zeros (ntimes )
1015+ computed = np .zeros (ntimes , bool )
10151016
10161017 continueOutput = os .path .exists (outputFileName )
10171018 if continueOutput :
1018- self .logger .info (' Read in previously computed MOC time series' )
1019+ self .logger .info (f ' Read in previously computed MOC time series { outputFileName } ' )
10191020 with open_mpas_dataset (fileName = outputFileName ,
10201021 calendar = self .calendar ,
10211022 timeVariableNames = None ,
@@ -1028,32 +1029,30 @@ def _compute_moc_time_series_analysismember(self):
10281029
10291030 if moc is None :
10301031 sizes = dsMOCIn .sizes
1031- moc = np .zeros ((len ( inputFiles ) , sizes ['depth' ],
1032- sizes ['lat' ]))
1032+ moc = np .zeros ((ntimes , sizes ['depth' ],
1033+ sizes ['lat' ]))
10331034 refTopDepth = dsMOCIn .depth .values
10341035
10351036 # first, copy all computed data
1036- for inIndex in range (dsMOCIn .sizes ['Time' ]):
1037-
1038- mask = np .logical_and (
1039- dsMOCIn .year [inIndex ].values == years ,
1040- dsMOCIn .month [inIndex ].values == months )
1041-
1042- outIndex = np .where (mask )[0 ][0 ]
1043-
1044- mocRegion [outIndex ] = dsMOCIn .mocAtlantic26 [inIndex ]
1045- moc [outIndex , :, :] = dsMOCIn .mocAtlantic [inIndex , :, :]
1046- times [outIndex ] = dsMOCIn .Time [inIndex ]
1047- computed [outIndex ] = True
1037+ outIndex = 0
1038+ for load_year in np .arange (self .startYear , self .endYear + 1 ):
1039+ for load_month in np .arange (1 , 13 ):
1040+ mask = np .logical_and (dsMOCIn .year .values == load_year ,
1041+ dsMOCIn .month .values == load_month )
1042+ if np .sum (mask ) >= 1 :
1043+ inIndex = np .where (mask )[0 ][0 ]
1044+ mocRegion [outIndex ] = dsMOCIn .mocAtlantic26 [inIndex ]
1045+ moc [outIndex , :, :] = dsMOCIn .mocAtlantic [inIndex , :, :]
1046+ times [outIndex ] = dsMOCIn .Time [inIndex ]
1047+ computed [outIndex ] = True
1048+
1049+ outIndex += 1
10481050
10491051 if np .all (computed ):
10501052 # no need to waste time writing out the data set again
10511053 return dsMOCIn
10521054
10531055 for timeIndex , fileName in enumerate (inputFiles ):
1054- if computed [timeIndex ]:
1055- continue
1056-
10571056 dsLocal = open_mpas_dataset (
10581057 fileName = fileName ,
10591058 calendar = self .calendar ,
@@ -1067,12 +1066,15 @@ def _compute_moc_time_series_analysismember(self):
10671066
10681067 self .logger .info (' date: {:04d}-{:02d}' .format (date .year ,
10691068 date .month ))
1069+ computedIndex = 12 * (date .year - self .startYear ) + date .month - 1
1070+ if computed [computedIndex ]:
1071+ continue
10701072
10711073 # hard-wire region=0 (Atlantic) for now
10721074 indRegion = 0
10731075 mocVar = dsLocal .timeMonthly_avg_mocStreamvalLatAndDepthRegion
10741076 mocTop = mocVar [indRegion , :, :].values
1075- mocRegion [timeIndex ] = np .amax (mocTop [:, indlat26 ])
1077+ mocRegion [computedIndex ] = np .amax (mocTop [:, indlat26 ])
10761078
10771079 if moc is None :
10781080 sizes = dsLocal .sizes
@@ -1087,7 +1089,8 @@ def _compute_moc_time_series_analysismember(self):
10871089 refTopDepth = np .zeros (nVertLevels + 1 )
10881090 refTopDepth [1 :nVertLevels + 1 ] = refBottomDepth [0 :nVertLevels ]
10891091
1090- moc [timeIndex , 0 :- 1 , :] = mocTop
1092+ moc [computedIndex , 0 :- 1 , :] = mocTop
1093+
10911094
10921095 description = 'Max MOC Atlantic streamfunction nearest to RAPID ' \
10931096 'Array latitude (26.5N)'
0 commit comments