Skip to content

Commit d211109

Browse files
committed
keep oiDatasDiscarded in SelectorResult to visualize filtered data (gray)
support multiple values on filters (targetUID, insModeUID, nightId) added derived columns StaIndexName and StaConfName (stable)
1 parent d96c6e9 commit d211109

20 files changed

Lines changed: 642 additions & 239 deletions

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
415415
/* derived columns */
416416
/** STA_CONF derived OIData column as short[] */
417417
public final static String COLUMN_STA_CONF = "STA_CONF";
418+
/** STA_INDEX_NAME derived OIData column as String[] */
419+
public final static String COLUMN_STA_INDEX_NAME = "STA_INDEX_NAME";
420+
/** STA_CONF_NAME derived OIData column as String[] */
421+
public final static String COLUMN_STA_CONF_NAME = "STA_CONF_NAME";
418422
/** HOUR_ANGLE derived OIData column as double[] */
419423
public final static String COLUMN_HOUR_ANGLE = "HOUR_ANGLE";
420424
/** RADIUS derived OIData column as double[] */

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

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,17 @@ private static void merge(final String[] args) throws FitsException, IOException
236236
final Selector selector = new Selector();
237237

238238
if (hasOptionArg(args, OPTION_TARGET)) {
239-
selector.setTargetUID(getOptionArgValue(args, OPTION_TARGET));
239+
selector.setTargetUIDs(parseStrings(getOptionArgValues(args, OPTION_TARGET)));
240240
} else if (hasOptionArg(args, OPTION_TARGET_ID)) {
241-
selector.setTargetUID(getOptionArgValue(args, OPTION_TARGET_ID));
241+
selector.setTargetUIDs(parseStrings(getOptionArgValues(args, OPTION_TARGET_ID)));
242242
}
243243
if (hasOptionArg(args, OPTION_INSNAME)) {
244-
selector.setInsModeUID(getOptionArgValue(args, OPTION_INSNAME));
244+
selector.setInsModeUIDs(parseStrings(getOptionArgValues(args, OPTION_INSNAME)));
245245
}
246246
if (hasOptionArg(args, OPTION_NIGHT)) {
247-
selector.setNightID(Integer.valueOf(getOptionArgValue(args, OPTION_NIGHT)));
247+
selector.parseNightIDs(parseStrings(getOptionArgValues(args, OPTION_NIGHT)));
248248
} else if (hasOptionArg(args, OPTION_NIGHT_ID)) {
249-
selector.setNightID(Integer.valueOf(getOptionArgValue(args, OPTION_NIGHT_ID)));
249+
selector.parseNightIDs(parseStrings(getOptionArgValues(args, OPTION_NIGHT_ID)));
250250
}
251251

252252
if (!addRangeFilter(selector, Selector.FILTER_MJD, args, OPTION_MJD_RANGES)) {
@@ -405,9 +405,9 @@ protected static void showArgumentsHelp() {
405405
info("| [-o] or [-output] <file_path> Complete path, absolute or relative, for output file |");
406406
info("--------------------------------------------------------------------------------------");
407407
info("| Filter options available to the command " + COMMAND_MERGE + ": |");
408-
info("| [-target] <value> Filter result on given Target |");
409-
info("| [-insname] <value> Filter result on given InsName |");
410-
info("| [-night] <value> Filter result on given Night (integer) |");
408+
info("| [-target] <value> Filter result on given Targets (comma-separated) |");
409+
info("| [-insname] <value> Filter result on given InsNames (comma-separated) |");
410+
info("| [-night] <value> Filter result on given Nights (integer, comma-separated) |");
411411
info("| |");
412412
info("| [-baselines] <values> Filter result on given Baselines or Triplets (comma-separated) |");
413413
info("| [-mjds] <values> Filter result on given MJD ranges (comma-separated pairs) |");
@@ -438,12 +438,30 @@ private static void parseStrings(final List<String> values, final String input)
438438
}
439439
}
440440

441-
private static StringBuilder dumpStrings(final List<String> values, final StringBuilder sb) {
441+
private static List<String> parseStrings(final List<String> inputs) {
442+
List<String> values = null;
443+
444+
if ((inputs != null) && !inputs.isEmpty()) {
445+
for (String input : inputs) {
446+
if ((input != null) && !input.isEmpty()) {
447+
for (String value : input.split(",")) {
448+
if (values == null) {
449+
values = new ArrayList<>();
450+
}
451+
values.add(value.trim());
452+
}
453+
}
454+
}
455+
}
456+
return values;
457+
}
458+
459+
private static StringBuilder dumpStrings(final List<?> values, final StringBuilder sb) {
442460
if (values == null || values.isEmpty()) {
443461
return sb;
444462
}
445-
for (String v : values) {
446-
sb.append(v).append(",");
463+
for (Object o : values) {
464+
sb.append(o).append(",");
447465
}
448466
sb.deleteCharAt(sb.length() - 1);
449467
return sb;
@@ -486,14 +504,17 @@ public static String generateCLIargs(final Selector selector) {
486504
final StringBuilder sb = new StringBuilder(128);
487505
sb.append("CLI args: ");
488506

489-
if (selector.getTargetUID() != null) {
490-
appendColumnArg(sb, Selector.FILTER_TARGET_ID).append(" ").append(selector.getTargetUID()).append(" ");
507+
if (selector.getTargetUIDs() != null) {
508+
appendColumnArg(sb, Selector.FILTER_TARGET_ID).append(" ");
509+
dumpStrings(selector.getTargetUIDs(), sb).append(" ");
491510
}
492-
if (selector.getInsModeUID() != null) {
493-
sb.append(OIFitsProcessor.OPTION_INSNAME).append(" ").append(selector.getInsModeUID()).append(" ");
511+
if (selector.getInsModeUIDs() != null) {
512+
sb.append(OIFitsProcessor.OPTION_INSNAME).append(" ");
513+
dumpStrings(selector.getInsModeUIDs(), sb).append(" ");
494514
}
495-
if (selector.getNightID() != null) {
496-
appendColumnArg(sb, Selector.FILTER_NIGHT_ID).append(" ").append(selector.getNightID()).append(" ");
515+
if (selector.getNightIDs() != null) {
516+
appendColumnArg(sb, Selector.FILTER_NIGHT_ID).append(" ");
517+
dumpStrings(selector.getNightIDs(), sb).append(" ");
497518
}
498519
/* no way to define selector.tables via CLI */
499520

src/main/java/fr/jmmc/oitools/model/AbstractMapper.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public abstract class AbstractMapper<K> {
5151
/** global item keyed by local item */
5252
protected final Map<K, K> globalPerLocal = new IdentityHashMap<K, K>();
5353
/** local items keyed by global item */
54-
protected final Map<K, List<K>> localsPerGlobal = new IdentityHashMap<K, List<K>>();
54+
protected final Map<K, ArrayList<K>> localsPerGlobal = new IdentityHashMap<K, ArrayList<K>>();
5555
/** sorted unique aliases by global item */
5656
private final Map<K, List<String>> sortedAliasesPerGlobal = new HashMap<K, List<String>>();
5757

@@ -91,7 +91,7 @@ public final void register(final K local) {
9191
}
9292
}
9393

94-
final List<K> locals;
94+
final ArrayList<K> locals;
9595
if (match == null) {
9696
// Generate UID:
9797
final String uid = generateUid(getName(local));
@@ -136,12 +136,26 @@ public final int getLocalCount() {
136136
return globalPerLocal.size();
137137
}
138138

139-
public final List<K> getGlobals(Comparator<K> comparator) {
140-
final List<K> globals = new ArrayList<K>(localsPerGlobal.keySet());
139+
public final ArrayList<K> getGlobals(Comparator<K> comparator) {
140+
final ArrayList<K> globals = new ArrayList<K>(localsPerGlobal.keySet());
141141
Collections.sort(globals, comparator);
142142
return globals;
143143
}
144144

145+
public final ArrayList<K> getGlobalsByUID(final List<String> uids) {
146+
ArrayList<K> globals = null;
147+
for (String uid : uids) {
148+
final K global = getGlobalByUID(uid);
149+
if (global != null) {
150+
if (globals == null) {
151+
globals = new ArrayList<K>(uids.size());
152+
}
153+
globals.add(global);
154+
}
155+
}
156+
return globals;
157+
}
158+
145159
public final K getGlobalByUID(final String uid) {
146160
return globalUids.get(uid);
147161
}
@@ -154,7 +168,7 @@ public final boolean hasLocal(final K global) {
154168
return getLocals(global) != null;
155169
}
156170

157-
public final List<K> getLocals(final K global) {
171+
public final ArrayList<K> getLocals(final K global) {
158172
return localsPerGlobal.get(global);
159173
}
160174

@@ -210,7 +224,7 @@ public final List<String> getSortedUniqueAliases(final K global) {
210224

211225
protected abstract List<K> getGlobals();
212226

213-
private static <K> boolean containsInstance(final List<K> list, final K value) {
227+
private static <K> boolean containsInstance(final ArrayList<K> list, final K value) {
214228
final int len = list.size();
215229
for (int i = 0; i < len; i++) {
216230
// identity comparison:

src/main/java/fr/jmmc/oitools/model/Analyzer.java

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ public void visit(final OIFitsFile oiFitsFile) {
9696
process(oiArray);
9797
}
9898

99-
// finally: process OIData tables:
99+
// process OIData tables:
100100
for (final OIData oiData : oiFitsFile.getOiDataList()) {
101101
process(oiData);
102102
}
103103

104+
// post-process OIData tables to compute derived columns
105+
// STA_INDEX_NAME using oiFitsFile.getUsedStaNamesMap()
106+
for (final OIData oiData : oiFitsFile.getOiDataList()) {
107+
postProcess(oiData);
108+
}
109+
104110
if (isLogDebug) {
105111
logger.log(Level.FINE, "process: OIFitsFile[{0}] usedStaNamesMap: {1}",
106112
new Object[]{oiFitsFile.getAbsoluteFilePath(), oiFitsFile.getUsedStaNamesMap().entrySet()});
@@ -296,6 +302,18 @@ private void process(final OIData oiData) {
296302
}
297303
}
298304

305+
/**
306+
* Process the given OIData table to compute derived columns
307+
* @param oiData OIData table to process
308+
*/
309+
private void postProcess(final OIData oiData) {
310+
if (isLogDebug) {
311+
logger.log(Level.FINE, "postProcess: OIData[{0}]", oiData);
312+
}
313+
314+
processStaIndexAndStaConfNames(oiData);
315+
}
316+
299317
/**
300318
* Process the given OIArray table
301319
* @param oiArray OIArray table to process
@@ -415,6 +433,38 @@ private void process(final OITarget oiTarget) {
415433
}
416434

417435
// --- baseline / configuration processing
436+
/**
437+
* Computes station index and conf names on the given OIData table
438+
* @param oiData OIData table to process
439+
*/
440+
private void processStaIndexAndStaConfNames(final OIData oiData) {
441+
final OIFitsFile oiFitsFile = oiData.getOIFitsFile();
442+
final Map<String, StaNamesDir> usedStaNamesMap = oiFitsFile.getUsedStaNamesMap();
443+
444+
if (isLogDebug) {
445+
logger.log(Level.FINE, "processStaIndexAndStaConfNames: OIData[{0}] usedStaNamesMap: {1}",
446+
new Object[]{oiData.idToString(), usedStaNamesMap.entrySet()});
447+
}
448+
449+
final int nRows = oiData.getNbRows();
450+
451+
if (nRows != 0) {
452+
// StaIndex column:
453+
final short[][] staIndexes = oiData.getStaIndex();
454+
455+
// Derived StaIndexName column:
456+
final String[] staIndexNames = oiData.getStaIndexName();
457+
458+
for (int i = 0; i < nRows; i++) {
459+
staIndexNames[i] = oiData.getRealStaNames(usedStaNamesMap, staIndexes[i]);
460+
}
461+
462+
if (isLogDebug) {
463+
logger.log(Level.FINE, "processStaIndexAndStaConfNames: OIData[{0}] done", oiData.idToString());
464+
}
465+
}
466+
}
467+
418468
/**
419469
* Process station indexes on the given OIData table
420470
* @param oiData OIData table to process
@@ -1048,10 +1098,13 @@ private void processStaConf(final OIData oiData) {
10481098
}
10491099
}
10501100

1051-
// FINALLY: Fill StaConf derived column:
1101+
// FINALLY: Fill StaConf and StaConfName derived column:
10521102
// StaIndex column:
10531103
final short[][] staIndexes = oiData.getStaIndex();
10541104

1105+
// Derived StaConfName column:
1106+
final String[] staConfNames = oiData.getStaConfName();
1107+
10551108
short[] staIndex;
10561109
for (int i = 0; i < nRows; i++) {
10571110
staIndex = staIndexes[i];
@@ -1061,8 +1114,9 @@ private void processStaConf(final OIData oiData) {
10611114

10621115
if (staConfs[i] == null) {
10631116
logger.log(Level.WARNING, "MISSING station configuration for station index:{0} !", oiData.getStaNames(staIndex));
1064-
10651117
}
1118+
// store as String (stable):
1119+
staConfNames[i] = oiData.getStaNames(staConfs[i]);
10661120
}
10671121
}
10681122

src/main/java/fr/jmmc/oitools/model/Granule.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public enum GranuleExtraField {
4949
}
5050

5151
/* members */
52-
private Target target;
53-
private InstrumentMode insMode;
54-
private NightId night;
52+
private Target target = null;
53+
private InstrumentMode insMode = null;
54+
private NightId night = null;
5555
/* extra information (filters) */
5656
/** MJD range */
5757
private Range mjdRange = null;
@@ -61,11 +61,7 @@ public enum GranuleExtraField {
6161
private Set<String> distinctStaConfs = null;
6262

6363
public Granule() {
64-
this(null, null, null);
65-
}
66-
67-
public Granule(final Target target, final InstrumentMode insMode, final NightId night) {
68-
set(target, insMode, night);
64+
super();
6965
}
7066

7167
public void set(final Target target, final InstrumentMode insMode, final NightId night) {

0 commit comments

Comments
 (0)