1 |
779bac69
|
Marc NICOLAS
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
package fr.ias.sitools.converters;
|
8 |
|
|
|
9 |
|
|
import fr.cnes.sitools.common.validator.ConstraintViolation;
|
10 |
|
|
import fr.cnes.sitools.common.validator.ConstraintViolationLevel;
|
11 |
|
|
import fr.cnes.sitools.common.validator.Validator;
|
12 |
|
|
import fr.cnes.sitools.dataset.converter.business.AbstractConverter;
|
13 |
|
|
import fr.cnes.sitools.dataset.converter.model.ConverterParameter;
|
14 |
|
|
import fr.cnes.sitools.dataset.converter.model.ConverterParameterType;
|
15 |
|
|
import fr.cnes.sitools.datasource.jdbc.model.AttributeValue;
|
16 |
|
|
import fr.cnes.sitools.datasource.jdbc.model.Record;
|
17 |
|
|
import java.util.HashSet;
|
18 |
|
|
import java.util.Map;
|
19 |
|
|
import java.util.Set;
|
20 |
|
|
import java.util.logging.Level;
|
21 |
|
|
import java.util.logging.Logger;
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
public class RaDecToXYZConverter extends AbstractConverter {
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
private static final Logger LOGGER = Logger.getLogger(RaDecToXYZConverter.class.getName());
|
40 |
|
|
|
41 |
|
|
public RaDecToXYZConverter() {
|
42 |
|
|
|
43 |
|
|
this.setName("RaDecToXYZConverter");
|
44 |
|
|
this.setDescription("A converter applying an unit conversion from Ra and Dec into X, Y and Z coordinates");
|
45 |
|
|
this.setClassAuthor("Marc NICOLAS");
|
46 |
|
|
this.setClassOwner("IAS");
|
47 |
|
|
this.setClassVersion("0.1");
|
48 |
|
|
|
49 |
|
|
ConverterParameter colRa = new ConverterParameter("colRa", "row of dataset with the ra coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN);
|
50 |
|
|
ConverterParameter colDec = new ConverterParameter("colDec", "row of dataset with the dec coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN);
|
51 |
|
|
|
52 |
|
|
ConverterParameter colX = new ConverterParameter("colX", "Column for coordiante X", ConverterParameterType.CONVERTER_PARAMETER_OUT);
|
53 |
|
|
ConverterParameter colY = new ConverterParameter("colY", "Column for coordiante Y", ConverterParameterType.CONVERTER_PARAMETER_OUT);
|
54 |
|
|
ConverterParameter colZ = new ConverterParameter("colZ", "Column for coordiante Z", ConverterParameterType.CONVERTER_PARAMETER_OUT);
|
55 |
|
|
|
56 |
|
|
this.addParam(colRa);
|
57 |
|
|
this.addParam(colDec);
|
58 |
|
|
this.addParam(colX);
|
59 |
|
|
this.addParam(colY);
|
60 |
|
|
this.addParam(colZ);
|
61 |
|
|
|
62 |
|
|
LOGGER.log(Level.INFO, "Converter :{0} version {1}", new Object[] { this.getName(), this.getClassVersion() });
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
@Override
|
68 |
|
|
public Record getConversionOf(Record record) throws Exception {
|
69 |
|
|
Record out = record;
|
70 |
|
|
Double x, y, z;
|
71 |
|
|
|
72 |
|
|
AttributeValue attrOutX = this.getOutParam("colX", out);
|
73 |
|
|
AttributeValue attrOutY = this.getOutParam("colY", out);
|
74 |
|
|
AttributeValue attrOutZ = this.getOutParam("colZ", out);
|
75 |
|
|
|
76 |
|
|
AttributeValue attrInRa = this.getInParam("colRa", out);
|
77 |
|
|
AttributeValue attrInDec = this.getInParam("colDec", out);
|
78 |
|
|
|
79 |
|
|
if(!isNull(attrInRa) && !isNull(attrInRa)){
|
80 |
|
|
try{
|
81 |
|
|
Double ra = Double.parseDouble(attrInRa.getValue().toString());
|
82 |
|
|
Double dec = Double.parseDouble(attrInDec.getValue().toString());
|
83 |
|
|
|
84 |
|
|
x = Math.cos(dec)*Math.cos(ra);
|
85 |
|
|
y = Math.cos(dec)*Math.sin(ra);
|
86 |
|
|
z = Math.sin(dec);
|
87 |
|
|
|
88 |
|
|
if(!x.isNaN()){
|
89 |
|
|
attrOutX.setValue(x);
|
90 |
|
|
}
|
91 |
|
|
if(!y.isNaN()){
|
92 |
|
|
attrOutY.setValue(y);
|
93 |
|
|
}
|
94 |
|
|
if(!z.isNaN()){
|
95 |
|
|
|
96 |
|
|
attrOutZ.setValue(z);
|
97 |
|
|
}
|
98 |
|
|
}catch(NumberFormatException e){
|
99 |
|
|
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
return out;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
@Override
|
107 |
|
|
public Validator<?> getValidator() {
|
108 |
|
|
|
109 |
|
|
return new Validator<AbstractConverter>() {
|
110 |
|
|
|
111 |
|
|
@Override
|
112 |
|
|
public Set<ConstraintViolation> validate(AbstractConverter item) {
|
113 |
|
|
Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>();
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
return constraints;
|
136 |
|
|
}
|
137 |
|
|
};
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
} |