-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reduction.cs
170 lines (156 loc) · 6.06 KB
/
Reduction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// --------------------------------------------------------------------------------
// VariScan module
//
// Description:
//
// Environment: Windows 10 executable, 32 and 64 bit
//
// Usage: TBD
//
// Author: (REM) Rick McAlister, [email protected]
//
// Edit Log: Rev 1.0 Initial Version
//
// Date Who Vers Description
// ----------- --- ----- -------------------------------------------------------
//
// ---------------------------------------------------------------------------------
//
using System;
using System.Collections.Generic;
using System.Linq;
using TheSky64Lib;
namespace VariScan
{
public class Reduction
{
//list of calibration library names, by reduction group index (zero based)
private List<ReductionLibrary> LibraryList = new List<ReductionLibrary>();
//list of filter names, by filter index (zero based)
private string[] FilterList;
public string ReductionGroupName { get; set; } = "";
private class ReductionLibrary
{
//Calibration libraries should have format B<*>_T<*>_E<*>_F<*>
public string Name { get; set; } = "";
public string Filter { get; set; } = "";
public double Exposure { get; set; } = 0;
public int Temperature { get; set; } = 0;
public string Binning { get; set; } = "1x1";
public ReductionLibrary(string name)
{
Name = name;
List<string> codeList = (name.Split('_')).ToList();
foreach (string cType in codeList)
{
char c = cType[0];
switch (c)
{
case 'T':
{
Temperature = Convert.ToInt32(cType.Remove(0, 1));
break;
}
case 'B':
{
Binning = cType.Remove(0, 1);
break;
}
case 'E':
{
Exposure = Convert.ToDouble(cType.Remove(0, 1));
break;
};
case 'F':
{
Filter = cType.Remove(0, 1);
break;
}
default:
{
break;
}
}
}
}
}
/*
* Note: Calibration folders are expected to have the format
*
* Group_B<*>_T<*>_E<*>_F<*>
*
* Object decription
*
* Opening a reduction object produces list of calibration folders
* that can be parsed for specific temp, filter and exposure
*/
public Reduction()
{
ccdsoftCamera tsxc = new ccdsoftCamera();
//Figure out the filter mapping
//Find the filter name for the filter filter Number
FilterList = Filters.FilterNameSet();
int reductionGroupCount = tsxc.ReductionGroupCount;
for (int g = 0; g < reductionGroupCount; g++)
{
string parseName = tsxc.ReductionGroupFromIndex(g);
if (parseName.Contains("Group_"))
{
ReductionLibrary reductionLib = new ReductionLibrary(parseName);
LibraryList.Add(reductionLib);
}
}
}
/// <summary>
/// Selects and sets the Reduction Group prior to imaging a light frame
/// </summary>
/// <param name="filterNumber">Filter to be used</param>
/// <param name="exposure">Exposure length of image</param>
/// <param name="temperature">Set temperature of camera</param>
/// <param name="binning">Set binning level of image</param>
/// <returns></returns>
public bool SetReductionGroup(int filterNumber, double exposure, int temperature, string binning = "1X1")
{
{
//
ccdsoftCamera tsxc = new ccdsoftCamera();
//Translate filterNumber into filterName
string filterName = FilterList[filterNumber];
//Build sublist for filterNumber, temperature and binning
List<ReductionLibrary> rsubList = LibraryList.Where(x => (x.Filter == filterName) && (x.Temperature == temperature) && (x.Binning == binning)).ToList();
if (rsubList.Count == 0)
return false;
ReductionGroupName = ClosestExposure(rsubList, exposure);
if (ReductionGroupName != "")
{
ReductionGroupName = ReductionGroupName.Remove(0, 6);
tsxc.ReductionGroupName = ReductionGroupName;
return true;
}
else
return false;
}
}
/// <summary>
///Returns calibration library name whose exposure is closest to exposure argument
/// </summary>
/// <param name="rlib">Sublist of calibration libraries in TSX that match filter, temp and binning</param>
/// <param name="exposure">in seconds for image to be noise reduced</param>
/// <returns>name of appropriate reduction library or null if none found</returns>
private string ClosestExposure(List<ReductionLibrary> rlib, double exposure)
{
string calLibName = null;
int closest = int.MaxValue;
foreach (ReductionLibrary rl in rlib)
{
int current = (int)Math.Abs(rl.Exposure - exposure);
if (current <= closest)
{
calLibName = rl.Name;
closest = current;
}
}
return calLibName;
}
}
}