Index: trunk/tests/test_data/system_tests_nc/dummy_hs_gridded.nc =================================================================== diff -u Binary files differ Index: trunk/SDToolBox/extract_data.py =================================================================== diff -u -r75 -r76 --- trunk/SDToolBox/extract_data.py (.../extract_data.py) (revision 75) +++ trunk/SDToolBox/extract_data.py (.../extract_data.py) (revision 76) @@ -328,12 +328,14 @@ nn_lat_idx = self.__set_nn( input_values=input_data._input_lat, reference_list=ref_dataset.variables[self.lat_key][:], - output_values=cases_dict[OutputData.var_lat_key] + output_values=cases_dict[OutputData.var_lat_key], + is_gridded=input_data.is_gridded ) nn_lon_idx = self.__set_nn( input_values=input_data._input_lon, reference_list=ref_dataset.variables[self.lon_key][:], output_values=cases_dict[OutputData.var_lon_key], + is_gridded=input_data.is_gridded ) return nn_lon_idx, nn_lat_idx @@ -359,19 +361,33 @@ self, input_values: List[float], reference_list: List[float], - output_values: List[float]) -> List[int]: + output_values: List[float], + is_gridded: bool) -> List[int]: """Sets the nearest neighbor for all the elements given in the points_list. Arguments: input_values {List[float]} -- List of elements to correct. reference_list {List[float]} -- Available neighbor list. output_values {List[float]} -- Corrected values. + is_gridded {bool} -- Needs to extract nn as gridded dataset. Returns: List[int] -- Indices of the nearest neighbors positions """ output_idx = [] + if is_gridded: + min_idx, min_value = self.get_nearest_neighbor( + min(input_values), + reference_list) + max_idx, max_value = self.get_nearest_neighbor( + max(input_values), + reference_list) + nn_idx = sorted([min_idx, max_idx]) + output_values.extend( + reference_list[nn_idx[0]:nn_idx[-1]]) + return list(nn_idx) + # Non-gridded. for point in input_values: idx, value = self.get_nearest_neighbor( point, @@ -394,15 +410,34 @@ return index_found, value_found @staticmethod - def __get_case_subset(dataset, variable_name, input_data, lon, lat): + def __get_case_subset( + dataset: Dataset, + variable_name: str, + input_data: InputData, + lon: List[int], + lat: List[int]): + """Gets the subset given a lat-lon. + + Arguments: + dataset {netCDF4.Dataset} -- Input Dataset. + variable_name {str} -- Name of the variable to extract. + input_data {InputData} -- Input parameters. + lon {List[int]} -- Longitude indices. + lat {List[int]} -- Latitude indices. + + Returns: + netCDF4.array -- Dataset result subset. + """ + # Dataset[Variable][time, latitude, longitude] if not input_data.is_gridded: vc = [] # We access to the points individually. for l in range(0, len(lat)): vc.append(dataset[variable_name][:, lat[l], lon[l]]) return vc - # Is gridded, we get only an ortogonal of the lat-lon. + # Is gridded, we ge + # it only an ortogonal of the lat-lon. return dataset[variable_name][ :, lat[0]:lat[-1], Index: trunk/SDToolBox/input_data.py =================================================================== diff -u -r75 -r76 --- trunk/SDToolBox/input_data.py (.../input_data.py) (revision 75) +++ trunk/SDToolBox/input_data.py (.../input_data.py) (revision 76) @@ -157,8 +157,8 @@ self.__get_corrected_longitude(lon) for lon in self._input_lon] if self.is_gridded: - self._input_lat = set(self._input_lat) - self._input_lon = list(set(self._input_lon)) + self._input_lat = sorted(set(self._input_lat)) + self._input_lon = list(sorted(set(self._input_lon))) self._input_lat = list(self._input_lat) def __get_corrected_longitude(self, longitude: int): Index: trunk/tests/test_data/system_tests_nc/dummy_hs_non_gridded.nc =================================================================== diff -u Binary files differ Index: trunk/SDToolBox/output_data.py =================================================================== diff -u -r75 -r76 --- trunk/SDToolBox/output_data.py (.../output_data.py) (revision 75) +++ trunk/SDToolBox/output_data.py (.../output_data.py) (revision 76) @@ -591,5 +591,10 @@ continue # Assign the data from the frame towards the netCDF-parameter print('writing variable {}'.format(var_name)) - netcdf.variables[var_name.upper()][:] = \ - np.transpose(variables[var_name]) + if self.is_gridded: + netcdf.variables[var_name.upper()][:] = \ + variables[var_name] + else: + # When non-gridded we need to transpose the dimensions. + netcdf.variables[var_name.upper()][:] = \ + np.transpose(variables[var_name])