Commit b9a32b13 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Improved DID_INS_* interpolation by local correction of ts_master to GPS

time using near 1pps sample
parent 2b8ae048
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -5525,14 +5525,20 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
			EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
			EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
			CLT_PARAMETERS.batch_run = true;
			CLT_PARAMETERS.batch_run = true;
			String imx_logs = CORRECTION_PARAMETERS.getImsSourceDirectory(); // sourceImsDirectory;
			String imx_logs = CORRECTION_PARAMETERS.getImsSourceDirectory(); // sourceImsDirectory;
			String debug_path = null; // CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"debug_local_master";
			if (EVENT_LOGGER == null) {
			if (EVENT_LOGGER == null) {
				if ((imx_logs != null) && !imx_logs.equals("")) {
				if ((imx_logs != null) && !imx_logs.equals("")) {
					EVENT_LOGGER = new EventLogger (imx_logs);
					EVENT_LOGGER = new EventLogger (
							imx_logs,
							debug_path);
				} else {
				} else {
					System.out.println("sourceImsDirectory is not set. Use Setup CLT Batch parameters to define it.");
					System.out.println("sourceImsDirectory is not set. Use Setup CLT Batch parameters to define it.");
				}
				}
			}
			}
			if (EVENT_LOGGER != null) {
			if (EVENT_LOGGER != null) {
				//print2Pps
				EVENT_LOGGER.print2Pps(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"rec_1pps");
				EVENT_LOGGER.printStrobeInTime(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_strobe_in_time");
				EVENT_LOGGER.printPimu(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_pimu");
				EVENT_LOGGER.printPimu(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_pimu");
				EVENT_LOGGER.printGps(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_gps", 7);
				EVENT_LOGGER.printGps(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_gps", 7);
				EVENT_LOGGER.printDidIns1(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_ins1");
				EVENT_LOGGER.printDidIns1(CORRECTION_PARAMETERS.getImsPrintDirectory()+Prefs.getFileSeparator()+"did_ins1");
+8 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,14 @@ public abstract class Did_ins <T extends Did_ins <T>>{
		return frac * v_next + (1.0 - frac) * v_this;
		return frac * v_next + (1.0 - frac) * v_this;
	}
	}
	
	
	public double getDoubleTime() {
		return ((double) week) * WEEK_SECONDS + timeOfWeek;
	}
	
	public int [] getWeekTimeMs() { // for compatibility with DID_STROBE_IN_TIME
		return new int [] { week, (int)Math.round(timeOfWeek * 1000.0)}; 
	}
	
//https://www.swtestacademy.com/return-subclass-instance-java-generics/	
//https://www.swtestacademy.com/return-subclass-instance-java-generics/	
	public void interpolateBase(double frac, T next_did, T new_did) {
	public void interpolateBase(double frac, T next_did, T new_did) {
		new_did.week =     this.week;
		new_did.week =     this.week;
+24 −0
Original line number Original line Diff line number Diff line
@@ -2,6 +2,9 @@ package com.elphel.imagej.ims;


import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ByteOrder;
import java.util.Properties;

import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;


/* (DID_STROBE_IN_TIME) Timestamp for input strobe.
/* (DID_STROBE_IN_TIME) Timestamp for input strobe.
typedef struct PACKED
typedef struct PACKED
@@ -121,4 +124,25 @@ public class Did_strobe_in_time {
		s += String.format("count:        %d\n", count); 
		s += String.format("count:        %d\n", count); 
		return s;
		return s;
	}
	}
	
	
 	public void getProperties(String prefix, Properties properties) {
		if (properties.getProperty(prefix+"week")!=null)         this.week= Integer.parseInt(properties.getProperty(prefix+"week"));
		if (properties.getProperty(prefix+"timeOfWeekMs")!=null) this.timeOfWeekMs= Integer.parseInt(properties.getProperty(prefix+"week"));
		if (properties.getProperty(prefix+"pin")!=null)          this.pin= Integer.parseInt(properties.getProperty(prefix+"pin"));
		if (properties.getProperty(prefix+"count")!=null)        this.count= Integer.parseInt(properties.getProperty(prefix+"count"));
	}
 	
	public Properties setProperties(String prefix, Properties properties){ // save // USED in lwir
		if (properties == null) {
			properties = new Properties();
		}
		properties.setProperty(prefix+"week",         this.week+"");
		properties.setProperty(prefix+"timeOfWeekMs", this.timeOfWeekMs+"");
		properties.setProperty(prefix+"pin",          this.pin+"");
		properties.setProperty(prefix+"count",        this.count+"");
		return properties;
	}
	
	
}
}
 No newline at end of file
+64 −44
Original line number Original line Diff line number Diff line
@@ -14,8 +14,7 @@ import ij.Prefs;


public class EventLogger {
public class EventLogger {
	public  EventLoggerFileInfo [] logger_files;
	public  EventLoggerFileInfo [] logger_files;

	public EventLogger (String dir, String debug_prefix) { // dir should contain only event logger files
	public EventLogger (String dir) { // dir should contain only event logger files
		if (!dir.endsWith(Prefs.getFileSeparator())) {
		if (!dir.endsWith(Prefs.getFileSeparator())) {
			dir+=Prefs.getFileSeparator();
			dir+=Prefs.getFileSeparator();
		}
		}
@@ -26,8 +25,9 @@ public class EventLogger {
			      .collect(Collectors.toSet()));
			      .collect(Collectors.toSet()));
		logger_files = new EventLoggerFileInfo [files.size()];
		logger_files = new EventLoggerFileInfo [files.size()];
		for (int nf = 0; nf < logger_files.length; nf++) { // may use threads (per file)
		for (int nf = 0; nf < logger_files.length; nf++) { // may use threads (per file)
			String debug_path= (debug_prefix != null) ? (debug_prefix+nf+".csv") : null;
			try {
			try {
				logger_files[nf] = new EventLoggerFileInfo(dir+files.get(nf), false);
				logger_files[nf] = new EventLoggerFileInfo(dir+files.get(nf), false, debug_path);
			} catch (IOException e) {
			} catch (IOException e) {
				logger_files[nf] = null;
				logger_files[nf] = null;
				e.printStackTrace();
				e.printStackTrace();
@@ -38,43 +38,6 @@ public class EventLogger {
//		testInterpolateDidIns1();
//		testInterpolateDidIns1();
//		testInterpolateDidIns1();
//		testInterpolateDidIns1();
//		testInterpolateDidIns1();
//		testInterpolateDidIns1();
		/*
//		String out_did_gps_path = "/home/elphel/lwir16-proc/office_04/did_gps";
		String out_did_gps_path = dir+"../did_gps/did_gps";
		out_did_gps_path = Paths.get(out_did_gps_path).normalize().toString();
		Path op_did_gps = Paths.get(out_did_gps_path);
		op_did_gps=op_did_gps.normalize();
		(new File(op_did_gps.getParent().toString())).mkdirs();
		int gps_mask = 7; // +1 - DID_GPS1_POS, +2 - DID_GPS2_POS, +4 - DID_GPS1_UBX_POS
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_did_gps_path+"-"+String.format("%03d", nf)+".out";
			System.out.println("Printing all DID_GPS data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
				logger_files[nf].listGPS(out_path, gps_mask, false);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		*/
//		String out_did1_path = "/media/elphel/SSD3-4GB/lwir16-proc/berdich/ims/test_out/did_ins1";
		/*
		String out_did1_path = dir+"../did_ins1/did_ins1";
		out_did1_path = Paths.get(out_did1_path).normalize().toString();
		Path op_did1 = Paths.get(out_did1_path);
		op_did1=op_did1.normalize();
		(new File(op_did1.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_did1_path+"-"+String.format("%03d", nf)+".out";
			System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
				logger_files[nf].listDid1(out_path,false);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		*/
		System.out.println("Processed "+logger_files.length+" event log files");
		System.out.println("Processed "+logger_files.length+" event log files");
	}
	}
	
	
@@ -86,7 +49,7 @@ public class EventLogger {
		op_did_gps=op_did_gps.normalize();
		op_did_gps=op_did_gps.normalize();
		(new File(op_did_gps.getParent().toString())).mkdirs();
		(new File(op_did_gps.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_did_gps_path+"-"+String.format("%03d", nf)+".out";
			String out_path= out_did_gps_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_GPS data in "+logger_files[nf].abs_path+" to "+out_path);
			System.out.println("Printing all DID_GPS data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
			try {
				logger_files[nf].listGPS(out_path, gps_mask, false);
				logger_files[nf].listGPS(out_path, gps_mask, false);
@@ -104,7 +67,7 @@ public class EventLogger {
		op_did1=op_did1.normalize();
		op_did1=op_did1.normalize();
		(new File(op_did1.getParent().toString())).mkdirs();
		(new File(op_did1.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_did1_path+"-"+String.format("%03d", nf)+".out";
			String out_path= out_did1_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
			System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
			try {
				logger_files[nf].listDidIns1(out_path,false);
				logger_files[nf].listDidIns1(out_path,false);
@@ -121,7 +84,7 @@ public class EventLogger {
		op_did2=op_did2.normalize();
		op_did2=op_did2.normalize();
		(new File(op_did2.getParent().toString())).mkdirs();
		(new File(op_did2.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_did2_path+"-"+String.format("%03d", nf)+".out";
			String out_path= out_did2_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_INS_2 data in "+logger_files[nf].abs_path+" to "+out_path);
			System.out.println("Printing all DID_INS_2 data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
			try {
				logger_files[nf].listDidIns2(out_path,false);
				logger_files[nf].listDidIns2(out_path,false);
@@ -138,7 +101,7 @@ public class EventLogger {
		op_pimu=op_pimu.normalize();
		op_pimu=op_pimu.normalize();
		(new File(op_pimu.getParent().toString())).mkdirs();
		(new File(op_pimu.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_pimu_path+"-"+String.format("%03d", nf)+".out";
			String out_path= out_pimu_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
			System.out.println("Printing all DID_INS_1 data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
			try {
				logger_files[nf].listPimu(out_path,false);
				logger_files[nf].listPimu(out_path,false);
@@ -149,6 +112,40 @@ public class EventLogger {
		}
		}
	}
	}
	
	
	public void printStrobeInTime(String out_sit_path) {
		out_sit_path = Paths.get(out_sit_path).normalize().toString();
		Path op_sit = Paths.get(out_sit_path);
		op_sit=op_sit.normalize();
		(new File(op_sit.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_sit_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_STROBE_IN_TIME data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
				logger_files[nf].listStrobeInTime(out_path,false);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public void print2Pps(String out_1pps_path) {
		out_1pps_path = Paths.get(out_1pps_path).normalize().toString();
		Path op_1pps = Paths.get(out_1pps_path);
		op_1pps=op_1pps.normalize();
		(new File(op_1pps.getParent().toString())).mkdirs();
		for (int nf = 0; nf < logger_files.length; nf++) {
			String out_path= out_1pps_path+"-"+String.format("%03d", nf)+".csv";
			System.out.println("Printing all DID_STROBE_IN_TIME data in "+logger_files[nf].abs_path+" to "+out_path);
			try {
				logger_files[nf].list1Pps(out_path,false);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	
	public void testInterpolateDidIns1() {
	public void testInterpolateDidIns1() {
		boolean exit_now = false;
		boolean exit_now = false;
@@ -353,6 +350,29 @@ public class EventLogger {
			}
			}
			return Double.NaN;
			return Double.NaN;
		}
		}
		// if it is DID_INS_1 or DID_INS_2 use TOW for calculating fraction
		if ((did == Imx5.DID_INS_1) || (did == Imx5.DID_INS_2)) {
			double tow_corr = logger_files[file_index_below].getTimeOfWeekCorrection(ts_master);
			int week0, week1;
			double tow0, tow1;
			if (!Double.isNaN(tow_corr)) { 
				double tow = logger_files[file_index_below].getLinearTimeOfWeek(ts_master) - tow_corr;
				@SuppressWarnings("rawtypes")
				Did_ins did_ins_0 = (did == Imx5.DID_INS_2) ?
						(new Did_ins_2(ByteBuffer.wrap(payload[0]))) : (new Did_ins_1(ByteBuffer.wrap(payload[0])));
				@SuppressWarnings("rawtypes")
				Did_ins did_ins_1 = (did == Imx5.DID_INS_2) ?
						(new Did_ins_2(ByteBuffer.wrap(payload[1]))) : (new Did_ins_1(ByteBuffer.wrap(payload[1])));
				tow0 = did_ins_0.timeOfWeek;
				tow1 = did_ins_1.timeOfWeek;
				if (did_ins_1.week > did_ins_0.week) {
					tow1+=	Did_ins.WEEK_SECONDS;
				}
				frac = (tow - tow0) /(tow1-tow0);
			} else {
				System.out.println("ERROR: getDidAtTS(): tow_corr is NaN, keeping frac="+frac);
			}
		}
		return frac; 
		return frac; 
	}
	}
	
	
Loading