1616
1717import static com .bc .fiduceo .post .plugin .era5 .VariableUtils .*;
1818
19- class MatchupFields {
19+ class MatchupFields extends FieldsProcessor {
2020
2121 private static final int SECS_PER_HOUR = 3600 ;
2222
2323 private Map <String , TemplateVariable > variables ;
2424
25+ private static Array createTimeArray (NetcdfFile reader , MatchupFieldsConfiguration matchupConfig , int numTimeSteps , Variable nwpTimeVariable ) throws IOException , InvalidRangeException {
26+ final Array timeArray = VariableUtils .readTimeArray (matchupConfig .get_time_variable_name (), reader );
27+ final Array era5TimeArray = convertToEra5TimeStamp (timeArray );
28+ final int numMatchups = era5TimeArray .getShape ()[0 ];
29+
30+ final Array targetTimeArray = Array .factory (DataType .INT , nwpTimeVariable .getShape ());
31+ final Index targetIndex = targetTimeArray .getIndex ();
32+
33+ final int offset = -matchupConfig .get_time_steps_past ();
34+ final Index index = era5TimeArray .getIndex ();
35+ for (int i = 0 ; i < numMatchups ; i ++) {
36+ index .set (i );
37+ final int timeStamp = era5TimeArray .getInt (index );
38+ for (int k = 0 ; k < numTimeSteps ; k ++) {
39+ final int timeStep = timeStamp + (offset + k ) * SECS_PER_HOUR ;
40+ targetIndex .set (i , k );
41+ targetTimeArray .setInt (targetIndex , timeStep );
42+ }
43+ }
44+ return targetTimeArray ;
45+ }
46+
2547 void prepare (MatchupFieldsConfiguration matchupFieldsConfig , NetcdfFile reader , NetcdfFileWriter writer ) {
2648 matchupFieldsConfig .verify ();
2749
@@ -127,28 +149,6 @@ void compute(Configuration config, NetcdfFile reader, NetcdfFileWriter writer) t
127149 }
128150 }
129151
130- private static Array createTimeArray (NetcdfFile reader , MatchupFieldsConfiguration matchupConfig , int numTimeSteps , Variable nwpTimeVariable ) throws IOException , InvalidRangeException {
131- final Array timeArray = VariableUtils .readTimeArray (matchupConfig .get_time_variable_name (), reader );
132- final Array era5TimeArray = convertToEra5TimeStamp (timeArray );
133- final int numMatchups = era5TimeArray .getShape ()[0 ];
134-
135- final Array targetTimeArray = Array .factory (DataType .INT , nwpTimeVariable .getShape ());
136- final Index targetIndex = targetTimeArray .getIndex ();
137-
138- final int offset = - matchupConfig .get_time_steps_past ();
139- final Index index = era5TimeArray .getIndex ();
140- for (int i = 0 ; i < numMatchups ; i ++) {
141- index .set (i );
142- final int timeStamp = era5TimeArray .getInt (index );
143- for (int k = 0 ; k < numTimeSteps ; k ++) {
144- final int timeStep = timeStamp + (offset + k ) * SECS_PER_HOUR ;
145- targetIndex .set (i , k );
146- targetTimeArray .setInt (targetIndex , timeStep );
147- }
148- }
149- return targetTimeArray ;
150- }
151-
152152 private void addTimeVariable (MatchupFieldsConfiguration matchupFieldsConfig , List <Dimension > dimensions , NetcdfFileWriter writer ) {
153153 final String timeVariableName = matchupFieldsConfig .get_nwp_time_variable_name ();
154154 final String escapedName = NetCDFUtils .escapeVariableName (timeVariableName );
@@ -168,7 +168,7 @@ List<Dimension> getDimensions(MatchupFieldsConfiguration matchupFieldsConfig, Ne
168168 final int time_steps_past = matchupFieldsConfig .get_time_steps_past ();
169169 final int time_steps_future = matchupFieldsConfig .get_time_steps_future ();
170170 final int time_dim_length = time_steps_past + time_steps_future + 1 ;
171- final String time_dim_name = matchupFieldsConfig .get_time_dim_name ();
171+ final String time_dim_name = NetCDFUtils . escapeVariableName ( matchupFieldsConfig .get_time_dim_name () );
172172
173173 final Dimension timeDimension = writer .addDimension (time_dim_name , time_dim_length );
174174 dimensions .add (timeDimension );
@@ -180,16 +180,16 @@ List<Dimension> getDimensions(MatchupFieldsConfiguration matchupFieldsConfig, Ne
180180 Map <String , TemplateVariable > getVariables (MatchupFieldsConfiguration configuration ) {
181181 final HashMap <String , TemplateVariable > variablesMap = new HashMap <>();
182182
183- variablesMap .put ("an_sfc_u10" , new TemplateVariable (configuration .get_an_u10_name (), "m s**-1" , "10 metre U wind component" , null , false ));
184- variablesMap .put ("an_sfc_v10" , new TemplateVariable (configuration .get_an_v10_name (), "m s**-1" , "10 metre V wind component" , null , false ));
185- variablesMap .put ("an_sfc_siconc" , new TemplateVariable (configuration .get_an_siconc_name (), "(0 - 1)" , "Sea ice area fraction" , "sea_ice_area_fraction" , false ));
186- variablesMap .put ("an_sfc_sst" , new TemplateVariable (configuration .get_an_sst_name (), "K" , "Sea surface temperature" , null , false ));
187- variablesMap .put ("fc_sfc_metss" , new TemplateVariable (configuration .get_fc_metss_name (), "N m**-2" , "Mean eastward turbulent surface stress" , null , false ));
188- variablesMap .put ("fc_sfc_mntss" , new TemplateVariable (configuration .get_fc_mntss_name (), "N m**-2" , "Mean northward turbulent surface stress" , null , false ));
189- variablesMap .put ("fc_sfc_mslhf" , new TemplateVariable (configuration .get_fc_mslhf_name (), "W m**-2" , "Mean surface latent heat flux" , null , false ));
190- variablesMap .put ("fc_sfc_msnlwrf" , new TemplateVariable (configuration .get_fc_msnlwrf_name (), "W m**-2" , "Mean surface net long-wave radiation flux" , null , false ));
191- variablesMap .put ("fc_sfc_msnswrf" , new TemplateVariable (configuration .get_fc_msnswrf_name (), "W m**-2" , "Mean surface net short-wave radiation flux" , null , false ));
192- variablesMap .put ("fc_sfc_msshf" , new TemplateVariable (configuration .get_fc_msshf_name (), "W m**-2" , "Mean surface sensible heat flux" , null , false ));
183+ variablesMap .put ("an_sfc_u10" , createTemplate (configuration .get_an_u10_name (), "m s**-1" , "10 metre U wind component" , null , false ));
184+ variablesMap .put ("an_sfc_v10" , createTemplate (configuration .get_an_v10_name (), "m s**-1" , "10 metre V wind component" , null , false ));
185+ variablesMap .put ("an_sfc_siconc" , createTemplate (configuration .get_an_siconc_name (), "(0 - 1)" , "Sea ice area fraction" , "sea_ice_area_fraction" , false ));
186+ variablesMap .put ("an_sfc_sst" , createTemplate (configuration .get_an_sst_name (), "K" , "Sea surface temperature" , null , false ));
187+ variablesMap .put ("fc_sfc_metss" , createTemplate (configuration .get_fc_metss_name (), "N m**-2" , "Mean eastward turbulent surface stress" , null , false ));
188+ variablesMap .put ("fc_sfc_mntss" , createTemplate (configuration .get_fc_mntss_name (), "N m**-2" , "Mean northward turbulent surface stress" , null , false ));
189+ variablesMap .put ("fc_sfc_mslhf" , createTemplate (configuration .get_fc_mslhf_name (), "W m**-2" , "Mean surface latent heat flux" , null , false ));
190+ variablesMap .put ("fc_sfc_msnlwrf" , createTemplate (configuration .get_fc_msnlwrf_name (), "W m**-2" , "Mean surface net long-wave radiation flux" , null , false ));
191+ variablesMap .put ("fc_sfc_msnswrf" , createTemplate (configuration .get_fc_msnswrf_name (), "W m**-2" , "Mean surface net short-wave radiation flux" , null , false ));
192+ variablesMap .put ("fc_sfc_msshf" , createTemplate (configuration .get_fc_msshf_name (), "W m**-2" , "Mean surface sensible heat flux" , null , false ));
193193
194194 return variablesMap ;
195195 }
0 commit comments