Skip to content

Commit

Permalink
major refactoring (column error, column orientation) to interpret (so…
Browse files Browse the repository at this point in the history
…rted) StaNames (baselines/triplets), MJD Ranges (rounded to 1s) and filter on baselines, mjd ranges and wavelength ranges (in progress) in Merger / OIFitsProcessor (CLI)
  • Loading branch information
bourgesl committed Apr 20, 2021
1 parent 00e3cef commit 47fe4ed
Show file tree
Hide file tree
Showing 89 changed files with 6,103 additions and 4,213 deletions.
Binary file added lib/jel-2.1.2.jar
Binary file not shown.
14 changes: 9 additions & 5 deletions parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
<!-- 2021.04.15: Java 8 required -->
<source>8</source>
<target>8</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -278,19 +279,22 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<dependency>
<groupId>org.gnu.jel</groupId>
<artifactId>JEL</artifactId>
<version>2.1.1-jdk5</version>
<version>2.1.2</version>
</dependency>

</dependencies>
Expand All @@ -82,10 +82,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<inherited>false</inherited>
<phase>process-resources</phase> <!-- just before compilation -->
<configuration>
<file>lib/jel-2.1.1_jdk5.jar</file>
<file>lib/jel-2.1.2.jar</file>
<groupId>org.gnu.jel</groupId>
<artifactId>JEL</artifactId>
<version>2.1.1-jdk5</version>
<version>2.1.2</version>
<packaging>jar</packaging>
</configuration>
</execution>
Expand Down
42 changes: 27 additions & 15 deletions src/main/java/fr/jmmc/jmcs/util/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class NumberUtils {
private final static NumberFormat _fmtDef;
/** scientific formatter */
private final static NumberFormat _fmtScience = new DecimalFormat("0.000E0");

static {
_fmtDef = new DecimalFormat("0.000");
}
Expand Down Expand Up @@ -85,14 +85,14 @@ public static boolean isFinite(final float value) {

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

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

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

/**
Expand All @@ -127,6 +127,9 @@ public static boolean isFinitePositive(final double value) {
* @return double value with only 1 decimal digit
*/
public static double trimTo1Digits(final double value) {
if (!Double.isFinite(value)) {
return value;
}
return ((long) (10.0 * value)) / 10.0;
}

Expand All @@ -136,6 +139,9 @@ public static double trimTo1Digits(final double value) {
* @return double value with only 3 decimal digits
*/
public static double trimTo3Digits(final double value) {
if (!Double.isFinite(value)) {
return value;
}
return ((long) (1e3d * value)) / 1e3d;
}

Expand All @@ -145,6 +151,9 @@ public static double trimTo3Digits(final double value) {
* @return double value with only 5 decimal digits
*/
public static double trimTo5Digits(final double value) {
if (!Double.isFinite(value)) {
return value;
}
return ((long) (1e5d * value)) / 1e5d;
}

Expand All @@ -154,6 +163,9 @@ public static double trimTo5Digits(final double value) {
* @return double value with only 9 decimal digits
*/
public static double trimTo9Digits(final double value) {
if (!Double.isFinite(value)) {
return value;
}
return ((long) (1e9d * value)) / 1e9d;
}

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

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

/** lower value */
static final int low = -1024;
static final int LOW = -1024;
/** higher value */
static final int high = 128 * 1024;
static final int HIGH = 128 * 1024;
/** Integer cache */
static final Integer cache[];
static final Integer[] CACHE;

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

cache = new Integer[(high - low) + 1];
int j = low;
for (int k = 0, len = cache.length; k < len; k++) {
cache[k] = Integer.valueOf(j++);
CACHE = new Integer[(HIGH - LOW) + 1];
int j = LOW;
for (int k = 0, len = CACHE.length; k < len; k++) {
CACHE[k] = Integer.valueOf(j++);
}
}

Expand All @@ -396,8 +408,8 @@ private static final class IntegerCache {
* @return cached Integer instance or new one
*/
static Integer get(final int i) {
if (i >= low && i <= high) {
return cache[i + (-low)];
if (i >= LOW && i <= HIGH) {
return CACHE[i + (-LOW)];
}
return Integer.valueOf(i);
}
Expand Down
105 changes: 98 additions & 7 deletions src/main/java/fr/jmmc/oitools/OIFitsCollectionViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
import fr.jmmc.oitools.model.Target;
import fr.jmmc.oitools.model.TargetIdMatcher;
import fr.jmmc.oitools.model.TargetManager;
import fr.jmmc.oitools.model.range.Range;
import fr.jmmc.oitools.util.StationNamesComparator;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -43,6 +49,15 @@
*/
public final class OIFitsCollectionViewer {

/** Logger */
protected final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(OIFitsCollectionViewer.class.getName());

/* constants */
private final static String SEP = "\t";

/** double formatter for MJD (6 digits) to have 1s precision */
private final static NumberFormat df6 = new DecimalFormat("0.00000#");

private OIFitsCollectionViewer() {
super();
}
Expand Down Expand Up @@ -79,11 +94,11 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
final InstrumentMode gInsMode = granule.getInsMode();
// OIWavelength info
final String insName = gInsMode.getInsName(); // global UID
final float minWavelength = gInsMode.getLambdaMin();
final float maxWavelength = gInsMode.getLambdaMax();
final int nbChannels = gInsMode.getNbChannels();
final double minWavelength = gInsMode.getLambdaMin();
final double maxWavelength = gInsMode.getLambdaMax();
// Resolution = lambda / delta_lambda
final float resPower = gInsMode.getResPower();
final double resPower = gInsMode.getResPower();

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

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

for (int i = 0; i < targetIds.length; i++) {
boolean match = false;

for (int i = 0; i < nbRows; i++) {
// same target and same night:
if (targetIdMatcher.match(targetIds[i]) && (gNightId == nightIds[i])) {
// TODO: count flag? what to do with flagged measures?
Expand Down Expand Up @@ -136,10 +154,11 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
if (t < intTime) {
intTime = t;
}
}
}

if (facilityName.isEmpty() && oiData.getArrName() != null) {
match = true;
}
} // rows
if (match && facilityName.isEmpty() && oiData.getArrName() != null) {
facilityName = oiData.getArrName(); // potential multiple ARRNAME values !
}
}
Expand All @@ -153,4 +172,76 @@ public static void targetMetadata(final OIFitsCollection oiFitsCollection, final
}
}
}

public static void processBaselines(final OIFitsCollection oiFitsCollection) {
final StringBuilder sb = new StringBuilder(1024);

baselinesPerGranule(oiFitsCollection, sb);

OIFitsCommand.info(sb.toString());
}

public static void baselinesPerGranule(final OIFitsCollection oiFitsCollection, final StringBuilder out) {
out.append("instrument_name").append(SEP)
.append("em_min").append(SEP)
.append("em_max").append(SEP)
.append("night_id").append(SEP)
.append("target_name").append(SEP)
.append("s_ra").append(SEP)
.append("s_dec").append(SEP)
.append("mjds").append(SEP)
.append("baselines").append('\n');

final List<Granule> granules = oiFitsCollection.getSortedGranules();

final List<String> sortedStaNames = new ArrayList<String>(16);
final List<Range> sortedMJDRanges = new ArrayList<Range>(16);

for (Granule granule : granules) {
final Target gTarget = granule.getTarget();
// Target info
final String targetName = gTarget.getTarget(); // global UID
final double targetRa = gTarget.getRaEp0();
final double targetDec = gTarget.getDecEp0();

final InstrumentMode gInsMode = granule.getInsMode();
// OIWavelength info
final String insName = gInsMode.getInsName(); // global UID
final double minWavelength = gInsMode.getLambdaMin();
final double maxWavelength = gInsMode.getLambdaMax();

// night
final int gNightId = granule.getNight().getNightId();

// Sort StaNames by name:
sortedStaNames.clear();
sortedStaNames.addAll(granule.getDistinctStaNames());
Collections.sort(sortedStaNames, StationNamesComparator.INSTANCE);

// Sort MJD Ranges:
sortedMJDRanges.clear();
sortedMJDRanges.addAll(granule.getDistinctMjdRanges());
Collections.sort(sortedMJDRanges);

out.append(insName).append(SEP)
.append(minWavelength).append(SEP)
.append(maxWavelength).append(SEP)
.append(gNightId).append(SEP)
.append(targetName).append(SEP)
.append(targetRa).append(SEP)
.append(targetDec).append(SEP);

// distinct MJD ranges:
for (Range r : sortedMJDRanges) {
out.append('[').append(df6.format(r.getMin())).append(',').append(df6.format(r.getMax())).append("] ");
}
out.append(SEP);

// distinct StaNames:
for (String staName : sortedStaNames) {
out.append(staName).append(' ');
}
out.append('\n');
}
}
}
15 changes: 11 additions & 4 deletions src/main/java/fr/jmmc/oitools/OIFitsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
public final static String COLUMN_SPATIAL_FREQ = "SPATIAL_FREQ";
/** NIGHT_ID derived OiData column as double[] */
public final static String COLUMN_NIGHT_ID = "NIGHT_ID";
/** MJD_START derived OiData column as double[] */
public final static String COLUMN_MJD_START_R = "MJD_START";
/** MJD_END derived OiData column as double[] */
public final static String COLUMN_MJD_END_R = "MJD_END";
/** UCOORD_SPATIAL derived OIData column as double[][] */
public final static String COLUMN_UCOORD_SPATIAL = "UCOORD_SPATIAL";
/** VCOORD_SPATIAL derived OIData column as double[][] */
Expand All @@ -434,7 +438,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
public final static String COLUMN_U2COORD_SPATIAL = "U2COORD_SPATIAL";
/** V2COORD_SPATIAL derived OIData column as double[][] */
public final static String COLUMN_V2COORD_SPATIAL = "V2COORD_SPATIAL";

/** SNR_VIS2 derived OIVIS2 column as double[][] */
public final static String COLUMN_SNR_VIS2 = "SNR_VIS2";
/** SNR_MODEL_VIS2 derived OIVIS2 column as double[][] */
Expand All @@ -445,7 +449,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
public final static String COLUMN_SNR_NS_PHOT = "SNR_NS_PHOT";
/** RES_VIS2_MODEL derived OIVIS2 column as double[][] */
public final static String COLUMN_RES_VIS2_MODEL = "RES_VIS2_MODEL";

/** SNR_VISAMP derived OIVIS column as double[][] */
public final static String COLUMN_SNR_VISAMP = "SNR_VISAMP";
/** SNR_VISPHI derived OIVIS column as double[][] */
Expand All @@ -454,7 +458,7 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
public final static String COLUMN_RES_VISAMP_MODEL = "RES_VISAMP_MODEL";
/** RES_VISPHI_MODEL derived OIVIS column as double[][] */
public final static String COLUMN_RES_VISPHI_MODEL = "RES_VISPHI_MODEL";

/** SNR_T3AMP derived T3 column as double[][] */
public final static String COLUMN_SNR_T3AMP = "SNR_T3AMP";
/** SNR_T3PHI derived T3 column as double[][] */
Expand All @@ -463,7 +467,10 @@ NS_MODEL_T3PHIERR D(NWAVE) Model of the error in triple-product phase in degrees
public final static String COLUMN_RES_T3AMP_MODEL = "RES_T3AMP_MODEL";
/** RES_T3PHI_MODEL derived T3 column as double[][] */
public final static String COLUMN_RES_T3PHI_MODEL = "RES_T3PHI_MODEL";


/** SNR_FLUX derived OI_FLUX column as double[][] */
public final static String COLUMN_SNR_FLUX = "SNR_FLUX";

/** Resolution value */
public final static String VALUE_RESOLUTION = "RESOLUTION";
}
Loading

0 comments on commit 47fe4ed

Please sign in to comment.