Skip to content

Commit 47fe4ed

Browse files
committed
major refactoring (column error, column orientation) to interpret (sorted) StaNames (baselines/triplets), MJD Ranges (rounded to 1s) and filter on baselines, mjd ranges and wavelength ranges (in progress) in Merger / OIFitsProcessor (CLI)
1 parent 00e3cef commit 47fe4ed

File tree

89 files changed

+6103
-4213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+6103
-4213
lines changed

lib/jel-2.1.2.jar

37.8 KB
Binary file not shown.

parent-pom/pom.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@
223223
<groupId>org.apache.maven.plugins</groupId>
224224
<artifactId>maven-compiler-plugin</artifactId>
225225
<configuration>
226-
<source>7</source>
227-
<target>7</target>
226+
<!-- 2021.04.15: Java 8 required -->
227+
<source>8</source>
228+
<target>8</target>
228229
</configuration>
229230
</plugin>
230231

@@ -278,19 +279,22 @@
278279
<groupId>org.apache.maven.plugins</groupId>
279280
<artifactId>maven-assembly-plugin</artifactId>
280281
<configuration>
281-
<descriptorRefs>
282-
<descriptorRef>jar-with-dependencies</descriptorRef>
283-
</descriptorRefs>
284282
<archive>
285283
<manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
286284
</archive>
287285
</configuration>
288286
<executions>
289287
<execution>
288+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
290289
<phase>package</phase>
291290
<goals>
292291
<goal>single</goal>
293292
</goals>
293+
<configuration>
294+
<descriptorRefs>
295+
<descriptorRef>jar-with-dependencies</descriptorRef>
296+
</descriptorRefs>
297+
</configuration>
294298
</execution>
295299
</executions>
296300
</plugin>

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6262
<dependency>
6363
<groupId>org.gnu.jel</groupId>
6464
<artifactId>JEL</artifactId>
65-
<version>2.1.1-jdk5</version>
65+
<version>2.1.2</version>
6666
</dependency>
6767

6868
</dependencies>
@@ -82,10 +82,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
8282
<inherited>false</inherited>
8383
<phase>process-resources</phase> <!-- just before compilation -->
8484
<configuration>
85-
<file>lib/jel-2.1.1_jdk5.jar</file>
85+
<file>lib/jel-2.1.2.jar</file>
8686
<groupId>org.gnu.jel</groupId>
8787
<artifactId>JEL</artifactId>
88-
<version>2.1.1-jdk5</version>
88+
<version>2.1.2</version>
8989
<packaging>jar</packaging>
9090
</configuration>
9191
</execution>

src/main/java/fr/jmmc/jmcs/util/NumberUtils.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class NumberUtils {
5757
private final static NumberFormat _fmtDef;
5858
/** scientific formatter */
5959
private final static NumberFormat _fmtScience = new DecimalFormat("0.000E0");
60-
60+
6161
static {
6262
_fmtDef = new DecimalFormat("0.000");
6363
}
@@ -85,14 +85,14 @@ public static boolean isFinite(final float value) {
8585

8686
/**
8787
* Returns {@code true} if the argument is a finite floating-point
88-
* value and greater or equals to 0; returns {@code false} otherwise (for negative and NaN and infinity
88+
* value and greater than +0.0; returns {@code false} otherwise (for negative and NaN and infinity
8989
* arguments).
9090
* @param value the {@code double} value to be tested
9191
* @return {@code true} if the argument is a finite positive
9292
* floating-point value, {@code false} otherwise.
9393
*/
9494
public static boolean isFinitePositive(final float value) {
95-
return isFinite(value) && (value >= 0f);
95+
return isFinite(value) && (value > +0.0f);
9696
}
9797

9898
/**
@@ -111,14 +111,14 @@ public static boolean isFinite(final double value) {
111111

112112
/**
113113
* Returns {@code true} if the argument is a finite floating-point
114-
* value and greater or equals to 0; returns {@code false} otherwise (for negative and NaN and infinity
114+
* value and greater than +0.0; returns {@code false} otherwise (for negative and NaN and infinity
115115
* arguments).
116116
* @param value the {@code double} value to be tested
117117
* @return {@code true} if the argument is a finite positive
118118
* floating-point value, {@code false} otherwise.
119119
*/
120120
public static boolean isFinitePositive(final double value) {
121-
return isFinite(value) && (value >= 0d);
121+
return isFinite(value) && (value > +0.0);
122122
}
123123

124124
/**
@@ -127,6 +127,9 @@ public static boolean isFinitePositive(final double value) {
127127
* @return double value with only 1 decimal digit
128128
*/
129129
public static double trimTo1Digits(final double value) {
130+
if (!Double.isFinite(value)) {
131+
return value;
132+
}
130133
return ((long) (10.0 * value)) / 10.0;
131134
}
132135

@@ -136,6 +139,9 @@ public static double trimTo1Digits(final double value) {
136139
* @return double value with only 3 decimal digits
137140
*/
138141
public static double trimTo3Digits(final double value) {
142+
if (!Double.isFinite(value)) {
143+
return value;
144+
}
139145
return ((long) (1e3d * value)) / 1e3d;
140146
}
141147

@@ -145,6 +151,9 @@ public static double trimTo3Digits(final double value) {
145151
* @return double value with only 5 decimal digits
146152
*/
147153
public static double trimTo5Digits(final double value) {
154+
if (!Double.isFinite(value)) {
155+
return value;
156+
}
148157
return ((long) (1e5d * value)) / 1e5d;
149158
}
150159

@@ -154,6 +163,9 @@ public static double trimTo5Digits(final double value) {
154163
* @return double value with only 9 decimal digits
155164
*/
156165
public static double trimTo9Digits(final double value) {
166+
if (!Double.isFinite(value)) {
167+
return value;
168+
}
157169
return ((long) (1e9d * value)) / 1e9d;
158170
}
159171

@@ -179,7 +191,7 @@ public static String format(final double val) {
179191
return "0";
180192
}
181193

182-
if (abs < 1e-3d || abs > 1e6d) {
194+
if ((abs < 1e-3d) || (abs > 1e6d)) {
183195
return FormatterUtils.format(_fmtScience, val);
184196
}
185197
return FormatterUtils.format(_fmtDef, val);
@@ -374,19 +386,19 @@ public static Integer valueOf(final String s) throws NumberFormatException {
374386
private static final class IntegerCache {
375387

376388
/** lower value */
377-
static final int low = -1024;
389+
static final int LOW = -1024;
378390
/** higher value */
379-
static final int high = 128 * 1024;
391+
static final int HIGH = 128 * 1024;
380392
/** Integer cache */
381-
static final Integer cache[];
393+
static final Integer[] CACHE;
382394

383395
static {
384396
// high value may be configured by system property (NumberUtils.IntegerCache.high)
385397

386-
cache = new Integer[(high - low) + 1];
387-
int j = low;
388-
for (int k = 0, len = cache.length; k < len; k++) {
389-
cache[k] = Integer.valueOf(j++);
398+
CACHE = new Integer[(HIGH - LOW) + 1];
399+
int j = LOW;
400+
for (int k = 0, len = CACHE.length; k < len; k++) {
401+
CACHE[k] = Integer.valueOf(j++);
390402
}
391403
}
392404

@@ -396,8 +408,8 @@ private static final class IntegerCache {
396408
* @return cached Integer instance or new one
397409
*/
398410
static Integer get(final int i) {
399-
if (i >= low && i <= high) {
400-
return cache[i + (-low)];
411+
if (i >= LOW && i <= HIGH) {
412+
return CACHE[i + (-LOW)];
401413
}
402414
return Integer.valueOf(i);
403415
}

src/main/java/fr/jmmc/oitools/OIFitsCollectionViewer.java

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
import fr.jmmc.oitools.model.Target;
3333
import fr.jmmc.oitools.model.TargetIdMatcher;
3434
import fr.jmmc.oitools.model.TargetManager;
35+
import fr.jmmc.oitools.model.range.Range;
36+
import fr.jmmc.oitools.util.StationNamesComparator;
37+
import java.text.DecimalFormat;
38+
import java.text.NumberFormat;
39+
import java.util.ArrayList;
40+
import java.util.Collections;
3541
import java.util.List;
3642
import java.util.Map;
3743
import java.util.Set;
@@ -43,6 +49,15 @@
4349
*/
4450
public final class OIFitsCollectionViewer {
4551

52+
/** Logger */
53+
protected final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(OIFitsCollectionViewer.class.getName());
54+
55+
/* constants */
56+
private final static String SEP = "\t";
57+
58+
/** double formatter for MJD (6 digits) to have 1s precision */
59+
private final static NumberFormat df6 = new DecimalFormat("0.00000#");
60+
4661
private OIFitsCollectionViewer() {
4762
super();
4863
}
@@ -79,11 +94,11 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
7994
final InstrumentMode gInsMode = granule.getInsMode();
8095
// OIWavelength info
8196
final String insName = gInsMode.getInsName(); // global UID
82-
final float minWavelength = gInsMode.getLambdaMin();
83-
final float maxWavelength = gInsMode.getLambdaMax();
8497
final int nbChannels = gInsMode.getNbChannels();
98+
final double minWavelength = gInsMode.getLambdaMin();
99+
final double maxWavelength = gInsMode.getLambdaMax();
85100
// Resolution = lambda / delta_lambda
86-
final float resPower = gInsMode.getResPower();
101+
final double resPower = gInsMode.getResPower();
87102

88103
// night
89104
final int gNightId = granule.getNight().getNightId();
@@ -101,12 +116,15 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
101116

102117
if (targetIdMatcher != null) {
103118
/* one oiData table, search for target by targetid (and nightid) */
119+
final int nbRows = oiData.getNbRows();
104120
final short[] targetIds = oiData.getTargetId();
105121
final int[] nightIds = oiData.getNightId();
106122
final double[] mjds = oiData.getMJD();
107123
final double[] intTimes = oiData.getIntTime();
108124

109-
for (int i = 0; i < targetIds.length; i++) {
125+
boolean match = false;
126+
127+
for (int i = 0; i < nbRows; i++) {
110128
// same target and same night:
111129
if (targetIdMatcher.match(targetIds[i]) && (gNightId == nightIds[i])) {
112130
// TODO: count flag? what to do with flagged measures?
@@ -136,10 +154,11 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
136154
if (t < intTime) {
137155
intTime = t;
138156
}
139-
}
140-
}
141157

142-
if (facilityName.isEmpty() && oiData.getArrName() != null) {
158+
match = true;
159+
}
160+
} // rows
161+
if (match && facilityName.isEmpty() && oiData.getArrName() != null) {
143162
facilityName = oiData.getArrName(); // potential multiple ARRNAME values !
144163
}
145164
}
@@ -153,4 +172,76 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
153172
}
154173
}
155174
}
175+
176+
public static void processBaselines(final OIFitsCollection oiFitsCollection) {
177+
final StringBuilder sb = new StringBuilder(1024);
178+
179+
baselinesPerGranule(oiFitsCollection, sb);
180+
181+
OIFitsCommand.info(sb.toString());
182+
}
183+
184+
public static void baselinesPerGranule(final OIFitsCollection oiFitsCollection, final StringBuilder out) {
185+
out.append("instrument_name").append(SEP)
186+
.append("em_min").append(SEP)
187+
.append("em_max").append(SEP)
188+
.append("night_id").append(SEP)
189+
.append("target_name").append(SEP)
190+
.append("s_ra").append(SEP)
191+
.append("s_dec").append(SEP)
192+
.append("mjds").append(SEP)
193+
.append("baselines").append('\n');
194+
195+
final List<Granule> granules = oiFitsCollection.getSortedGranules();
196+
197+
final List<String> sortedStaNames = new ArrayList<String>(16);
198+
final List<Range> sortedMJDRanges = new ArrayList<Range>(16);
199+
200+
for (Granule granule : granules) {
201+
final Target gTarget = granule.getTarget();
202+
// Target info
203+
final String targetName = gTarget.getTarget(); // global UID
204+
final double targetRa = gTarget.getRaEp0();
205+
final double targetDec = gTarget.getDecEp0();
206+
207+
final InstrumentMode gInsMode = granule.getInsMode();
208+
// OIWavelength info
209+
final String insName = gInsMode.getInsName(); // global UID
210+
final double minWavelength = gInsMode.getLambdaMin();
211+
final double maxWavelength = gInsMode.getLambdaMax();
212+
213+
// night
214+
final int gNightId = granule.getNight().getNightId();
215+
216+
// Sort StaNames by name:
217+
sortedStaNames.clear();
218+
sortedStaNames.addAll(granule.getDistinctStaNames());
219+
Collections.sort(sortedStaNames, StationNamesComparator.INSTANCE);
220+
221+
// Sort MJD Ranges:
222+
sortedMJDRanges.clear();
223+
sortedMJDRanges.addAll(granule.getDistinctMjdRanges());
224+
Collections.sort(sortedMJDRanges);
225+
226+
out.append(insName).append(SEP)
227+
.append(minWavelength).append(SEP)
228+
.append(maxWavelength).append(SEP)
229+
.append(gNightId).append(SEP)
230+
.append(targetName).append(SEP)
231+
.append(targetRa).append(SEP)
232+
.append(targetDec).append(SEP);
233+
234+
// distinct MJD ranges:
235+
for (Range r : sortedMJDRanges) {
236+
out.append('[').append(df6.format(r.getMin())).append(',').append(df6.format(r.getMax())).append("] ");
237+
}
238+
out.append(SEP);
239+
240+
// distinct StaNames:
241+
for (String staName : sortedStaNames) {
242+
out.append(staName).append(' ');
243+
}
244+
out.append('\n');
245+
}
246+
}
156247
}

src/main/java/fr/jmmc/oitools/OIFitsConstants.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
422422
public final static String COLUMN_SPATIAL_FREQ = "SPATIAL_FREQ";
423423
/** NIGHT_ID derived OiData column as double[] */
424424
public final static String COLUMN_NIGHT_ID = "NIGHT_ID";
425+
/** MJD_START derived OiData column as double[] */
426+
public final static String COLUMN_MJD_START_R = "MJD_START";
427+
/** MJD_END derived OiData column as double[] */
428+
public final static String COLUMN_MJD_END_R = "MJD_END";
425429
/** UCOORD_SPATIAL derived OIData column as double[][] */
426430
public final static String COLUMN_UCOORD_SPATIAL = "UCOORD_SPATIAL";
427431
/** VCOORD_SPATIAL derived OIData column as double[][] */
@@ -434,7 +438,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
434438
public final static String COLUMN_U2COORD_SPATIAL = "U2COORD_SPATIAL";
435439
/** V2COORD_SPATIAL derived OIData column as double[][] */
436440
public final static String COLUMN_V2COORD_SPATIAL = "V2COORD_SPATIAL";
437-
441+
438442
/** SNR_VIS2 derived OIVIS2 column as double[][] */
439443
public final static String COLUMN_SNR_VIS2 = "SNR_VIS2";
440444
/** SNR_MODEL_VIS2 derived OIVIS2 column as double[][] */
@@ -445,7 +449,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
445449
public final static String COLUMN_SNR_NS_PHOT = "SNR_NS_PHOT";
446450
/** RES_VIS2_MODEL derived OIVIS2 column as double[][] */
447451
public final static String COLUMN_RES_VIS2_MODEL = "RES_VIS2_MODEL";
448-
452+
449453
/** SNR_VISAMP derived OIVIS column as double[][] */
450454
public final static String COLUMN_SNR_VISAMP = "SNR_VISAMP";
451455
/** SNR_VISPHI derived OIVIS column as double[][] */
@@ -454,7 +458,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
454458
public final static String COLUMN_RES_VISAMP_MODEL = "RES_VISAMP_MODEL";
455459
/** RES_VISPHI_MODEL derived OIVIS column as double[][] */
456460
public final static String COLUMN_RES_VISPHI_MODEL = "RES_VISPHI_MODEL";
457-
461+
458462
/** SNR_T3AMP derived T3 column as double[][] */
459463
public final static String COLUMN_SNR_T3AMP = "SNR_T3AMP";
460464
/** SNR_T3PHI derived T3 column as double[][] */
@@ -463,7 +467,10 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
463467
public final static String COLUMN_RES_T3AMP_MODEL = "RES_T3AMP_MODEL";
464468
/** RES_T3PHI_MODEL derived T3 column as double[][] */
465469
public final static String COLUMN_RES_T3PHI_MODEL = "RES_T3PHI_MODEL";
466-
470+
471+
/** SNR_FLUX derived OI_FLUX column as double[][] */
472+
public final static String COLUMN_SNR_FLUX = "SNR_FLUX";
473+
467474
/** Resolution value */
468475
public final static String VALUE_RESOLUTION = "RESOLUTION";
469476
}

0 commit comments

Comments
 (0)