-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter improvment and some small new abilities #348
Changes from 12 commits
53df3e5
d351275
b1dfd9c
7e2d3db
4c9ce3e
e8acd32
4259f89
1bf9e96
1a75fcf
25855be
999a5bc
341420e
8bcc014
73656ff
ce6c178
8658e57
92c35ca
69a8e69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
package fact.datacorrection; | ||
|
||
import fact.Constants; | ||
import fact.Utils; | ||
import fact.io.hdureader.BinTable; | ||
import fact.io.hdureader.BinTableReader; | ||
import fact.io.hdureader.FITS; | ||
|
@@ -26,21 +27,32 @@ | |
* either as File or URL and will read the DRS data from that. This data is then | ||
* applied to all FactEvents processed by this class. | ||
* | ||
* @author Christian Bockermann <[email protected]> | ||
* @author Christian Bockermann <[email protected]> , Michael Bulinski <[email protected]> | ||
*/ | ||
public class DrsCalibration implements StatefulProcessor { | ||
static Logger log = LoggerFactory.getLogger(DrsCalibration.class); | ||
|
||
@Parameter | ||
@Parameter(required = false, description = "The data key that will hold the resulting data array.") | ||
public String outputKey = "DataCalibrated"; | ||
|
||
@Parameter(required = false, description = "Data array to be calibrated", defaultValue = "Data") | ||
public String key = "Data"; | ||
|
||
@Parameter(required = false, description = "Key to the StartCellData.") | ||
public String startCellKey = "StartCellData"; | ||
|
||
@Parameter(required = false, description = "A URL to the DRS calibration data (in FITS formats)", | ||
defaultValue = "Null. Will try to find path to drsFile from the stream.") | ||
public URL url = null; | ||
|
||
@Parameter(required = false, description = "The name of the key that holds the drs filename.", | ||
defaultValue = "@drsFile") | ||
public String drsKey = "@drsFile"; | ||
|
||
@Parameter(required = false, description = "Whether to reverse the process.", defaultValue = "false") | ||
public boolean reverse = false; | ||
|
||
Data drsData = null; | ||
|
||
private File currentDrsFile = new File(""); | ||
|
||
|
@@ -84,7 +96,6 @@ protected void loadDrsData(URL in) { | |
this.drsTriggerOffsetRms = row.getFloatArray("TriggerOffsetRms").orElseThrow(() -> new RuntimeException("File does not contain key TriggerOffsetRms")); | ||
this.drsGainMean = row.getFloatArray("GainMean").orElseThrow(() -> new RuntimeException("File does not contain key GainMean")); | ||
this.drsGainRms = row.getFloatArray("GainRms").orElseThrow(() -> new RuntimeException("File does not contain key GainRms")); | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
@@ -99,7 +110,7 @@ public Data process(Data data) { | |
|
||
if (this.url == null) { | ||
//file not loaded yet. try to find by magic. | ||
File drsFile = (File) data.get("@drsFile"); | ||
File drsFile = (File) data.get(drsKey); | ||
if (drsFile != null) { | ||
if (!drsFile.equals(currentDrsFile)) { | ||
currentDrsFile = drsFile; | ||
|
@@ -108,52 +119,67 @@ public Data process(Data data) { | |
loadDrsData(drsFile.toURI().toURL()); | ||
} catch (MalformedURLException e) { | ||
//pass. | ||
throw new RuntimeException("URL malformed"); | ||
} | ||
} | ||
} else { | ||
throw new IllegalArgumentException("No drs file set or no @drsFile key in data stream"); | ||
} | ||
} | ||
|
||
double[] rawfloatData; | ||
log.debug("Processing Data item by applying DRS calibration..."); | ||
short[] rawData = (short[]) data.get(key); | ||
if (rawData == null) { | ||
log.error(" data .fits file did not contain the value for the key " | ||
+ key + ". cannot apply drscalibration"); | ||
throw new RuntimeException( | ||
" data .fits file did not contain the value for the key \"" + key + "\". Cannot apply drs calibration)"); | ||
} | ||
if (!reverse) { | ||
short[] rawData = (short[]) data.get(key); | ||
if (rawData == null) { | ||
log.error(" data .fits file did not contain the value for the key " | ||
+ key + ". cannot apply drscalibration"); | ||
throw new RuntimeException( | ||
" data .fits file did not contain the value for the key \"" + key + "\". Cannot apply drs calibration)"); | ||
} | ||
|
||
double[] rawfloatData = new double[rawData.length]; | ||
// System.arraycopy(rawData, 0, rawfloatData, 0, rawfloatData.length); | ||
for (int i = 0; i < rawData.length; i++) { | ||
rawfloatData[i] = rawData[i]; | ||
rawfloatData = new double[rawData.length]; | ||
// System.arraycopy(rawData, 0, rawfloatData, 0, rawfloatData.length); | ||
for (int i = 0; i < rawData.length; i++) { | ||
rawfloatData[i] = rawData[i]; | ||
} | ||
} else { | ||
Utils.isKeyValid(data, key, double[].class); | ||
rawfloatData = (double[]) data.get(key); | ||
} | ||
|
||
short[] startCell = (short[]) data.get("StartCellData"); | ||
short[] startCell = (short[]) data.get(startCellKey); | ||
if (startCell == null) { | ||
log.error(" data .fits file did not contain startcell data. cannot apply drscalibration"); | ||
return null; | ||
} | ||
log.debug("raw data has {} elements", rawData.length); | ||
log.debug("raw data has {} elements", rawfloatData.length); | ||
log.debug("StartCellData has {} elements", startCell.length); | ||
|
||
double[] output = rawfloatData; | ||
if (!key.equals(outputKey)) { | ||
output = new double[rawData.length]; | ||
output = new double[rawfloatData.length]; | ||
} | ||
|
||
double[] calibrated = applyDrsCalibration(rawfloatData, output, startCell); | ||
|
||
data.put(outputKey, calibrated); | ||
double[] calibrated = applyDrsCalibration(rawfloatData, output, startCell, reverse); | ||
if (!reverse) | ||
data.put(outputKey, calibrated); | ||
else { | ||
short[] decalibratedShortData = new short[calibrated.length]; | ||
// System.arraycopy(rawData, 0, rawfloatData, 0, rawfloatData.length); | ||
for (int i = 0; i < calibrated.length; i++) { | ||
decalibratedShortData[i] = (short) calibrated[i]; | ||
} | ||
data.put(outputKey, decalibratedShortData); | ||
} | ||
|
||
// add color value if set | ||
//TODO add color value if set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just remove this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
|
||
return data; | ||
} | ||
|
||
public double[] applyDrsCalibration(double[] data, double[] destination, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think two functions would be more clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. split into two functions |
||
short[] startCellVector) { | ||
short[] startCellVector, boolean reverse_calibration) { | ||
|
||
if (destination == null || destination.length != data.length) | ||
destination = new double[data.length]; | ||
|
@@ -240,13 +266,24 @@ public double[] applyDrsCalibration(double[] data, double[] destination, | |
offsetPos = pixel * drsBaselineMean.length / Constants.N_PIXELS | ||
+ ((slice + start) % (drsBaselineMean.length / Constants.N_PIXELS)); | ||
|
||
triggerOffsetPos = pixel * drsTriggerOffsetMean.length / Constants.N_PIXELS + slice; | ||
|
||
vraw = data[pos] * dconv; | ||
vraw -= drsBaselineMean[offsetPos]; | ||
vraw -= drsTriggerOffsetMean[triggerOffsetPos]; | ||
vraw /= drsGainMean[offsetPos]; | ||
vraw *= 1907.35; | ||
triggerOffsetPos = pixel * drsTriggerOffsetMean.length / Constants.N_PIXELS | ||
+ slice; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line break makes things worse imho There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed this one and the other ones too |
||
|
||
if (!reverse_calibration) { | ||
vraw = data[pos]; | ||
vraw *= dconv; | ||
vraw -= drsBaselineMean[offsetPos]; | ||
vraw -= drsTriggerOffsetMean[triggerOffsetPos]; | ||
vraw /= drsGainMean[offsetPos]; | ||
vraw *= 1907.35; | ||
} else { | ||
vraw = data[pos]; | ||
vraw /= 1907.35; | ||
vraw *= drsGainMean[offsetPos]; | ||
vraw += drsTriggerOffsetMean[triggerOffsetPos]; | ||
vraw += drsBaselineMean[offsetPos]; | ||
vraw /= dconv; | ||
} | ||
|
||
// slice_pt = pixel_pt + sl; | ||
// drs_cal_offset = ( sl + StartCellVector[ pixel ] ) % | ||
|
@@ -286,6 +323,4 @@ public void resetState() throws Exception { | |
public void finish() throws Exception { | ||
|
||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,12 @@ public class InterpolateTimeSeries implements Processor { | |
@Parameter(required = false, description = "The minimum number of neighboring pixels required for interpolation", defaultValue = "3") | ||
public int minPixelToInterpolate = 3; | ||
|
||
@Parameter(required = false, description = "The key for the resulting badPixelSet.") | ||
public String badPixelKey = "badPixels"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this an xml Parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the processor twice, so i added this in case someone want to preserve the output and not override the key with the second processor. I think it is cleaner this way, but I can remove it. |
||
|
||
@Parameter(required = false, description = "The key to the unixTimeUTC of the Event.") | ||
public String unixTimeKey = "UnixTimeUTC"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this processor twice for different inputs with different times one will use 'UnixTimeUTC' the other 'LONS_UnixTimeUTC'. This is due to the fact that i have to calibrate the pedestal that I superimpose. |
||
|
||
private FactPixelMapping pixelMap = FactPixelMapping.getInstance(); | ||
|
||
|
||
|
@@ -46,9 +52,9 @@ public Data process(Data item) { | |
|
||
ZonedDateTime timeStamp = null; | ||
|
||
if (item.containsKey("UnixTimeUTC") == true) { | ||
Utils.isKeyValid(item, "UnixTimeUTC", int[].class); | ||
int[] eventTime = (int[]) item.get("UnixTimeUTC"); | ||
if (item.containsKey(unixTimeKey) == true) { | ||
Utils.isKeyValid(item, unixTimeKey, int[].class); | ||
int[] eventTime = (int[]) item.get(unixTimeKey); | ||
timeStamp = Utils.unixTimeUTCToZonedDateTime(eventTime); | ||
} else { | ||
// MC Files don't have a UnixTimeUTC in the data item. Here the timestamp is hardcoded to 1.1.2000 | ||
|
@@ -67,7 +73,7 @@ public Data process(Data item) { | |
} | ||
|
||
item.put(dataOutputKey, data); | ||
item.put("badPixels", badPixelSet); | ||
item.put(badPixelKey, badPixelSet); | ||
return item; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ public class PatchJumpRemoval implements Processor { | |
@Parameter(required = true) | ||
public String startCellKey = null; | ||
|
||
@Parameter(required = false, description = "The key containing the UnixTimeUTC") | ||
public String unixTimeKey = "UnixTimeUTC"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this processor twice for different inputs with different times one will use 'UnixTimeUTC' the other 'LONS_UnixTimeUTC'. This is due to the fact that i have to calibrate the pedestal that I superimpose. |
||
|
||
@Parameter | ||
public double jumpLimit = 5.0; | ||
|
||
|
@@ -94,10 +97,10 @@ public Data process(Data item) { | |
Utils.isKeyValid(item, prevEventsKey, PreviousEventInfoContainer.class); | ||
Utils.isKeyValid(item, startCellKey, short[].class); | ||
Utils.isKeyValid(item, "NROI", Integer.class); | ||
Utils.isKeyValid(item, "UnixTimeUTC", int[].class); | ||
Utils.isKeyValid(item, unixTimeKey, int[].class); | ||
|
||
// Get variables out of data item | ||
int[] currentTime = (int[]) item.get("UnixTimeUTC"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This processor apperently still uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently intentional, this is because the |
||
int[] currentTime = (int[]) item.get(unixTimeKey); | ||
roi = (Integer) item.get("NROI"); | ||
short[] currentStartCells = (short[]) item.get(startCellKey); | ||
double[] data = (double[]) item.get(dataKey); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,9 @@ public class SourcePosition implements StatefulProcessor { | |
@Service(required = false, description = "Name of the service that provides aux files") | ||
public AuxiliaryService auxService; | ||
|
||
@Parameter(required = false, description = "The key containing the UnixTimeUTC") | ||
public String unixTimeKey = "UnixTimeUTC"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a Parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this processor twice for different inputs with different times one will use 'UnixTimeUTC' the other 'LONS_UnixTimeUTC'. This is due to the fact that i have to get the sourceposition of the pedestal that I superimpose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is LONS supposed to mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Light of night sky' before it was PED but we already have stuff that is called pedestal so I use LONS, that way there is no conflict with the other stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm against inventing new abbreviations that nobody uses. The commonly used abbreviation is |
||
|
||
@Parameter(description = "If set, the fixed x position of the source in mm") | ||
public Double x = null; | ||
|
||
|
@@ -133,9 +136,9 @@ public Data process(Data data) { | |
|
||
} else { | ||
// Assume observations | ||
int[] unixTimeUTC = (int[]) data.get("UnixTimeUTC"); | ||
int[] unixTimeUTC = (int[]) data.get(unixTimeKey); | ||
if (unixTimeUTC == null) { | ||
log.error("The key \"UnixTimeUTC\" was not found in the event. Ignoring event"); | ||
log.error("The key \""+unixTimeKey+"\" was not found in the event. Ignoring event"); | ||
return null; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* | ||
*/ | ||
package fact.utils; | ||
|
||
import fact.Utils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import stream.Data; | ||
import stream.Processor; | ||
import stream.annotations.Parameter; | ||
|
||
/** | ||
* Combine two Pixel Arrays of the same size with each other | ||
* Allows for either addition, substraction, multiplication or division. | ||
* | ||
* @author Michael Bulinski <[email protected]> | ||
*/ | ||
public class CombineDataArrays implements Processor { | ||
static Logger log = LoggerFactory.getLogger(RemappingKeys.class); | ||
|
||
@Parameter(required = true, description = "The key to your first array.") | ||
public String firstArrayKey; | ||
@Parameter(required = true, description = "The key to your second array.") | ||
public String secondArrayKey; | ||
@Parameter(required = false, description = "The key for the resulting array.") | ||
public String outputKey; | ||
@Parameter(required = true, description = "The operation to perform, (add, sub, mul, div)") | ||
public String op; | ||
|
||
|
||
/* (non-Javadoc) | ||
* @see stream.Processor#process(stream.Data) | ||
*/ | ||
@Override | ||
public Data process(Data input) { | ||
Utils.isKeyValid(input, firstArrayKey, double[].class); | ||
Utils.isKeyValid(input, secondArrayKey, double[].class); | ||
|
||
double[] array1 = (double[]) input.get(firstArrayKey); | ||
double[] array2 = (double[]) input.get(secondArrayKey); | ||
|
||
if (array1.length != array2.length) { | ||
throw new RuntimeException("Given arrays are different lengths"); | ||
} | ||
double[] resultArray = new double[array1.length]; | ||
|
||
|
||
if (op.equals("add")) { | ||
for (int pix = 0; pix < array1.length; pix++) { | ||
resultArray[pix] = (double) (array1[pix] + array2[pix]); | ||
} | ||
} else if (op.equals("sub")) { | ||
for (int pix = 0; pix < array1.length; pix++) { | ||
resultArray[pix] = (double) (array1[pix] - array2[pix]); | ||
} | ||
} else if (op.equals("mul")) { | ||
for (int pix = 0; pix < array1.length; pix++) { | ||
resultArray[pix] = (double) (array1[pix] * array2[pix]); | ||
} | ||
} else if (op.equals("div")) { | ||
for (int pix = 0; pix < array1.length; pix++) { | ||
resultArray[pix] = (double) (array1[pix] / array2[pix]); | ||
} | ||
} else { | ||
throw new RuntimeException("The given operation op: " + op + " is not supported"); | ||
} | ||
|
||
input.put(outputKey, resultArray); | ||
|
||
return input; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,11 @@ public class PreviousEventInfo implements Processor { | |
@Parameter(required = true) | ||
public String outputKey = null; | ||
|
||
int limitEvents = 20; | ||
@Parameter(required = false, description = "The key containing the UnixTimeUTC") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the case someone wants to set it, we have an variable in 'settings.properties' for this but no way to set it in this processor (only in the jumpRemoval). So either this one goes or, the thing in setting.properties makes little sense because it is a constant. |
||
public String unixTimeKey = "UnixTimeUTC"; | ||
|
||
@Parameter(required = false, description = "Set the amount of events to buffer for the jumpremoval.") | ||
public int limitEvents = 20; | ||
|
||
PreviousEventInfoContainer previousEventInfo = new PreviousEventInfoContainer(); | ||
|
||
|
@@ -28,9 +32,9 @@ public Data process(Data item) { | |
|
||
Utils.isKeyValid(item, startCellKey, short[].class); | ||
Utils.isKeyValid(item, "NROI", Integer.class); | ||
Utils.isKeyValid(item, "UnixTimeUTC", int[].class); | ||
Utils.isKeyValid(item, unixTimeKey, int[].class); | ||
|
||
int[] eventTime = (int[]) item.get("UnixTimeUTC"); | ||
int[] eventTime = (int[]) item.get(unixTimeKey); | ||
short[] startCellArray = (short[]) item.get(startCellKey); | ||
int length = (Integer) item.get("NROI"); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this one and the other.