|
|
|
@ -4,21 +4,19 @@ import com.aliyun.tablestore.grid.consts.AttributionEnum;
|
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSet;
|
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSetMeta;
|
|
|
|
|
import com.aliyun.tablestore.grid.model.grid.Grid4D;
|
|
|
|
|
import com.htfp.weather.griddata.common.GfsVariableHeightEnum;
|
|
|
|
|
import com.htfp.weather.griddata.common.GfsVariableIsobaricEnum;
|
|
|
|
|
import com.htfp.weather.download.gfs.GfsVariableHeightEnum;
|
|
|
|
|
import com.htfp.weather.download.gfs.GfsVariableIsobaricEnum;
|
|
|
|
|
import com.htfp.weather.griddata.common.TableConfig;
|
|
|
|
|
import com.htfp.weather.griddata.operation.GfsDataFetcher;
|
|
|
|
|
import com.htfp.weather.griddata.utils.ValueRange;
|
|
|
|
|
import com.htfp.weather.griddata.common.ValueRange;
|
|
|
|
|
import com.htfp.weather.info.Constant;
|
|
|
|
|
import com.htfp.weather.info.GfsLevelsEnum;
|
|
|
|
|
import com.htfp.weather.download.gfs.GfsLevelsEnum;
|
|
|
|
|
import com.htfp.weather.utils.DateTimeUtils;
|
|
|
|
|
import com.htfp.weather.web.exception.AppException;
|
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.NowWeatherStatus;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.PlaneResponse;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.ProfileResponse;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.TimeSeriesDataset;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import ucar.ma2.Array;
|
|
|
|
@ -30,7 +28,6 @@ import java.time.Duration;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -201,8 +198,22 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public ProfileDataset getProfileByPressure(OffsetDateTime targetTime, double latitude, double longitude) {
|
|
|
|
|
try {
|
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(GfsLevelsEnum.UPPER.getCode());
|
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getProfileByPressure(variableNames, targetTime, latitude, longitude);
|
|
|
|
|
ProfileDataset profile = buildProfileDataset(gridDataSet, GfsLevelsEnum.UPPER);
|
|
|
|
|
profile.setLatitude(latitude);
|
|
|
|
|
profile.setLongitude(longitude);
|
|
|
|
|
return profile;
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定变量、时间、高度的二维数组数据
|
|
|
|
@ -304,16 +315,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
// 利用反射构建数据集
|
|
|
|
|
Class<? extends TimeSeriesDataset> aClass = result.getClass();
|
|
|
|
|
for (Map.Entry<String, Grid4D> entry : gridDataSet.getVariables().entrySet()) {
|
|
|
|
|
String variableNameInFile = entry.getKey();
|
|
|
|
|
String variableNameInApi;
|
|
|
|
|
if (GfsLevelsEnum.SURFACE.equals(levelFlag)) {
|
|
|
|
|
variableNameInApi = GfsVariableHeightEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
} else {
|
|
|
|
|
variableNameInApi = GfsVariableIsobaricEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
}
|
|
|
|
|
if (variableNameInApi == null) {
|
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE);
|
|
|
|
|
}
|
|
|
|
|
String variableNameInApi = getVariableNameInApi(levelFlag, entry);
|
|
|
|
|
Grid4D grid4D = entry.getValue();
|
|
|
|
|
int[] origin = grid4D.getOrigin(); // grid4D的起始坐标全局索引
|
|
|
|
|
int[] shape = grid4D.getShape();
|
|
|
|
@ -381,16 +383,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
// 利用反射构建数据集
|
|
|
|
|
Class<? extends NowWeatherStatus> aClass = result.getClass();
|
|
|
|
|
for (Map.Entry<String, Grid4D> entry : gridDataSet.getVariables().entrySet()) {
|
|
|
|
|
String variableNameInFile = entry.getKey();
|
|
|
|
|
String variableNameInApi;
|
|
|
|
|
if (GfsLevelsEnum.SURFACE.equals(levelFlag)) {
|
|
|
|
|
variableNameInApi = GfsVariableHeightEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
} else {
|
|
|
|
|
variableNameInApi = GfsVariableIsobaricEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
}
|
|
|
|
|
if (variableNameInApi == null) {
|
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE);
|
|
|
|
|
}
|
|
|
|
|
String variableNameInApi = getVariableNameInApi(levelFlag, entry);
|
|
|
|
|
Grid4D grid4D = entry.getValue(); Index4D index = new Index4D(grid4D.getShape());
|
|
|
|
|
int[] origin = grid4D.getOrigin(); // grid4D的起始坐标全局索引
|
|
|
|
|
try {
|
|
|
|
@ -410,6 +403,48 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProfileDataset buildProfileDataset(GridDataSet gridDataSet, GfsLevelsEnum levelFlag) {
|
|
|
|
|
ProfileDataset result = new ProfileDataset();
|
|
|
|
|
// 利用反射构建数据集
|
|
|
|
|
Class<? extends ProfileDataset> aClass = result.getClass();
|
|
|
|
|
for (Map.Entry<String, Grid4D> entry : gridDataSet.getVariables().entrySet()) {
|
|
|
|
|
try {
|
|
|
|
|
String variableNameInApi = getVariableNameInApi(levelFlag, entry);
|
|
|
|
|
Grid4D grid4D = entry.getValue();
|
|
|
|
|
int[] shape = grid4D.getShape();
|
|
|
|
|
int zSize = shape[1];
|
|
|
|
|
String setMethodName = "set" + variableNameInApi.substring(0, 1).toUpperCase() + variableNameInApi.substring(1);
|
|
|
|
|
Method method = aClass.getDeclaredMethod(setMethodName, aClass.getDeclaredField(variableNameInApi).getType());
|
|
|
|
|
// TODO 2024/6/20: 这里的toArray操作在数据量较大的时候会比较吃内存和cpu
|
|
|
|
|
float[] values = (float[]) grid4D.toArray().section(
|
|
|
|
|
new int[]{0, 0, 0, 0}, new int[]{1, zSize, 1, 1}
|
|
|
|
|
).copyTo1DJavaArray();
|
|
|
|
|
method.invoke(result, values);
|
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE, e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new AppException(ErrorCode.RESPONSE_DATA_BUILD_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.setPressureLevels(tableConfig.getPressureList());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
private static String getVariableNameInApi(GfsLevelsEnum levelFlag, Map.Entry<String, Grid4D> variable) {
|
|
|
|
|
String variableNameInFile = variable.getKey();
|
|
|
|
|
String variableNameInApi;
|
|
|
|
|
if (GfsLevelsEnum.SURFACE.equals(levelFlag)) {
|
|
|
|
|
variableNameInApi = GfsVariableHeightEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
} else {
|
|
|
|
|
variableNameInApi = GfsVariableIsobaricEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
|
}
|
|
|
|
|
if (variableNameInApi == null) {
|
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE);
|
|
|
|
|
}
|
|
|
|
|
return variableNameInApi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, List> getFutureTimeIndexList(GridDataSetMeta lastGridDataSetMeta) {
|
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
|