// Compute pattern angle of a vector on the sky
double procedure AngleFromVector {
{double,double} vector = {1.0,1.0}; // Vector
}{
double degpi = 180.0 / 3.14159265;
double fullcircle = 360.0;
double angle = atan2(vector{0},vector{1}) * degpi;
// translate into range between 0 and 360 degrees
angle = (angle + fullcircle) % fullcircle;
return angle;
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the OTF observing mode
procedure OTFmap_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // chunk size given by the data rates and optimum speed
int nlines_tot = 1; // Total number of lines to scan
int n_linesperscan = 1; // Number of lines between two OFFs
int n_intoff = 3; // Number of data dumps for the OFF integration time
int n_pp = 10; // Number of data dumps per line
int n_loadinterval = 1; // number of nods before a load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,2,2,40,10,20,21,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int toffslew = telescopetimes[6];
// slew dead time between points
int tline = telescopetimes[4];
// Time in line
// The telescope slew can be a bit further than requested
int line_inttime = n_pp * data_time;
{int,int} otfline = OtfTelescopeLine(line_inttime,tline);
int line_startdelay = otfline{1};
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
// Count OFFs by hand, their counter is not returned in the state array
int ioff = 0;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
if(state[0] == 4) {
// OFF Integration
HIFIConfigureContIntegration(data_time,n_intoff,band,lo_freq,backendreadoutparms);
HIFIContOffIntegration(data_time,n_intoff,rates);
// OFF counter
ioff = ioff + 1;
// Check for normal slew after OFF
if(state[2] * state[3] < nlines_tot) {
HIFIActiveHK("normal",toffslew);
}
}
if(state[0] == 8) {
// OTF integration
delay(line_startdelay);
// Check whether we come from the OFF
if((state[2] + n_linesperscan - 1) % n_linesperscan == 0) {
HIFIConfigureContIntegration(data_time,n_pp,band,lo_freq,backendreadoutparms);
}
HIFIContOnIntegration(data_time,n_pp,rates);
// Check for normal slew towards the OFF
if(state[2] % n_linesperscan == 0) {
if(ioff % n_loadinterval > 0) {
HIFIActiveHK("normal",toffslew);
}
}
}
if(state[0] == 9) {
// Load slew
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
if(state[0] == 5) {
// Final hold - close observation
delay(readoutdead);
HIFICloseObs();
}
}
}
//////////////////////////////////////////////////////////////////
// Procedure to compute detailed pre timing for the version of the
// frequency switch mode with baseline measurement
//
{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int} procedure FSwitch_pre_timing {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_chop_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on ON
int n_chop_off = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF calibration cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// First check validity of frequencies
CheckLOFrequencies(band,lo_freq + min(freq_throw,0.0),lo_freq + max(freq_throw,0.0));
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// First perform consistency checks
// Check chunk size given by the data rates
CheckDataTaking(backendreadoutparms,data_time);
CheckDataTaking(backendreadoutparms,data_time_off);
CheckFswOutOfBand(band,lo_freq,freq_throw,backendreadoutparms);
int jitterdead = GetMaxTimeJitter(band,lo_freq);
// Compute parameters for the instrument timing
int on_inttime = 2 * n_chop_on * data_time;
int off_inttime = 2 * n_chop_off * data_time_off;
// compute load integration time
int loadlength = duration(DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms));
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
loadlength = loadlength + readoutdead;
// For double phases I can use the added jitterdead in both phases for load
int halfloadlength = (loadlength - jitterdead + 1) / 2;
// Compare load interval and position switch interval
int load_spacing = CheckedLoadSpacing(load_interval - loadlength,8);
int n_load_on = on_inttime / load_spacing;
int n_load_off = off_inttime / load_spacing;
// This determines the order of the loops
if(load_spacing > 2 * on_inttime) {
int n_per_on = n_chop_on;
bool end_load_on = false;
int on_pointing = on_inttime + jitterdead;
} else {
n_per_on = n_chop_on / (n_load_on + 1);
if(n_per_on < 1) {
SError("FS phase length on source too long relative to load period.");
}
end_load_on = true;
on_inttime = 2 * n_per_on * (n_load_on + 1) * data_time;
on_pointing = on_inttime + halfloadlength + n_load_on * loadlength + jitterdead;
}
if(load_spacing > 2 * off_inttime) {
int n_per_off = n_chop_off;
bool end_load_off = false;
int off_pointing = off_inttime + jitterdead;
} else {
n_per_off = n_chop_off / (n_load_off + 1);
if(n_per_off < 1) {
SError("FS phase length on OFF position too long relative to load period.");
}
end_load_off = true;
off_inttime = 2 * n_per_off * (n_load_off + 1) * data_time_off;
off_pointing = off_inttime + halfloadlength + n_load_off * loadlength + jitterdead;
}
// Duration of initial set up
// determine exact duration only in case of full commanding
if(docommands) {
int initlength = duration(HIFIInitObs());
initlength = initlength + duration(TuneHIFIFsw(band,lo_freq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},"normal"));
// Add time for HK readout
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
initlength = initlength + hkduration;
} else {
initlength = GetRoughInitLength(band,lo_freq,true);
}
initlength = initlength + loadlength;
// Compute the overall cycle length
// First estimate of the load interval
int n_loadinterval = imax(load_interval / (on_pointing + off_pointing),1);
// Exception handling for very uneven phases
if(end_load_on || end_load_off) {
n_loadinterval = 1;
}
// dangling time given by readout dead time
int dangling = readoutdead;
// Return all the times needed for telescope call and post_timing processing
return {on_inttime,off_inttime,on_pointing,off_pointing,loadlength,jitterdead,load_spacing,n_loadinterval,n_per_on,n_per_off,n_load_on,n_load_off,end_load_on,end_load_off,initlength,dangling};
}
// common statistics messages
procedure PerformanceMessages {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{double,double,double,double,double} noisevalues = {1.0,1.0,1.0,1.0,0.0}; // Noise values from noisecomputer
int totaltime = 180; // HIFI time without initial slew
double posinttime = 10.0; // Integration time on source
double posofftime = 10.0; // Integration time on OFF
double timeefficiency = 0.5; // time efficiency
double noiseefficiency = 0.125; // noise efficiency
double relnoise = 0.01; // drift noise contribution
bool reduced = false; // whether deconvolution is assumed
}{
// close any previous messages
message("
");
message("Observing mode performance
");
message("Noise predictions");
message("Fluctuation bandwidth | ");
if(reduced) {
message("Individual LOs | Deconvolved SSB |
");
} else {
message("LSB | USB | ");
}
message("" + eff_resolution{0} + " MHz | ", 2);
message("" + noisevalues{3} + " K | ", 3);
message("" + noisevalues{1} + " K |
", 3);
message("" + eff_resolution{1} + " MHz | ", 2);
message("" + noisevalues{2} + " K | ", 3);
message("" + noisevalues{0} + " K |
", 3);
message("");
// Actual messages
message("Observing time without initial slew " + totaltime + "s
");
message("On-source integration time " + posinttime + "s
", 1);
message("OFF integration time " + posofftime + "s
", 1);
message("Overhead " + (double(totaltime) - posinttime - posofftime) + "s
", 1);
message("
");
message("Total time efficiency " + timeefficiency * 100.0 + "%
", 1);
message("Total noise efficiency " + noiseefficiency * 100.0 + "%
", 1);
message("Drift noise contribution " + relnoise * 100.0 + "%
", 2);
message("
");
// Auxiliary explanations - Main beam
double fwhm = GetMainBeamSize(band,lo_freq);
fwhm = fwhm * 3600.0;
double eta_mb = InterpolateCoupling(band,lo_freq);
// System temperature is recomputed to be printed without passing
double tsys = InterpolateTsys(band,lo_freq);
double[] gssb = InterpolateGssb(band,lo_freq);
double tsys_lsb = tsys / (eta_mb * gssb[0]);
double tsys_usb = tsys / (eta_mb * gssb[1]);
message("");
message("The system noise temperature at " + lo_freq / 1000.0 + " GHz is " + tsys_lsb + " K in the lower and " + tsys_usb + " K in the upper sideband.", 0);
message("
");
if(reduced) {
message("Noise values are given at this frequency for the single-sideband" + " deconvolution product, and the double-sideband pipeline " + "products for individual LO settings on a " + "polarization-averaged, " + "single-sideband, main beam temperature scale of a " + fwhm + "'' beam with a main beam efficiency of " + eta_mb * 100.0 + "%.", 1);
} else {
message("Noise values are given on a polarization-averaged," + " single-sideband, main beam temperature scale of a " + fwhm + "'' beam with a main beam efficiency of " + eta_mb * 100.0 + "%.", 1);
}
message("
");
}
//Systematic deflux after LO switch-on, procedure
procedure Deflux_at_switchon_proc_aot {
string band = "4a" in ["ALL","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band. ALL does all bands and all multipliers
}{
//
}
/////////////////////////////////////////////////////////////////
// Second step of timing computation after telescope behaviour
// is known - Spectral Scan DBS observing mode
//
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},double,double,double} procedure SScanDBS_post_timing {
{int,int,int,int,int,int,int,int,int,bool,int,int,int} pre_timing = {4,15,4,21,11,1800,22,32,1,false,0,50,0}; // pre_timing parameter list
int[] telescopetimes = [300,180,20,1,21,0];
int grouplen = 1;
int groupnumber = 50; // Total umber of frequency groups
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
bool fastchop = false; // whether fast-chop is used instead of slow-chop
}{
// Get all values from the pre_timing section
int inttime = pre_timing{0};
int pointing = pre_timing{1};
int readouttime = pre_timing{2};
int loadlength = pre_timing{3};
int jitterdead = pre_timing{4};
int load_spacing = pre_timing{5};
int bigtunestep = pre_timing{6};
int n_loadinterval = pre_timing{7};
int n_bchop = pre_timing{8};
bool end_load = pre_timing{9};
int smallstep = pre_timing{10};
int initlength = pre_timing{11};
int dangling = pre_timing{12};
// Computation for slow-chop or fast-chop
if(fastchop) {
int readoutperchop = 1;
} else {
readoutperchop = 2;
}
// Get all values from the telescope section
int telinit = telescopetimes[1];
// Initial slew time
int slewtime = telescopetimes[2];
// Slew time to OFF
int longslew = telescopetimes[4];
// Actual slew time for load slew
int pointwaittime = telescopetimes[3];
// Idle time between two phases
int tend = telescopetimes[5];
// Final deceleration time
//////////////////////////////////////////////////////////////////
// Now we start the actual computations
// Pointwaittime is used for tuning
// In all non-tuning cycles, pointwaittime acts like a longer slew
slewtime = slewtime + pointwaittime;
longslew = longslew + pointwaittime;
// Half tune step has to be rounded up
int halftunestep = (bigtunestep - jitterdead - pointwaittime + 1) / 2;
//////////////////////////////////////////////////////////////////////
// Compute timing parameters for the two cases divided by n_cycles > 1
//
// Observations with ncycles >1 may be somewhat less efficient
//
if(n_cycles > 1) {
int scan_time = 2 * inttime + slewtime;
// How often do I have to perform a load slew
// Never switch between short load and long load here
if(n_loadinterval > 1) {
int old_n_loadinterval = n_loadinterval;
n_loadinterval = imax((load_spacing + slewtime) / scan_time,1);
// fit with n_cycles
n_loadinterval = imin(n_loadinterval,n_cycles);
n_loadinterval = IMultiple(n_loadinterval,n_cycles);
if(n_loadinterval <= 1) {
n_loadinterval = old_n_loadinterval;
}
}
// part of integrations is removed for tuning
int n_add = iceil(double(halftunestep) / double(readoutperchop * readouttime));
n_bchop = n_bchop - n_add;
if(n_bchop <= 0) {
SError("Readout cycle too long relative to nod cycle.");
}
// Pointing time
pointing = inttime + jitterdead;
// Average times for noise estimate
int shortint = n_bchop * readoutperchop * readouttime;
double effinttime = double((n_cycles - 1) * inttime + shortint) / double(n_cycles);
int loadpercycle = n_cycles / n_loadinterval;
double cycletime = double(2 * pointing) + double(loadpercycle * longslew + (n_cycles - loadpercycle) * slewtime) / double(n_cycles);
double avchopnum = double(n_cycles * (n_bchop + n_add) - n_add) / double(n_cycles);
// Compute total duration
int totaltime = iround(cycletime * double(groupnumber * n_cycles));
} else {
// Retuning after each nod cycle
// Check group length limited by load_interval
scan_time = 2 * (grouplen * inttime + (grouplen - 1) * smallstep) + bigtunestep + slewtime;
if(scan_time > load_spacing + slewtime && grouplen > 1) {
SError("Frequency group length too large for load interval.");
}
pointing = grouplen * inttime + (grouplen - 1) * smallstep + halftunestep + jitterdead;
// Average times for noise estimate
effinttime = double(grouplen * inttime);
// ignore the tuning time between cycles
cycletime = double(longslew + 2 * pointing - bigtunestep);
avchopnum = double(n_bchop);
// Compute total duration
totaltime = (iround(cycletime) + bigtunestep) * groupnumber;
}
double tdead = cycletime - 2.0 * effinttime;
//////////////////////////////////////////////////////////////////////
// The initial time is no longer contained in the total time
initlength = initlength - halftunestep;
int shiftlength = halftunestep;
// Compute total duration, remove pointwaittime for last slew
int closelength = duration(HIFICloseObs());
dangling = imax(dangling + closelength - tend,0);
totaltime = totaltime + dangling - pointwaittime + tend;
// show gyro-propagation messages
int pointcycle = longslew + 2 * pointing;
GCPMessages(pointing,2 * pointcycle,tend);
// Return all the times needed in the observing mode modules
return {totaltime,{inttime,pointing,readouttime,loadlength,jitterdead,load_spacing,bigtunestep,n_loadinterval,n_bchop,end_load,shiftlength,initlength,dangling},avchopnum,cycletime,tdead};
}
/////////////////////////////////////////////////////////////////
// Fast chop dual beam switch observing mode
//
// Implemented as procedure returning time and noise levels for HSPOT
{string,double,double}[] procedure HifiPointProcFastDBSSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Get the drift parameters to compute the drift noise
{double,double} phaselengths = DBSPhaseLengths(band,lo_freq,effResolution,continuumDetection,oneGHzReference);
// Compute derived quantities
// Top down approach here
int main_phase = iceil(phaselengths{0});
int data_time_guess = 40;
int n_switch_on_guess = main_phase / data_time_guess;
if(n_switch_on_guess < 2) {
n_switch_on_guess = 2;
data_time_guess = main_phase / n_switch_on_guess;
}
// Check with data rate
{int,double[]} dataparms = DataTaking(backendreadoutparms,8);
int datalimit = 2 * dataparms{0};
if(data_time_guess < datalimit) {
data_time_guess = datalimit;
n_switch_on_guess = 1;
}
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// Chop phase length
double phase_min = min(max(phaselengths{1},0.15),1.5);
int n_int_on_guess = ifloor(double(data_time_guess) / (2.0 * phase_min));
int n_int_on_range = -n_int_on_guess / 2;
if(n_int_on_range == 0) {
n_int_on_range = 1;
}
// Add pointing requirements condition: >=10s
{int,int} new_data_time = MatchMinPointing(data_time_guess,data_time_range,n_switch_on_guess);
data_time_guess = new_data_time{0};
data_time_range = new_data_time{1};
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_int_on",double(n_int_on_guess),double(n_int_on_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)}];
return retvalues;
}
// Read addresses and get checksum for a given band
// Returns:
// - the array of address_start, address_length
// - the full checksum of a given band
// - the full length of all concatenated address areas
//
{{int,int}[],int,int} procedure LcuGetTableAddress_ops {
string band = "1a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
}{
string tab = "LcuAddressTable_R.config";
int bandnb = ilookup(tab,band,"bnum");
{int,int}[] pairs = [];
int total_length = 0;
int total = 12;
//Get inputs for band 1a - loop on location types
for(int line = 1 .. total) {
string add_name_S = "a" + line + "S";
//Start address in Hex
string add_name_L = "a" + line + "L";
//Length in byte
int add_S_1a = ilookup(tab,"1a",add_name_S);
int add_L_1a = ilookup(tab,"1a",add_name_L);
int add_S_band = add_S_1a + (bandnb - 1) * add_L_1a;
int add_L_band = add_L_1a;
pairs[line - 1] = {add_S_band,add_L_band};
//Full length of all concatenated address areas
total_length = total_length + add_L_band;
}
//Complement with zeroes until getting to 48 pairs
int hifi_NStep = 48;
for(int line2 = total + 1 .. hifi_NStep) {
add_S_band = 0;
add_L_band = 0;
pairs[line2 - 1] = {add_S_band,add_L_band};
}
//Get checksum
int crc = ilookup(tab,band,"crc");
return {pairs,crc,total_length};
}
// Procedure to compute the LO settling delay for a particular frequency
//
int procedure LOSettlingTime {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double rest_lofreq = 978.2; // LO frequency in GHz ! (David's units!)
bool usesVectorScan = false; // whether to make room for the vector scan
bool extradelay = true; //whether extra settling time is needed after chain is configured
}{
// check for needed overhead factor
if(usesVectorScan) {
double tune_range_factor = 1.05;
} else {
tune_range_factor = 1.0;
}
// Get all parameters needed to compute config_lo_delay in Configure_LCU
string name_configlcutune = "name_configlcutune_a";
if(band == "1b" || band == "2b" || band == "3b" || band == "4b" || band == "5b" || band == "6b" || band == "7b") {
name_configlcutune = "name_configlcutune_b";
}
//
// Compute largest delay possible anticipating worst redshift
// Maximum redshift given by maximum accepted radial velocity
// Needs to be compliant with code in VelCorr
// maxredshift=1 + 30.7km/s / 299999.6km/s;
double maxredshift = 1.0001023;
double drain2_bluemax_lowredshift = Get_BLUE_LIMIT_D2_proc_fm(band,rest_lofreq / maxredshift);
{double,string}[] result = ConfigurationReader(name_configlcutune,["drain2_v"],band,rest_lofreq / maxredshift);
double drain2_lowredshift = min(result[0]{0} * tune_range_factor,drain2_bluemax_lowredshift);
double drain2_bluemax_highredshift = Get_BLUE_LIMIT_D2_proc_fm(band,rest_lofreq * maxredshift);
result = ConfigurationReader(name_configlcutune,["drain2_v"],band,rest_lofreq * maxredshift);
double drain2_highredshift = min(result[0]{0} * tune_range_factor,drain2_bluemax_highredshift);
//
// Safe value
// (LO frequency must be in GHz here in contrast to other cal files.)
double[] cresult = CalibrationReader("name_lcu_safe_values",["d2_v"],band,rest_lofreq);
double drain2_safe = cresult[0];
//
// Finally get config_lo_delay
result = ConfigurationReader("name_delays",["lock_lo_delay","vd2_rampup_speed"],band,rest_lofreq);
int config_lo_delay = iceil(result[0]{0} + (max(drain2_lowredshift,drain2_highredshift) - drain2_safe) / result[1]{0});
//
//Add extra time if needed
if(extradelay) {
cresult = CalibrationReader("tunetime",["extra_tune_delay"],band,rest_lofreq);
config_lo_delay = config_lo_delay + iceil(cresult[0]);
}
// return result
return config_lo_delay;
}
//Set LOU to dissipative, block
block Set_LO_Dissipative_block_aot HIFI 6627 {
}{
mois_step("Switch to dissipative mode");
{double,string}[] result = ConfigurationReader("name_delays",["set_to_nominal_delay"],"0",0.0);
int set_to_nominal_delay = iround(result[0]{0});
//
Hifi_HIFI_HL_dissipative($BBID);
delay(set_to_nominal_delay);
//
}
procedure HalfFastDBSRaster_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 10 in [4,80]; // data dump interval
int n_int = 20; // number chop cycles to integrate in ICU before transfer
int n_seq = 1; // number of data transfer cycles per pointing
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles
int n_pointsperscan = 1; // Number of points measured before moving to the second pointing phase
int n_loadinterval = 10; // number of nods before a load measurement
int n_load = 0; // additional load measurements in one pointing phase
bool final_load = false; // Need for final load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,10,0,10,20,21,0,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
bool iscross = false; // Whether we use a cross instead of a raster
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Fixed timings in the fast-chop mode
int load_datatime = GetStdLoadReadout(band,lo_freq);
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time / 2);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,true);
int readoutdead = FastChopReadoutDelay(band,lo_freq,backendreadoutparms);
// Count phases by hand to allow simultaneous usage by Raster and Cross
int iphase = 0;
// There is no nod counter in the return values - count this by hand
int inod = 0;
// Do I have to make loads in short nods and subsequent holds?
if(iscross) {
bool holdforload = n_pointsperscan > 1;
} else {
holdforload = n_pointsperscan == 1 && n_loadinterval > n_cycles;
}
bool isOffAtPoint = false;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
int[] choppars = [2 * n_int,0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - hkduration - loadlength);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = false;
iphase = iphase + 1;
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
// Check whether we are in a cross mode using computed OFF
isOffAtPoint = iscross && inod % 2 == 0;
// Configure measurement
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
// The use of n_load differs by 1 from the other observing modes here
for(int i1 = 1 .. n_load - 1) {
if(isOffAtPoint) {
HIFIFastHalfChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
} else {
HIFIFastHalfChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
}
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
if(isOffAtPoint) {
HIFIFastHalfChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
} else {
HIFIFastHalfChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
}
// Load measurement if required - time included in pointing
if(n_load > 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
}
// Final point before nod
// Special treatment for all cases where load has to be replaced by hold:
// n_pointsperscan=1, n_loadinterval > n_cycles
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == 1) {
inod = inod + 1;
if(holdforload && inod % n_loadinterval == 0 && n_load == 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// keep shift if we come from a holdforload nod, otherwise reset
if(!holdforload) {
runintostate = false;
}
}
// Update phase counter
iphase = iphase + 1;
}
// Second pointing phase
if(state[0] == 7) {
// second nod position
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
for(int i2 = 1 .. n_load - 1) {
HIFIFastHalfChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle
HIFIFastHalfChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Load measurement if required - time included in pointing
if(n_load > 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
}
// Final point before nod
// Special treatment for all cases where load has to be replaced by hold:
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == 1) {
inod = inod + 1;
if(holdforload && inod % n_loadinterval == 0 && n_load == 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// keep shift if we come from a holdforload nod, otherwise reset
if(!holdforload) {
runintostate = false;
}
}
// Update phase counter
iphase = iphase + 1;
}
// Load nod
if(state[0] == 9) {
// Load nod
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = false;
}
// Hold
if(state[0] == 6) {
// finished shift of instrument operations relative to pointing command
runintostate = false;
}
// Final load
if(state[0] == 5) {
delay(readoutdead);
if(final_load) {
// Perform final load measurement
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
}
runintostate = false;
HIFICloseObs();
}
}
}
// Compute the offset between two points
// This is an approximation for small offsets
{double,double} procedure ApproxAngularOffset {
{double,double} vector1 = {0.0,0.0}; // First vector
{double,double} vector2 = {0.2,0.2}; // Second vector
}{
double pideg = 3.14159265 / 180.0;
double fac = cos(0.5 * pideg * (vector1{1} + vector2{1}));
return {(vector2{0} - vector1{0}) * fac,vector2{1} - vector1{1}};
}
//////////////////////////////////////////////////////////////////////
// Procedure to perform the noise level evaluation for the observing mode
{double,double,double,double,double} procedure SScanDBS_noisecomputer {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference LO frequency in scan center
int nfreq = 4; // Number of frequency points per IF
bool dsb = true; // Both sidebands covered
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuum = false; // Whether timing is for total-power level
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
double tscan = 60.0; // Total average duration of one scan
{double,double,double} tact = {10.0,4.9,0.05}; // Field of actual dead and integration times
}{
// spectral scans always use the full bandwidth for reference
bool oneGHzReference = false;
double tdead = tact{0};
// Average total dead time in one scan
double inttimeperphase = tact{1};
// Actual integration time
double deadtimeperphase = tact{2};
// Dead time per switch phase
// Currently it is not possible to return both drift noise and radiometric
// noise so that only their sum is computed.
//
// Get parameters which are needed
double tsys = InterpolateTsys(band,reffreq);
double eta_mb = InterpolateCoupling(band,reffreq);
double[] gssb = InterpolateGssb(band,reffreq);
// Get the drift parameters to compute the drift noise
if(continuum) {
double[] allanparms = InterpolateTpAllan(band,reffreq,oneGHzReference);
} else {
allanparms = InterpolateSpecAllan(band,reffreq,oneGHzReference);
}
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / eff_resolution{1},binningexp);
double allan_time_hires = allanparms[0] * pow(1.0 / eff_resolution{0},binningexp);
// Differential Allan variance
if(continuum) {
allanparms = InterpolateTpChopAllan(band,reffreq,oneGHzReference);
} else {
allanparms = InterpolateSpecChopAllan(band,reffreq,oneGHzReference);
}
// rescale to frequency resolution
double dalpha = allanparms[1];
binningexp = 1.0 / allanparms[2];
double dallan_time_lores = allanparms[0] * pow(1.0 / eff_resolution{1},binningexp);
double dallan_time_hires = allanparms[0] * pow(1.0 / eff_resolution{0},binningexp);
// Compute integration time in one pointing cycle
double deadtimeperswitch = deadtimeperphase;
double effinttime = (tscan - tdead) / 2.0;
// Get actual noise
// This is returned twice: for both limiting resolutions
double systemnoise_lores = DoubleDifferenceNoise(inttimeperphase / allan_time_lores,[1.0,1.0,effinttime / allan_time_lores,effinttime / allan_time_lores,deadtimeperswitch / allan_time_lores,tdead / allan_time_lores,alpha,dallan_time_lores / allan_time_lores,dalpha]);
double systemnoise_hires = DoubleDifferenceNoise(inttimeperphase / allan_time_hires,[1.0,1.0,effinttime / allan_time_hires,effinttime / allan_time_hires,deadtimeperswitch / allan_time_hires,tdead / allan_time_hires,alpha,dallan_time_hires / allan_time_hires,dalpha]);
double noiseratio = DoubleDifferenceNoiseRatio(inttimeperphase / allan_time_lores,[1.0,1.0,effinttime / allan_time_lores,effinttime / allan_time_lores,deadtimeperswitch / allan_time_lores,tdead / allan_time_lores,alpha,dallan_time_lores / allan_time_lores,dalpha]);
// Compute total double sideband noise
// Correct for signal in difference phase
double dsbnoise_lores = systemnoise_lores / (eff_resolution{1} * 4000000.0 * tscan);
double dsbnoise_hires = systemnoise_hires / (eff_resolution{0} * 4000000.0 * tscan);
// Divide by n_cycles and number of frequencies
double accumulation = double(nfreq * n_cycles);
// Compute noise temperature
dsbnoise_lores = tsys * sqrt(dsbnoise_lores / accumulation);
dsbnoise_hires = tsys * sqrt(dsbnoise_hires / accumulation);
// Translate to the main beam scale, correct for eta_mb
// (This is typically not done at ground based telescopes,
// but leads often to problems there - to be discussed.)
dsbnoise_lores = dsbnoise_lores / eta_mb;
dsbnoise_hires = dsbnoise_hires / eta_mb;
// Check for double sideband coverage
double avgainfac = 0.5 / gssb[0] + 0.5 / gssb[1];
double rescalefac = sqrt(double(nfreq)) * avgainfac;
if(dsb) {
// Combine both sidebands
// In full spectral scans we have only a combined noise temperature for
// both sidebands
double decnoise_lores = dsbnoise_lores / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double decnoise_hires = dsbnoise_hires / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double indnoise_lores = dsbnoise_lores * rescalefac;
double indnoise_hires = dsbnoise_hires * rescalefac;
} else {
// Get single sideband noise equivalent
decnoise_lores = dsbnoise_lores * avgainfac;
decnoise_hires = dsbnoise_hires * avgainfac;
indnoise_lores = dsbnoise_lores * rescalefac;
indnoise_hires = dsbnoise_hires * rescalefac;
}
// In spectral scans we have only a combined noise temperature for both
// sidebands, so that the USB/LSB separation is not used
return {decnoise_lores,decnoise_hires,indnoise_lores,indnoise_hires,noiseratio};
}
// Equivalent procedure for configuration parameters following
// the master file structure currently used for these calibration files
//
// This is the generic part used for ILT and AOTs
//
{double,string}[] procedure FlexibleConfigurationReader {
string mainmasterfile = "configuration_masterfile"; // Configuration master file
string topicname = "name_confilfpu"; // Name of entry in master file
string[] objectnames = ["bias_standby_h"]; // Names of calibration objects to be read
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
// first step: read band master file
string masterfile = slookup(mainmasterfile,band,"filename");
// read master file
string calibfile = slookup(masterfile,topicname,"value_string");
int dep = ilookup(masterfile,topicname,"dependence");
int readnum = length(objectnames);
{double,string}[] retvalues = [];
if(dep == 0) {
// Quantity is only band dependent
// directly read from file looking up the object
for(int k = 1 .. readnum) {
double dres = dlookup(calibfile,objectnames[k - 1],"value");
string sres = slookup(calibfile,objectnames[k - 1],"value_string");
retvalues[k - 1] = {dres,sres};
}
} else {
// Quantity is band and frequency dependent
// read interpolated value from the data base
for(int j = 1 .. readnum) {
dres = interpolate(calibfile,objectnames[j - 1],lo_freq);
sres = "";
retvalues[j - 1] = {dres,sres};
}
}
return retvalues;
}
// Double load chop measurement performed at both frequencies
// of a frequency switch observation
// Most code is dublicated from normal load measurement
//
// Most generic version for spectral scans with potentially different
// frequencies for tuning and timing and retuning switch
//
procedure SScanDoubleLoadMeasurement {
string band = "4a"; // HIFI band (needed to estimate stabilization)
double tuning_freq = 978200.0; // LO tuning frequency
double lo_freq = 978200.0; // LO calibration frequency
double freq_throw = -40.0; // throw of frequency switch in MHz
bool retunelo = true; // Whether LO retuning is enabled
double deltanu = 1.0; // minimum effective resolution of the calibrated data
int data_time = 4; // time between subsequent data readouts
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
}{
// Initial computations
{int,int,bool} calinit = HIFICalInit(band,lo_freq,deltanu,data_time);
int used_datatime = calinit{0};
int n_inttime = calinit{1};
bool retuning = calinit{2} && retunelo;
// Perform zero and comb measurement
ZeroCombMeasurement(band,lo_freq,used_datatime,backendreadoutparms);
// No we perform the actual hot-cold measurement - 2 frequencies
int danglingreadout = HIFI_DoubleCalibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,retuning);
// Retune and another load if we are in HEB bands
if(retuning) {
// we have to wait for readout
delay(danglingreadout);
// Another LO vector scan at the same frequency for a stable HEB operation
// For FSW measurements a full preamble of 2xLCU_Configure is needed
// as for a new setting (not fully confirmed yet, but safe solution !)
HIFITuneFreqFsw(band,tuning_freq,tuning_freq + freq_throw,true,"");
danglingreadout = HIFI_DoubleCalibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,false);
}
}
// Get standard load read out data cycle used only in fast-chop observations
int procedure GetStdLoadReadout {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] dead = CalibrationReader("stdloadreadout",["loadreadout"],band,lo_freq);
return iceil(dead[0]);
}
// procedure called to get the WBS lasers switched on
procedure HifiSetFromDissipative_I_IntoDissipative_II {
string band_dissipate = "4a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
}{
//Temporarily, HEBs cannot be used - needs new MIB
if(band_dissipate == "6a" || band_dissipate == "6b" || band_dissipate == "7a" || band_dissipate == "7b") {
//error("HEB bands cannot yet be used in dissipative mode");
}
//
//WBS stand-by with laser ON
WBS_standby_block_aot("ON");
//Warm-up LOU with next band to be used
if(band_dissipate == "0") {
//Do nothing as one should already be in band0
} else {
//Clear potential failure mode
Set_LO_Nominal_block_aot();
//Heater will remain at 4V
LCU_config_dissipative_w_D2_proc_aot(band_dissipate);
}
//
}
/////////////////////////////////////////////////////////////////
// Fast chop dual beam switch observing mode
//
// The timing is defined as WBS timing, the HRS takes more data during
// the WBS read out, but this is ignored in the computations here.
//
// Combination of four modules implementing the new structure
//
// Implemented as procedure returning time and noise levels for HSPOT
{int,double,double,double,double,double} obs HifiPointProcFastDBS {
/* Setup parameters */
int naifid = 0; // Tracing object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Single Point - DBS fastChop",{data_time,0,n_switch_on,n_int_on,0,0,0,0,n_cycles,load_interval},false);
ChopMessages(true,data_time,n_int_on);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,bool,int,int,int} pre_timing = FastDBS_pre_timing(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},bool,double,double} post_timing = DBS_post_timing(pre_timing,telescopetimes,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
bool end_load = post_timing{1}{9};
int shiftlength = post_timing{1}{10};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
FastDBS_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_load,n_loadinterval,end_load,final_load,startobs,telescopetimes,loadlength,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double} tact = FastDBS_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_load,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBS_performance(band,lo_freq,effResolution,noisevalues,timeTaken,n_cycles,n_seq * n_int_on * (n_load + 1),tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
{string,double,double}[] procedure HifiPointModeDBSSequencerInit {
string modeName = "dbs";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// Get the drift parameters to compute the drift noise
{double,double} phaselengths = DBSPhaseLengths(band,lo_freq,effResolution,continuumDetection,oneGHzReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
int n_switch_on_guess = imax(iceil(phaselengths{0} / (2.0 * double(data_time_guess))),1);
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// Add pointing requirements condition: >=10s
{int,int} new_data_time = MatchMinPointing(data_time_guess,data_time_range,2 * n_switch_on_guess);
data_time_guess = new_data_time{0};
data_time_range = new_data_time{1};
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)}];
return retvalues;
}
////////////////////////////////////
// Special DBS raster - cross observing mode
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiMappingProcDBSCross {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the two raster lines
int npoints = 10 in [2,100]; // Number of points per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Mapping - DBS Cross Map slowChop",{data_time,0,0,n_switch_on,0,0,n_pointsperscan,0,n_cycles,load_interval},true);
ChopMessages(false,data_time,n_switch_on);
RasterSizeMessages({0.0,0.0},stepsize,2,npoints,true);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = DBSRaster_pre_timing(2,npoints,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,double[],double[],int[],double,double,int,int,int,int,int,int} tpar = DBSCross_telescope(naifid,onPosition,stepsize,npoints,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = custom_map_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} post_timing = DBSCross_post_timing(pre_timing,telescopetimes,npoints,n_switch_on,n_cycles,load_interval,false);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBSCross_telescope(naifid,onPosition,stepsize,npoints,band,lo_freq,"",post_timing{1},n_cycles);
telescopetimes = custom_map_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
int scansize = post_timing{1}{10};
int initlength = post_timing{1}{11};
int dangling = post_timing{1}{12};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
DBSRaster_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_cycles,scansize,n_loadinterval,n_load,final_load,startobs,telescopetimes,loadlength,true);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = DBSRaster_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,scansize,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBSRaster_performance(band,lo_freq,effResolution,noisevalues,timeTaken,2,npoints,n_cycles,n_seq * imax(n_load,1),tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Correct for double counting of central point
// The central point noise is returned only
double multiplier = sqrt(0.5);
noisevalues{0} = noisevalues{0} * multiplier;
noisevalues{1} = noisevalues{1} * multiplier;
noisevalues{2} = noisevalues{2} * multiplier;
noisevalues{3} = noisevalues{3} * multiplier;
noisevalues{4} = noisevalues{4} / multiplier;
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the OTF observing mode
procedure OTFFSwitch_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // chunk size given by the data rates and optimum speed
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_perline = 10; // Number of frequency switch cycles per line
int n_switch_off = 3; // Number of frequency switch cycles on OFF
int nlines_tot = 1; // Total number of lines to scan
int n_linesperscan = 1; // Number of lines between two OFFs
int n_loadinterval = 1; // number of nods before a load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,2,2,40,10,20,21,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int toffslew = telescopetimes[6];
// slew dead time between points
int tline = telescopetimes[4];
// Time in line
// The telescope slew can be a bit further than requested
int line_inttime = 2 * n_perline * data_time;
{int,int} otfline = OtfTelescopeLine(line_inttime,tline);
int line_startdelay = otfline{1};
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] onrates = dataparms{1};
dataparms = DataTaking(backendreadoutparms,data_time_off);
double[] offrates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
// Count OFFs by hand, their counter is not returned in the state array
int ioff = 0;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFIFsw(band,lo_freq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms);
}
if(state[0] == 4) {
// OFF Integration
HIFIConfigureFSwitchIntegration(data_time_off,n_switch_off,band,lo_freq,backendreadoutparms);
HIFIFSwitchOffIntegration(data_time_off,n_switch_off,band,lo_freq,offrates);
// OFF counter
ioff = ioff + 1;
// Check for normal slew after OFF
if(state[2] * state[3] < nlines_tot) {
HIFIActiveHK("normal",toffslew);
}
}
if(state[0] == 8) {
// OTF integration
delay(line_startdelay);
// Check whether we come from the OFF
if((state[2] + n_linesperscan - 1) % n_linesperscan == 0) {
HIFIConfigureFSwitchIntegration(data_time,n_perline,band,lo_freq,backendreadoutparms);
}
HIFIFSwitchOnIntegration(data_time,n_perline,band,lo_freq,onrates);
// Check for normal slew towards the OFF
if(state[2] % n_linesperscan == 0) {
if(ioff % n_loadinterval > 0) {
HIFIActiveHK("normal",toffslew);
}
}
}
if(state[0] == 9) {
// Load slew
delay(readoutdead);
DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms);
}
if(state[0] == 5) {
delay(readoutdead);
HIFICloseObs();
}
}
}
//Transition mode from normal to dissipative2
procedure HifiSetFromNormal_IntoDissipative_II {
string band_dissipate = "4a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
}{
//Temporarily, HEBs cannot be used - needs new MIB
if(band_dissipate == "6a" || band_dissipate == "6b" || band_dissipate == "7a" || band_dissipate == "7b") {
//error("HEB bands cannot yet be used in dissipative mode");
}
//
if(band_dissipate == "0") {
//Clear potential failure mode
Set_LO_Nominal_block_aot();
//
LCU_switch_off_block_aot();
//Will put heaters to 6V
Set_LO_Dissipative_block_aot();
} else {
//Clear potential failure mode
Set_LO_Nominal_block_aot();
//Heater will remain at 4V
LCU_config_dissipative_w_D2_proc_aot(band_dissipate);
}
//
//FPU stand-by: HBB is ON, chopper to rest position
Init_MSA_aot("0","CLOSE",0.0,true,"ON");
//HRS stand-by
HRS_config_max_att_block_aot("0",["wb","wb"]);
//WBS stand-by with laser ON
WBS_standby_block_aot("ON");
//Enable checksum computation - moved to transition to diss1 (HIFI-3578)
//Enable_CRC_FDIR_block_ops();
}
{int,double,double,double,double,double} obs HifiMappingModeFSwitchOTFNoRef {
string modeName = "fs-raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period defines number of lines between two loads
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Mapping - OTF Map Frequency Switch noRef",{data_time,0,0,n_switch_on,0,0,0,0,n_cycles,load_interval},true);
// Auxiliary routine for API parameter correction
{double,double,int} mapused = ValidMapSize(band,lo_freq,lineDistance,nlines,stepsize,npoints,2 * data_time * n_switch_on,n_switch_on);
double line_used = mapused{0};
double scanvelocity = mapused{1};
int npoints_used = mapused{2};
// Call first part of the timing computer
{int,int,int,int,bool,int,int} pre_timing = OTFFSwitchNoRef_pre_timing(nlines,npoints_used,band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,double,double,int,int,int} tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,pre_timing);
// Dummy call to spacecraft command
int[] telescopetimes = line_scan_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,bool,int,int},double,double} post_timing = OTFDoubleChopNoRef_post_timing(pre_timing,telescopetimes,nlines,data_time,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,post_timing{1});
// Call telescope command
telescopetimes = line_scan_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{0};
bool end_load_on = post_timing{1}{4};
int n_loadinterval = post_timing{1}{2};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
OTFFSwitchNoRef_commanding(band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on,n_loadinterval,nlines * n_cycles,end_load_on,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = SingleChop_deadtimes("fs",band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on);
double tscan = 2.0 * (tact{1} + tact{2});
double tdead = 2.0 * tact{2};
//
// Call noise computer
{double,double,double,double,double} noisevalues = FSwitchNoRef_noisecomputer(band,lo_freq,effResolution,oneGHzReference,n_switch_on * n_cycles,tscan,tdead);
// Evaluate performance
OTFDoubleChopNoRef_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints_used,n_switch_on * n_cycles,true,tscan,tdead);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
//Get diplexer setting using "real" frequencies
double[] procedure Get_Diplexer_setting {
string band = "3a" in ["3a","3b","4a","4b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 810.0; //LO frequency
}{
//Compute real frequency
double real_lo_freq = Compute_Real_Freq(band,lo_freq);
{double,string}[] result_d = ConfigurationReader("name_confildipl",["diplex_h_a","diplex_v_a","diplex_h_b","diplex_v_b"],band,lo_freq);
if(band == "3a" || band == "4a" || band == "6a" || band == "7a") {
double[] final_setting = [result_d[0]{0},result_d[1]{0}];
} else {
final_setting = [result_d[2]{0},result_d[3]{0}];
}
return final_setting;
}
// Normal combination of zero and comb measurement
// 1s integration time, only WBS, maximum windows
// Inherited from blocks 3604 and 3605
//
// Returns dangling transmission time
//
int block WBS_Zero_Comb HIFI 6004 {
string band = "4a"; // HIFI band (needed to estimate stabilization)
double lo_freq = 978200.0; // LO frequency
}{
// Get delays
{double,string}[] result = ConfigurationReader("name_delays",["wbs_comb_delay"],band,lo_freq);
int wbs_comb_delay = iround(result[0]{0});
// data frame transmission time (always 2 spectra)
int data_time = wbs_comb_delay / 2;
int rest_delay = wbs_comb_delay - 2 * data_time;
wbs_comb_delay = wbs_comb_delay - rest_delay;
// Data rate computation
// The HIFI command is restricted to always read out both full WBS
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} fullreadoutparms = FrequencyCalibrationParms(true,true,false,false);
// data rate and read-out time
{int,double[]} fdataparms = AllDataRates(fullreadoutparms,data_time,false);
int readout = fdataparms{0};
// Get attenuators for comb measurement
{double,string}[] result_d = ConfigurationReader("name_configwbs",["hwh_att_band4_comb","hwh_att_band3_comb","hwh_att_band2_comb","hwh_att_band1_comb","hwh_att_in_comb","hwv_att_band4_comb","hwv_att_band3_comb","hwv_att_band2_comb","hwv_att_band1_comb","hwv_att_in_comb"],band,0.0);
int hwh_att_band4 = iround(result_d[0]{0});
int hwh_att_band3 = iround(result_d[1]{0});
int hwh_att_band2 = iround(result_d[2]{0});
int hwh_att_band1 = iround(result_d[3]{0});
int hwh_att_in = iround(result_d[4]{0});
int hwv_att_band4 = iround(result_d[5]{0});
int hwv_att_band3 = iround(result_d[6]{0});
int hwv_att_band2 = iround(result_d[7]{0});
int hwv_att_band1 = iround(result_d[8]{0});
int hwv_att_in = iround(result_d[9]{0});
//
// set data rates
non_ess_hk_data_rate(fdataparms{1}[2] / 1024.0);
data_rate(fdataparms{1}[0] / 1024.0);
// Insert a Noop because previous command could have been issued in second bus slot
Hifi_HIFI_noop();
// Call command
Hifi_HIFI_WBS_Comb($BBID,hwh_att_band4,hwh_att_band3,hwh_att_band2,hwh_att_band1,hwh_att_in,hwv_att_band4,hwv_att_band3,hwv_att_band2,hwv_att_band1,hwv_att_in);
// Currently I ignore that the COMB ends with ZERO=on (SCR 618)
delay(wbs_comb_delay);
// reset data rates
non_ess_hk_data_rate(fdataparms{1}[1] / 1024.0);
data_rate(0.0);
delay(rest_delay);
//
// additional delay for packet transmission before next zero depends
// on zero duration - needs to be introduced on higher level
return readout;
}
// Configuration for frequency-switch integration
block HIFIConfigureFSwitchIntegration HIFI 6037 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used, channel windows}
}{
// Call procedure doing the work
ConfigureSpectroscopy(data_time,2 * n_cycle,"fs",band,lo_freq,backendreadoutparms);
}
/////////////////////////////////////////////////////////////////
// Procedure to filter only those attenuator settings that are used
double[][] procedure GetSScanLevelGrid {
string band = "4a"; // HIFI band
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
double[] freqgrid = [978053.7,978301.8,978381.1]; // frequency grid
int groupnumber = 1; // Number of frequency groups
int[][] grouporder = [[0],[0]]; // Sequence to trace frequency points in groups
}{
// Reduce frequency field - select center frequency of groups only
if(groupnumber < length(freqgrid)) {
int nfreq = length(freqgrid);
double[] redfreq = [];
int oldindex = 0;
int groupsize = nfreq / groupnumber;
// It is not clear whether grouporder[0,0] or grouporder[1,0]
// is the better point. First better for DBS, second for NoRef.
for(int j1 = 0 .. groupnumber - 1) {
oldindex = j1 * groupsize + grouporder[0][0];
redfreq[j1] = freqgrid[oldindex];
}
} else {
redfreq = freqgrid;
}
// Make field of subbands that are used
int idest = 0;
int[] usedsubbands = [];
for(int i = 0 .. 3) {
if(wbs1{0} && wbs1{1}[i][1] - wbs1{1}[i][0] > 0) {
usedsubbands[idest] = i;
idest = idest + 1;
}
}
for(int ii = 0 .. 3) {
if(wbs2{0} && wbs2{1}[ii][1] - wbs2{1}[ii][0] > 0) {
usedsubbands[idest] = ii + 4;
idest = idest + 1;
}
}
// Create dB grid needed for backend retuning
double[][] retunegrid = GetSScanLevels(band,redfreq,usedsubbands);
return retunegrid;
}
////////////////////////////////////
// Functions for two dimensional vectors, e.g. coordinates on the sky
// Multiply a vector defined as a tuple with a scaler defined as a double
{double,double} procedure MultiplyScalarVector {
double scalar = 1.0;
{double,double} vector = {1.0,1.0};
}{
return {vector{0} * scalar,vector{1} * scalar};
}
////////////////////////////////////
// OTF observing mode
//
// Combination of four modules implementing the new structure
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiMappingProcOTF {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the map center
double dec = 0.0; // DEC coordinate of the map center
double raoff = 0.0; // RA coordinate of the OFF position
double decoff = 0.0; // DEC coordinate of the OFF position
bool refSelected = true; // Dummy parameter required by HSPOT
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,240]; // Number of rows in the map
double stepsize = 0.0050 in [0.0,0.13333]; // Distance between subsequent points in the OTF line
int npoints = 10 in [1,720]; // Number of data dumps per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,5]; // chunk size given by the data rates and optimum speed
int n_int_on = 1 in [1,1800]; // Supersamplingfactor
int n_linesperscan = 1 in [1,32]; // Number of lines between two OFFs
int n_switch_off = 3 in [1,3600]; // Number of data dumps for the OFF integration time
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Mapping - OTF Map Position Switch",{data_time,0,n_int_on,0,n_switch_off,n_linesperscan,0,0,n_cycles,load_interval},true);
// Auxiliary routine for API parameter correction
{double,double,int} mapused = ValidMapSize(band,lo_freq,lineDistance,nlines,stepsize,npoints,data_time * n_int_on,0);
double line_used = mapused{0};
double scanvelocity = mapused{1};
int npoints_used = mapused{2};
// Call first part of the timing computer
{int,int,int,int,int,int,int,int} pre_timing = OTFmap_pre_timing(nlines,npoints_used,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_linesperscan,n_switch_off,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{double,double} refPosition = {raoff,decoff};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,double,double,int,int,double,double,int,int,int,int,int} tpar = OTFmap_telescope(naifid,onPosition,lineDistance,nlines,line_used,refPosition,scanvelocity,band,lo_freq,n_linesperscan,n_cycles,pre_timing);
// Dummy call to spacecraft command
int[] telescopetimes = line_scan_with_off_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int},double,double} post_timing = OTFmap_post_timing(pre_timing,telescopetimes,data_time,n_linesperscan,n_cycles,load_interval);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = OTFmap_telescope(naifid,onPosition,lineDistance,nlines,line_used,refPosition,scanvelocity,band,lo_freq,n_linesperscan,n_cycles,post_timing{1});
// Call telescope command
telescopetimes = line_scan_with_off_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int n_pp = post_timing{1}{0};
int n_scans = post_timing{1}{1};
int loadlength = post_timing{1}{4};
int n_loadinterval = post_timing{1}{5};
double tscan = post_timing{2};
double tdead = post_timing{3};
// telescope time
int slewtime = telescopetimes[6];
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
OTFmap_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,nlines * n_cycles,n_linesperscan,n_switch_off,n_pp,n_loadinterval,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check])
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = OTFmap_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_linesperscan,n_switch_off,n_pp,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = OTFmap_noisecomputer(band,lo_freq,effResolution,oneGHzReference,nlines,npoints_used,n_int_on,n_linesperscan,n_cycles,slewtime,tscan,tact);
// Evaluate performance
OTF_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints_used,n_scans,n_cycles,tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// Procedure to support conditional LCU CRC computation
// together with standard HK configuration - HIFI-3415
procedure HIFILCUChecksumAndSetHKCloseObs {
string band = "1a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
bool alltables = true; //check all tables+unused (true), or only one band table (false)
string speed = "normal" in ["fast","normal","slow"]; // Select HK rate
bool active = false; // Whether to actively query the spectrometers
}{
HIFISetHK(speed,active);
LcuChecksumRecalcCloseObs_aot(band,alltables);
}
//Procedure to store currently tuned frequency, procedure
procedure HIFI_HL_store_tm_proc_fm {
}{
Hifi_HIFI_HL_store_tm($BBID);
//This commands sends a request to get FSW1/2 into non-periodic HK
//Removed as of SPR-1747
//Hifi_HIFI_LCU_macro_buffers();
delay(1);
}
//////////////////////////////////////////////////////////////////////////
// Procedure to compute detailed timing of DBS-raster observing mode
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} procedure DBSRaster_post_timing {
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = {4,10,4,21,1,1800,0,10,1,1,1,50,0}; // pre timing parameter list
int[] telescopetimes = [300,180,10,0,10,20,21,0,0,0];
int nlines_tot = 1; // Number of rows in the map
int npoints = 10; // Number of points per row
int n_chop = 2; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_cycles = 1; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800; // load period = f(band,lo_freq,eff_resolution{1})
bool fastchop = false; // whether fast-chop is used instead of slow-chop
}{
// Get all values from the pre_timing section
int inttime = pre_timing{0};
int pointing = pre_timing{1};
int readouttime = pre_timing{2};
int loadlength = pre_timing{3};
int jitterdead = pre_timing{4};
int load_spacing = pre_timing{5};
int n_load = pre_timing{6};
int n_loadinterval = pre_timing{7};
int n_seq = pre_timing{8};
int n_scans = pre_timing{9};
int scansize = pre_timing{10};
int initlength = pre_timing{11};
int dangling = pre_timing{12};
// Get all values from the telescope section
int telinit = telescopetimes[1];
// Initial slew time
int slewtime = telescopetimes[2];
// Slew time to next point
if(scansize > 1) {
int nodtime = telescopetimes[4];
// Slew time to second nod
int slewline = telescopetimes[3];
// Slew between lines
int longslew = telescopetimes[5];
// Actual slew time for load slew
int returntime = telescopetimes[6];
// Idle time between two phases
int tend = telescopetimes[7];
// Final deceleration time
} else {
nodtime = telescopetimes[5];
slewline = telescopetimes[4];
longslew = telescopetimes[6];
returntime = telescopetimes[3];
tend = telescopetimes[9];
}
int shortmove = imin(slewtime,slewline);
// tss not relevant for ncycles=1, scansize=1
if(scansize != 1 || n_cycles != 1) {
shortmove = imin(shortmove,returntime);
}
// Total number of scans
int n_tot = n_scans * n_cycles;
///////////////////////
// Long computation for scansize > 1 to obtain all slew durations
{int,int} alldeadtimes = Raster_slewtimes(nlines_tot,npoints,n_cycles,scansize,nodtime,slewtime,slewline,returntime);
int tinscandead = alldeadtimes{0};
int toutscandead = alldeadtimes{1};
// Compute total duration of measurement and average scan length
int totalscantime = n_tot * (2 * pointing * scansize) + tinscandead;
// approximate scan time for load comparison
int scan_time = iceil(double(totalscantime) / double(2 * n_tot));
if(load_spacing > 2 * scan_time) {
n_seq = n_chop;
pointing = inttime + jitterdead;
bool end_load = false;
} else {
// It could happen that the slew extends the scan too much - catch
if(scansize > 1) {
SError("Number of points in one scan too large for load period.");
}
n_load = n_load + 1;
n_seq = n_chop / n_load;
if(n_seq < 1) {
SError("Transfer cycle too long relative to load period.");
}
// adjust pointing time to include load measurements
int loadappend = imax(loadlength - shortmove,0);
end_load = true;
// Computation for slow-chop or fast-chop
if(fastchop) {
inttime = n_seq * n_load * readouttime;
} else {
inttime = 2 * n_seq * n_load * readouttime;
}
pointing = inttime + loadappend + (n_load - 1) * loadlength + jitterdead;
}
totalscantime = n_tot * (2 * pointing * scansize) + tinscandead + toutscandead;
scan_time = iceil(double(totalscantime) / double(2 * n_tot));
// compute the load interval in case of short scan_time
n_loadinterval = imax((load_interval - loadlength + nodtime) / (2 * scan_time),1);
// Special treatment for nodding_raster due to limitations in API
// Split into loads per point or per multiple points
if(scansize == 1 && n_loadinterval > n_cycles) {
n_loadinterval = n_cycles * (n_loadinterval / n_cycles);
// Translate load waiting time into a hold after the point
int holdlength = imax(loadlength - nodtime,0);
longslew = nodtime + holdlength;
} else {
holdlength = 0;
}
// Special treatment for loads per point to compensate counter reset
if(scansize == 1 && n_loadinterval < n_cycles) {
int dangling_period = n_cycles % n_loadinterval;
while(n_loadinterval > 1 && (dangling_period + n_loadinterval) * 2 * scan_time > load_interval - loadlength + nodtime) {
n_loadinterval = n_loadinterval - 1;
dangling_period = n_cycles % n_loadinterval;
}
int n_long = n_scans * (n_cycles / n_loadinterval);
} else {
n_long = n_tot / n_loadinterval;
}
// Compute total duration of measurement, correct for load nods
totalscantime = n_tot * (2 * pointing * scansize) + tinscandead + n_long * (longslew - nodtime);
// Average dead and scan time for drift estimate
double tscan = double(totalscantime) / double(n_tot);
double tdead = tscan - double(2 * inttime * scansize);
// Count integration times of other points of one nod as dead time
// Other points in the second nod are excluded from the scan
double othertime = double((scansize - 1) * inttime);
tdead = tdead + othertime;
// Reduce scan time by the other points in the second nod phase
tscan = tscan - othertime;
// Determine need for final load measurement
double rest = double(n_tot % n_loadinterval) + 0.5;
bool final_load = rest > 0.5001 * double(n_loadinterval);
// Compute total duration
// The initial time is no longer contained in the total time
// int totaltime=imax(initlength,telinit);
int totaltime = totalscantime + toutscandead;
// Add dangling load time if not included in pointing
// they are mutually exclusive, otherwise the readoutdelay applies
if(final_load) {
dangling = loadlength;
}
if(end_load) {
dangling = loadlength - loadappend;
}
int closelength = duration(HIFICloseObs());
dangling = imax(dangling + closelength - tend,0);
totaltime = totaltime + dangling + tend;
// show gyro-propagation messages
if(scansize > 1) {
GCPMessages(0,totalscantime,tend);
} else {
GCPMessages(pointing,totalscantime,tend);
}
// Return all the times needed in the observing mode modules
return {totaltime,{inttime,pointing,readouttime,loadlength,holdlength,load_spacing,n_load,n_loadinterval,n_seq,n_scans,scansize,initlength,dangling},final_load,tscan,tdead};
}
// Rotate angle by -90 deg
double procedure RotateRight {
double angle = 0.0; // Original angle
}{
double fullcircle = 360.0;
return (angle + fullcircle * 0.75) % fullcircle;
}
/////////////////////////////////////////////////////////////////
// Auxiliary routine to determine the two loop phase durations and
// the OFF resolution for all load-chop modes
{double,double,double,double} procedure LoadChopPhaseLengths {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
}{
// limits from noise section
// resolution of OFF phase
double sw_resolution = GetLoadChopSWResolution(band,lo_freq);
sw_resolution = max(effResolution{1},sw_resolution);
// Get the drift parameters to compute the drift noise
// System Allan variance
double[] allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
double allan_time_off = allanparms[0] * pow(1.0 / sw_resolution,binningexp);
// Differential Allan variance
allanparms = InterpolateSpecLChopAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double dalpha = allanparms[1];
binningexp = 1.0 / allanparms[2];
double dallan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// phase lengths
double main_phase = 0.3 * dallan_time_lores;
double chop_phase = 0.3 * allan_time_lores;
double chop_phase_off = 0.3 * allan_time_off;
// Constrain by load period
int loadper = LoadPeriod(band,lo_freq,effResolution{0});
main_phase = min(main_phase,0.4 * double(loadper));
return {main_phase,chop_phase,chop_phase_off,sw_resolution};
}
////////////////////////////////////
// Peakup observing mode
//
obs HifiEngPeakup {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the raster line
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
string backend = "WBS" in ["WBS","HRS"]; // backend to use - resolution
string polarization = "H" in ["H","V"]; // backend to use - polarization
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = PeakupBackendSettings(backend,polarization,band,lo_freq,1);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
// Call first part of the timing computer
{int,int,int,int,int,double,int,int} pre_timing = Peakup_pre_timing(3,3,band,lo_freq,hr1,hr2,wb1,wb2);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,int,double,double} tpar = Peakup_telescope(naifid,onPosition,stepsize,3,3,band,lo_freq,pre_timing);
int[] telescopetimes = basic_raster_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,double,int,int}} post_timing = Peakup_post_timing(pre_timing,telescopetimes,3,3);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = Peakup_telescope(naifid,onPosition,stepsize,3,3,band,lo_freq,post_timing{1});
telescopetimes = basic_raster_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int data_time = post_timing{1}{2};
int n_int = post_timing{1}{4};
double eff_resolution = post_timing{1}{5};
int initlength = post_timing{1}{6};
int dangling = post_timing{1}{7};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
///////////////////////////////////////////////////////////////////////
// Call instrument commands
Peakup_commanding(band,lo_freq,hr1,hr2,wb1,wb2,data_time,n_int,eff_resolution,stepsize,startobs,telescopetimes,loadlength);
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
}
////////////////////////////////////////////////////
// Building blocks used in general observations
//
// They call procedures which should be common between ILT and space
// Actual building blocks possible when numbers are
// assigned.
//
// Currently, these blocks contain the data rate computations.
/////////////////////////////////////////////////////////////////////////////
// Collection of identical procedures for continuous data read out
// calling different building blocks to make data distinguisable
// Set observation ID for the current observation - start of every obs
block HIFIInitObs HIFI 6000 {
}{
// new delay to allow for insertion of BUSCONFIG by MPS
// email from Larry, October 19, 2007
// applies only to RMS and SOVT - removed again in HSPOT version
// delay(1);
// Set ObsId as very first step
Hifi_HIFI_Set_OBS_ID($BBID,$OBSID);
}
// OBS SFT, block
procedure OBS_SEU_check_aot {
string memory_area = "PM_LOW" in ["PM_LOW","PM_HIGH","DM","EEPROM1","EEPROM2","BSW","ALL"];
}{
if(memory_area == "ALL") {
// Add 1 sec idle delay to collect HK - HIFI-3882
delay(1);
//De-activate S/S HK collection during the checks
Hifi_HIFI_Housekeeping_off();
delay(1);
}
//Parameters for PM-low: this is for OBS6.4.1
int check_start = ilookup("config_icu_memory.config","PM_LOW","start");
int check_end = ilookup("config_icu_memory.config","PM_LOW","end_or_length");
int check_crc = ilookup("config_icu_memory.config","PM_LOW","crc");
//PM_LOW check
if(memory_area == "PM_LOW" || memory_area == "ALL") {
mois_spacon("In the following TC, parameters HP231197, HP232197 and HP233197 should be treated as formal parameters");
Hifi_HIFI_check_PM_memory(check_start,check_end,check_crc);
delay(3);
mois_tmcheck("Verify that no 1,8 has been generated. Otherwise, please inform the HIFI ICC.");
}
//PM_HIGH check
if(memory_area == "PM_HIGH" || memory_area == "ALL") {
check_start = check_start + 0x3ffff;
check_end = check_end + 0x3ffff;
mois_spacon("In the following TC, parameters HP231197, HP232197 and HP233197 should be treated as formal parameters");
Hifi_HIFI_check_PM_memory(check_start,check_end,check_crc);
delay(3);
mois_tmcheck("Verify that no 1,8 has been generated. Otherwise, please inform the HIFI ICC.");
}
//PROM copy into PM (BSW) check
if(memory_area == "BSW" || memory_area == "ALL") {
check_start = ilookup("config_icu_memory.config","BSW","start");
check_end = ilookup("config_icu_memory.config","BSW","end_or_length");
check_crc = ilookup("config_icu_memory.config","BSW","crc");
mois_spacon("In the following TC, parameters HP231197, HP232197 and HP233197 should be treated as formal parameters");
Hifi_HIFI_check_PM_memory(check_start,check_end,check_crc);
delay(1);
mois_tmcheck("Verify that no 1,8 has been generated. Otherwise, please inform the HIFI ICC.");
}
//DM check
if(memory_area == "DM" || memory_area == "ALL") {
//There are three segments to consider here
check_start = ilookup("config_icu_memory.config","DM1","start");
int check_length = ilookup("config_icu_memory.config","DM1","end_or_length");
mois_spacon("In the following TCs, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("DM",check_start,check_length);
delay(1);
//
check_start = ilookup("config_icu_memory.config","DM2","start");
check_length = ilookup("config_icu_memory.config","DM2","end_or_length");
Hifi_HIFI_check_memory("DM",check_start,check_length);
delay(1);
//
check_start = ilookup("config_icu_memory.config","DM3","start");
check_length = ilookup("config_icu_memory.config","DM3","end_or_length");
Hifi_HIFI_check_memory("DM",check_start,check_length);
delay(1);
//
}
//EEPROM1 check: done in two chunks due to length limit to 16 bits
if(memory_area == "EEPROM1" || memory_area == "ALL") {
check_start = ilookup("config_icu_memory.config","EEPROM1_1","start");
check_length = ilookup("config_icu_memory.config","EEPROM1_1","end_or_length");
mois_spacon("In the following TC, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("EEPROM",check_start,check_length);
delay(1);
check_start = ilookup("config_icu_memory.config","EEPROM1_2","start");
check_length = ilookup("config_icu_memory.config","EEPROM1_2","end_or_length");
mois_spacon("In the following TC, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("EEPROM",check_start,check_length);
delay(1);
}
//EEPROM2 check: done in two chunks due to length limit to 16 bits
if(memory_area == "EEPROM2" || memory_area == "ALL") {
check_start = ilookup("config_icu_memory.config","EEPROM2_1","start");
check_length = ilookup("config_icu_memory.config","EEPROM2_1","end_or_length");
mois_spacon("In the following TC, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("EEPROM",check_start,check_length);
delay(1);
check_start = ilookup("config_icu_memory.config","EEPROM2_2","start");
check_length = ilookup("config_icu_memory.config","EEPROM2_2","end_or_length");
mois_spacon("In the following TC, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("EEPROM",check_start,check_length);
delay(1);
check_start = ilookup("config_icu_memory.config","EEPROM2_3","start");
check_length = ilookup("config_icu_memory.config","EEPROM2_3","end_or_length");
mois_spacon("In the following TC, parameters HP003197 and HP004197 should be treated as formal parameters");
Hifi_HIFI_check_memory("EEPROM",check_start,check_length);
delay(1);
}
//
if(memory_area == "ALL") {
//Re-activate S/S HK collection during the checks
Hifi_HIFI_Housekeeping_on("1_pkt_per_s","ON","ON","ON","ON","ON","ON");
}
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure FastSScanDBS_commanding {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference characteristic LO frequency
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int grouplen = 1; // Number of frequency steps per nodding phase
int[][] grouporder = [[0],[0]]; // Sequence to trace frequency points in both phases
double[] freqgrid = [978053.7,978301.8,978381.1]; // Table of frequency points
bool retuning = false; // need for WBS retuning
double[] targetlevels = [1.0,1.0,1.0]; // WBS tuning levels
int data_time = 10; // data dump interval
int n_int = 20; // number chop cycles to integrate in ICU before transfer
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
int allsteps = 4; // Total number of frequency pointing periods
int n_bchop = 1; // Normal number of chop cycles per frequency and pointing
int n_long = 1; // Chop cycles per frequency and pointing without retuning
int n_loadinterval = 1; // number of nods before a load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,20,1,21,0]; // Timing of the observation from telescope
int shiftlength = 10; // Shift of the loop start relative to the pointing
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int tnodslew = telescopetimes[2];
// slew dead time between points
// First frequency
double runningfreq = freqgrid[grouporder[0][0]];
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time / 2);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,true);
int readoutdead = FastChopReadoutDelay(band,reffreq,backendreadoutparms);
// recompute load duration for initial load measurement
int load_datatime = GetStdLoadReadout(band,reffreq);
int loadlength = duration(SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},load_datatime,backendreadoutparms));
loadlength = loadlength + readoutdead;
bool retuneload = n_loadinterval > 1;
// Tuning levels
string[] targetnames = TargetNames(band,reffreq,retuning,targetlevels);
string target = targetnames[0];
// All commands with a duration possibly depending on the frequency
// are taken at the reference frequency to guarantee synchonization
// Declare auxiliary variables to be used in the loops
int i_freqcycles = 0;
int i_group = 0;
int i_phase = 0;
int[] choppars = [1,0];
// variables storing the configuration setting
bool islong = false;
bool isinvalid = true;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
HIFIInitObs();
TuneHIFI(band,runningfreq,hrs1,hrs2,wbs1{0},wbs2{0},target);
delay(tinitslew - (time() - startobs) - loadlength + shiftlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},load_datatime,backendreadoutparms);
if(shiftlength > 0) {
runintostate = true;
} else {
runintostate = false;
}
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
i_phase = (state[2] + 1) % 2;
// Reset group counter
i_group = 0;
runintostate = false;
// long integrations not possible in last and first nod cycle
if(n_cycles > 1 && state[2] % n_cycles != state[2] % 2) {
if(isinvalid || !islong) {
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_long,band,reffreq,backendreadoutparms);
islong = true;
isinvalid = false;
}
HIFIFastChopOnIntegration(data_time,n_long,band,reffreq,choppars,rates);
} else {
if(isinvalid || islong) {
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_bchop,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
while(i_group < grouplen - 1) {
HIFIFastChopOnIntegration(data_time,n_bchop,band,reffreq,choppars,rates);
// retune
i_group = i_group + 1;
runningfreq = freqgrid[grouporder[i_phase][i_group] + i_freqcycles * grouplen];
HIFIChangeFreq(band,runningfreq);
}
HIFIFastChopOnIntegration(data_time,n_bchop,band,reffreq,choppars,rates);
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && i_phase == 1) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freqcycles = i_freqcycles + 1;
runningfreq = freqgrid[grouporder[0][0] + i_freqcycles * grouplen];
target = targetnames[i_freqcycles];
HIFIRetuneFreq(band,runningfreq,target);
runintostate = true;
}
}
}
// Active WBS HK if we have a nod slew without calibration
if(state[2] % 2 == 1 && state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
if(state[0] == 7) {
// second nod position
i_phase = state[2] % 2;
// First nodding position
// Reset group counter
i_group = 0;
runintostate = false;
// long integrations not possible in last and first nod cycle
if(n_cycles > 1 && state[2] % n_cycles != (state[2] % 2 + 1) % 2) {
if(isinvalid || !islong) {
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_long,band,reffreq,backendreadoutparms);
islong = true;
isinvalid = false;
}
HIFIFastChopOffIntegration(data_time,n_long,band,reffreq,choppars,rates);
} else {
if(isinvalid || islong) {
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_bchop,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
while(i_group < grouplen - 1) {
HIFIFastChopOffIntegration(data_time,n_bchop,band,reffreq,choppars,rates);
// retune
i_group = i_group + 1;
runningfreq = freqgrid[grouporder[i_phase][i_group] + i_freqcycles * grouplen];
HIFIChangeFreq(band,runningfreq);
}
HIFIFastChopOffIntegration(data_time,n_bchop,band,reffreq,choppars,rates);
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && i_phase == 1) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freqcycles = i_freqcycles + 1;
runningfreq = freqgrid[grouporder[0][0] + i_freqcycles * grouplen];
target = targetnames[i_freqcycles];
HIFIRetuneFreq(band,runningfreq,target);
runintostate = true;
}
}
}
// Active WBS HK if we have a nod slew without calibration
if(state[2] % 2 == 0 && state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
if(state[0] == 9) {
// Load nod
delay(readoutdead);
SScanLoadMeasurement(band,runningfreq,reffreq,retuneload,eff_resolution{0},load_datatime,backendreadoutparms);
isinvalid = true;
runintostate = false;
}
if(state[0] == 5) {
// The instrument stops halftunelength before the telescope
// but I have to wait to close the observation
HIFICloseObs();
}
}
}
// Compute the integration time required on the thermal loads
int procedure LoadIntegrationTime {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
double deltanu = 1.0; // minimum effective resolution of the calibrated data
}{
// get load temperatures
{double,double} loadtemp = LoadTemperatures(band,lo_freq);
double t_hot = loadtemp{0};
double t_cold = loadtemp{1};
double t_sys = InterpolateTsys(band,lo_freq);
// compare to load period
int loadperiod = LoadPeriod(band,lo_freq,deltanu);
// exception handling for zero frequency resolutions
if(deltanu < 0.01) {
int intload = loadperiod / 8;
} else {
// estimator equation guaranteeing only 1% error from load calibration
double tload = 0.01 / deltanu * ((t_hot + t_sys) * (t_hot + t_sys) + (t_cold + t_sys) * (t_cold + t_sys)) / ((t_hot - t_cold) * (t_hot - t_cold));
intload = iceil(tload);
// never exceed half of the load period, even for FSwitch
intload = imin(intload,loadperiod / 8);
}
return intload;
}
/////////////////////////////////////////////////////////////////
// Procedure to compute total dead times for the mode
//
{double,double,double,double,double} procedure SScanDoubleChop_deadtimes {
string chopmode = "chop" in ["chop","lchop","fs"]; // chop mode
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int grouplen = 1; // Number of frequency steps per nodding phase
int data_time = 4; // data dump interval on ON
int data_time_off = 4; // data dump interval on OFF
int n_chop_on = 3; // number of chop cycles in one integration on ON
int n_chop_off = 3; // number of chop cycles in one integration on OFF
int n_long_on = 3; // number of chop cycles for long integration on ON
int n_long_off = 3; // number of chop cycles for long integration on OFF
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
double avnumchop_on = 1.0; // Average number of ON chop cycles per frequency
double avnumchop_off = 1.0; // Average number of OFF chop cycles per frequency
double tscan = 10.0; // Dead time from telescope
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Compute parameters for the instrument timing in normal phases
// Four different cases involved
{double,double} tinst = GetInstDeadSlowChop(data_time,2 * n_chop_on,chopmode,band,lo_freq,backendreadoutparms);
// dead time
double tdeadint_on = double(data_time * 2 * n_chop_on) - tinst{0};
// subtract dead times in switches
// keep dead times between A-A and B-B in total dead time
tdeadint_on = tdeadint_on - double(n_chop_on) * tinst{1};
// treat integration times of other frequencies as dead time
double tdeadother_on = double(data_time * 2 * n_chop_on);
// Store
double tswitch_on = tinst{1};
// Integration time
double tphaseint_on = tinst{0};
// Correcton in case of cycles with longer integrations
if(n_cycles > 1) {
tinst = GetInstDeadSlowChop(data_time,2 * n_long_on,chopmode,band,lo_freq,backendreadoutparms);
// dead time
double tdeadlong = double(data_time * 2 * n_long_on) - tinst{0};
// subtract dead times in switches
tdeadlong = tdeadlong - double(n_long_on) * tinst{1};
// weigh
int numlong_on = 2 * (n_cycles / 2);
double wlong = double(numlong_on) / double(grouplen * n_cycles);
double wshort = double(n_cycles * grouplen - numlong_on) / double(grouplen * n_cycles);
tdeadint_on = wlong * tdeadlong + wshort * tdeadint_on;
tphaseint_on = (wlong * tinst{0} + wshort * tphaseint_on) / (2.0 * avnumchop_on);
tdeadother_on = wshort * tdeadother_on + double(data_time * 2 * n_long_on) * wlong;
} else {
tphaseint_on = tphaseint_on / (2.0 * avnumchop_on);
}
// OFF phase
tinst = GetInstDeadSlowChop(data_time_off,2 * n_chop_off,chopmode,band,lo_freq,backendreadoutparms);
// dead time
double tdeadint_off = double(data_time_off * 2 * n_chop_off) - tinst{0};
// subtract dead times in switches
// keep dead times between A-A and B-B in total dead time
tdeadint_off = tdeadint_off - double(n_chop_off) * tinst{1};
// treat integration times of other frequencies as dead time
double tdeadother_off = double(data_time_off * 2 * n_chop_off);
// Store
double tswitch_off = tinst{1};
// Integration time
double tphaseint_off = tinst{0};
// Correcton in case of cycles with longer integrations
if(n_cycles > 1) {
tinst = GetInstDeadSlowChop(data_time_off,2 * n_long_off,chopmode,band,lo_freq,backendreadoutparms);
// dead time
tdeadlong = double(data_time_off * 2 * n_long_off) - tinst{0};
// subtract dead times in switches
tdeadlong = tdeadlong - double(n_long_off) * tinst{1};
// weigh
int numlong_off = 2 * ((n_cycles - 1) / 2);
wlong = double(numlong_off) / double(grouplen * n_cycles);
wshort = double(n_cycles * grouplen - numlong_off) / double(grouplen * n_cycles);
tdeadint_off = wlong * tdeadlong + wshort * tdeadint_off;
tphaseint_off = (wlong * tinst{0} + wshort * tphaseint_off) / (2.0 * avnumchop_off);
tdeadother_off = wshort * tdeadother_off + double(data_time_off * 2 * n_long_off) * wlong;
} else {
tphaseint_off = tphaseint_off / (2.0 * avnumchop_off);
}
// Total dead time per cycle
double tdead = tscan - double(grouplen * 2 * data_time) * avnumchop_on - double(grouplen * 2 * data_time_off) * avnumchop_off;
double tdead_tot = tdead + tdeadint_on + tdeadint_off;
// Add integration times of other frequencies as dead time
tdead_tot = tdead_tot + double(grouplen - 1) * (tdeadother_on + tdeadother_off);
// Return total dead time and the dead times in the two chops
return {tdead_tot,tphaseint_on,tphaseint_off,tswitch_on,tswitch_off};
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure SScanFSwitchNoRef_commanding {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference characteristic LO frequency
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int grouplen = 1; // Number of frequency steps per nodding phase
int[][] grouporder = [[0],[0]]; // Sequence to trace frequency points in both phases
double[] freqgrid = [978053.7,978301.8,978381.1]; // Table of frequency points
bool retuning = false; // need for WBS retuning
double[] targetlevels = [1.0,1.0,1.0]; // WBS tuning levels
int data_time = 4; // chunk size
int n_per_on = 1; // number of half load-sky-sky-load cycles on ON
int n_load_on = 0; // additional load measurements in ON pointing phase
int groupnumber = 4; // Total number of frequency groups
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,0]; // Timing of observation from telescope
int loadlength = 50; // Load duration
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,reffreq,backendreadoutparms);
// First frequency
double runningfreq = freqgrid[grouporder[0][0]];
string[] targetnames = TargetNames(band,reffreq,retuning,targetlevels);
string target = targetnames[0];
// All commands with a duration possibly depending on the frequency
// are taken at the reference frequency to guarantee synchonization
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
HIFIInitObs();
TuneHIFIFsw(band,runningfreq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},target);
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,true,eff_resolution{0},data_time,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
for(int i_freq = 0 .. groupnumber - 1) {
// First frequency
// Loop over load cycles
for(int i1 = 1 .. n_load_on) {
// Actual measurement
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,rates);
// Perform load calibration
delay(readoutdead);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
}
if(n_load_on == 0) {
// This is the only measurement executed with nload=0
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,rates);
}
// Other frequencies
// Reset group counter
for(int i_group = 1 .. grouplen - 1) {
// retune
runningfreq = freqgrid[grouporder[0][i_group] + i_freq * grouplen];
HIFIChangeFreqFsw(band,runningfreq,freq_throw);
if(n_load_on > 0) {
// First load
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
} else {
// This is the only measurement executed with nload=0
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,rates);
}
// Loop over load cycles
for(int i2 = 1 .. n_load_on) {
// Actual measurement
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,rates);
// Perform load calibration
delay(readoutdead);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
}
}
// Now we switch to the next frequency group or repeat the cycle
// Big tuning step, but not at end of observation
if(i_freq < groupnumber - 1) {
runningfreq = freqgrid[grouporder[0][0] + (i_freq + 1) * grouplen];
target = targetnames[i_freq + 1];
HIFIRetuneFsw(band,runningfreq,freq_throw,target);
// first load or main load for n_load=0
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
}
}
}
if(state[0] == 5) {
if(n_load_on == 0) {
delay(readoutdead);
}
HIFICloseObs();
}
}
}
/////////////////////////////////////////////////////////////////
// Procedure to derive the backend settings for spectral scans
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} procedure SScanBackendSettings {
string band = "4a"; // HIFI band
int redundancy = 4; // Frequency scan redundancy
bool wbs1_used = true; // whether WBS1 is used
bool wbs2_used = true; // whether WBS2 is used
int data_time = 4; // data dump interval
}{
// Standard configuration of the backends
// Get appropriate settings for selected HIFI band
double[] x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,0.0);
int[][] stdWbsWindows = [[iround(x[0]),iround(x[1])],[iround(x[2]),iround(x[3])],[iround(x[4]),iround(x[5])],[iround(x[6]),iround(x[7])]];
{bool,int[][]} wbs1 = {wbs1_used,stdWbsWindows};
{bool,int[][]} wbs2 = {wbs2_used,stdWbsWindows};
// WBS parameters ={used, channel windows}
// Check whether we can use the HRS in parallel
// Get fixed HRS parameters
{{bool,int,double[],bool[]},{bool,int,double[],bool[]}} hrsparms = GetSpectralScanHRS(redundancy,band);
{bool,int,double[],bool[]} hrs1 = hrsparms{0};
{bool,int,double[],bool[]} hrs2 = hrsparms{1};
string[] resolstring = ["high-resolution","nominal-resolution","low-resolution","wide-resolution"];
// Create a composite readout structure
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Compute chunk size given by the data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
// Test whether HRS can be used
if(dataparms{0} > data_time) {
// No HRS possible
// HRS parameters when not used
hrs1 = {false,1,[-110.0,110.0,0.0,0.0],[false,false,false,false]};
hrs2 = {false,1,[-110.0,110.0,0.0,0.0],[false,false,false,false]};
message("No parallel HRS usage due to short chop phase length.
");
// Create a composite readout structure
backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Check chunk size given by the data rates
CheckDataTaking(backendreadoutparms,data_time);
} else {
message("HRS running parallel in " + resolstring[hrs1{1}] + " mode.
");
}
return {hrs1,hrs2,wbs1,wbs2};
}
{int,double,double,double,double,double} obs HifiPointModeFSwitchNoRef {
string modeName = "fs";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int n_cycles = 2 in [1,3600]; // number of half nu1-nu2-nu2-nu1 cycles on ON
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Single Point - Frequency Switch noRef",{data_time,0,0,0,0,0,0,0,n_cycles,load_interval},false);
// Two cases: fine pointing or position switch
// Call first part of the timing computer
{int,int,int,int,int,int,bool,int,int} pre_timing_f = FSwitchNoRef_pre_timing(band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_cycles,load_interval,docommands);
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,double,double,int} tpar_f = Fine_telescope(naifid,onPosition,band,lo_freq,pre_timing_f);
// Dummy call to spacecraft command
int[] telescopetimes = basic_fine_pointing(false,tpar_f{0},tpar_f{1},tpar_f{2},tpar_f{3},tpar_f{4},tpar_f{5},tpar_f{6},tpar_f{7},tpar_f{8},tpar_f{9});
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,bool,int,int},double,double} post_timing_f = SingleChopNoRef_post_timing(pre_timing_f,telescopetimes);
// Now the actual observation starts
// Prepare telescope command
tpar_f = Fine_telescope(naifid,onPosition,band,lo_freq,post_timing_f{1});
// Call telescope command
telescopetimes = basic_fine_pointing(true,tpar_f{0},tpar_f{1},tpar_f{2},tpar_f{3},tpar_f{4},tpar_f{5},tpar_f{6},tpar_f{7},tpar_f{8},tpar_f{9});
// Consistency check
int totaltime = post_timing_f{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
//////////////////////////////////////////////////////////////////////
// standard parameters for fine pointing
int loadlength = post_timing_f{1}{2};
int n_per_on = post_timing_f{1}{4};
int n_load_on = post_timing_f{1}{5};
bool end_load_on = post_timing_f{1}{6};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
//////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
FSwitchNoRef_commanding(band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_per_on,n_load_on,end_load_on,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double} tact = SingleChop_deadtimes("fs",band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_per_on);
double tscan = 2.0 * (tact{1} + tact{2});
double tdead = 2.0 * tact{2};
//
// Call noise computer
{double,double,double,double,double} noisevalues = FSwitchNoRef_noisecomputer(band,lo_freq,effResolution,oneGHzReference,n_per_on * (n_load_on + 1),tscan,tdead);
// Evaluate performance
SingleChopNoRef_performance(band,lo_freq,effResolution,noisevalues,timeTaken,n_per_on * (n_load_on + 1),true,tscan,tdead);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
/////////////////////////////////////////////////////////////////
// Procedure to compute detailed timing for a
// Spectral Scan Frequency-Switch observing mode
//
{{int,int,int,int,int,int,bool,int,int},{int,double,double[],int[][],bool,double[],int,bool}} procedure SScanFSwitchNoRef_pre_timing {
string band = "4a"; // HIFI band
double lo_freq_low = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4; // Frequency scan redundancy
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_chop_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Create composite readout structure for backends
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Get frequency grid characteristic parameters
{int,double,double[],int[][],int,bool} fqparms = MakeFreqGrid(band,lo_freq_low,lo_freq_up,redundancy,"fs",freq_throw,n_freq_point);
int groupnumber = fqparms{0};
double reffreq = fqparms{1};
double[] freqgrid = fqparms{2};
int[][] grouporder = fqparms{3};
// Process tuning level grid
double[][] levelgrid = GetSScanLevelGrid(band,wbs1,wbs2,freqgrid,fqparms{0},grouporder);
{bool,double[]} targets = TargetLevels(band,reffreq,levelgrid);
bool retuning = targets{0};
double[] targetgrid = targets{1};
string reftarget = "";
if(retuning) {
reftarget = "sscan_normal";
}
{int,double,double[],int[][],bool,double[],int,bool} spectralparms = {fqparms{0},reffreq,freqgrid,grouporder,retuning,targetgrid,fqparms{4},fqparms{5}};
//////////////////////////////////////////////////////////////////////
// Get timing within the normal frequency-switch observations
int readoutdead = SlowChopReadoutDelay(band,reffreq,backendreadoutparms);
int jitterdead = GetMaxTimeJitter(band,reffreq);
// Integration time per frequency and pointing
int on_inttime = 2 * n_chop_on * data_time;
// Tuning delays
int bigtunestep = duration(HIFIRetuneFsw(band,reffreq,freq_throw,reftarget));
// Correct for variation within the band
int tunediff = ComputeLOTimeDifference(band,lo_freq_low,lo_freq_up,reffreq,true);
bigtunestep = bigtunestep + 2 * tunediff;
// A step within a group could be faster than a large step
if(n_freq_point > 1) {
int smallstep = duration(HIFIChangeFreqFsw(band,reffreq,freq_throw));
tunediff = ComputeLOTimeDifference(band,lo_freq_low,lo_freq_up,reffreq,false);
smallstep = smallstep + 2 * tunediff;
} else {
smallstep = bigtunestep;
}
int grouptime = n_freq_point * on_inttime + (n_freq_point - 1) * smallstep;
// Duration of initial set up
// Staying at the same frequency makes no sense here.
// First frequency point
double runningfreq = freqgrid[grouporder[0][0]];
// Compute load integration time
int loadlength = duration(SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,true,eff_resolution{0},data_time,backendreadoutparms));
loadlength = loadlength + readoutdead;
// determine exact duration only in case of full commanding
if(docommands) {
int initlength = duration(HIFIInitObs());
initlength = initlength + duration(TuneHIFIFsw(band,runningfreq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},"sscan_normal"));
// Add time for HK readout
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,false);
initlength = initlength + hkduration;
} else {
initlength = GetRoughInitLength(band,runningfreq,true);
}
initlength = initlength + loadlength;
int initloadlength = loadlength;
// recompute load length during slews - no retuning
loadlength = duration(SScanDoubleLoadMeasurement(band,reffreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms));
loadlength = loadlength + readoutdead;
// Compare load interval with duration of the observation
int load_spacing = CheckedLoadSpacing(load_interval - loadlength,8);
if(load_spacing < grouptime && n_freq_point > 1) {
SError("Load period too short for frequency group size.");
}
// Here we bracket each cycle by loads, this leads to a grace period
int n_load_on = on_inttime / load_spacing;
// In the following the definition of n_load_on is higher by 1 relative to
// that used in normal frequency switch!
// This determines the order of the loops
if(n_load_on == 0) {
int n_per_on = n_chop_on;
bool end_load_on = false;
} else {
// grace condition
if(double(on_inttime) > 1.2 * double(load_spacing)) {
n_load_on = n_load_on + 1;
}
n_per_on = n_chop_on / n_load_on;
if(n_per_on < 1) {
SError("FS phase length on source too long relative to load period.");
}
end_load_on = true;
on_inttime = 2 * n_per_on * n_load_on * data_time;
// This cannot happen for n_freq_point > 1
grouptime = on_inttime + n_load_on * loadlength;
}
int on_pointing = groupnumber * (grouptime + bigtunestep + loadlength) - bigtunestep - loadlength + jitterdead;
// dangling time given by readout dead time
int dangling = readoutdead;
// Return all the times needed for telescope call and post_timing processing
return {{on_inttime,on_pointing,initloadlength,load_spacing,n_per_on,n_load_on,end_load_on,initlength,dangling},spectralparms};
}
{string,double,double}[] procedure HifiPointModeLoadChopSequencerInit {
string modeName = "load";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half load-sky-sky-load cycles on ON
int n_switch_off = 2 in [1,900]; // number of half load-sky-sky-load cycles on OFF
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF calibration cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// limit on data rate
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
{double,double,double,double} phaselengths = LoadChopPhaseLengths(band,lo_freq,effResolution,oneGHzReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
int n_switch_on_guess = imax(iceil(phaselengths{0} / (2.0 * double(data_time_guess))),1);
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// OFF phase
int data_time_off_guess = imin(imax(iceil(phaselengths{2}),datalimit),20);
int data_time_off_range = datalimit - data_time_off_guess;
if(data_time_off_range == 0) {
data_time_off_range = 1;
}
int n_switch_off_guess = imax(iceil(double(data_time_guess * n_switch_on_guess) / (double(data_time_off_guess) * sqrt(phaselengths{3} / effResolution{1}))),1);
int n_switch_off_range = 1 - n_switch_off_guess;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Add pointing requirements condition: >=10s
{int,int} new_data_time = MatchMinPointing(data_time_guess,data_time_range,2 * n_switch_on_guess);
data_time_guess = new_data_time{0};
data_time_range = new_data_time{1};
new_data_time = MatchMinPointing(data_time_off_guess,data_time_off_range,2 * n_switch_off_guess);
data_time_off_guess = new_data_time{0};
data_time_off_range = new_data_time{1};
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"data_time_off",double(data_time_off_guess),double(data_time_off_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)}];
return retvalues;
}
// Procedure to get timing in a spectroscopy measurement
{double,double} procedure GetInstDeadSlowChop {
/* Integration time */
int data_time = 4; // Integration time between two data readouts
int n_int = 2; // Integration time counter
string chopmode = "chop" in ["chop","lchop","fs","hot-cold","tp"]; // Chop mode determining the modulation dead time
/* Parameters determining the delays - used in calibration reader */
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
/* Backend settings */
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used,channel windows}
}{
// Get timing parameters
{int,int,int,int,int,int,int,int,int,int} timing = ConfigureSpectroscopyParams(data_time,n_int,chopmode,band,lo_freq,backendreadoutparms);
int tdead = timing{8};
int tint = timing{9};
// Return dead time per full integration
double tintall = double(tint) / 1000.0;
double tdeadphase = double(tdead) / 1000.0;
return {tintall,tdeadphase};
}
// Combine radiometric and drift noise from an OTF observation
// Normalized to mapping without overhead
//
{double,double} procedure OtfNoiseValues {
double n = 10.0; // number of points in one scan
double[] parameters = [0.02,0.4,0.05,0.667,2.5]; // Parameters: integration time, delay, slew from OFF relative to Allan time, ratio of t_off time to sqrt(n)*t_on, drift exponent
}{
// Assign parameters
double npoints = double(ifloor(n));
double x = parameters[0];
double d = parameters[1];
double doff = parameters[2];
double qval = parameters[3];
double alpha = parameters[4];
if(npoints > 0.0) {
// OFF integration time
double xr = qval * sqrt(npoints) * x;
// Total delay
double dtot = (npoints - 1.0) * x + d;
// Try two points at the edge and the center of a scan to get the extremes
double[] pp = [0.0,0.5];
double[] yn = [0.0,0.5];
double[] yd = [0.0,0.5];
double[] yy = [0.0,0.5];
double p = 0.0;
for(int ip = 0 .. 1) {
p = pp[ip];
// Delay length before measured point
double d1 = doff + double(ifloor(p * npoints)) * x + p * (d - 2.0 * doff);
// Remaining delay
double d2 = dtot - d1;
// add radiometric and drift noise
yn[ip] = OtfRadioNoise(x,xr,d1,d2);
yd[ip] = OtfDrift(x,xr,d1,d2,alpha);
yy[ip] = yn[ip] + yd[ip];
}
// Normalization - relative to mapping without overhead
double norm = (x + xr + dtot) / npoints;
// Get worst case
if(yy[0] > yy[1]) {
double ynm = yn[0] * norm;
double ydm = yd[0] * norm;
} else {
ynm = yn[1] * norm;
ydm = yd[1] * norm;
}
// Artificially forbid OTF scans much longer than the Allan time
double driftadd = max(dtot + x - 10.0,0.0) * 0.1;
ydm = ydm + driftadd * ynm;
} else {
// forbid negative point numbers
ynm = 1.0E11;
ydm = 1.0E11;
}
return {ynm,ydm};
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure SScanLoadChopNoRef_commanding {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference characteristic LO frequency
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int grouplen = 1; // Number of frequency steps per nodding phase
int[][] grouporder = [[0],[0]]; // Sequence to trace frequency points in both phases
double[] freqgrid = [978053.7,978301.8,978381.1]; // Table of frequency points
bool retuning = false; // need for WBS retuning
double[] targetlevels = [1.0,1.0,1.0]; // WBS tuning levels
int data_time = 4; // chunk size
int n_per_on = 1; // number of half load-sky-sky-load cycles on ON
int n_load_on = 0; // additional load measurements in ON pointing phase
int groupnumber = 4; // Total number of frequency groups
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,0]; // Timing of observation from telescope
int loadlength = 50; // Load duration
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,reffreq,backendreadoutparms);
bool retuneload = n_load_on > 0;
// First frequency
double runningfreq = freqgrid[grouporder[0][0]];
string[] targetnames = TargetNames(band,reffreq,retuning,targetlevels);
string target = targetnames[0];
// All commands with a duration possibly depending on the frequency
// are taken at the reference frequency to guarantee synchonization
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
HIFIInitObs();
TuneHIFI(band,runningfreq,hrs1,hrs2,wbs1{0},wbs2{0},target);
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},data_time,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
for(int i_freq = 0 .. groupnumber - 1) {
// First frequency
// Loop over load cycles
for(int i1 = 1 .. n_load_on) {
// Actual measurement
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFILoadChopOnIntegration(data_time,n_per_on,band,reffreq,rates);
// Perform load calibration
delay(readoutdead);
SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},data_time,backendreadoutparms);
}
if(n_load_on == 0) {
// This is the only measurement executed with nload=0
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFILoadChopOnIntegration(data_time,n_per_on,band,reffreq,rates);
}
// Other frequencies
// Reset group counter
for(int i_group = 1 .. grouplen - 1) {
// retune
runningfreq = freqgrid[grouporder[0][i_group] + i_freq * grouplen];
HIFIChangeFreq(band,runningfreq);
if(retuneload) {
// First load
SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},data_time,backendreadoutparms);
} else {
// This is the only measurement executed with nload=0
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFILoadChopOnIntegration(data_time,n_per_on,band,reffreq,rates);
}
// Loop over load cycles
for(int i2 = 1 .. n_load_on) {
// Actual measurement
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
HIFILoadChopOnIntegration(data_time,n_per_on,band,reffreq,rates);
// Perform load calibration
delay(readoutdead);
SScanLoadMeasurement(band,runningfreq,reffreq,true,eff_resolution{0},data_time,backendreadoutparms);
}
}
// Now we switch to the next frequency group or repeat the cycle
// Big tuning step, but not at end of observation
if(i_freq < groupnumber - 1) {
runningfreq = freqgrid[grouporder[0][0] + (i_freq + 1) * grouplen];
target = targetnames[i_freq + 1];
HIFIRetuneFreq(band,runningfreq,target);
// first load or main load for n_load=0
SScanLoadMeasurement(band,runningfreq,reffreq,retuneload,eff_resolution{0},data_time,backendreadoutparms);
}
}
}
if(state[0] == 5) {
if(n_load_on == 0) {
delay(readoutdead);
}
HIFICloseObs();
}
}
}
// Total noise from an asymmetric double difference observation
// This is still to be scaled by a factor 1.0/(B_fluct*T_obs)
double procedure DoubleDifferenceNoise {
double x = 0.1; // value for integration time relative to Allan time
double[] parameters = [1.0,1.0,0.8,0.8,0.05,0.3,2.5,5.0,2.5]; // Parameters: ratio of integration times, ratio of effective resolutions, delay in phase1, in phase 2, between phases relative to Allan time, drift exponents
}{
// Assign parameters
double tpa = parameters[2];
// total length of A pointing phase
double tpb = parameters[3];
// total length of B pointing phase
double d = parameters[5];
// position switch dead time relative to differential Allan
{double,double} noisevalues = DoubleDifferenceNoiseValues(x,parameters);
// Add and normalize with respect to total observing time
double y = (noisevalues{0} + noisevalues{1}) * (tpa + tpb + d);
return y;
}
// Perform load chop integration at OFF position ON-OFF-OFF-ON...
block HIFILoadChopOffIntegration HIFI 6036 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_slow_chop_proc_aot(data_time,n_cycle,band,lo_freq,["chop_cold","chop_M3"],rates);
}
// Give sequence of frequency steps in a spectral scan mode within one group
double[][] procedure SpreadHRS {
string band = "4a"; // HIFI band
int[] resolution = [1,1]; // Frequency resolution
double[] offset = [0.0,0.0]; // Center offsets
}{
// Define using the values for resolution=0
double[][] settings = [[offset[0],0.0,0.0,0.0],[offset[1],0.0,0.0,0.0]];
// set up individually for the two HRS's
for(int i = 0 .. 1) {
int res = resolution[i];
double off = offset[i];
// create settings
if(res == 0) {
double[] subset = [off,0.0,0.0,0.0];
} else {
// Set subband width
double singlewidth = GetBackendBandwidth(band,0.0,res);
// Arrange with some overlap
double hrsgranularity = 20.0;
double doff = 0.5 * (singlewidth - hrsgranularity);
if(res == 1) {
subset = [off - doff,off + doff,0.0,0.0];
} else {
subset = [off - 3.0 * doff,off - doff,off + doff,off + 3.0 * doff];
}
}
settings[i] = subset;
}
return settings;
}
// Change of HK rate - setting of corresponding data rates
block HIFISetHK HIFI 6001 {
string speed = "normal" in ["fast","normal","slow"]; // Select HK rate
bool active = false; // Whether to actively query the spectrometers
}{
// Get parameters
{string,int,double,double,double,double} hkparms = PeriodicHKParms(speed);
non_ess_hk_data_rate(hkparms{3} / 1024.0);
ess_hk_data_rate(hkparms{5} / 1024.0);
// Subsystems to be queried
string[] pattern = QueryHKPattern(active);
Hifi_HIFI_Housekeeping_on(hkparms{0},pattern[0],pattern[1],pattern[2],pattern[3],pattern[4],pattern[5]);
delay(1);
}
{string,double,double}[] procedure HifiMappingModeFSwitchOTFNoRefSequencerInit {
string modeName = "fs-raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period defines number of lines between two loads
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// inherit from load-chop mode
{string,double,double}[] retvalues = HifiMappingProcLoadChopOTFNoRefSequencerInit(naifid,ra,dec,lineDistance,nlines,stepsize,npoints,band,lo_freq,effResolution,oneGHzReference,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
return retvalues;
}
{string,double,double}[] procedure HifiMappingModeFastDBSCrossSequencerInit {
string modeName = "cross";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// inherit from dbs-raster mode
{string,double,double}[] retvalues = HifiMappingProcFastDBSRasterSequencerInit(naifid,ra,dec,{0.0,double(npoints / 2) * stepsize},2,stepsize,npoints,band,lo_freq,effResolution,continuumDetection,oneGHzReference,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
return retvalues;
}
//Compute "real" frequencies
double procedure Compute_Real_Freq {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978.2; //LO frequency
}{
//Read parameters
double[] result = CalibrationReader("name_lsu_convertion",["multiplier","f_offset","n10","n20"],band,lo_freq);
double multiplier = result[0];
double f_offset = result[1];
int n10 = iround(result[2]);
int n20 = iround(result[3]);
//
//Compute LSU frequency IN MHZ
double f_lsu = lo_freq * 1000.0 / multiplier;
//Compute total frequency
double f_total = f_lsu + f_offset;
//Compute parameter n
int n = ifloor(15.0 * (f_total / 1.875 - double(ifloor(f_total / 1.875))));
//Compute main and offset loop parameters
int n1 = n10 + n;
// offset loop
int d1 = 15;
//offset loop
int n2 = iround(abs(double(n20 - ifloor(f_total / 1.875) + n)));
//main loop
int d2 = 16;
//
//Compute A,M and R parameters for main and offset loop
int m1 = ifloor(double(n1) / 10.0) - 1;
// offset loop
int a1 = n1 - 10 * ifloor(double(n1) / 10.0);
// offset loop
int r1 = d1 - 1;
// offset loop
int m2 = ifloor(double(n2) / 10.0) - 1;
// main loop
int a2 = n2 - 10 * ifloor(double(n2) / 10.0);
// main loop
int r2 = d2 - 1;
// main loop
//
int[] lsu_a_m_r_parameter = [0,0,0,0,0,0];
lsu_a_m_r_parameter[0] = m1;
lsu_a_m_r_parameter[1] = a1;
lsu_a_m_r_parameter[2] = r1;
lsu_a_m_r_parameter[3] = m2;
lsu_a_m_r_parameter[4] = a2;
lsu_a_m_r_parameter[5] = r2;
//
//Conversion into main and offset LSU word
int main_word = iround(pow(2.0,18.0) * double(ifloor(double(r2) % pow(2.0,6.0) / pow(2.0,4.0))) + pow(2.0,15.0) * double(ifloor(double(m2) % pow(2.0,9.0) / pow(2.0,7.0))) + pow(2.0,8.0) * (double(m2) % pow(2.0,9.0)) + pow(2.0,4.0) * (double(r2) % pow(2.0,6.0) % pow(2.0,4.0)) + double(a2) % pow(2.0,4.0));
int offset_word = iround(pow(2.0,18.0) * double(ifloor(double(r1) % pow(2.0,6.0) / pow(2.0,4.0))) + pow(2.0,15.0) * double(ifloor(double(m1) % pow(2.0,9.0) / pow(2.0,7.0))) + pow(2.0,8.0) * (double(m1) % pow(2.0,9.0)) + pow(2.0,4.0) * (double(r1) % pow(2.0,6.0) % pow(2.0,4.0)) + double(a1) % pow(2.0,4.0));
//
//debug_print("LSU conversion result " + lsu_a_m_r_parameter);
//debug_print("main: " + main_word + ", offset: " + offset_word);
//
//Compute real LO frequency set by A,M,R combination
double nn1 = double(10 * (m1 + 1) + a1);
double dd1 = double(r1 + 1);
double nn2 = double(10 * (m2 + 1) + a2);
double dd2 = double(r2 + 1);
double flsu_back = 24000.0 + 30.0 * (nn1 / dd1 + nn2 / dd2);
if(band == "2a" || band == "3b") {
flsu_back = 24000.0 + 30.0 * (nn1 / dd1 - nn2 / dd2);
}
double flo_back = flsu_back * multiplier;
//debug_print("Real tuned frequency: " + flo_back);
//
return flo_back;
}
//Procedure to calculate individual LCU memory segments
procedure LcuChecksumRecalcSegmented_aot {
string band = "1a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string code_category = "Safe" in ["Safe","Critical","Table","Table_all","Unused"]; //Safe, Critical, Table, Unused or Table_all
string hifi_HIF_block_when_nok = "NO" in ["YES","NO"]; // HIF_block_when_nok
}{
//Band 0 can be chosen in transition to dissipative_II
//If it is selected and test is on table, only the delay is kept
if(band == "0" && code_category == "Table") {
delay(2);
} else {
//If we are in band 0, band number has to be changed as place-holder
if(band == "0") {
band = "1a";
}
//
//Criticality keyword
string hifi_HIF_lcu_critical = "Safe";
if(code_category == "Table") {
hifi_HIF_lcu_critical = "Table";
}
if(code_category == "Critical") {
hifi_HIF_lcu_critical = "Critical";
}
//
{int,int}[] addresses = [];
int hifi_Nsteps = 48;
//Fix number of entries in addresses
//Get tupple of addresses and checksum
if(code_category == "Table") {
{{int,int}[],int,int} add_crc = LcuGetTableAddress_ops(band);
addresses = add_crc{0};
int crc_total = add_crc{1};
int length_total = add_crc{2};
}
if(code_category == "Safe" || code_category == "Critical" || code_category == "Unused") {
add_crc = LcuGetCodeAddress_ops(code_category);
addresses = add_crc{0};
crc_total = add_crc{1};
length_total = add_crc{2};
}
if(code_category == "Table_all") {
//Get start address, and length for one band
add_crc = LcuGetTableAddress_ops("1a");
int address_start = add_crc{0}[0]{0};
crc_total = add_crc{1};
length_total = 14 * add_crc{2};
addresses = add_crc{0};
addresses[0] = {address_start,length_total};
for(int j = 1 .. hifi_Nsteps - 1) {
addresses[j] = {0,0};
}
//Loop on bands for individual checksums
string[] band_array = ["1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"];
for(int i = 0 .. 12) {
add_crc = LcuGetTableAddress_ops(band_array[i]);
crc_total = crc_total + add_crc{1};
}
//Wrap-around CRC
crc_total = crc_total % (0xffff + 1);
//
}
//Send TC to ICU
Hifi_HIFI_check_LCU_memparts($BBID,hifi_HIF_lcu_critical,band,hifi_HIF_block_when_nok,crc_total,hifi_Nsteps,addresses);
//Compute total delay: proportional to size to compute
double crc_speed = 66000.0;
//in byte/sec
int checksum_total_delay = iceil(double(length_total) / crc_speed) + 1;
delay(checksum_total_delay);
//
}
}
// Total noise from an OTF observation
//
double procedure OtfNoise {
double n = 10.0; // number of points in one scan
double[] parameters = [0.02,0.4,0.05,0.667,2.5]; // Parameters: integration time, delay, slew from OFF relative to Allan time, ratio of t_off time to sqrt(n)*t_on, drift exponent
}{
{double,double} noisevalues = OtfNoiseValues(n,parameters);
double y = noisevalues{0} + noisevalues{1};
return y;
}
//////////////////////////////////////////////////////////////////////
// Procedure to perform the noise level evaluation for the observing mode
{double,double,double,double,double} procedure SScanFSwitch_noisecomputer {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference LO frequency in scan center
int nfreq = 4; // Number of frequency points per IF
bool dsb = true; // Both sidebands covered
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
int on_inttime = 16; // Integration time per ON phase
int off_inttime = 16; // Integration time per OFF phase
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
double tscan = 60.0; // Total average duration of one scan
{double,double,double,double,double} tact = {10.0,4.9,4.9,0.05,0.05}; // Field of actual dead and integration times
}{
// spectral scans always use the full bandwidth for reference
bool oneGHzReference = false;
// Call FS noise computer
{double,double,double,double,double} noisevalues = FSwitch_noisecomputer(band,reffreq,eff_resolution,oneGHzReference,on_inttime,off_inttime,n_cycles,tscan,tact);
// Combined sideband scaling
double[] gssb = InterpolateGssb(band,reffreq);
double avgainfac = 0.5 / gssb[0] + 0.5 / gssb[1];
double rescalefac = gssb[1] * avgainfac;
// Correct for multiple frequencies
double multiplier = sqrt(1.0 / double(nfreq));
noisevalues{0} = noisevalues{0} * gssb[0] * multiplier;
noisevalues{1} = noisevalues{1} * gssb[0] * multiplier;
// Check for double sideband coverage
if(dsb) {
// Combine LSB-USB noise
// In spectral scans we have only a combined noise temperature for both
// sidebands, so that the USB/LSB separation is not used
double decnoise_lores = noisevalues{0} / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double decnoise_hires = noisevalues{1} / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double indnoise_lores = noisevalues{2} * rescalefac;
double indnoise_hires = noisevalues{3} * rescalefac;
} else {
// Get single sideband noise equivalent
decnoise_lores = noisevalues{0} * avgainfac;
decnoise_hires = noisevalues{1} * avgainfac;
indnoise_lores = noisevalues{2} * rescalefac;
indnoise_hires = noisevalues{3} * rescalefac;
}
// Return noise values and the maximum ratio of drift to radiometric noise
return {decnoise_lores,decnoise_hires,indnoise_lores,indnoise_hires,noisevalues{4}};
}
// Length of a vector in degrees
double procedure VectorLength {
{double,double} vector = {1.0,1.0};
}{
return sqrt(vector{0} * vector{0} + vector{1} * vector{1});
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the DBS raster mode
procedure FastDBSRaster_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 10 in [4,80]; // data dump interval
int n_int = 20; // number chop cycles to integrate in ICU before transfer
int n_seq = 1; // number of data transfer cycles per pointing
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles
int n_pointsperscan = 1; // Number of points measured before moving to the second pointing phase
int n_loadinterval = 10; // number of nods before a load measurement
int n_load = 0; // additional load measurements in one pointing phase
bool final_load = false; // Need for final load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,10,0,10,20,21,0,0,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
bool iscross = false; // Whether we use a cross instead of a raster
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Fixed timings in the fast-chop mode
int load_datatime = GetStdLoadReadout(band,lo_freq);
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time / 2);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,true);
int readoutdead = FastChopReadoutDelay(band,lo_freq,backendreadoutparms);
// Count phases by hand to allow simultaneous usage by Raster and Cross
int iphase = 0;
// There is no nod counter in the return values - count this by hand
int inod = 0;
int ihold = 0;
// Do I have to make loads in short nods and subsequent holds?
if(iscross) {
bool holdforload = n_pointsperscan > 1;
int phaseshift = 0;
} else {
holdforload = n_pointsperscan == 1 && n_loadinterval > n_cycles;
phaseshift = 1;
}
bool isOffAtPoint = false;
bool isLastPhase = false;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
int[] choppars = [2 * n_int,0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - hkduration - loadlength);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = false;
iphase = iphase + 1;
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
// Sanity check
if(runintostate && iscross) {
CError("Ongoing integration while arriving at ON nodding position.");
}
// Check whether we are in a cross mode using computed OFF
isOffAtPoint = iscross && holdforload && inod % 2 == 1;
// Configure measurement
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
// The use of n_load differs by 1 from the other observing modes here
for(int i1 = 1 .. n_load - 1) {
if(isOffAtPoint) {
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
} else {
HIFIFastChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
}
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
if(isOffAtPoint) {
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
} else {
HIFIFastChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
}
// Final point before nod
// Dirty trick to find out whether we are at the very last point
isLastPhase = telescopetimes[0] + tinitslew - (time() - startobs) < data_time * n_seq;
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == 1) {
inod = inod + 1;
}
// Special treatment for all cases where load has to be replaced by hold:
// n_pointsperscan=1, n_loadinterval > n_cycles
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == phaseshift) {
ihold = ihold + 1;
if(holdforload && ihold % n_loadinterval == 0 && n_load == 0 && !isLastPhase) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// keep shift if we come from a holdforload nod, otherwise reset
if(!holdforload) {
runintostate = false;
}
// Load measurement between two A-A or B-B phases if required
// Time partially included in pointing
if(n_load > 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
// Run into final hold for very last point
if(isLastPhase) {
runintostate = true;
}
}
}
// Update phase counter
iphase = iphase + 1;
}
// Second pointing phase
if(state[0] == 7) {
// second nod position
// Sanity check
if(runintostate && iscross) {
CError("Ongoing integration while arriving at OFF nodding position.");
}
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
for(int i2 = 1 .. n_load - 1) {
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Final point before nod
// Dirty trick to find out whether we are at the very last point
isLastPhase = telescopetimes[0] + tinitslew - (time() - startobs) < data_time * n_seq;
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == 1) {
inod = inod + 1;
}
// Special treatment for all cases where load has to be replaced by hold:
if(iphase % n_pointsperscan == 0 && iphase / n_pointsperscan % 2 == phaseshift) {
ihold = ihold + 1;
if(holdforload && ihold % n_loadinterval == 0 && n_load == 0 && !isLastPhase) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// keep shift if we come from a holdforload nod, otherwise reset
if(!holdforload) {
runintostate = false;
}
// Load measurement between two A-A or B-B phases if required
// Time partially included in pointing
if(n_load > 0) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
// Run into final hold for very last point
if(isLastPhase) {
runintostate = true;
}
}
}
// Update phase counter
iphase = iphase + 1;
}
// Load nod
if(state[0] == 9) {
// Load nod
// Sanity check
if(runintostate) {
CError("Ongoing integration while starting load calibration slew.");
}
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = false;
}
// Hold
if(state[0] == 6) {
// finished shift of instrument operations relative to pointing command
runintostate = false;
}
// Final load
if(state[0] == 5) {
if(!runintostate) {
delay(readoutdead);
}
if(final_load) {
// Perform final load measurement
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
}
runintostate = false;
HIFICloseObs();
}
}
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure EngSScanDBS_commanding {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference characteristic LO frequency
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
double[] freqgrid = [978053.7,978301.8,978381.1]; // Table of frequency points
bool retunediplexer = false; // need for diplexer retuning
bool retunelo = false; // whether to retune LO Vd2 with freq
int data_time = 4; // chunk size
int n_chop = 1; // Normal number of chop cycles per frequency and pointing
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
int allsteps = 4; // Total number of frequency pointing periods
int shiftlength = 10; // Shift of the loop start relative to the pointing
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,20,1,21,0]; // Timing of the observation from telescope
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int tnodslew = telescopetimes[2];
// slew dead time between points
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,reffreq,backendreadoutparms);
// recompute tune duration for initial load measurement
int bigtunestep = duration(HIFIChangeLO(band,freqgrid[0],reffreq,retunediplexer,retunelo));
int n_loadinterval = n_cycles;
// All commands with a duration possibly depending on the frequency
// are taken at the reference frequency to guarantee synchonization
// Declare auxiliary variables to be used in the loops
int i_freq = 0;
int i_phase = 0;
// variables storing the configuration setting
bool islong = false;
bool isinvalid = true;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Instrument Initialization:
// Start with setup at reference frequency, go to grid in the next step
//
HIFIInitObs();
TuneHIFI(band,reffreq,hrs1,hrs2,wbs1{0},wbs2{0},"sscan_normal");
// First load measurement
HIFISetHK("normal",false);
SScanLoadMeasurement(band,reffreq,reffreq,true,eff_resolution{0},data_time,backendreadoutparms);
delay(tinitslew - (time() - startobs) - bigtunestep + shiftlength - hkduration);
//
// Now switch to the actual frequency grid to be measured
double runningfreq = freqgrid[i_freq];
HIFIChangeLO(band,runningfreq,reffreq,retunediplexer,retunelo);
runintostate = true;
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
// state counters
runintostate = false;
i_phase = (state[2] + 1) % 2;
// intermediate nod cycles without retuning
// (Check for match with first or last cycle index)
if(n_cycles > 1 && state[2] % n_cycles != state[2] % 2) {
delay(shiftlength);
}
// Actual integration
HIFIConfigureSlowChopIntegration(data_time,n_chop,band,reffreq,backendreadoutparms);
HIFISlowChopOnIntegration(data_time,n_chop,band,reffreq,rates);
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && i_phase == 1) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freq = i_freq + 1;
runningfreq = freqgrid[i_freq];
HIFIChangeLO(band,runningfreq,reffreq,retunediplexer,retunelo);
runintostate = true;
}
}
// Active Backend HK if we have a nod slew without calibration
if(i_phase == 0 && state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
if(state[0] == 7) {
// Second nodding position
// state counters
runintostate = false;
i_phase = state[2] % 2;
// intermediate nod cycles without retuning
if(n_cycles > 1 && state[2] % n_cycles != (state[2] + 1) % 2) {
delay(shiftlength);
}
// Actual integration
HIFIConfigureSlowChopIntegration(data_time,n_chop,band,reffreq,backendreadoutparms);
HIFISlowChopOffIntegration(data_time,n_chop,band,reffreq,rates);
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && i_phase == 1) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freq = i_freq + 1;
runningfreq = freqgrid[i_freq];
HIFIChangeLO(band,runningfreq,reffreq,retunediplexer,retunelo);
runintostate = true;
}
}
// Active Backend HK if we have a nod slew without calibration
if(i_phase == 0 && state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
if(state[0] == 9) {
// Load nod
delay(readoutdead);
SScanLoadMeasurement(band,runningfreq,reffreq,false,eff_resolution{0},data_time,backendreadoutparms);
runintostate = false;
}
if(state[0] == 5) {
// The instrument stops shiftlength before the telescope
// but I have to wait to close the observation
HIFICloseObs();
}
}
}
//General LO configuration command
block HIFI_Configure_LCU_dissipative_block_aot HIFI 6717 {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978.2; //LO frequency
int freq_nx = 0; // HL_freq_nx
int lsu_main = 0; // HL_LSU_main
int lsu_offset = 0; // HL_LSU_offset
int d2_step = 1; // HL_D2_step
double plevel_v = 0.0;
double m1_v = 9.0;
double m2_v = -2.0;
double m3_v = 0.0;
double gate1_v = -2.5;
double gate2_v = -2.5;
double drain1_v = 2.8;
string curlim1_v = "1.4";
double drain2_v = 2.6;
string curlim2_v = "1.4";
int macro_checksum = 0; // HL_macro_checksum
int config_lo_delay = 6;
}{
//Check that Vd2 is within the blue limits
drain2_v = Check_BLUE_LIMIT_D2_proc_fm(band,lo_freq,drain2_v);
//
//
//Execute configuration
//Check which LO band is used
if(band == "1a") {
//Band 1a
Hifi_HIFI_Conf_safe_LCU_ch1a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "1b") {
//Band 1b
Hifi_HIFI_Conf_safe_LCU_ch1b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "2a") {
//Band 2a
Hifi_HIFI_Conf_safe_LCU_ch2a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "2b") {
//Band 2b
Hifi_HIFI_Conf_safe_LCU_ch2b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "3a") {
//Band 3a
Hifi_HIFI_Conf_safe_LCU_ch3a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "3b") {
//Band 3b
Hifi_HIFI_Conf_safe_LCU_ch3b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "4a") {
//Band 4a
Hifi_HIFI_Conf_safe_LCU_ch4a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "4b") {
//Band 4b
Hifi_HIFI_Conf_safe_LCU_ch4b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "5a") {
//Band 5a
Hifi_HIFI_Conf_safe_LCU_ch5a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "5b") {
//Band 5b
Hifi_HIFI_Conf_safe_LCU_ch5b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "6a") {
//Band 6a
Hifi_HIFI_Conf_safe_LCU_ch6a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "6b") {
//Band 6b
Hifi_HIFI_Conf_safe_LCU_ch6b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "7a") {
//Band 7a
Hifi_HIFI_Conf_safe_LCU_ch7a($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
if(band == "7b") {
//Band 7b
Hifi_HIFI_Conf_safe_LCU_ch7b($BBID,freq_nx,lsu_main,lsu_offset,d2_step,drain2_v,curlim2_v,macro_checksum);
}
//
delay(config_lo_delay);
//
//Read TM pages and clear error flags
LCU_Read_TM_pages_proc_aot();
}
{string,double,double}[] procedure HifiSScanModeLoadChopNoRefSequencerInit {
string modeName = "load-freq";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_cycles = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,data_time);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// Get frequency grid characteristic parameters
{double,int,double} gfref = GetFReference(band,lo_freq,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,"lchop");
int n_freq_point_guess = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
// inherit from fs-noref mode
// spectral scans always use the full bandwidth for reference
bool narrowReference = false;
{string,double,double}[] retvalues = HifiPointProcLoadChopNoRefSequencerInit(naifid,ra,dec,band,reffreq,effResolution,narrowReference,hr1,hr2,wb1,wb2,data_time,n_cycles,load_interval,docommands);
// Additional constraint of compatibility of group size with load period
int loadperiod = LoadPeriod(band,reffreq,effResolution{1});
// 80% margin
int periodlimit = loadperiod * 4 / 5;
// elements of cycle - compute cycle duration
int tunedelay = LOSettlingTime(band,reffreq / 1000.0,false,true);
int load_datatime = iceil(retvalues[0]{1});
int loadlength = duration(SScanLoadMeasurement(band,reffreq,reffreq,true,effResolution{0},load_datatime,backendreadoutparms));
int perfreqtime = 2 * load_datatime + tunedelay;
int cycle = perfreqtime * n_freq_point_guess + loadlength;
if(cycle > periodlimit) {
n_freq_point_guess = imax((periodlimit - loadlength) / perfreqtime,1);
}
int n_freq_point_range = 1 - n_freq_point_guess;
if(n_freq_point_range == 0) {
n_freq_point_range = 1;
}
retvalues[1] = {"n_freq_point",double(n_freq_point_guess),double(n_freq_point_range)};
return retvalues;
}
////////////////////////////////////////////////////////////////////////
// Radiometric noise from an OTF observation
// This is still to be scaled by a factor 1.0/(B_fluct*T_A)
double procedure OtfRadioNoise {
double x = 0.02; // integration time (everything relative to the Allan time)
double xr = 0.06; // reference integration time
double d1 = 0.3; // time difference between last OFF and point
double d2 = 0.3; // time difference between point and next OFF
}{
if(x > 0.0 && xr > 0.0) {
// Auxiliary parameters
double l = (d2 + 0.5 * (xr + x)) / (d1 + d2 + xr + x);
double ladd = 1.0 - 2.0 * l + 2.0 * l * l;
//
// finally the radiometric noise
double y = 1.0 / x + ladd / xr;
} else {
// forbid x values <=0
y = 1.0E11 * (1.0 - x);
}
return y;
}
/////////////////////////////////////////////////////////////////
// Treatment of calibration parameters for spectral scans
//
// Get frequency steps from long calibration table
/////////////////////////////////////////////////////////////////
// First get index range
{int,int} procedure GetFIndex {
string band = "4a"; // HIFI band
double lo_freq1 = 978200.0 in [480000.0,1950000.0]; // LO frequency
double lo_freq2 = 979600.0 in [480000.0,1950000.0]; // LO frequency
}{
// first step: read master file
string calibfile = slookup("frequencystep_masterfile",band,"tablefile");
int iindex1 = ibracket(calibfile,"stepnumber",lo_freq1);
//reduce the upper frequency by epsilon to guarantee bracketing
double eps = 0.1;
int iindex2 = ibracket(calibfile,"stepnumber",lo_freq2 - eps);
// Exception handling
int tsize = table_size(calibfile);
if(iindex1 == 0 || iindex1 == tsize - 2) {
IError("LO frequency " + lo_freq1 + " not covered by available range!");
}
if(iindex2 == 0 || iindex2 == tsize - 2) {
IError("LO frequency " + lo_freq2 + " not covered by available range!");
} else {
iindex2 = iindex2 + 1;
}
return {iindex1,iindex2};
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure DBS_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // chunk size
int n_seq = 1; // Number of continuous chop cycles
int n_load = 0; // additional load measurements in one pointing phase
int n_loadinterval = 10; // number of nods before a load measurement
bool end_load = false; // Need for load after each pointing phase
bool final_load = false; // Need for final load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,20,1,21,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
int shiftlength = 10; // Shift of the loop start relative to the pointing
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int tnodslew = telescopetimes[2];
// slew dead time between points
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength + shiftlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
if(shiftlength > 0) {
runintostate = true;
} else {
runintostate = false;
}
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
HIFIConfigureSlowChopIntegration(data_time,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i1 = 1 .. n_load) {
HIFISlowChopOnIntegration(data_time,n_seq,band,lo_freq,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
HIFIConfigureSlowChopIntegration(data_time,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFISlowChopOnIntegration(data_time,n_seq,band,lo_freq,rates);
// Second phase in first nod position
// occurs for even cycle numbers
runintostate = false;
if(state[2] % 2 == 0) {
if(end_load) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
runintostate = true;
}
} else {
// A nod slew follows - active HK if not used by load measurement
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 7) {
// second nod position
HIFIConfigureSlowChopIntegration(data_time,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i2 = 1 .. n_load) {
// Use asymmetric scheme now to minimize setup uncertainties
HIFISlowChopOffIntegration(data_time,n_seq,band,lo_freq,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
HIFIConfigureSlowChopIntegration(data_time,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFISlowChopOffIntegration(data_time,n_seq,band,lo_freq,rates);
// First phase in second nod position
// occurs for odd cycle numbers
runintostate = false;
if(state[2] % 2 == 1) {
if(end_load) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
runintostate = true;
}
} else {
// A nod slew follows - active HK if not used by load measurement
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 9) {
// Load nod
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
runintostate = false;
}
if(state[0] == 5) {
delay(readoutdead);
if(final_load) {
// Perform final load measurement
// ( Does not occur if end_load is set)
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
runintostate = false;
HIFICloseObs();
}
}
}
{int,double,double,double,double,double} obs HifiSScanModeLoadChop {
string modeName = "load-freq";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_switch_off = 1 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Spectral Scan - Load Chop Ref",{data_time,data_time_off,0,n_switch_on,n_switch_off,0,0,n_freq_point,n_cycles,load_interval},false);
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,imin(data_time,data_time_off));
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
//////////////////////////////////////////////////////////////////////
// Call first part of the timing computer
{{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},{int,double,double[],int[][],bool,double[],int,bool}} pre_timing = SScanLoadChop_pre_timing(band,lo_freq,lo_freq_up,redundancy,effResolution,hr1,hr2,wb1,wb2,data_time,data_time_off,n_switch_on,n_switch_off,n_freq_point,n_cycles,load_interval,docommands);
// frequency parameters
int groupnumber = pre_timing{1}{0};
double reffreq = pre_timing{1}{1};
double[] freqgrid = pre_timing{1}{2};
int[][] grouporder = pre_timing{1}{3};
bool retuning = pre_timing{1}{4};
double[] targetlevels = pre_timing{1}{5};
int nfreq_if = pre_timing{1}{6};
bool dsb = pre_timing{1}{7};
int n_total = groupnumber * n_cycles;
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{double,double} refPosition = {raoff,decoff};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,pre_timing{0},n_total);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},double,double,double} post_timing = SScanDoubleChop_post_timing(pre_timing{0},telescopetimes,n_freq_point,groupnumber,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,post_timing{1},n_total);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
// normal pre_timing values
int on_inttime = post_timing{1}{0};
int off_inttime = post_timing{1}{1};
int n_loadinterval = post_timing{1}{7};
int n_long_on = post_timing{1}{8};
int n_long_off = post_timing{1}{9};
int shiftlength = post_timing{1}{5};
int initlength = post_timing{1}{14};
bool final_load = post_timing{1}{12};
// efficiency parameters
double avnumchop_on = post_timing{2};
double avnumchop_off = post_timing{3};
double tscan = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
SScanLoadChop_commanding(band,reffreq,effResolution,hr1,hr2,wb1,wb2,n_freq_point,grouporder,freqgrid,retuning,targetlevels,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,n_total,n_loadinterval,final_load,startobs,telescopetimes,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double,double,double} tact = SScanDoubleChop_deadtimes("lchop",band,reffreq,hr1,hr2,wb1,wb2,n_freq_point,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,avnumchop_on,avnumchop_off,tscan);
//
// Call noise computer
{double,double,double,double,double} noisevalues = SScanLoadChop_noisecomputer(band,reffreq,nfreq_if,dsb,effResolution,on_inttime,off_inttime,n_cycles,tscan,tact);
// Evaluate performance
SScanDoubleChop_performance(band,reffreq,nfreq_if,dsb,effResolution,noisevalues,timeTaken,n_freq_point,n_cycles,groupnumber * n_freq_point,avnumchop_on,avnumchop_off,false,tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hr1{0},hr2{0},wb1{0},wb2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// Compute the distance of two vectors in angular coordinates
// General accurate equation
double procedure AngularDistance {
{double,double} vector1 = {0.0,0.0}; // First vector
{double,double} vector2 = {0.2,0.2}; // Second vector
}{
double pideg = 3.14159265 / 180.0;
double l1 = vector1{0} * pideg;
double b1 = vector1{1} * pideg;
double l2 = vector2{0} * pideg;
double b2 = vector2{1} * pideg;
double dist = acos(sin(b1) * sin(b2) + cos(b1) * cos(b2) * cos(l1 - l2)) / pideg;
return dist;
}
//General script to read TM1, TM2,etc, procedure
//Will also clear the error flags
procedure LCU_Read_TM_pages_proc_aot {
}{
//Page 7AH dump
Hifi_HIFI_LCU_read_settings();
//It will use one single MIB TC, and clear the error flag at end
Hifi_HIFI_LCU_all_tuning_hk();
//
delay(1);
}
// Load calibration measurement
//
// Most generic version for spectral scans with potentially different
// frequencies for tuning and timing and retuning switch
//
// We might consider removing zero and comb as well - needs discussion !!!
procedure SScanLoadMeasurement {
string band = "4a"; // HIFI band (needed to estimate stabilization)
double tuning_freq = 978200.0; // LO tuning frequency
double lo_freq = 978200.0; // LO calibration frequency
bool retunelo = true; // Whether LO retuning is enabled
double deltanu = 1.0; // minimum effective resolution of the calibrated data
int data_time = 4; // time between subsequent data readouts
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
}{
// Initial computations
{int,int,bool} calinit = HIFICalInit(band,lo_freq,deltanu,data_time);
int used_datatime = calinit{0};
int n_inttime = calinit{1};
bool retuning = calinit{2} && retunelo;
// Perform zero and comb measurement
ZeroCombMeasurement(band,lo_freq,used_datatime,backendreadoutparms);
// No we perform the actual hot-cold measurement
// slow_chop_spectroscopy
int danglingreadout = HIFI_Calibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,false);
// Retune and another load if we are in HEB bands
if(retuning) {
// we have to wait for readout
delay(danglingreadout);
// Another LO vector scan at the same frequency for a stable HEB operation
HIFITuneFreq(band,tuning_freq,false,"");
danglingreadout = HIFI_Calibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,false);
}
}
////////////////////////////////////
// DBS raster observing mode - Engineering version with half throw
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiEngHalfThrowDBSRaster {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,100]; // Number of rows in the map
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the raster line
int npoints = 10 in [2,100]; // Number of points per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Engineering - DBS Raster Map halfThrow slowChop",{data_time,0,0,n_switch_on,0,0,n_pointsperscan,0,n_cycles,load_interval},true);
ChopMessages(false,data_time,n_switch_on);
RasterSizeMessages(lineDistance,stepsize,nlines,npoints,false);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = DBSRaster_pre_timing(nlines,npoints,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
// Check for NoddingInRaster or NoddingOfRaster
int scansize = pre_timing{10};
if(scansize > 1) {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,double,double,int,int,int,int,int} tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_of_raster_pointing(false,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,int,double,double,int,int,int,double,double,int,int,int,int} tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",pre_timing,n_cycles);
telescopetimes = nodding_raster_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} post_timing = DBSRaster_post_timing(pre_timing,telescopetimes,nlines,npoints,n_switch_on,n_cycles,load_interval,false);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
if(scansize > 1) {
tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_of_raster_pointing(true,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",post_timing{1},n_cycles);
telescopetimes = nodding_raster_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
int initlength = post_timing{1}{11};
int dangling = post_timing{1}{12};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
HalfDBSRaster_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_cycles,scansize,n_loadinterval,n_load,final_load,startobs,telescopetimes,loadlength,false);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = DBSRaster_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,scansize,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBSRaster_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints,n_cycles,n_seq * imax(n_load,1),tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
/////////////////////////////////////////////////////////////////
// Redundancy enhancement at the edges
// Return increased redundancy and length of application
{int,double,double} procedure GetEdgeEnhance {
int redundancy = 4; // Standard redundancy of the scan
string band = "4a"; // HIFI band
}{
double[] edge = SpectralScanReader("fscanedge",["bandwidth","edgelength","edgeredun"],band,redundancy);
int newredun = iround(edge[2]);
return {newredun,edge[1],edge[0]};
}
////////////////////////////////////
// OTF frequency switch observing mode without baseline calibration
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiMappingProcFSwitchOTFNoRef {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,240]; // Number of rows in the map
double stepsize = 0.0050 in [0.0,0.13333]; // Distance between subsequent points in the OTF line
int npoints = 10 in [1,720]; // Number of data dumps per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period defines number of lines between two loads
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Mapping - OTF Map Frequency Switch noRef",{data_time,0,0,n_switch_on,0,0,0,0,n_cycles,load_interval},true);
// Auxiliary routine for API parameter correction
{double,double,int} mapused = ValidMapSize(band,lo_freq,lineDistance,nlines,stepsize,npoints,2 * data_time * n_switch_on,n_switch_on);
double line_used = mapused{0};
double scanvelocity = mapused{1};
int npoints_used = mapused{2};
// Call first part of the timing computer
{int,int,int,int,bool,int,int} pre_timing = OTFFSwitchNoRef_pre_timing(nlines,npoints_used,band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,double,double,int,int,int} tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,pre_timing);
// Dummy call to spacecraft command
int[] telescopetimes = line_scan_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,bool,int,int},double,double} post_timing = OTFDoubleChopNoRef_post_timing(pre_timing,telescopetimes,nlines,data_time,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,post_timing{1});
// Call telescope command
telescopetimes = line_scan_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{0};
bool end_load_on = post_timing{1}{4};
int n_loadinterval = post_timing{1}{2};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
OTFFSwitchNoRef_commanding(band,lo_freq,freq_throw,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on,n_loadinterval,nlines * n_cycles,end_load_on,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = SingleChop_deadtimes("fs",band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on);
double tscan = 2.0 * (tact{1} + tact{2});
double tdead = 2.0 * tact{2};
//
// Call noise computer
{double,double,double,double,double} noisevalues = FSwitchNoRef_noisecomputer(band,lo_freq,effResolution,oneGHzReference,n_switch_on * n_cycles,tscan,tdead);
// Evaluate performance
OTFDoubleChopNoRef_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints_used,n_switch_on * n_cycles,true,tscan,tdead);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
////////////////////////////////////
// OTF frequency switch observing mode
//
{string,double,double}[] procedure HifiMappingProcFSwitchOTFSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double raoff = 0.0; // RA coordinate of the OFF position
double decoff = 0.0; // DEC coordinate of the OFF position
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,240]; // Number of rows in the map
double stepsize = 0.0050 in [0.0,0.13333]; // Distance between subsequent points in the OTF line
int npoints = 10 in [1,720]; // Number of data dumps per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_switch_off = 3 in [1,3600]; // Number of data dumps for the OFF integration time
int n_linesperscan = 1 in [1,32]; // Number of lines between two OFFs
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// limit on data rate
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
{double,double,double,double} phaselengths = FSwitchPhaseLengths(band,lo_freq,effResolution,oneGHzReference);
// Compute derived quantities
// Main loop
int main_phase = iceil(phaselengths{0});
// How many lines could we do at most?
int n_linesperscan_guess = main_phase / (2 * datalimit) + 1;
n_linesperscan_guess = imax(n_linesperscan_guess * n_linesperscan_guess / npoints,1);
// restrict the scan size
if(nlines == 1 && n_linesperscan_guess > 1) {
n_linesperscan_guess = 2;
} else {
n_linesperscan_guess = IMultiple(n_linesperscan_guess,nlines);
n_linesperscan_guess = imin(n_linesperscan_guess,nlines);
}
int n_linesperscan_range = 1 - n_linesperscan_guess;
if(n_linesperscan_range == 0) {
n_linesperscan_range = 1;
}
double n_pointsperscan = double(n_linesperscan * npoints);
// Compute back
int int_time_guess = main_phase / iceil(sqrt(n_pointsperscan));
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int n_switch_on_guess = imax(int_time_guess / (2 * data_time_guess),1);
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
data_time_guess = imax(imin(5,int_time_guess / (2 * n_switch_on_guess)),datalimit);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// OFF phase
int data_time_off_guess = imin(imax(iceil(phaselengths{2}),datalimit),20);
int data_time_off_range = datalimit - data_time_off_guess;
if(data_time_off_range == 0) {
data_time_off_range = 1;
}
int n_switch_off_guess = imax(iceil(double(data_time_guess * n_switch_on_guess) * 0.67 * sqrt(n_pointsperscan) / (double(data_time_off_guess) * sqrt(phaselengths{3} / effResolution{1}))),1);
int n_switch_off_range = 1 - n_switch_off_guess;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"data_time_off",double(data_time_off_guess),double(data_time_off_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)},{"n_linesperscan",double(n_linesperscan_guess),double(n_linesperscan_range)}];
return retvalues;
}
//Get true chopper angles for a chopped observation
{bool,double,double} procedure GetChopVoltages {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
string chop1string = "chop_M3left"; // first chopper position
string chop2string = "chop_M3right"; // second chopper position
}{
// get chopper angles for the two positions in prime configuration
{double,string}[] result = ConfigurationReader("name_confilfpu",[chop1string,chop2string],band,lo_freq);
double chop1 = result[0]{0};
double chop2 = result[1]{0};
//Check prime or redundant status
{double,string}[] result_d = ConfigurationReader("name_chopper",["prime_or_redundant","p_to_r_coeff_0","p_to_r_coeff_1","p_to_r_coeff_2","prime_endstop_min","prime_endstop_max","red_endstop_min","red_endstop_max"],band,lo_freq);
bool isPrime = result_d[0]{1} == "prime";
if(isPrime) {
// check the chopper angle is within the ranges
double endstop_min = result_d[4]{0};
double endstop_max = result_d[5]{0};
if(chop1 > endstop_max || chop1 < endstop_min) {
IError("The chopper voltage (requested is " + chop1 + " V) in prime" + " mode has to be between " + endstop_min + " and " + endstop_max + " V.");
}
if(chop2 > endstop_max || chop2 < endstop_min) {
IError("The chopper voltage (requested is " + chop2 + " V) in prime" + " mode has to be between " + endstop_min + " and " + endstop_max + " V.");
}
} else {
//Change chopper voltage if necessary
chop1 = result_d[3]{0} * pow(chop1,2.0) + result_d[2]{0} * chop1 + result_d[1]{0};
chop2 = result_d[3]{0} * pow(chop2,2.0) + result_d[2]{0} * chop2 + result_d[1]{0};
//Now check the chopper angle is within the ranges
endstop_min = result_d[6]{0};
endstop_max = result_d[7]{0};
if(chop1 > endstop_max || chop1 < endstop_min) {
IError("The chopper voltage (requested is " + chop1 + " V) in redundant" + " mode has to be between " + endstop_min + " and " + endstop_max + " V.");
}
if(chop2 > endstop_max || chop2 < endstop_min) {
IError("The chopper voltage (requested is " + chop2 + " V) in redundant" + " mode has to be between " + endstop_min + " and " + endstop_max + " V.");
}
}
return {isPrime,chop1,chop2};
}
//Configure backends
procedure ConfigureBackend {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
}{
//HRS configuration:
//Internal LO relative to IF centre
double if_centre = 6.0;
//
//Resolution mode
string hrs_mode_h = "hr";
double[] hrsH_LO = [if_centre + hrs1{2}[0] / 1000.0,if_centre + hrs1{2}[1] / 1000.0,if_centre + hrs1{2}[2] / 1000.0,if_centre + hrs1{2}[3] / 1000.0];
if(hrs1{0}) {
// Resolution strings and LO assignment
if(hrs1{1} == 1) {
// medium resolution
hrs_mode_h = "mr";
hrsH_LO = [if_centre + hrs1{2}[0] / 1000.0,if_centre + hrs1{2}[2] / 1000.0,if_centre + hrs1{2}[3] / 1000.0,if_centre + hrs1{2}[1] / 1000.0];
}
if(hrs1{1} == 2) {
// low resolution
hrs_mode_h = "lr";
hrsH_LO = [if_centre + hrs1{2}[0] / 1000.0,if_centre + hrs1{2}[3] / 1000.0,if_centre + hrs1{2}[1] / 1000.0,if_centre + hrs1{2}[2] / 1000.0];
}
if(hrs1{1} == 3) {
// wide-band resolution
hrs_mode_h = "wb";
}
}
string hrs_mode_v = "hr";
double[] hrsV_LO = [if_centre + hrs2{2}[0] / 1000.0,if_centre + hrs2{2}[1] / 1000.0,if_centre + hrs2{2}[2] / 1000.0,if_centre + hrs2{2}[3] / 1000.0];
if(hrs2{0}) {
// Resolution strings and LO assignment
if(hrs2{1} == 1) {
// medium resolution
hrs_mode_v = "mr";
hrsV_LO = [if_centre + hrs2{2}[0] / 1000.0,if_centre + hrs2{2}[2] / 1000.0,if_centre + hrs2{2}[3] / 1000.0,if_centre + hrs2{2}[1] / 1000.0];
}
if(hrs2{1} == 2) {
// low resolution
hrs_mode_v = "lr";
hrsV_LO = [if_centre + hrs2{2}[0] / 1000.0,if_centre + hrs2{2}[3] / 1000.0,if_centre + hrs2{2}[1] / 1000.0,if_centre + hrs2{2}[2] / 1000.0];
}
if(hrs2{1} == 3) {
// wide-band resolution
hrs_mode_v = "wb";
}
}
//
// Apply
string[] hrs_mode = [hrs_mode_h,hrs_mode_v];
HRS_config_resol_block_aot(band,hrs_mode);
HRS_config_att_lo_block_aot(band,hrs_mode,hrsH_LO,hrsV_LO);
//
//WBS configuration: set all attenuators to max. Maybe superfluous
WBS_config_block_aot(band);
//
}
/////////////////////////////////////////////////////////////////
// Procedure to translate levels into strings
string[] procedure TargetNames {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // reference LO frequency in MHz
bool retuning = false; // need for WBS retuning
double[] targetlevels = [1.0,1.0,1.0]; // WBS target levels
}{
// Get target limits
double[] limits = CalibrationReader("attenuator_levels",["sscan_max","sscan_min","sscan_high","sscan_normal","sscan_low"],band,lo_freq);
// Criteria for the table setup
double halfwidth = 0.67 * (limits[2] - limits[4]);
// Output field
string[] target = [];
int nfreq = length(targetlevels);
// Check for retuning needs
if(retuning) {
// Construct table of actual target levels from differences
double oldtarget = targetlevels[0];
double step = 0.0;
int oldindex = 0;
target[0] = "";
for(int jjj = 1 .. nfreq - 1) {
target[jjj] = "";
step = targetlevels[jjj] - oldtarget;
if(abs(step) > halfwidth) {
if(step > 0.0) {
target[oldindex] = "sscan_low";
} else {
target[oldindex] = "sscan_high";
}
oldtarget = targetlevels[jjj];
oldindex = jjj;
}
// Final tuning
if(step > 0.0) {
target[oldindex] = "sscan_low";
} else {
target[oldindex] = "sscan_high";
}
}
} else {
// No retuning needed
// search again for minimum - use for target level
double absmin = arraymin(targetlevels);
if(limits[0] - absmin < halfwidth) {
target[0] = "sscan_normal";
} else {
if(targetlevels[0] > limits[3]) {
if(targetlevels[0] > limits[2]) {
target[0] = "sscan_max";
} else {
target[0] = "sscan_high";
}
} else {
if(targetlevels[0] < limits[4]) {
target[0] = "sscan_min";
} else {
target[0] = "sscan_low";
}
}
}
// Fill the table with empty values
for(int jjjj = 1 .. nfreq - 1) {
target[jjjj] = "";
}
}
// table with either a single entry or entries at tuning points
return target;
}
////////////////////////////////////
// Load chop mode without baseline calibration
//
// The implementation now assumes that the corresponding Herschel
// pseudo-pointing mode will be available
//
{int,double,double,double,double,double} obs HifiPointProcLoadChopNoRef {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int n_cycles = 2 in [1,3600]; // number of half load-sky-sky-load cycles on ON
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Single Point - Load Chop noRef",{data_time,0,0,0,0,0,0,0,n_cycles,load_interval},false);
// Call first part of the timing computer
{int,int,int,int,int,int,bool,int,int} pre_timing_f = LoadChopNoRef_pre_timing(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_cycles,load_interval,docommands);
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,double,double,int} tpar_f = Fine_telescope(naifid,onPosition,band,lo_freq,pre_timing_f);
// Dummy call to spacecraft command
int[] telescopetimes = basic_fine_pointing(false,tpar_f{0},tpar_f{1},tpar_f{2},tpar_f{3},tpar_f{4},tpar_f{5},tpar_f{6},tpar_f{7},tpar_f{8},tpar_f{9});
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,bool,int,int},double,double} post_timing_f = SingleChopNoRef_post_timing(pre_timing_f,telescopetimes);
// Now the actual observation starts
// Prepare telescope command
tpar_f = Fine_telescope(naifid,onPosition,band,lo_freq,post_timing_f{1});
// Call telescope command
telescopetimes = basic_fine_pointing(true,tpar_f{0},tpar_f{1},tpar_f{2},tpar_f{3},tpar_f{4},tpar_f{5},tpar_f{6},tpar_f{7},tpar_f{8},tpar_f{9});
// Consistency check
int totaltime = post_timing_f{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
//////////////////////////////////////////////////////////////////////
// standard parameters for fine pointing
int loadlength = post_timing_f{1}{2};
int n_per_on = post_timing_f{1}{4};
int n_load_on = post_timing_f{1}{5};
bool end_load_on = post_timing_f{1}{6};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
//////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
LoadChopNoRef_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_per_on,n_load_on,end_load_on,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// There are no telescope dead times involved in this mode
{double,double,double} tact = SingleChop_deadtimes("lchop",band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_per_on);
double tscan = 2.0 * (tact{1} + tact{2});
double tdead = 2.0 * tact{2};
//
// Call noise computer
{double,double,double,double,double} noisevalues = PositionSwitch_noisecomputer(band,lo_freq,effResolution,oneGHzReference,n_per_on * (n_load_on + 1),tscan,tdead);
// Evaluate performance
SingleChopNoRef_performance(band,lo_freq,effResolution,noisevalues,timeTaken,n_per_on * (n_load_on + 1),false,tscan,tdead);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
{int,double,double,double,double,double} obs HifiMappingModeOTF {
string modeName = "fly";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,5]; // chunk size given by the data rates and optimum speed
int n_int_on = 1 in [1,1800]; // Supersamplingfactor
int n_linesperscan = 1 in [1,32]; // Number of lines between two OFFs
int n_switch_off = 3 in [1,3600]; // Number of data dumps for the OFF integration time
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Mapping - OTF Map Position Switch",{data_time,0,n_int_on,0,n_switch_off,n_linesperscan,0,0,n_cycles,load_interval},true);
// Auxiliary routine for API parameter correction
{double,double,int} mapused = ValidMapSize(band,lo_freq,lineDistance,nlines,stepsize,npoints,data_time * n_int_on,0);
double line_used = mapused{0};
double scanvelocity = mapused{1};
int npoints_used = mapused{2};
// Call first part of the timing computer
{int,int,int,int,int,int,int,int} pre_timing = OTFmap_pre_timing(nlines,npoints_used,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_linesperscan,n_switch_off,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{double,double} refPosition = {raoff,decoff};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,double,double,int,int,double,double,int,int,int,int,int} tpar = OTFmap_telescope(naifid,onPosition,lineDistance,nlines,line_used,refPosition,scanvelocity,band,lo_freq,n_linesperscan,n_cycles,pre_timing);
// Dummy call to spacecraft command
int[] telescopetimes = line_scan_with_off_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int},double,double} post_timing = OTFmap_post_timing(pre_timing,telescopetimes,data_time,n_linesperscan,n_cycles,load_interval);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = OTFmap_telescope(naifid,onPosition,lineDistance,nlines,line_used,refPosition,scanvelocity,band,lo_freq,n_linesperscan,n_cycles,post_timing{1});
// Call telescope command
telescopetimes = line_scan_with_off_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int n_pp = post_timing{1}{0};
int n_scans = post_timing{1}{1};
int loadlength = post_timing{1}{4};
int n_loadinterval = post_timing{1}{5};
double tscan = post_timing{2};
double tdead = post_timing{3};
// telescope time
int slewtime = telescopetimes[6];
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
OTFmap_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,nlines * n_cycles,n_linesperscan,n_switch_off,n_pp,n_loadinterval,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check])
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = OTFmap_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_linesperscan,n_switch_off,n_pp,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = OTFmap_noisecomputer(band,lo_freq,effResolution,oneGHzReference,nlines,npoints_used,n_int_on,n_linesperscan,n_cycles,slewtime,tscan,tact);
// Evaluate performance
OTF_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints_used,n_scans,n_cycles,tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// HRS attenuator tuning, block
// Both polarizations are treated
// !!! The routine is 1s too short to get rid of all the data.
// It must be externally guaranteed that there is always a dangling
// second without data frames produced !!!
block HRS_tune_block_aot HIFI 6601 {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
}{
Tune_HRS_aot(band);
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure LoadChopNoRef_FCal_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // data dump interval limited by the data rates
int n_per_on = 2; // number of half load-sky-sky-load cycles on ON
int n_load_on = 0; // additional load measurements in ON pointing phase
bool end_load_on = false; // Need for load after ON pointing phase
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,0]; // Timing of observation from telescope
int loadlength = 21; // Load duration
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement_FCal(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// ON integration
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i1 = 1 .. n_load_on) {
HIFILoadChopOnIntegration(data_time,n_per_on,band,lo_freq,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement_FCal(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFILoadChopOnIntegration(data_time,n_per_on,band,lo_freq,rates);
}
if(state[0] == 5) {
delay(readoutdead);
if(end_load_on) {
// Perform final load measurement
LoadMeasurement_FCal(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
HIFICloseObs();
}
}
}
/////////////////////////////////////////////////////////////////
// Spectral scan in load-chop with OFF calibration
//
// Implemented as procedure returning time and noise levels for HSPOT
{int,double,double,double,double,double} obs HifiSScanProcLoadChop {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double raoff = 0.0; // RA coordinate of the OFF position
double decoff = 0.0; // DEC coordinate of the OFF position
bool refSelected = true; // Dummy parameter required by HSPOT
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4 in [1,12]; // Frequency scan redundancy
{double,double} effResolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool wbs1Used = true; // whether WBS1 is used
bool wbs2Used = true; // whether WBS2 is used
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_switch_off = 1 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Spectral Scan - Load Chop Ref",{data_time,data_time_off,0,n_switch_on,n_switch_off,0,0,n_freq_point,n_cycles,load_interval},false);
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,imin(data_time,data_time_off));
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
//////////////////////////////////////////////////////////////////////
// Call first part of the timing computer
{{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},{int,double,double[],int[][],bool,double[],int,bool}} pre_timing = SScanLoadChop_pre_timing(band,lo_freq,lo_freq_up,redundancy,effResolution,hr1,hr2,wb1,wb2,data_time,data_time_off,n_switch_on,n_switch_off,n_freq_point,n_cycles,load_interval,docommands);
// frequency parameters
int groupnumber = pre_timing{1}{0};
double reffreq = pre_timing{1}{1};
double[] freqgrid = pre_timing{1}{2};
int[][] grouporder = pre_timing{1}{3};
bool retuning = pre_timing{1}{4};
double[] targetlevels = pre_timing{1}{5};
int nfreq_if = pre_timing{1}{6};
bool dsb = pre_timing{1}{7};
int n_total = groupnumber * n_cycles;
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{double,double} refPosition = {raoff,decoff};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,pre_timing{0},n_total);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},double,double,double} post_timing = SScanDoubleChop_post_timing(pre_timing{0},telescopetimes,n_freq_point,groupnumber,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,post_timing{1},n_total);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
// normal pre_timing values
int on_inttime = post_timing{1}{0};
int off_inttime = post_timing{1}{1};
int n_loadinterval = post_timing{1}{7};
int n_long_on = post_timing{1}{8};
int n_long_off = post_timing{1}{9};
int shiftlength = post_timing{1}{5};
int initlength = post_timing{1}{14};
bool final_load = post_timing{1}{12};
// efficiency parameters
double avnumchop_on = post_timing{2};
double avnumchop_off = post_timing{3};
double tscan = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
SScanLoadChop_commanding(band,reffreq,effResolution,hr1,hr2,wb1,wb2,n_freq_point,grouporder,freqgrid,retuning,targetlevels,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,n_total,n_loadinterval,final_load,startobs,telescopetimes,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double,double,double} tact = SScanDoubleChop_deadtimes("lchop",band,reffreq,hr1,hr2,wb1,wb2,n_freq_point,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,avnumchop_on,avnumchop_off,tscan);
//
// Call noise computer
{double,double,double,double,double} noisevalues = SScanLoadChop_noisecomputer(band,reffreq,nfreq_if,dsb,effResolution,on_inttime,off_inttime,n_cycles,tscan,tact);
// Evaluate performance
SScanDoubleChop_performance(band,reffreq,nfreq_if,dsb,effResolution,noisevalues,timeTaken,n_freq_point,n_cycles,groupnumber * n_freq_point,avnumchop_on,avnumchop_off,false,tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hr1{0},hr2{0},wb1{0},wb2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
////////////////////////////////////////////////////////////////////////
// Radiometric noise from an asymmetric two-phase observation
// This is still to be scaled by a factor 1.0/(B_fluct_A*T_Allan)
double procedure AsymmetricRadioNoise {
double xa = 0.1; // integration time in phase A relative to Allan time
double xb = 0.1; // integration time in phase B relative to Allan time
double resrat = 1.0; // Ratio in the effective resolution B/A
}{
if(xa > 0.0) {
double y = 1.0 / xa + 1.0 / (xb * resrat);
} else {
// forbid x values <=0
y = 1.0E11 * (1.0 - xa);
}
return y;
}
//////////////////////////////////////////////////////////////////////
// Generic procedure to determine backend parameters for a
// Configure_spectroscopy command
{int,int,int,int,int[],int[],string} procedure ConfigSpectroscopyBackends {
/* Integration time */
int data_time = 4; // Integration time between two data readouts
/* Backend settings */
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands}, WBS1/2 {used, channel windows}
}{
// The following parameters are hard-wired here as they should never change
int wbs16bitlimit = 5;
int wbs16bitrshift1 = 1;
int wbs16bitrshift2 = 2;
int wbs24bitrshift0 = 20;
int wbs24bitrshift1 = 40;
int wbs24bitrshift2 = 80;
int hrsrshift0 = 16;
int hrsrshift1 = 32;
int hrsrshift2 = 64;
// Compute transfer mode
// 16 bit format for short integrations
if(data_time <= wbs16bitlimit) {
string packing = "16_bits_format";
// Right shift depends in data_time
if(data_time <= wbs16bitrshift1) {
int wbs_rshift = 1;
} else {
if(data_time <= wbs16bitrshift2) {
wbs_rshift = 2;
} else {
wbs_rshift = 3;
}
}
// 24 bit mode for long integrations
} else {
packing = "24_bits_format";
// Right shift to produce valid IF power HK data
if(data_time <= wbs24bitrshift0) {
wbs_rshift = 0;
} else {
if(data_time <= wbs24bitrshift1) {
wbs_rshift = 1;
} else {
if(data_time <= wbs24bitrshift2) {
wbs_rshift = 2;
} else {
wbs_rshift = 3;
}
}
}
}
// bit shift for HRS
if(data_time <= hrsrshift0) {
int hrs_rshift = 0;
} else {
if(data_time <= hrsrshift1) {
hrs_rshift = 1;
} else {
if(data_time <= hrsrshift2) {
hrs_rshift = 2;
} else {
hrs_rshift = 3;
}
}
}
// Backend selection
// HRS
{int,int,int,int} hrssets = HrsSubbandSelection(backendreadoutparms);
int hrsh_sel = hrssets{0};
int hrsv_sel = hrssets{1};
// WBS windows
// WBS-H
// Initialize to zero
int[] wbsh_pars = [0,0,2048,0,4096,0,6144,0];
if(backendreadoutparms{2}{0}) {
// Set defined boundaries
wbsh_pars[0] = backendreadoutparms{2}{1}[0][0] + wbsh_pars[0];
wbsh_pars[1] = backendreadoutparms{2}{1}[0][1] - backendreadoutparms{2}{1}[0][0];
wbsh_pars[2] = backendreadoutparms{2}{1}[1][0] + wbsh_pars[2];
wbsh_pars[3] = backendreadoutparms{2}{1}[1][1] - backendreadoutparms{2}{1}[1][0];
wbsh_pars[4] = backendreadoutparms{2}{1}[2][0] + wbsh_pars[4];
wbsh_pars[5] = backendreadoutparms{2}{1}[2][1] - backendreadoutparms{2}{1}[2][0];
wbsh_pars[6] = backendreadoutparms{2}{1}[3][0] + wbsh_pars[6];
wbsh_pars[7] = backendreadoutparms{2}{1}[3][1] - backendreadoutparms{2}{1}[3][0];
}
// WBS-V
// Initialize to zero
int[] wbsv_pars = [0,0,2048,0,4096,0,6144,0];
if(backendreadoutparms{3}{0}) {
// Set defined boundaries
wbsv_pars[0] = backendreadoutparms{3}{1}[0][0] + wbsv_pars[0];
wbsv_pars[1] = backendreadoutparms{3}{1}[0][1] - backendreadoutparms{3}{1}[0][0];
wbsv_pars[2] = backendreadoutparms{3}{1}[1][0] + wbsv_pars[2];
wbsv_pars[3] = backendreadoutparms{3}{1}[1][1] - backendreadoutparms{3}{1}[1][0];
wbsv_pars[4] = backendreadoutparms{3}{1}[2][0] + wbsv_pars[4];
wbsv_pars[5] = backendreadoutparms{3}{1}[2][1] - backendreadoutparms{3}{1}[2][0];
wbsv_pars[6] = backendreadoutparms{3}{1}[3][0] + wbsv_pars[6];
wbsv_pars[7] = backendreadoutparms{3}{1}[3][1] - backendreadoutparms{3}{1}[3][0];
}
//
return {wbs_rshift,hrs_rshift,hrsh_sel,hrsv_sel,wbsh_pars,wbsv_pars,packing};
}
// Perform frequency-switch integration at OFF position ON-OFF-OFF-ON...
block HIFIFSwitchOffIntegration HIFI 6039 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_fswitch_proc_aot(data_time,n_cycle,band,lo_freq,rates);
}
// Configuration for slow-chop integration
block HIFIConfigureSlowChopIntegration HIFI 6030 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used, channel windows}
}{
// Call procedure doing the work
ConfigureSpectroscopy(data_time,2 * n_cycle,"chop",band,lo_freq,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// Procedure to perform the noise level evaluation for the observing mode
{double,double,double,double,double} procedure FSwitch_noisecomputer {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
int on_inttime = 16; // Integration time per ON phase
int off_inttime = 16; // Integration time per OFF phase
int n_cycles = 1; // Number of half OFF-ON-ON-OFF calibration cycles
double tscan = 60.0; // Total average duration of one scan
{double,double,double,double,double} tact = {10.0,4.9,4.9,0.05,0.05}; // Field of actual dead and integration times
}{
double tdead = tact{0};
// Average total dead time in one scan
double inttimeperonphase = tact{1};
// Actual integration time in ON phase
double inttimeperoffphase = tact{2};
// Actual integration time in OFF phase
double deadtimeperonphase = tact{3};
// Dead time per switch phase on ON
// Get parameters which are needed
double tsys = InterpolateTsys(band,lo_freq);
double eta_mb = InterpolateCoupling(band,lo_freq);
double[] gssb = InterpolateGssb(band,lo_freq);
// Get the drift parameters to compute the drift noise
// System Allan variance
double[] allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / eff_resolution{1},binningexp);
double allan_time_hires = allanparms[0] * pow(1.0 / eff_resolution{0},binningexp);
// Differential Allan variance
allanparms = InterpolateSpecFSwitchAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double dalpha = allanparms[1];
binningexp = 1.0 / allanparms[2];
double dallan_time_lores = allanparms[0] * pow(1.0 / eff_resolution{1},binningexp);
double dallan_time_hires = allanparms[0] * pow(1.0 / eff_resolution{0},binningexp);
// resolution of OFF phase
double sw_resolution = GetFSwitchSWResolution(band,lo_freq);
double sw_resolution_lores = max(eff_resolution{1},sw_resolution);
double sw_resolution_hires = max(eff_resolution{0},sw_resolution);
// Compute the relative noise for the detailed timing
double on_int = double(on_inttime);
double off_int = double(off_inttime);
// The dead time per switch might deviate between ON and OFF - ignored
double deadtimeperswitch = deadtimeperonphase;
// Get actual noise
// This is returned twice: for both limiting resolutions
double systemnoise_lores = DoubleDifferenceNoise(inttimeperonphase / allan_time_lores,[inttimeperoffphase / inttimeperonphase,sw_resolution_lores / eff_resolution{1},on_int / allan_time_lores,off_int / allan_time_lores,deadtimeperswitch / allan_time_lores,tdead / allan_time_lores,alpha,dallan_time_lores / allan_time_lores,dalpha]);
double systemnoise_hires = DoubleDifferenceNoise(inttimeperonphase / allan_time_hires,[inttimeperoffphase / inttimeperonphase,sw_resolution_hires / eff_resolution{0},on_int / allan_time_hires,off_int / allan_time_hires,deadtimeperswitch / allan_time_hires,tdead / allan_time_hires,alpha,dallan_time_hires / allan_time_hires,dalpha]);
double noiseratio = DoubleDifferenceNoiseRatio(inttimeperonphase / allan_time_lores,[inttimeperoffphase / inttimeperonphase,sw_resolution_lores / eff_resolution{1},on_int / allan_time_lores,off_int / allan_time_lores,deadtimeperswitch / allan_time_lores,tdead / allan_time_lores,alpha,dallan_time_lores / allan_time_lores,dalpha]);
// Compute total double sideband noise
// Correct for signal in both pases
double dsbnoise_lores = tsys * sqrt(systemnoise_lores / (eff_resolution{1} * 2000000.0 * double(n_cycles) * tscan));
double dsbnoise_hires = tsys * sqrt(systemnoise_hires / (eff_resolution{0} * 2000000.0 * double(n_cycles) * tscan));
// Translate to the main beam scale, correct for eta_mb
// (This is typically not done at ground based telescopes,
// but leads often to problems there - to be discussed.)
dsbnoise_lores = dsbnoise_lores / eta_mb;
dsbnoise_hires = dsbnoise_hires / eta_mb;
// Get single sideband noise equivalent
double usbnoise_lores = dsbnoise_lores / gssb[0];
double usbnoise_hires = dsbnoise_hires / gssb[0];
double lsbnoise_lores = dsbnoise_lores / gssb[1];
double lsbnoise_hires = dsbnoise_hires / gssb[1];
// Return noise values and the maximum ratio of drift to radiometric noise
return {usbnoise_lores,usbnoise_hires,lsbnoise_lores,lsbnoise_hires,noiseratio};
}
// Switch on LO band - version using the slew towards a fixed point for
// stabilization
// assumes HIFI is prime and LO is in nominal mode
obs HifiEngSwitchonLO_inslew {
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
bool robust = true; // whether the subsequent AOR is chopped+spectroscopic
}{
// First part - determine timing and telescope parameters
// Fixed parameters
int data_time = 4;
// Data readout period
{double,double} eff_resolution = {1.1,1.1};
// Native WBS resolution as goal resolution
// Get reference frequency
string startfreqname = "keyfreq";
//this is for cold LO operations
string stablefreqname = "stablefreq";
//this is for cold LO operations
// "keyfreq" for cold LO operations
// "keyfreq_dummy" for dummy LO operations
// "midfreq" old approach
double[] result_d = CalibrationReader("name_keyfreq",[startfreqname,stablefreqname],band,0.0);
double lo_freq_start = result_d[0] * 1000.0;
double lo_freq_stable = result_d[1] * 1000.0;
// Backend settings
// standard routine from spectral scans
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,2,true,true,data_time);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
// Call specific pre_timing computer
{int,int,int,int,int,int} pre_timing = SwitchOnLoadChop_pre_timing(band,lo_freq_start,lo_freq_stable,eff_resolution,hr1,hr2,wb1,wb2,data_time,robust);
// get parameters for fine pointing
int totaltime = pre_timing{0};
// total duration for check
int on_pointing = pre_timing{1};
// Pointing time
int initlength = pre_timing{2};
// Initial setup time
int dangling = pre_timing{3};
// Final load measurement
int n_cycles1 = pre_timing{4};
// Number of chop cycles before retuning
int n_cycles = pre_timing{5};
// Number of chop cycles after retuning
// In the slew mode we rearrange the times
initlength = initlength + on_pointing;
on_pointing = dangling;
dangling = 0;
// Prepare telescope command
{double,double} onPosition = {ra,dec};
// standard timing parameter list to reuse Fine_telescope procedure
{int,int,int,int,int,int,bool,int,int} std_timing = {on_pointing,on_pointing,on_pointing,0,0,0,false,initlength,dangling};
{int,int,int,string,int,double,double,double,double,int} tpar_f = Fine_telescope(naifid,onPosition,band,lo_freq_stable,std_timing);
// Call telescope command
int[] telescopetimes = basic_fine_pointing(true,tpar_f{0},tpar_f{1},tpar_f{2},tpar_f{3},tpar_f{4},tpar_f{5},tpar_f{6},tpar_f{7},tpar_f{8},tpar_f{9});
}{
// Second part - instrument commanding
// Get final deceleration time from the telescope section
int telinit = telescopetimes[1];
// Initial slew time
int tend = telescopetimes[2];
// Final deceleration time
totaltime = totaltime + tend + telinit - initlength;
// Backend settings
// Create a composite readout structure
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// additional fixed parameters like in standard observing modes
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int readoutdead = SlowChopReadoutDelay(band,lo_freq_stable,backendreadoutparms);
//////////////////
// Instrument commanding
sync();
int startobs = time();
// use state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
HIFIInitObs();
HIFILCUChecksumAndSetHK(band,"fast",true);
// Actual switch-on
// The switch will always be done at the same frequency
LCU_switchon_proc_aot(band,lo_freq_start / 1000.0);
// Initial setup and LO tuning
Init_Mixing_proc_aot(band,lo_freq_start / 1000.0);
//Deflux will do be done for bands 1 to 4
Deflux_SingleBand_proc_aot(band,lo_freq_start / 1000.0);
// Standard backend tuning
string target_name = "normal";
// Name of target level
if(wb1{0} || wb2{0}) {
WBS_attenuators_block(band,lo_freq_start / 1000.0,target_name,false);
}
if(hr1{0} || hr2{0}) {
HRS_tune_block_aot(band);
}
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq_start,eff_resolution{0},data_time,backendreadoutparms);
// ON integration - long hot-cold measurement
if(n_cycles1 > 0) {
HIFI_Calibrate_hot_cold(band,lo_freq_stable,data_time,2 * n_cycles1,backendreadoutparms,false);
}
HIFIRetuneFreq(band,lo_freq_stable,"");
HIFI_Calibrate_hot_cold(band,lo_freq_stable,data_time,2 * n_cycles,backendreadoutparms,false);
}
if(state[0] == 3) {
delay(readoutdead);
// Perform final load measurement
LoadMeasurement(band,lo_freq_stable,eff_resolution{0},data_time,backendreadoutparms);
HIFICloseObs();
}
}
// Finalize observations
// consistency check
int timeTaken = time() - startobs;
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
// Noise estimates could be easily added, but are not done here
// in the current implementation
}
{int,double,double,double,double,double} obs HifiSScanModeFastDBS {
string modeName = "freq";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Spectral Scan - DBS fastChop",{data_time,0,n_switch_on,n_int_on,0,0,0,n_freq_point,n_cycles,load_interval},false);
ChopMessages(true,data_time,n_int_on);
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,data_time / 2);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
//////////////////////////////////////////////////////////////////////
// Call first part of the timing computer
{{int,int,int,int,int,int,int,int,int,bool,int,int,int},{int,double,double[],int[][],bool,double[],int,bool}} pre_timing = FastSScanDBS_pre_timing(band,lo_freq,lo_freq_up,redundancy,effResolution,hr1,hr2,wb1,wb2,data_time,n_int_on,n_switch_on,n_freq_point,n_cycles,load_interval,docommands);
// frequency parameters
int groupnumber = pre_timing{1}{0};
double reffreq = pre_timing{1}{1};
double[] freqgrid = pre_timing{1}{2};
int[][] grouporder = pre_timing{1}{3};
bool retuning = pre_timing{1}{4};
double[] targetlevels = pre_timing{1}{5};
int nfreq_if = pre_timing{1}{6};
bool dsb = pre_timing{1}{7};
int n_total = groupnumber * n_cycles;
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = DBS_telescope(naifid,onPosition,band,reffreq,"",pre_timing{0},n_total);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},double,double,double} post_timing = SScanDBS_post_timing(pre_timing{0},telescopetimes,n_freq_point,groupnumber,n_cycles,true);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBS_telescope(naifid,onPosition,band,reffreq,"",post_timing{1},n_total);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
// normal pre_timing values
int n_loadinterval = post_timing{1}{7};
int n_bchop = post_timing{1}{8};
int shiftlength = post_timing{1}{10};
int initlength = post_timing{1}{11};
double avnumchop = post_timing{2};
// efficiency parameters
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
FastSScanDBS_commanding(band,reffreq,effResolution,hr1,hr2,wb1,wb2,n_freq_point,grouporder,freqgrid,retuning,targetlevels,data_time,n_int_on,n_cycles,n_total,n_bchop,n_switch_on,n_loadinterval,startobs,telescopetimes,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double} tact = FastSScanDBS_deadtimes(band,reffreq,hr1,hr2,wb1,wb2,n_freq_point,data_time,n_int_on,n_bchop,n_switch_on,n_cycles,avnumchop,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = SScanDBS_noisecomputer(band,reffreq,nfreq_if,dsb,effResolution,continuumDetection,n_cycles,tscan,tact);
// Evaluate performance
SScanDBS_performance(band,reffreq,nfreq_if,dsb,effResolution,noisevalues,timeTaken,n_total,groupnumber * n_freq_point,avnumchop * double(n_int_on),tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hr1{0},hr2{0},wb1{0},wb2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
////////////////////////////////////
// Auxiliary function to compute the noise of an ideal instrument with
// 100% observing efficiency for comparison
{int,double,double,double,double,double} procedure IdealHifi {
/* Setup parameters */
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4; // Frequency scan redundancy
int nlines = 1 in [1,240]; // Number of rows in the map
int npoints = 10 in [1,720]; // Number of data dumps per row
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
int goalTime = 8; // Total integration time
/* Sequence parameters */
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// Get parameters which are needed
double center_lo_freq = 0.5 * (lo_freq + lo_freq_up);
double tsys = InterpolateTsys(band,center_lo_freq);
double eta_mb = InterpolateCoupling(band,center_lo_freq);
double[] gssb = InterpolateGssb(band,center_lo_freq);
double phasetime = double(goalTime);
double noiseratio = 0.0;
// Compute total double sideband noise
double dsbnoise_lores = tsys * sqrt(1.0 / (effResolution{1} * 1000000.0 * phasetime));
double dsbnoise_hires = tsys * sqrt(1.0 / (effResolution{0} * 1000000.0 * phasetime));
// Translate to the main beam scale, correct for eta_mb
// (This is typically not done at ground based telescopes,
// but leads often to problems there - to be discussed.)
dsbnoise_lores = dsbnoise_lores / eta_mb;
dsbnoise_hires = dsbnoise_hires / eta_mb;
// Get single sideband noise equivalent
double usbnoise_lores = dsbnoise_lores / gssb[0];
double usbnoise_hires = dsbnoise_hires / gssb[0];
double lsbnoise_lores = dsbnoise_lores / gssb[1];
double lsbnoise_hires = dsbnoise_hires / gssb[1];
// return total time with initial slew
int returntime = goalTime;
// Originally I had added 180s from telescope
// Now make corrections for maps or spectral scans
if(npoints * nlines > 1) {
double factor = sqrt(double(nlines * npoints));
usbnoise_lores = usbnoise_lores * factor;
usbnoise_hires = usbnoise_hires * factor;
lsbnoise_lores = lsbnoise_lores * factor;
lsbnoise_hires = lsbnoise_hires * factor;
}
if(lo_freq_up > lo_freq) {
{int,double,double[],int[][],int,bool} fqparms = MakeFreqGrid(band,lo_freq,lo_freq_up,redundancy,"dbs",0.0,1);
factor = sqrt(double(fqparms{0} / fqparms{4}));
usbnoise_lores = usbnoise_lores * factor;
usbnoise_hires = usbnoise_hires * factor;
lsbnoise_lores = lsbnoise_lores * factor;
lsbnoise_hires = lsbnoise_hires * factor;
}
// Return noise values and the maximum ratio of drift to radiometric noise
return {returntime,usbnoise_lores,usbnoise_hires,lsbnoise_lores,lsbnoise_hires,noiseratio};
}
//Procedure to get from standby to primary mode
//Concerns LO and WBS settings
procedure HifiIntoPrimary {
}{
//Switch LO to nominal
Set_LO_Nominal_block_aot();
//Set applicable LO FDIR limits (SCR-2226)
//Set_LO_FDIR_temperatures_block_aot();
//Disable checksum FDIR - HIFI-3120
Disable_CRC_FDIR_block_ops();
}
// Generic A_M function for LSU setting
// DT - 18 Aug 2006
int[] procedure ComputeLSU_A_M_R {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978.2; //LO frequency
}{
//Read parameters
double[] result = CalibrationReader("name_lsu_convertion",["multiplier","f_offset","n10","n20"],band,lo_freq);
double multiplier = result[0];
double f_offset = result[1];
int n10 = iround(result[2]);
int n20 = iround(result[3]);
//
//Compute LSU frequency IN MHZ
double f_lsu = lo_freq * 1000.0 / multiplier;
//Compute total frequency
double f_total = f_lsu + f_offset;
//Compute parameter n
int n = ifloor(15.0 * (f_total / 1.875 - double(ifloor(f_total / 1.875))));
//Compute main and offset loop parameters
int n1 = n10 + n;
// offset loop
int d1 = 15;
//offset loop
int n2 = iround(abs(double(n20 - ifloor(f_total / 1.875) + n)));
//main loop
int d2 = 16;
//
//Compute A,M and R parameters for main and offset loop
int m1 = ifloor(double(n1) / 10.0) - 1;
// offset loop
int a1 = n1 - 10 * ifloor(double(n1) / 10.0);
// offset loop
int r1 = d1 - 1;
// offset loop
int m2 = ifloor(double(n2) / 10.0) - 1;
// main loop
int a2 = n2 - 10 * ifloor(double(n2) / 10.0);
// main loop
int r2 = d2 - 1;
// main loop
//
int[] lsu_a_m_r_parameter = [0,0,0,0,0,0];
lsu_a_m_r_parameter[0] = m1;
lsu_a_m_r_parameter[1] = a1;
lsu_a_m_r_parameter[2] = r1;
lsu_a_m_r_parameter[3] = m2;
lsu_a_m_r_parameter[4] = a2;
lsu_a_m_r_parameter[5] = r2;
//
//Conversion into main and offset LSU word
int main_word = iround(pow(2.0,18.0) * double(ifloor(double(r2) % pow(2.0,6.0) / pow(2.0,4.0))) + pow(2.0,15.0) * double(ifloor(double(m2) % pow(2.0,9.0) / pow(2.0,7.0))) + pow(2.0,8.0) * (double(m2) % pow(2.0,9.0)) + pow(2.0,4.0) * (double(r2) % pow(2.0,6.0) % pow(2.0,4.0)) + double(a2) % pow(2.0,4.0));
int offset_word = iround(pow(2.0,18.0) * double(ifloor(double(r1) % pow(2.0,6.0) / pow(2.0,4.0))) + pow(2.0,15.0) * double(ifloor(double(m1) % pow(2.0,9.0) / pow(2.0,7.0))) + pow(2.0,8.0) * (double(m1) % pow(2.0,9.0)) + pow(2.0,4.0) * (double(r1) % pow(2.0,6.0) % pow(2.0,4.0)) + double(a1) % pow(2.0,4.0));
//
//debug_print("LSU conversion result " + lsu_a_m_r_parameter);
//debug_print("main: " + main_word + ", offset: " + offset_word);
//
//Compute real LO frequency set by A,M,R combination
double nn1 = double(10 * (m1 + 1) + a1);
double dd1 = double(r1 + 1);
double nn2 = double(10 * (m2 + 1) + a2);
double dd2 = double(r2 + 1);
double flsu_back = 24000.0 + 30.0 * (nn1 / dd1 + nn2 / dd2);
if(band == "2a" || band == "3b") {
flsu_back = 24000.0 + 30.0 * (nn1 / dd1 - nn2 / dd2);
}
double flo_back = flsu_back * multiplier;
//debug_print("Real tuned frequency: " + flo_back);
//
int[] resu = [0,0];
resu[0] = main_word;
resu[1] = offset_word;
//Modification following SPR-1302
resu = [resu[0] + 0xf2200000,resu[1] + 0xf2300000];
//
return resu;
}
// Noise ratio from an OTF line for the special case of a
// multiple scan of the same line
//
double procedure OtfRepeatedNoiseRatio {
double num_scans = 2.0; // number of scans of the same line
double n = 10.0; // number of points in one scan
double[] parameters = [0.02,0.4,0.05,0.667,2.5]; // Parameters: integration time, delay and turn-around relative to Allan time, ratio of t_off time to sqrt(n)*t_on, line length, drift exponent
}{
// Assign parameters
double x = parameters[0];
double d = parameters[1];
double doff = parameters[2];
double qval = parameters[3];
double alpha = parameters[4];
// Make corrections for different calibration
double qcorr = qval * sqrt(num_scans);
{double,double} noisevalues = OtfNoiseValues(num_scans * n,[x,d,doff,qcorr,alpha]);
double yn = noisevalues{0};
yn = yn / num_scans;
double yd = noisevalues{1};
// Compute ratio
double y = yd / yn;
return y;
}
///////////////////////////////////////////////////////////////////////////////
// Subroutine for HRS settings shared between ConfigSpectroscopy and DataTaking
{int,int,int,int} procedure HrsSubbandSelection {
/* Backend settings */
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands}, WBS1/2 {used, channel windows}
}{
// Seection of HRS subbands in correct order
int[] widebits = [129,66,36,24];
// [10000001,01000010,00100100,00011000]
int[] lowbits = [192,48,12,3];
// [11000000,00110000,00001100,00000011]
int[] normalbits = [240,15];
// [11110000,00001111]
int[] highbits = [255];
// [11111111]
// HRS-H
int hrsh_sel = 0;
int n_hchannels = 0;
if(backendreadoutparms{0}{0} == true) {
// normal resolution
int maxbands = 2;
int[] bits = normalbits;
int n_perband = 2064;
if(backendreadoutparms{0}{1} > 2) {
// wide resolution
maxbands = 4;
bits = widebits;
n_perband = 1032;
} else {
if(backendreadoutparms{0}{1} > 1) {
// low resolution
maxbands = 4;
bits = lowbits;
n_perband = 1032;
} else {
if(backendreadoutparms{0}{1} < 1) {
// high resolution
maxbands = 1;
bits = highbits;
n_perband = 4128;
}
}
}
for(int i0 = 0 .. maxbands - 1) {
if(backendreadoutparms{0}{2}[i0]) {
hrsh_sel = hrsh_sel + bits[i0];
n_hchannels = n_hchannels + n_perband;
}
}
}
// HRS-V
int hrsv_sel = 0;
int n_vchannels = 0;
if(backendreadoutparms{1}{0} == true) {
// normal resolution
maxbands = 2;
bits = normalbits;
n_perband = 2064;
if(backendreadoutparms{1}{1} > 2) {
// wide resolution
maxbands = 4;
bits = widebits;
n_perband = 1032;
} else {
if(backendreadoutparms{1}{1} > 1) {
// low resolution
maxbands = 4;
bits = lowbits;
n_perband = 1032;
} else {
if(backendreadoutparms{1}{1} < 1) {
// high resolution
maxbands = 1;
bits = highbits;
n_perband = 4128;
}
}
}
for(int i1 = 0 .. maxbands - 1) {
if(backendreadoutparms{1}{2}[i1]) {
hrsv_sel = hrsv_sel + bits[i1];
n_vchannels = n_vchannels + n_perband;
}
}
}
return {hrsh_sel,hrsv_sel,n_hchannels,n_vchannels};
}
{int,double,double,double,double,double} obs HifiPointModeDBS {
string modeName = "dbs";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Single Point - DBS slowChop",{data_time,0,0,n_switch_on,0,0,0,0,n_cycles,load_interval},false);
ChopMessages(false,data_time,n_switch_on);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,bool,int,int,int} pre_timing = DBS_pre_timing(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},bool,double,double} post_timing = DBS_post_timing(pre_timing,telescopetimes,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_seq = post_timing{1}{8};
int n_loadinterval = post_timing{1}{7};
bool end_load = post_timing{1}{9};
int shiftlength = post_timing{1}{10};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
DBS_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,n_loadinterval,end_load,final_load,startobs,telescopetimes,loadlength,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double} tact = DBS_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBS_performance(band,lo_freq,effResolution,noisevalues,timeTaken,n_cycles,n_seq * (n_load + 1),tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
//////////////////////////////////////////////////////////////////////////
// Auxiliary procedure to compute sum of dead times across the map
{int,int,int} procedure GetAllCrossSlewTimes {
int[] telescopetimes = [300,180,20,0,21,0,2,10];
int scansize = 1; // Number of points measured in one scan
int n_cycles = 1; // Number of half OFF-ON-ON-OFF pointing cycles
}{
// Use telescope return parameters
int numpoints = telescopetimes[6];
if(scansize > 1) {
// Scan return field
int n_scans = numpoints / (2 * scansize * n_cycles);
int sumslews = 0;
int sumnods = 0;
int sumreturns = 0;
for(int i1 = 0 .. numpoints - 2) {
int theslew = telescopetimes[i1 + 7];
if(i1 % scansize == 0) {
if(i1 % (2 * scansize) == 0) {
// within A-A or B-B
sumreturns = sumreturns + theslew;
} else {
// Nod instead of slew
sumnods = sumnods + theslew;
}
} else {
sumslews = sumslews + theslew;
}
}
// Parameters irrelevant for scansize>1
int shortmove = 0;
// Main returns
int tinscandead = sumnods + sumslews;
int toutscandead = sumreturns;
} else {
// trivial computation for scansize=1;
// Single point per nod
int nodtime = telescopetimes[2];
// Slew time to second nod
int returntime = telescopetimes[3];
// Idle time between two phases
// Scan return field
numpoints = telescopetimes[6];
n_scans = numpoints / scansize;
sumreturns = n_scans * (n_cycles - 1) * returntime;
// Initial values
sumslews = 0;
shortmove = returntime;
// All return values
for(int i2 = 0 .. numpoints - 2) {
theslew = telescopetimes[i2 + 7];
sumslews = sumslews + theslew;
shortmove = imin(shortmove,theslew);
}
tinscandead = n_scans * n_cycles * nodtime;
toutscandead = sumslews + sumreturns;
}
return {tinscandead,toutscandead,shortmove};
}
//Transition mode from standby1 to dissipative1
procedure HifiSetFromStandby_I_IntoDissipative_I {
}{
//
//Clear potential failure mode
Set_LO_Nominal_block_aot();
//
LCU_switch_off_block_aot();
//Will put heaters to 6V
Set_LO_Dissipative_block_aot();
//
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// CUS scripts dedicated to instrument configuration
// and setup in AOT framework
//
// Main difference with ILT CUS is that input parameters
// are here in the form provided by HSPOT.
//
// DT - 05-June-06
// VO - 10-07-2006
// DT - 18-09-2006
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/////////////////////////////
// Global procedures
//Tune HIFI at frequency of interest
procedure HIFITune {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; //LO frequency
bool hrs1used = true; // HRS1 parameter =used
bool hrs2used = true; // HRS2 parameter
bool wbs1used = true; // WBS1 parameter =used
bool wbs2used = true; // WBS2 parameter
string target_name = "normal"; // Name of target level
}{
//LO power tuning: could use either H or V polar
{double,string}[] result = ConfigurationReader("name_confpolar4lotune",[band],band,lo_freq);
double x = result[0]{0};
string tuningbackend = "H";
if(iround(x) == 2) {
tuningbackend = "V";
} else {
tuningbackend = "H";
}
LO_tuning_block_aot(band,lo_freq / 1000.0,lo_freq / 1000.0,tuningbackend,true,true,false,true);
//Magnet tuning: use either HRS or WBS, not for bands 1,2,6,7 (SCR-2380)
if(band == "3a" || band == "3b" || band == "4a" || band == "4b" || band == "5a" || band == "5b") {
// Currently only the HRS is used
tuningbackend = "HRS";
Magnet_tuning_block_aot(band,lo_freq / 1000.0,tuningbackend);
}
//
//Spectrometer attenuator tuning on HBB
if(wbs1used || wbs2used) {
WBS_attenuators_block(band,lo_freq / 1000.0,target_name,false);
}
if(hrs1used || hrs2used) {
HRS_tune_block_aot(band);
}
}
{int,double,double,double,double,double} obs HifiMappingModeLoadChopOTFNoRef {
string modeName = "load-raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period defines number of lines between two loads
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Mapping - OTF Map Load Chop noRef",{data_time,0,0,n_switch_on,0,0,0,0,n_cycles,load_interval},true);
// Auxiliary routine for API parameter correction
{double,double,int} mapused = ValidMapSize(band,lo_freq,lineDistance,nlines,stepsize,npoints,2 * data_time * n_switch_on,n_switch_on);
double line_used = mapused{0};
double scanvelocity = mapused{1};
int npoints_used = mapused{2};
// Call first part of the timing computer
{int,int,int,int,bool,int,int} pre_timing = OTFLoadChopNoRef_pre_timing(nlines,npoints_used,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,double,double,int,int,int} tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,pre_timing);
// Dummy call to spacecraft command
int[] telescopetimes = line_scan_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,bool,int,int},double,double} post_timing = OTFDoubleChopNoRef_post_timing(pre_timing,telescopetimes,nlines,data_time,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = OTFDoubleChopNoRef_telescope(naifid,onPosition,lineDistance,nlines,line_used,scanvelocity,band,lo_freq,n_cycles,post_timing{1});
// Call telescope command
telescopetimes = line_scan_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{0};
bool end_load_on = post_timing{1}{4};
int n_loadinterval = post_timing{1}{2};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
OTFLoadChopNoRef_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on,n_loadinterval,nlines * n_cycles,end_load_on,startobs,telescopetimes,loadlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = SingleChop_deadtimes("fs",band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,npoints_used * n_switch_on);
double tscan = 2.0 * (tact{1} + tact{2});
double tdead = 2.0 * tact{2};
//
// Call noise computer
{double,double,double,double,double} noisevalues = PositionSwitch_noisecomputer(band,lo_freq,effResolution,oneGHzReference,n_switch_on * n_cycles,tscan,tdead);
// Evaluate performance
OTFDoubleChopNoRef_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints_used,n_switch_on * n_cycles,false,tscan,tdead);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
{int,double,double,double,double,double} obs HifiSScanModeFSwitch {
string modeName = "fs-freq";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_switch_off = 1 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Spectral Scan - Frequency Switch Ref",{data_time,data_time_off,0,n_switch_on,n_switch_off,0,0,n_freq_point,n_cycles,load_interval},false);
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,imin(data_time,data_time_off));
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
//////////////////////////////////////////////////////////////////////
// Call first part of the timing computer
{{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},{int,double,double[],int[][],bool,double[],int,bool}} pre_timing = SScanFSwitch_pre_timing(band,lo_freq,lo_freq_up,redundancy,freq_throw,effResolution,hr1,hr2,wb1,wb2,data_time,data_time_off,n_switch_on,n_switch_off,n_freq_point,n_cycles,load_interval,docommands);
// frequency parameters
int groupnumber = pre_timing{1}{0};
double reffreq = pre_timing{1}{1};
double[] freqgrid = pre_timing{1}{2};
int[][] grouporder = pre_timing{1}{3};
bool retuning = pre_timing{1}{4};
double[] targetlevels = pre_timing{1}{5};
int nfreq_if = pre_timing{1}{6};
bool dsb = pre_timing{1}{7};
int n_total = groupnumber * n_cycles;
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{double,double} refPosition = {raoff,decoff};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,pre_timing{0},n_total);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},double,double,double} post_timing = SScanDoubleChop_post_timing(pre_timing{0},telescopetimes,n_freq_point,groupnumber,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = PositionSwitch_telescope(naifid,onPosition,refPosition,band,reffreq,post_timing{1},n_total);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},true);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
// normal pre_timing values
int on_inttime = post_timing{1}{0};
int off_inttime = post_timing{1}{1};
int n_loadinterval = post_timing{1}{7};
int n_long_on = post_timing{1}{8};
int n_long_off = post_timing{1}{9};
int shiftlength = post_timing{1}{5};
int initlength = post_timing{1}{14};
bool final_load = post_timing{1}{12};
// efficiency parameters
double avnumchop_on = post_timing{2};
double avnumchop_off = post_timing{3};
double tscan = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
SScanFSwitch_commanding(band,reffreq,freq_throw,effResolution,hr1,hr2,wb1,wb2,n_freq_point,grouporder,freqgrid,retuning,targetlevels,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,n_total,n_loadinterval,final_load,startobs,telescopetimes,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double,double,double} tact = SScanDoubleChop_deadtimes("fs",band,reffreq,hr1,hr2,wb1,wb2,n_freq_point,data_time,data_time_off,n_switch_on,n_switch_off,n_long_on,n_long_off,n_cycles,avnumchop_on,avnumchop_off,tscan);
//
// Call noise computer
{double,double,double,double,double} noisevalues = SScanFSwitch_noisecomputer(band,reffreq,nfreq_if,dsb,effResolution,on_inttime,off_inttime,n_cycles,tscan,tact);
// Evaluate performance
SScanDoubleChop_performance(band,reffreq,nfreq_if,dsb,effResolution,noisevalues,timeTaken,n_freq_point,n_cycles,groupnumber * n_freq_point,avnumchop_on,avnumchop_off,true,tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hr1{0},hr2{0},wb1{0},wb2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// Reset observation ID - closes observation
block HIFICloseObs HIFI 6999 {
}{
// Previous command my have used second bus slot - use NOOP to fill
Hifi_HIFI_noop();
// Switch to slow housekeeping
{string,int,double,double,double,double} hkparms = PeriodicHKParms("slow");
string[] pattern = QueryHKPattern(true);
Hifi_HIFI_Housekeeping_on(hkparms{0},pattern[0],pattern[1],pattern[2],pattern[3],pattern[4],pattern[5]);
//Fetch last obsid applicable
{double,string}[] result = ConfigurationReader("name_lastobsid",["last_obsid_current"],"0",0.0);
int closing_obsid = iround(result[0]{0});
//Close OBSID
Hifi_HIFI_Set_OBS_ID(0,closing_obsid);
// clean bus
delay(1);
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure SScanFSwitch_commanding {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference characteristic LO frequency
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int grouplen = 1; // Number of frequency steps per nodding phase
int[][] grouporder = [[0],[0]]; // Sequence to trace frequency points in both phases
double[] freqgrid = [978053.7,978301.8,978381.1]; // Table of frequency points
bool retuning = false; // need for WBS retuning
double[] targetlevels = [1.0,1.0,1.0]; // WBS tuning levels
int data_time = 4; // chunk size
int data_time_off = 4; // data dump interval on OFF
int n_per_on = 1; // number of half nu1-nu2-nu2-nu1 cycles on ON
int n_per_off = 1; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_long_on = 1; // number of cycles on ON without retuning
int n_long_off = 1; // number of cycles on OFF without retuning
int n_cycles = 1; // Number of half OFF-ON-ON-OFF cycles at one frequency
int allsteps = 4; // Total number of frequency pointing periods
int n_loadinterval = 1; // number of nods before a load measurement
bool final_load = false; // Need for final load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,20,1,21,0]; // Timing of the observation from telescope
int shiftlength = 0; // Shift of the loop start relative to the pointing
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int tnodslew = telescopetimes[2];
// slew dead time between points
// First frequency
double runningfreq = freqgrid[grouporder[1][0]];
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] onrates = dataparms{1};
dataparms = DataTaking(backendreadoutparms,data_time_off);
double[] offrates = dataparms{1};
int hkduration = HkReadoutTime(band,reffreq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,reffreq,backendreadoutparms);
// recompute load duration for initial load measurement
int loadlength = duration(SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,true,eff_resolution{0},data_time,backendreadoutparms));
loadlength = loadlength + readoutdead;
// Tuning levels
string[] targetnames = TargetNames(band,reffreq,retuning,targetlevels);
string target = targetnames[0];
// All commands with a duration possibly depending on the frequency
// are taken at the reference frequency to guarantee synchonization
// Declare auxiliary variables to be used in the loops
int i_freqcycles = 0;
int i_group = 0;
int i_phase = 0;
// variables storing the configuration setting
bool islong = false;
bool isinvalid = true;
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
HIFIInitObs();
TuneHIFIFsw(band,runningfreq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},target);
delay(tinitslew - (time() - startobs) - loadlength + shiftlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,true,eff_resolution{0},data_time,backendreadoutparms);
if(shiftlength > 0) {
runintostate = true;
} else {
runintostate = false;
}
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 7) {
i_phase = (state[2] + 1) % 2;
// The NOD-state represents our OFF position
// Reset group counter
i_group = 0;
runintostate = false;
// long integrations not possible in last and first PS cycle
if(n_cycles > 1 && state[2] % n_cycles != state[2] % 2) {
if(isinvalid || !islong) {
HIFIConfigureFSwitchIntegration(data_time_off,n_long_off,band,reffreq,backendreadoutparms);
islong = true;
isinvalid = false;
}
HIFIFSwitchOffIntegration(data_time_off,n_long_off,band,reffreq,offrates);
} else {
if(isinvalid || islong) {
HIFIConfigureFSwitchIntegration(data_time_off,n_per_off,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
// No group scanning on OFF
HIFIFSwitchOffIntegration(data_time_off,n_per_off,band,reffreq,offrates);
}
// Other frequencies
// Reset group counter
i_group = 1;
while(i_group <= grouplen - 1) {
// retune
runningfreq = freqgrid[grouporder[i_phase][i_group] + i_freqcycles * grouplen];
HIFIChangeFreqFsw(band,runningfreq,freq_throw);
if(i_group == 1) {
if(isinvalid || islong) {
HIFIConfigureFSwitchIntegration(data_time_off,n_per_off,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
}
HIFIFSwitchOnIntegration(data_time_off,n_per_off,band,reffreq,onrates);
i_group = i_group + 1;
}
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && state[2] % 2 == 0) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freqcycles = i_freqcycles + 1;
runningfreq = freqgrid[grouporder[1][0] + i_freqcycles * grouplen];
target = targetnames[i_freqcycles];
HIFIRetuneFsw(band,runningfreq,freq_throw,target);
runintostate = true;
} else {
// final load measurement if requested
if(final_load) {
delay(readoutdead);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
runintostate = true;
}
}
}
// Active WBS HK if we have a nod slew without calibration
if(state[2] % 2 == 1) {
isinvalid = true;
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 3) {
// The POINT-state represents our source position
i_phase = state[2] % 2;
// ON integration
runintostate = false;
// long integrations not possible in last and first nod cycle
if(n_cycles > 1 && state[2] % n_cycles != (state[2] % 2 + 1) % 2) {
if(isinvalid || !islong) {
HIFIConfigureFSwitchIntegration(data_time,n_long_on,band,reffreq,backendreadoutparms);
islong = true;
isinvalid = false;
}
HIFIFSwitchOnIntegration(data_time,n_long_on,band,reffreq,onrates);
} else {
if(isinvalid || islong) {
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,onrates);
}
// Other frequencies
// Reset group counter
i_group = 1;
while(i_group <= grouplen - 1) {
// retune
runningfreq = freqgrid[grouporder[i_phase][i_group] + i_freqcycles * grouplen];
HIFIChangeFreqFsw(band,runningfreq,freq_throw);
if(i_group == 1) {
if(isinvalid || islong) {
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,reffreq,backendreadoutparms);
islong = false;
isinvalid = false;
}
}
HIFIFSwitchOnIntegration(data_time,n_per_on,band,reffreq,onrates);
i_group = i_group + 1;
}
// Now we switch to the next frequency group or repeat the cycle
if(state[2] % n_cycles == 0 && i_phase == 1) {
// Big tuning step, but not at end of observation
if(state[2] < allsteps) {
i_freqcycles = i_freqcycles + 1;
runningfreq = freqgrid[grouporder[0][0] + i_freqcycles * grouplen];
target = targetnames[i_freqcycles];
HIFIRetuneFsw(band,runningfreq,freq_throw,target);
runintostate = true;
} else {
// final load measurement if requested
if(final_load) {
delay(readoutdead);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
runintostate = true;
}
}
}
// Active WBS HK if we have a nod slew without calibration
if(state[2] % 2 == 0) {
isinvalid = true;
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 9) {
// Load switch
delay(readoutdead);
SScanDoubleLoadMeasurement(band,runningfreq,reffreq,freq_throw,false,eff_resolution{0},data_time,backendreadoutparms);
isinvalid = true;
runintostate = false;
}
// Danging load - already covered above
// otherwise the instrument stops halftunelength before the telescope
if(state[0] == 5) {
// finished shift of instrument operations relative to pointing command
runintostate = false;
HIFICloseObs();
}
}
}
// Get dead time for frequency switch
double procedure GetFSwitchDeadTime {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] dead = CalibrationReader("fs_deadtime",["duration"],band,lo_freq);
return dead[0];
}
// Compute the additional time needed for HK readout setting at first load
int procedure HkReadoutTime {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
bool fast = false; //whether fast chop is used
}{
// get time added already for normal readout
if(fast) {
int readoutdead = FastChopReadoutDelay(band,lo_freq,backendreadoutparms);
} else {
readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
}
// HK readout time
int hkreadouttime = duration(HIFISetHK("normal",false));
int remain = imax(hkreadouttime - readoutdead,0);
return remain;
}
// Procedure to compute all parameters needed in a Configure_spectroscopy
{int,int,int,int,int,int,int,int,int,int} procedure ConfigureSpectroscopyParams {
/* Integration time */
int data_time = 4; // Integration time between two data readouts
int n_data = 2; // Integration time counter
/* Parameters determining the delays - used in calibration reader */
string chopmode = "chop" in ["chop","lchop","fs","hot-cold","tp"]; // Chop mode determining the modulation dead time
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
/* Backend settings */
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used,channel windows}
}{
// Get fixed parameters from configuration and calibration files
// Command jitter time is the default delay
{double,string}[] result = ConfigurationReader("name_delays",["add_jitter"],band,lo_freq);
int add_jitter = iround(result[0]{0});
// WBS delta time
// Default total power. This should be 0.
int del_wbs = add_jitter;
// WBS delta time given by switch dead time
if(chopmode == "chop") {
double res = GetSkyChopDeadTime(band,lo_freq);
del_wbs = iceil(res * 1000.0);
}
if(chopmode == "lchop") {
res = GetLoadChopDeadTime(band,lo_freq);
del_wbs = iceil(res * 1000.0);
}
if(chopmode == "fs") {
res = GetFSwitchDeadTime(band,lo_freq);
del_wbs = iceil(res * 1000.0);
}
if(chopmode == "hot-cold") {
bool wbsused = backendreadoutparms{2}{0} || backendreadoutparms{3}{0};
res = HotColdRelaxTime(band,lo_freq,wbsused);
del_wbs = iceil(res * 1000.0);
}
// HRS delta time - should be zero as well
int del_hrs = add_jitter;
// Additional delays in the readout loops - given in OBS user manual
result = ConfigurationReader("name_delays",["add_hrs","add_wbs","add_jitter","wbs_init","wbs_chunksize","tacc_add","hrs_phase","min_wbs_acc","scos_jitter"],band,lo_freq);
int add_hrs = iround(result[0]{0});
int add_wbs = iround(result[1]{0});
int wbs_init = iround(result[3]{0}) + iround(result[8]{0});
int wbs_chunksize = iround(result[4]{0});
int tacc_add = iround(result[5]{0});
int hrs_phase = iround(result[6]{0});
// HRS standard phase length
int min_wbs_acc = iround(result[7]{0});
// WBS transfer time
// Split total integration time
int tint = data_time * n_data * 1000;
// dead time has to be an integer multiple of the 10ms chunk time
int tdead = del_wbs + add_wbs + add_jitter;
int nchunk = (tdead - 1) / wbs_chunksize + 1;
int tcorr = nchunk * wbs_chunksize - tdead;
del_wbs = del_wbs + tcorr;
tdead = tdead + tcorr;
// Accumulation time
// Ignores that total power can be slightly more efficient
int t_acc_wbs = (tint - wbs_init) / n_data - tdead;
// discretize in 10ms chunks
nchunk = (t_acc_wbs - tacc_add) / wbs_chunksize;
t_acc_wbs = nchunk * wbs_chunksize + tacc_add;
// Check relative to minimum accumulation tim
if(t_acc_wbs + del_wbs + add_wbs < min_wbs_acc + add_jitter) {
SError("WBS integration too short for readout. Increase duration.");
}
// No WBS addition in ICU
int n_wbs_integr = 1;
int n_wbs_start = n_data;
// HRS
int hrs_fullphase = hrs_phase + del_hrs + add_hrs;
int r_hrs = (t_acc_wbs + hrs_fullphase - add_jitter) / hrs_fullphase;
int t_acc_hrs = (t_acc_wbs - add_jitter) / r_hrs - del_hrs - add_hrs;
// for n_wbs_integr=1 identical to r_hrs
int n_hrs_integr = r_hrs;
// Compute actual integration time and dead time per readout
// If WBS is used count only the WBS time
if(backendreadoutparms{2}{0} || backendreadoutparms{3}{0}) {
int tint_act = nchunk * wbs_chunksize * n_data;
tdead = tdead + tacc_add;
} else {
tint_act = t_acc_hrs * r_hrs * n_data;
tdead = tdead + r_hrs * (del_hrs + add_hrs) + add_jitter;
}
// Return all config_spectroscopy timing parameters
return {n_wbs_start,r_hrs,n_wbs_integr,n_hrs_integr,del_hrs,del_wbs,t_acc_wbs,t_acc_hrs,tdead,tint_act};
}
// Check frequency throw relative to HRS bandwidth
procedure CheckFswOutOfBand {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
}{
bool hrs1used = backendreadoutparms{0}{0};
// HRS1 to be used
int hrs1resol = backendreadoutparms{0}{1};
// resolution
bool hrs2used = backendreadoutparms{1}{0};
// HRS2 to be used
int hrs2resol = backendreadoutparms{1}{1};
// resolution
// get minimum bandwidth covered
// Start from full IF
double bw = GetBackendBandwidth(band,lo_freq,-1);
// Both HRS
if(hrs1used) {
double hbw = GetBackendBandwidth(band,lo_freq,hrs1resol);
bw = min(bw,hbw);
}
if(hrs2used) {
hbw = GetBackendBandwidth(band,lo_freq,hrs2resol);
bw = min(bw,hbw);
}
// Compare with frequency throw
if(abs(freq_throw) > 0.5 * bw) {
// Generate messages - first close previous paragraph
message("");
message("Warning
");
message("");
message("The chosen frequency throw of " + freq_throw + " MHz is large " + "compared to the HRS subband coverage. It is likely that the HRS " + "does not see some lines in both frequency-switch phases. In this " + "case, the actual S/N ratio will be lower by a factor two than the " + "predicted one.");
}
}
// Fast chop integration OFF-ON-OFF-ON... with telescope at OFF position
block HIFIFastHalfChopOffIntegration HIFI 6054 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // readout cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
int[] parms = [1,0]; // Parameters for chop cycles
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_fast_chop_proc_aot(data_time,n_cycle,band,lo_freq,["chop_M3","chop_M3right"],parms,rates);
}
// Procedure to get timing in a spectroscopy measurement
{double,double} procedure GetInstDeadFastChop {
/* Integration time */
int data_time = 10 in [4,128]; // data dump interval
int n_int = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_data = 2; // Integration time counter
/* Parameters determining the delays - used in calibration reader */
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
/* Backend settings */
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used,channel windows}
}{
// Get timing parameters
bool wbs_used = backendreadoutparms{2}{0} || backendreadoutparms{3}{0};
{int,int,int,int,int,int,int,int,int,int,int,int,int} timing = FastConfigureSpectroscopyParams(data_time,n_int,n_data,band,lo_freq,wbs_used);
int tdead_chop = timing{10};
int tdead_data = timing{11};
int tint = timing{12};
// For the noise computation there is no difference between initial dead
// and readout dead, they are all summed up
// Return dead time per full integration
double tintall = double(tint) / 1000.0;
double tdeadphase = double(tdead_chop) / 1000.0;
return {tintall,tdeadphase};
}
{string,double,double}[] procedure HifiPointModeFSwitchNoRefSequencerInit {
string modeName = "fs";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int n_cycles = 2 in [1,3600]; // number of half nu1-nu2-nu2-nu1 cycles on ON
int load_interval = 1800 in [10,7200]; // load period in seconds
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// inherit from load-chop mode
{string,double,double}[] retvalues = HifiPointProcLoadChopNoRefSequencerInit(naifid,ra,dec,band,lo_freq,effResolution,oneGHzReference,hrs1,hrs2,wbs1,wbs2,data_time,n_cycles,load_interval,docommands);
return retvalues;
}
// Recalculate and verify LCU Unused memory checksum at end of HIFI block - HIFI-4049
block LcuChecksumSegmentedUnused_block_aot HIFI 7908 {
}{
//Check un-used area - done in transition to Diss-1
string block_IF_NOK = "NO";
LcuChecksumRecalcSegmented_aot("0","Unused",block_IF_NOK);
}
// Read addresses and get checksum for a given code category
// Returns:
// - the array of address_start, address_length
// - the full checksum of all concatenated address areas
// - the full length of all concatenated address areas
//
{{int,int}[],int,int} procedure LcuGetCodeAddress_ops {
string code_category = "Safe" in ["Safe","Critical","Unused"]; //safe, critical or unused
}{
string tab = "LcuAddressCode" + code_category + "_R.config";
{int,int}[] pairs = [];
int total_length = 0;
int total_crc = 0;
int total = table_size(tab);
//Get inputs for band 1a - loop on location types
for(int line = 1 .. total) {
int add_S = ilookup(tab,"" + line,"a1S");
int add_L = ilookup(tab,"" + line,"a1L");
pairs[line - 1] = {add_S,add_L};
total_crc = total_crc + ilookup(tab,"" + line,"crc");
total_length = total_length + add_L;
}
//Complement with zeroes until getting to 48 pairs
int hifi_NStep = 48;
for(int line2 = total + 1 .. hifi_NStep) {
add_S = 0;
add_L = 0;
pairs[line2 - 1] = {add_S,add_L};
}
//Wrap-around CRC
total_crc = total_crc % (0xffff + 1);
//
return {pairs,total_crc,total_length};
}
// Load calibration measurement
procedure LoadMeasurement_FCal {
string band = "4a"; // HIFI band (needed to estimate stabilization)
double lo_freq = 978200.0; // LO frequency
double deltanu = 1.0; // minimum effective resolution of the calibrated data
int data_time = 4; // time between subsequent data readouts
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
}{
// Initial computations
{int,int,bool} calinit = HIFICalInit(band,lo_freq,deltanu,data_time);
int used_datatime = calinit{0};
int n_inttime = calinit{1};
bool retuning = calinit{2};
// Perform zero and comb measurement
ZeroCombMeasurement_FCal(band,lo_freq,used_datatime,backendreadoutparms);
// No we perform the actual hot-cold measurement
// slow_chop_spectroscopy
int danglingreadout = HIFI_Calibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,retuning);
// Retune and another load if we are in HEB bands
if(retuning) {
// we have to wait for readout
delay(danglingreadout);
// Another LO vector scan at the same frequency for a stable HEB operation
HIFITuneFreq(band,lo_freq,false,"");
danglingreadout = HIFI_Calibrate_hot_cold(band,lo_freq,used_datatime,n_inttime,backendreadoutparms,false);
}
}
/////////////////////////////////////////////////////////////////
// Spectral scan in DBS observing modes
//
{string,double,double}[] procedure HifiSScanProcDBSSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4 in [1,12]; // Frequency scan redundancy
{double,double} effResolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool wbs1Used = true; // whether WBS1 is used
bool wbs2Used = true; // whether WBS2 is used
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per frequency and pointing
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,data_time);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// Get frequency grid characteristic parameters
{double,int,double} gfref = GetFReference(band,lo_freq,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,"dbs");
int n_freq_point_guess = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
// Now general part of DBS modes
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// Get the drift parameters to compute the drift noise
// spectral scans always use the full bandwidth for reference
bool narrowReference = false;
{double,double} phaselengths = DBSPhaseLengths(band,reffreq,effResolution,continuumDetection,narrowReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// remaining part for n_switch
int n_switch_on_guess = iceil(phaselengths{0}) / (n_freq_point_guess * 2 * data_time_guess) + 1;
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// Additional constraint of compatibility of group size with load period
int loadperiod = LoadPeriod(band,reffreq,effResolution{1});
// 80% margin
int periodlimit = loadperiod * 4 / 5;
// elements of cycle - compute cycle duration
int tunedelay = LOSettlingTime(band,reffreq / 1000.0,false,true);
int loadlength = duration(SScanLoadMeasurement(band,reffreq,reffreq,true,effResolution{0},data_time_guess,backendreadoutparms));
int perfreqtime = 2 * (2 * data_time_guess * n_switch_on_guess + tunedelay);
int cycle = perfreqtime * n_freq_point_guess + loadlength;
if(cycle > periodlimit) {
n_freq_point_guess = imax((periodlimit - loadlength) / perfreqtime,1);
}
int n_freq_point_range = 1 - n_freq_point_guess;
if(n_freq_point_range == 0) {
n_freq_point_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_freq_point",double(n_freq_point_guess),double(n_freq_point_range)}];
return retvalues;
}
// Fast chop integration OFF-ON-OFF-ON... with telescope at ON position
block HIFIFastHalfChopOnIntegration HIFI 6053 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // readout cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
int[] parms = [1,0]; // Parameters for chop cycles
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_fast_chop_proc_aot(data_time,n_cycle,band,lo_freq,["chop_M3","chop_M3right"],parms,rates);
}
{string,double,double}[] procedure HifiMappingModeOTFSequencerInit {
string modeName = "fly";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,5]; // chunk size given by the data rates and optimum speed
int n_int_on = 1 in [1,1800]; // Supersamplingfactor
int n_linesperscan = 1 in [1,32]; // Number of lines between two OFFs
int n_switch_off = 3 in [1,3600]; // Number of data dumps for the OFF integration time
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
// Get the drift parameters to compute the drift noise
// System Allan variance
double[] allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// Compute derived quantities
int main_phase = iceil(0.3 * allan_time_lores);
// How many lines could we do at most using datalimit?
int n_linesperscan_guess = main_phase / datalimit + 1;
n_linesperscan_guess = imax(n_linesperscan_guess * n_linesperscan_guess / npoints,1);
// restrict the scan size
if(nlines == 1 && n_linesperscan_guess > 1) {
n_linesperscan_guess = 2;
} else {
n_linesperscan_guess = IMultiple(n_linesperscan_guess,nlines);
n_linesperscan_guess = imin(n_linesperscan_guess,nlines);
}
int n_linesperscan_range = 1 - n_linesperscan_guess;
if(n_linesperscan_range == 0) {
n_linesperscan_range = 1;
}
double n_pointsperscan = double(n_linesperscan * npoints);
// Compute back
int int_time_guess = imax(main_phase / iceil(sqrt(n_pointsperscan)),datalimit);
int data_time_guess = imin(5,int_time_guess);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
int n_int_on_guess = imax(int_time_guess / data_time_guess,1);
int n_int_on_range = 1 - n_int_on_guess;
if(n_int_on_range == 0) {
n_int_on_range = 1;
}
// OFF integration
int n_switch_off_guess = ifloor(double(n_int_on) * 0.67 * sqrt(n_pointsperscan));
int n_switch_off_range = n_switch_off_guess / 3;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_int_on",double(n_int_on_guess),double(n_int_on_range)},{"n_linesperscan",double(n_linesperscan_guess),double(n_linesperscan_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)}];
return retvalues;
}
/////////////////////////////////////////////////////////////////
// Get valid table range
{int,int} procedure GetFScanBoundaries {
string band = "4a"; // HIFI band
double freq_throw = -40.0; // throw of frequency switch in MHz
}{
// read master file
string calibfile = slookup("frequencystep_masterfile",band,"tablefile");
double[] allfpoints = dcolumn(calibfile,"lo_frequency");
// get table size
int iindex1 = length(allfpoints);
if(freq_throw < 0.0) {
int istart = 1;
int iend = iindex1 - 2;
double goallo = allfpoints[1] - freq_throw;
while(allfpoints[istart] < goallo) {
istart = istart + 1;
}
} else {
istart = 1;
iend = iindex1 - 2;
goallo = allfpoints[iindex1 - 2] - freq_throw;
while(allfpoints[iend] > goallo) {
iend = iend - 1;
}
}
return {istart,iend};
}
// Fast chop integration OFF-ON-OFF-ON... with telescope at OFF position
block HIFIFastChopOffIntegration HIFI 6043 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // readout cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
int[] parms = [1,0]; // Parameters for chop cycles
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_fast_chop_proc_aot(data_time,n_cycle,band,lo_freq,["chop_M3left","chop_M3right"],parms,rates);
}
//////////////////////////////////////////////////////////////////////////
// Procedure to generate the composite position telescope command for the
// observing mode
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} procedure PositionSwitch_telescope {
int naifid = 0; // Tracking object ID
{double,double} onposition = {0.0,0.0}; // Coordinates of the source
{double,double} offposition = {0.2,0.2}; // Coordinates of the OFF position
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int} timing = {16,16,16,16,21,11,1800,32,2,2,0,0,false,false,50,0};
int n_cycles = 2; // Number of half OFF-ON-ON-OFF cycles
}{
// Assign values
int on_pointing = timing{2};
// Pointing on on-position
int off_pointing = timing{3};
// Pointing OFF on-position
int loadlength = timing{4};
// Load duration
int n_loadinterval = timing{7};
// Number of nods between load measurements
int initlength = timing{14};
// Initial setup time
int dangling = timing{15};
// Final load measurement
// Create variables for telescope command
string ib = GetBoresight(band,lo_freq,false);
// A change of ra-dec depending on naifid may be needed
double ra = onposition{0};
double dec = onposition{1};
// Compute offset: This is always in sky coordinates
{double,double} offset = AngularOffset(onposition,offposition);
double patt = AngleFromVector(offset);
double slewlength = AngleVectorLength(offset);
slewlength = max(slewlength * 3600.0,2.0);
// Check parameter compatibility with pointing command for parameters
// which are no direct input parameters
if(on_pointing < 10) {
SError("Source pointing phase length too short. Increase the number of integrations.");
}
if(off_pointing < 10) {
SError("OFF pointing phase length too short. Increase the number of integrations.");
}
if(slewlength > 7200.0) {
IError("Slew distance too long. Choose a closer OFF position.");
}
// repetition at multiple frequencies not yet implemented:
int thold = 0;
int nhold = 0;
int n_repeat = n_cycles;
// return parameters in required order
return {initlength,0,dangling,ib,naifid,ra,dec,true,patt,0.0,0.0,n_repeat,slewlength,on_pointing,off_pointing,loadlength,n_loadinterval,thold,nhold};
}
// Drift noise from an asymmetric two-phase observation
// This is still to be scaled by a factor 1.0/(B_fluct_A*T_Allan)
double procedure AsymmetricDrift {
double xa = 0.1; // integration time in phase A relative to Allan time
double xb = 0.1; // integration time in phase B relative to Allan time
double d = 0.3; // delay relative to Allan time
double alpha = 2.5; // drift exponent
}{
if(xa >= 0.0) {
double a1 = alpha + 1.0;
double y = ((pow(xa + xb + d,a1) - pow(xa + d,a1) - pow(xb + d,a1) + pow(d,a1)) / (xa * xb) - pow(xa,a1) / (xa * xa) - pow(xb,a1) / (xb * xb)) / (pow(2.0,alpha) - 2.0);
} else {
// forbid x values <=0
y = 1.0E11 * (1.0 - xa);
}
return y;
}
// Drift noise from a symmetric two-phase observation
// This is still to be scaled by a factor 1.0/(B_fluct*T_Allan)
double procedure TwoPhaseDrift {
double x = 0.1; // integration time relative to Allan time
double d = 0.3; // delay relative to Allan time
double alpha = 2.5; // drift exponent
}{
if(x >= 0.0) {
double a1 = alpha + 1.0;
double y = (pow(2.0 * x + d,a1) - 2.0 * pow(x + d,a1) + pow(d,a1) - 2.0 * pow(x,a1)) / ((pow(2.0,alpha) - 2.0) * x * x);
} else {
// forbid x values <=0
y = 1.0E11 * (1.0 - x);
}
return y;
}
///////////////////////////////////////////////////////
// Generic procedures to tune S/S in HIFI
// Set magnet currents for both polarizations, procedure
procedure Set_Magnet_current_proc_fm {
double mag_curr_h = 1.0; //Magnet current H polarization
double mag_curr_v = 1.0; //Magnet current V polarization
}{
Hifi_HIFI_CH1_MX_MG_C($BBID,mag_curr_h);
Hifi_HIFI_CV1_MX_MG_C($BBID,mag_curr_v);
delay(1);
}
//Get blue min
double procedure Get_BLUE_MIN_D2_proc_fm {
string band = "4a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978.2; //LO Frequency
}{
//Anticipated implementation of SCR-2220
string name_configlcu = "name_configlcu_a";
if(band == "1b" || band == "2b" || band == "3b" || band == "4b" || band == "5b" || band == "6b" || band == "7b") {
name_configlcu = "name_configlcu_b";
}
{double,string}[] result = ConfigurationReader(name_configlcu,["drain2_v_blmn","drain2_v_blmx"],band,lo_freq);
double drain2_min = 0.0;
if(band == "1a") {
drain2_min = result[0]{0};
}
if(band == "1b") {
drain2_min = result[0]{0};
}
if(band == "2a") {
drain2_min = result[0]{0};
}
if(band == "2b") {
drain2_min = result[0]{0};
}
if(band == "3a") {
drain2_min = result[0]{0};
}
if(band == "3b") {
drain2_min = result[0]{0};
}
if(band == "4a") {
drain2_min = result[0]{0};
}
if(band == "4b") {
drain2_min = result[0]{0};
}
if(band == "5a") {
drain2_min = result[0]{0};
}
if(band == "5b") {
drain2_min = result[0]{0};
}
if(band == "6a") {
drain2_min = result[0]{0};
}
if(band == "6b") {
drain2_min = result[0]{0};
}
if(band == "7a") {
drain2_min = result[0]{0};
}
if(band == "7b") {
drain2_min = result[0]{0};
}
return drain2_min;
}
////////////////////////////////////
// Fast chop DBS raster - cross observing mode
//
{string,double,double}[] procedure HifiMappingProcFastDBSCrossSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the two raster lines
int npoints = 10 in [2,100]; // Number of points per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power levels
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// inherit from dbs-raster mode
{string,double,double}[] retvalues = HifiMappingProcFastDBSRasterSequencerInit(naifid,ra,dec,{0.0,double(npoints / 2) * stepsize},2,stepsize,npoints,band,lo_freq,effResolution,continuumDetection,oneGHzReference,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
return retvalues;
}
////////////////////////////////////
// Routine to provide initial guesses for sequence parameters
// Load chop mode without baseline calibration
//
{string,double,double}[] procedure HifiPointProcLoadChopNoRefSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rates
int n_cycles = 2 in [1,3600]; // number of half load-sky-sky-load cycles on ON
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// limit on data rate
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
// Get the drift parameters to compute the drift noise
// System Allan variance
double[] allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(0.3 * allan_time_lores),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// Contruct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)}];
return retvalues;
}
// Noise ratio from an OTF observation
//
double procedure OtfNoiseRatio {
double n = 10.0; // number of points in one scan
double[] parameters = [0.02,0.4,0.05,0.667,2.5]; // Parameters: integration time, delay, slew from OFF relative to Allan time, ratio of t_off time to sqrt(n)*t_on, drift exponent
}{
{double,double} noisevalues = OtfNoiseValues(n,parameters);
double y = noisevalues{1} / noisevalues{0};
return y;
}
// Slow chop integration at OFF position ON-OFF-OFF-ON...
block HIFISlowChopOffIntegration HIFI 6032 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_slow_chop_proc_aot(data_time,n_cycle,band,lo_freq,["chop_M3left","chop_M3right"],rates);
}
// Procedure used by the spectral scan sequencer to compute the
// maximum frequency group length
int procedure SpotSpectralScanGroupLength {
string band = "4a";
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
int redundancy = 4;
string modeName = "freq" in ["freq","fs-freq","load-freq"]; // reference scheme to use
}{
// start Volkers list
double lo_freq = 978200.0;
// Lower LO frequency limit in MHz
double lo_freq_up = 979600.0;
// Upper LO frequency limit in MHz
// general definitions
double factorMHzPerGHz = 1000.0;
// start translation
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
// translate modeName names ["freq",fs-freq",load-freq"] into
// refmode names ["dbs","fs","lchop"]
if(modeName == "fs-freq") {
string refmode = "fs";
} else {
if(modeName == "load-freq") {
refmode = "lchop";
} else {
refmode = "dbs";
}
}
// Call CUS routine
int grouplen = GetSpectralScanGroupLength(band,lo_freq,lo_freq_up,redundancy,refmode);
return grouplen;
}
// Recalculate and verify LCU memory checksum at end of obsid or OD
block LcuChecksumRecalcCloseObs_aot HIFI 7906 {
string band = "1a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
bool alltables = true; //check all tables+unused (true), or only one band table (false)
}{
if(alltables) {
//Check all tables
string block_IF_NOK = "NO";
LcuChecksumRecalcSegmented_aot(band,"Table_all",block_IF_NOK);
//Check un-used area: now moved to transition to diss-1- HIFI-4049
//block_IF_NOK = "NO";
//LcuChecksumRecalcSegmented_aot(band,"Unused",block_IF_NOK);
//ICU all memory checks - HIFI-3662 - commented out for the moment
OBS_SEU_check_aot("ALL");
} else {
//Check table only
block_IF_NOK = "NO";
LcuChecksumRecalcSegmented_aot(band,"Table",block_IF_NOK);
}
}
// Sort array, bubblesort, maximum will be first element
double[] procedure DSort {
double[] x = [0.0]; // Input array
int nlen = 1; // Array length (keep dan gling numbers untouched)
}{
double tmpstore = 0.0;
// double loop
for(int i = 0 .. nlen - 2) {
for(int j = 1 .. nlen - 1 - i) {
if(x[j] > x[j - 1]) {
tmpstore = x[j];
x[j] = x[j - 1];
x[j - 1] = tmpstore;
}
}
}
return x;
}
/////////////////////////////////////////////////////////////////
// Procedure to compute total dead times for the mode
//
{double,double,double} procedure FastDBSRaster_deadtimes {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // data dump interval
int n_int = 20; // number of integrations in one data dump interval
int n_data = 3; // number of chop cycles in one integration
int n_load = 0; // number of integrations in one pointing phase
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
double tdead = 10.0; // Dead time from telescope
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Special meaning of n_load here
if(n_load == 0) {
int n_seq = 1;
} else {
n_seq = n_load;
}
// Compute parameters for the instrument timing
{double,double} tinst = GetInstDeadFastChop(data_time,n_int,n_data,band,lo_freq,backendreadoutparms);
// dead time
double tdeadint = double(data_time * n_data) - tinst{0};
// subtract dead times in switches
// only half of them are subtracted due to ABAB scheme
tdeadint = tdeadint - double(n_int * n_data) * tinst{1};
// Total dead time per cycle, only one point still not covered
double tdead_tot = tdead + double(2 * n_seq) * tdeadint;
// Integration time
double tphaseint = tinst{0} / double(2 * n_int * n_data);
return {tdead_tot,tphaseint,tinst{1}};
}
{int,double,double,double,double,double} procedure HifiIdealMode {
string modeName = "pos";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// Get parameters which are needed
double center_lo_freq = 0.5 * (lo_freq + lo_freq_up);
double tsys = InterpolateTsys(band,center_lo_freq);
double eta_mb = InterpolateCoupling(band,center_lo_freq);
double[] gssb = InterpolateGssb(band,center_lo_freq);
double phasetime = double(goalTime);
double noiseratio = 0.0;
// Compute total double sideband noise
double dsbnoise_lores = tsys * sqrt(1.0 / (effResolution{1} * 1000000.0 * phasetime));
double dsbnoise_hires = tsys * sqrt(1.0 / (effResolution{0} * 1000000.0 * phasetime));
// Translate to the main beam scale, correct for eta_mb
// (This is typically not done at ground based telescopes,
// but leads often to problems there - to be discussed.)
dsbnoise_lores = dsbnoise_lores / eta_mb;
dsbnoise_hires = dsbnoise_hires / eta_mb;
// Get single sideband noise equivalent
double usbnoise_lores = dsbnoise_lores / gssb[0];
double usbnoise_hires = dsbnoise_hires / gssb[0];
double lsbnoise_lores = dsbnoise_lores / gssb[1];
double lsbnoise_hires = dsbnoise_hires / gssb[1];
// return total time with initial slew
int returntime = goalTime;
// Originally I had added 180s from telescope
// Now make corrections for maps or spectral scans
if(npoints * nlines > 1) {
double factor = sqrt(double(nlines * npoints));
usbnoise_lores = usbnoise_lores * factor;
usbnoise_hires = usbnoise_hires * factor;
lsbnoise_lores = lsbnoise_lores * factor;
lsbnoise_hires = lsbnoise_hires * factor;
}
if(lo_freq_up > lo_freq) {
{int,double,double[],int[][],int,bool} fqparms = MakeFreqGrid(band,lo_freq,lo_freq_up,redundancy,"dbs",0.0,1);
factor = sqrt(double(fqparms{0} / fqparms{4}));
usbnoise_lores = usbnoise_lores * factor;
usbnoise_hires = usbnoise_hires * factor;
lsbnoise_lores = lsbnoise_lores * factor;
lsbnoise_hires = lsbnoise_hires * factor;
}
// Return noise values and the maximum ratio of drift to radiometric noise
return {returntime,usbnoise_lores,usbnoise_hires,lsbnoise_lores,lsbnoise_hires,noiseratio};
}
// Routine to extract the settings for the two HK regimes
string[] procedure QueryHKPattern {
bool active = false; // Whether to actively query the spectrometers
}{
// HK pattern according to SRON-U/HIFI/SP/2001-001 4.3.2 PDU status
if(active) {
int pattern = ifloor(dlookup("datarates","allreadpattern","value"));
} else {
pattern = ifloor(dlookup("datarates","noreadpattern","value"));
}
// translate into new mask of arguments
string[] mask = ["OFF","OFF","OFF","OFF","OFF","OFF"];
for(int i = 0 .. 5) {
if(pattern % 2 > 0) {
mask[i] = "ON";
} else {
mask[i] = "OFF";
}
pattern = pattern / 2;
}
return mask;
}
/////////////////////////////////////////////////////////////////
// Slow chop dual beam switch observing mode - special version for Jupiter
//
// Implemented as procedure returning time and noise levels for HSPOT
{int,double,double,double,double,double} obs HifiPointProcJupiterDBS {
/* Setup parameters */
int naifid = 0; // Tracing object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Engineering - Jupiter - DBS slowChop",{data_time,0,0,n_switch_on,0,0,0,0,n_cycles,load_interval},false);
ChopMessages(false,data_time,n_switch_on);
// Call first part of the timing computer
// Two changes relative to the normal DBS
// 1) The longer load duration is enforced by zero resolution
{double,double} loadResolution = {0.0,effResolution{1}};
// 2) I assume that the tuning duration does not depend on the tuning level
// so that the normal pre_timing can be reused.
{int,int,int,int,int,int,int,int,int,bool,int,int,int} pre_timing = DBS_pre_timing(band,lo_freq,loadResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_switch_on,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,int,double,int,int,int,int,int,int} tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},bool,double,double} post_timing = DBS_post_timing(pre_timing,telescopetimes,n_cycles);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBS_telescope(naifid,onPosition,band,lo_freq,"",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},false);
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_seq = post_timing{1}{8};
int n_loadinterval = post_timing{1}{7};
bool end_load = post_timing{1}{9};
int shiftlength = post_timing{1}{10};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
JupiterDBS_commanding(band,lo_freq,loadResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,n_loadinterval,end_load,final_load,startobs,telescopetimes,loadlength,shiftlength);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the total rms we got out of this
//
// First get additional dead times from instrument
{double,double,double} tact = DBS_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_seq,n_load,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBS_performance(band,lo_freq,effResolution,noisevalues,timeTaken,n_cycles,n_seq * (n_load + 1),tscan,tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// Change LO frequency but keep backend configuration - used in spectral scans
//
// Currently, no adaption to a full HK reading is implemented here
procedure HIFIRetuneFsw {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency ion MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
string level = "sscan_normal"; // Name of target level
}{
ConfigureFPU(band,lo_freq + freq_throw / 2.0,false);
HIFITuneFreqFsw(band,lo_freq,lo_freq + freq_throw,true,level);
}
{string,double,double}[] procedure HifiMappingModeDBSRasterSequencerInit {
string modeName = "raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_switch_on = 2 in [1,900]; // number of half sky1-sky0-sky0-sky1 cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// Get the drift parameters to compute the drift noise
{double,double} phaselengths = DBSPhaseLengths(band,lo_freq,effResolution,continuumDetection,oneGHzReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// Combine points for n_switch=1
int main_phase = iceil(phaselengths{0});
int n_pointsperscan_guess = imin(imax(main_phase / (2 * data_time_guess),1),npoints * nlines);
int n_pointsperscan_range = 1 - n_pointsperscan_guess;
if(n_pointsperscan_range == 0) {
n_pointsperscan_range = 1;
}
// remaining part for n_switch
int n_switch_on_guess = main_phase / (n_pointsperscan_guess * 2 * data_time_guess) + 1;
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// Add pointing requirements condition: >=10s
{int,int} new_data_time = MatchMinPointing(data_time_guess,data_time_range,2 * n_switch_on_guess);
data_time_guess = new_data_time{0};
data_time_range = new_data_time{1};
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_pointsperscan",double(n_pointsperscan_guess),double(n_pointsperscan_range)}];
return retvalues;
}
//Check that drain2 is below blue max and above blue min
double procedure Check_BLUE_LIMIT_D2_proc_fm {
string band = "4a" in ["0","1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978.2; //LO Frequency
double drain2_v = 1.4; //Current drain2 to compare to blue limits
}{
//Check against blue max
//Implementation of SCR-2220
double drain2_max = Get_BLUE_LIMIT_D2_proc_fm(band,lo_freq);
//
double drain2_v_new = drain2_v;
if(drain2_v > drain2_max) {
drain2_v_new = drain2_max;
//this already accounts for the margin
message("Warning: drain2 (" + drain2_v + " V), was commanded above its blue max (" + drain2_max + " V).");
}
//Check against blue min
//Implementation of SCR-2220
double drain2_min = Get_BLUE_MIN_D2_proc_fm(band,lo_freq);
//
if(drain2_v < drain2_min) {
drain2_v_new = drain2_min;
message("Warning: drain2 (" + drain2_v + " V), was commanded below its blue min (" + drain2_min + " V).");
}
return drain2_v_new;
}
////////////////////////////////////////
// Procedure to calculate the post timing
//
{int,{int,int,int,int,int,int,int,int,int,bool,int,int,int},bool,double,double} procedure DBS_post_timing {
{int,int,int,int,int,int,int,int,int,bool,int,int,int} pre_timing = {4,10,4,21,11,1800,0,32,1,false,0,50,0}; // pre_timing parameter list
int[] telescopetimes = [300,180,20,1,21,0];
int n_cycles = 1; // Number of half OFF-ON-ON-OFF pointing cycles
}{
// Get all values from the pre_timing section
int inttime = pre_timing{0};
int pointing = pre_timing{1};
int readouttime = pre_timing{2};
int loadlength = pre_timing{3};
int jitterdead = pre_timing{4};
int load_spacing = pre_timing{5};
int n_load = pre_timing{6};
int n_loadinterval = pre_timing{7};
int n_seq = pre_timing{8};
bool end_load = pre_timing{9};
int shiftlength = pre_timing{10};
int initlength = pre_timing{11};
int dangling = pre_timing{12};
// Get all values from the telescope section
int telinit = telescopetimes[1];
// Initial slew time
int slewtime = telescopetimes[2];
// Slew time to OFF
int longslew = telescopetimes[4];
// Actual slew time for load slew
int pointwaittime = telescopetimes[3];
// Idle time between two phases
int tend = telescopetimes[5];
// Final deceleration time
//////////////////////////////////////////////////////////////////
// Now we start the actual computations
// Add pointwaittime to slew dead time in cycles
slewtime = slewtime + pointwaittime;
longslew = longslew + pointwaittime;
// If load is performed between the cycles use pointwaittime for load
if(end_load) {
int halfloadlength = (loadlength - jitterdead + 1) / 2;
int effhalfloadlength = (loadlength - jitterdead - pointwaittime + 1) / 2;
int subtracted = halfloadlength - effhalfloadlength;
pointing = pointing - subtracted;
shiftlength = effhalfloadlength;
}
// Now we can compute the true scan time
int scan_time = 2 * pointing + slewtime;
// Finally I can compute the load interval
n_loadinterval = imax((load_spacing + slewtime) / scan_time,1);
// Compute duration of measurement and average scan length
// Compute total dead time in one pointing cycle including load overhead
int scan_time_long = 2 * pointing + longslew;
int n_long = n_cycles / n_loadinterval;
int looplength = (n_cycles - n_long) * scan_time + n_long * scan_time_long;
double tscan = double(looplength) / double(n_cycles);
// Get pointing dead time, instrument dead time is added later
double tdead = tscan - double(2 * inttime);
// Determine need for final load measurement
double rest = double(n_cycles % n_loadinterval) + 0.5;
bool final_load = rest > 0.5001 * double(n_loadinterval);
// Compute total duration
initlength = initlength - shiftlength;
// The initial time is no longer contained in the total time
// int totaltime=imax(initlength,telinit);
int totaltime = looplength;
// Add dangling load time, either of the two can apply, but
// they are mutually exclusive, otherwise the readoutdelay applies
if(final_load) {
dangling = loadlength;
}
if(end_load) {
dangling = loadlength - shiftlength;
}
int closelength = duration(HIFICloseObs());
dangling = imax(dangling + closelength - tend,0);
// Compute total duration, remove pointwaittime for last slew
totaltime = totaltime + dangling - pointwaittime + tend;
// show gyro-propagation messages
GCPMessages(pointing,2 * scan_time_long,tend);
// Return all the times needed in the observing mode modules
// The second tuple contains the modified pre_timing parameters,
// the rest the newly computed parameters
return {totaltime,{inttime,pointing,readouttime,loadlength,jitterdead,load_spacing,n_load,n_loadinterval,n_seq,end_load,shiftlength,initlength,dangling},final_load,tscan,tdead};
}
/////////////////////////////////////////////////////////////////
// Spectral scan in load-chop with OFF calibration
//
{string,double,double}[] procedure HifiSScanProcLoadChopSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double raoff = 0.0; // RA coordinate of the OFF position
double decoff = 0.0; // DEC coordinate of the OFF position
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4 in [1,12]; // Frequency scan redundancy
{double,double} effResolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool wbs1Used = true; // whether WBS1 is used
bool wbs2Used = true; // whether WBS2 is used
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half load-sky-sky-load cycles per frequency and pointing
int n_switch_off = 1 in [1,900]; // number of half load-sky-sky-load cycles on OFF
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,imin(data_time,data_time_off));
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// Get frequency grid characteristic parameters
{double,int,double} gfref = GetFReference(band,lo_freq,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,"lchop");
int n_freq_point_guess = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
// Now general part of LoadChop modes
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
// spectral scans always use the full bandwidth for reference
bool narrowReference = false;
{double,double,double,double} phaselengths = LoadChopPhaseLengths(band,reffreq,effResolution,narrowReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// How much time for single ON phase
int n_switch_on_guess = iceil(phaselengths{0}) / (n_freq_point_guess * 2 * data_time_guess) + 1;
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// OFF phase
int data_time_off_guess = imin(imax(iceil(phaselengths{2}),datalimit),20);
int data_time_off_range = datalimit - data_time_off_guess;
if(data_time_off_range == 0) {
data_time_off_range = 1;
}
int n_switch_off_guess = imax(iceil(double(data_time_guess * n_switch_on_guess) / (double(data_time_off_guess) * sqrt(phaselengths{3} / effResolution{1}))),1);
int n_switch_off_range = 1 - n_switch_off_guess;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Additional constraint of compatibility of group size with load period
int loadperiod = LoadPeriod(band,reffreq,effResolution{1});
// 80% margin
int periodlimit = loadperiod * 4 / 5;
// elements of cycle - compute cycle duration
int tunedelay = LOSettlingTime(band,reffreq / 1000.0,false,true);
int load_datatime = imax(data_time_guess,data_time_off_guess);
int loadlength = duration(SScanLoadMeasurement(band,reffreq,reffreq,true,effResolution{0},load_datatime,backendreadoutparms));
int perfreqtime = 2 * (data_time_guess * n_switch_on_guess + data_time_off_guess * n_switch_off_guess + tunedelay);
int cycle = perfreqtime * n_freq_point_guess + loadlength;
if(cycle > periodlimit) {
n_freq_point_guess = imax((periodlimit - loadlength) / perfreqtime,1);
}
int n_freq_point_range = 1 - n_freq_point_guess;
if(n_freq_point_range == 0) {
n_freq_point_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"data_time_off",double(data_time_off_guess),double(data_time_off_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)},{"n_freq_point",double(n_freq_point_guess),double(n_freq_point_range)}];
return retvalues;
}
/////////////////////////////////////////////////////////////////////////
// Auxiliary routine to check the actual duration of telescope lines
//
{int,int} procedure OtfTelescopeLine {
int line_inttime = 10; // actual integration time in OTF line
int line_telescope = 11; // duration of an OTF line from spacecraft
}{
// Initialize
int line_time = line_inttime;
int line_start = 0;
// The telescope slew can be a bit further than requested
if(line_telescope < line_inttime) {
CError("OTF scan length returned by telescope too short for instrument.");
}
if(line_telescope > line_inttime) {
line_time = line_telescope;
line_start = (line_telescope - line_inttime) / 2;
}
return {line_time,line_start};
}
// HRS partial configuration, block
// Configures the resolution mode
block HRS_config_resol_block_aot HIFI 6618 {
string band = "4a"; // HIFI band
string[] hrs_mode = ["wb","wb"]; //HRS resolution code
}{
////////////////////////////////////////////////////////////////////
//Now Configure blocks
//H-polar
string hrs_filename_h = "name_confighrs_" + hrs_mode[0];
{double,string}[] result = ConfigurationReader(hrs_filename_h,["hrh_block_1","hrh_block_2","hrh_block_3","hrh_block_4","hrh_block_5","hrh_block_6","hrh_block_7","hrh_block_8"],band,0.0);
string hrh_block_1 = result[0]{1};
string hrh_block_2 = result[1]{1};
string hrh_block_3 = result[2]{1};
string hrh_block_4 = result[3]{1};
string hrh_block_5 = result[4]{1};
string hrh_block_6 = result[5]{1};
string hrh_block_7 = result[6]{1};
string hrh_block_8 = result[7]{1};
//
result = ConfigurationReader("name_delays",["hrs_config_delay"],band,0.0);
int hrs_config_delay = iround(result[0]{0});
//
Hifi_HIFI_Config_HRS_H_blocks($BBID,hrh_block_1,hrh_block_2,hrh_block_3,hrh_block_4,hrh_block_5,hrh_block_6,hrh_block_7,hrh_block_8);
//delay(hrs_config_delay);
//
//V-polar
string hrs_filename_v = "name_confighrs_" + hrs_mode[1];
result = ConfigurationReader(hrs_filename_v,["hrv_block_1","hrv_block_2","hrv_block_3","hrv_block_4","hrv_block_5","hrv_block_6","hrv_block_7","hrv_block_8"],band,0.0);
string hrv_block_1 = result[0]{1};
string hrv_block_2 = result[1]{1};
string hrv_block_3 = result[2]{1};
string hrv_block_4 = result[3]{1};
string hrv_block_5 = result[4]{1};
string hrv_block_6 = result[5]{1};
string hrv_block_7 = result[6]{1};
string hrv_block_8 = result[7]{1};
//
Hifi_HIFI_Config_HRS_V_blocks($BBID,hrv_block_1,hrv_block_2,hrv_block_3,hrv_block_4,hrv_block_5,hrv_block_6,hrv_block_7,hrv_block_8);
//
//Wait delay to allow all setting to be configured
delay(hrs_config_delay);
}
//////////////////////////////////////////////////////////////////////////
// Procedure to compute detailed timing of peakup mode
{int,int,int,int,int,double,int,int} procedure Peakup_pre_timing {
int nlines_tot = 3 in [1,100]; // Number of rows in the map
int npoints = 3 in [2,100]; // Number of points per row
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{bool,int,double[],bool[]} hrs1 = {false,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {false,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {false,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
}{
//////////////////////////////////////////////////////////////////////
// First check validity of frequencies
CheckLOFrequencies(band,lo_freq,lo_freq);
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Fixed parameters for peak-up
int data_time = 3;
// Data dump period
int n_chop = 1;
// Number of chop cycles
double eff_resolution = 1.6;
// Reference resolution for load measurement
int peakuptime = 3;
// Time neede for peakup integration
// First perform consistency checks
// Check chunk size given by the data rates
CheckDataTaking(backendreadoutparms,data_time);
// Compute parameters for the instrument timing
int jitterdead = GetMaxTimeJitter(band,lo_freq);
int inttime = 2 * n_chop * data_time;
// integer integration time
int pointing = inttime + peakuptime + jitterdead;
// Pointing time
// compute load integration time
int loadlength = duration(LoadMeasurement(band,lo_freq,eff_resolution,data_time,backendreadoutparms));
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
loadlength = loadlength + readoutdead;
// Duration of initial set up
int initlength = duration(HIFIInitObs());
initlength = initlength + duration(TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal"));
initlength = initlength + duration(HifiPeakupConfigure(data_time,n_chop,true,band,lo_freq,0.0,backendreadoutparms));
// Add time for HK readout
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
initlength = initlength + hkduration;
initlength = initlength + loadlength;
// dangling time given by readout dead time
int dangling = readoutdead;
// Return all the times needed for telescope call and post_timing processing
return {inttime,pointing,data_time,loadlength,n_chop,eff_resolution,initlength,dangling};
}
/////////////////////////////////////////////////////////////////////
// Procedure to generate the fine pointing telescope command for the
// observing mode
{int,int,int,string,int,double,double,double,double,int} procedure Fine_telescope {
int naifid = 0; // Tracking object ID
{double,double} onposition = {0.0,0.0}; // Coordinates of the source
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{int,int,int,int,int,int,bool,int,int} timing = {16,16,21,1800,2,0,false,50,0}; // timing parameter list
}{
// Assign values
int on_pointing = timing{1};
// Pointing time
int initlength = timing{7};
// Initial setup time
int dangling = timing{8};
// Final load measurement
// Create variables for telescope command
string ib = GetBoresight(band,lo_freq,false);
// A change of ra-dec depending on naifid may be needed
double ra = onposition{0};
double dec = onposition{1};
// Check parameter compatibility with pointing command for parameters
// which are no direct input parameters
if(on_pointing > 50000) {
IError("Pointing too long. Break up the observation into smaller pieces.");
}
// return parameters in required order
return {initlength,0,dangling,ib,naifid,ra,dec,0.0,0.0,on_pointing};
}
// Single zero measurement
block WBS_Zero_block HIFI 6015 {
}{
// dummy parameters for configuration reader
string band = "4a";
// HIFI band
double lo_freq = 978200.0;
// LO frequency
// Get delays
{double,string}[] result = ConfigurationReader("name_delays",["wbs_zero_delay"],band,lo_freq);
int wbs_zero_delay = iround(result[0]{0});
int data_time = wbs_zero_delay;
// Data rate computation
// The HIFI command is restricted to always read out both full WBS
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} fullreadoutparms = FrequencyCalibrationParms(true,true,false,false);
// data rate and read-out time
{int,double[]} fdataparms = AllDataRates(fullreadoutparms,data_time,false);
int readout = fdataparms{0};
// set data rates
non_ess_hk_data_rate(fdataparms{1}[2] / 1024.0);
data_rate(fdataparms{1}[0] / 1024.0);
// Call commands
Hifi_HIFI_WBS_Zero($BBID);
delay(wbs_zero_delay);
// reset data rates
non_ess_hk_data_rate(fdataparms{1}[1] / 1024.0);
data_rate(0.0);
// additional delay for packet transmission
// Not needed if followed by commands without science packets
// delay(readout);
}
int block HIFI_DoubleCalibrate_hot_cold HIFI 6006 {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
int data_time = 4; // time between subsequent data readouts
int n_data = 2; // Integration time counter
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
bool staycal = false; // whether we should stay at the hot load at the end
}{
// data rate and read-out time
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int readout = dataparms{0};
// send the configure spectroscopy command to configure the measurement
// returned dead times not needed here
ConfigureSpectroscopy(data_time,n_data,"hot-cold",band,lo_freq,backendreadoutparms);
// Switch to first FSW register
Hifi_HIFI_HL_set_FSW1($BBID);
// Spectroscopy should start at first bus slot
delay(1);
// Perform first slow-chop
HIFI_Spectr_slow_chop_proc_aot(data_time,n_data / 2,band,lo_freq,["chop_hot","chop_cold"],dataparms{1});
// Switch to second FSW register
Hifi_HIFI_HL_set_FSW2($BBID);
// delay required at the end
int sdelay = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
// Clean up for next spectroscopy
delay(sdelay);
// integrate
HIFI_Spectr_slow_chop_proc_aot(data_time,n_data / 2,band,lo_freq,["chop_hot","chop_cold"],dataparms{1});
if(!staycal) {
// Switch to back FSW register
Hifi_HIFI_HL_set_FSW1($BBID);
// Move chopper back to the sky
RotateChopper(band,lo_freq,"chop_M3");
}
// have clean bus timing for next spectroscopy block
delay(sdelay);
return readout;
}
// Routines for calibration data handling
/////////////////////////////////////////////////////////////////
// Routines using the generic reader
// A possible frequency dependence is hidden behind the reader
/////////////////////////////////////////////////////////////////
// Interpolate gain in corresponding sideband for the selected frequency
double[] procedure InterpolateGssb {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] gssb = CalibrationReader("gain",["Gusb","Glsb"],band,lo_freq);
return gssb;
}
//////////////////////////////////////////////////////////////////////////
// Procedure to generate the telescope command for the Peakup mode
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,int,double,double} procedure Peakup_telescope {
int naifid = 0; // Tracing object ID
{double,double} mapcenter = {0.0,0.0}; // Coordinates of the center of the map
double stepsize = 0.0050; // Distance between subsequent points in the raster line
int nlines = 1; // Number of rows in the map;
int npoints = 10; // Number of points per row
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{int,int,int,int,int,double,int,int} timing = {8,10,2,21,4,1.6,50,0}; // timing parameter list
}{
// Assign values
int pointing = timing{1};
int initlength = timing{6};
int dangling = timing{7};
// Create variables for telescope command
string ib = GetBoresight(band,lo_freq,false);
// A change of ra-dec depending on naifid may be needed
double ra = mapcenter{0};
double dec = mapcenter{1};
// Map always in spacecraft coordinates, always start in +Z direction
bool fixed = false;
double patt = 0.0;
// Map parameters
double rowstep = 0.5 / 3600.0;
double d1 = double(iceil(stepsize / rowstep)) * rowstep * 3600.0;
// Exception for the "impossible" case of spacings below 2arcsec
d1 = max(d1,2.0);
// Always isotropic for peakup
double d2 = d1;
// Check parameter compatibility with pointing command for parameters
// which are no direct input parameters
if(pointing < 10) {
SError("Pointing phase length too short. Increase the number of integrations.");
}
if(d1 > 480.0) {
IError("Raster spacing too coarse. Increase the sampling.");
}
// parameters for OFF position - not used
int koff = 0;
int toff = 0;
double raoff = 0.0;
double decoff = 0.0;
// return parameters in required order
return {initlength,0,dangling,ib,naifid,ra,dec,fixed,patt,0.0,0.0,npoints,nlines,d1,d2,pointing,koff,toff,raoff,decoff};
}
// Configuration for continuous integration
block HIFIConfigureContIntegration HIFI 6020 {
int data_time = 4; // Integration time between two data readouts
int n_int = 1; // Integration time counter
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used, channel windows}
}{
// Call procedure doing the work
ConfigureSpectroscopy(data_time,n_int,"tp",band,lo_freq,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// Procedure to perform the noise level evaluation for the observing mode
{double,double,double,double,double} procedure FSwitchNoRef_noisecomputer {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
int n_cycles = 1; // Number of map coverages
double tscan = 60.0; // Total average duration of one scan
double tdead = 10.0; // Average dead time in one slew
}{
// Call position switch noise computer
{double,double,double,double,double} noisevalues = PositionSwitch_noisecomputer(band,lo_freq,eff_resolution,oneGHzReference,n_cycles,tscan,tdead);
// Correct for signal in both phases
double multiplier = sqrt(0.5);
noisevalues{0} = noisevalues{0} * multiplier;
noisevalues{1} = noisevalues{1} * multiplier;
noisevalues{2} = noisevalues{2} * multiplier;
noisevalues{3} = noisevalues{3} * multiplier;
// Return noise values and the maximum ratio of drift to radiometric noise
return {noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
{string,double,double}[] procedure HifiMappingModeFSwitchOTFSequencerInit {
string modeName = "fs-raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_switch_off = 3 in [1,3600]; // Number of data dumps for the OFF integration time
int n_linesperscan = 1 in [1,32]; // Number of lines between two OFFs
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// limit on data rate
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
{double,double,double,double} phaselengths = FSwitchPhaseLengths(band,lo_freq,effResolution,oneGHzReference);
// Compute derived quantities
// Main loop
int main_phase = iceil(phaselengths{0});
// How many lines could we do at most?
int n_linesperscan_guess = main_phase / (2 * datalimit) + 1;
n_linesperscan_guess = imax(n_linesperscan_guess * n_linesperscan_guess / npoints,1);
// restrict the scan size
if(nlines == 1 && n_linesperscan_guess > 1) {
n_linesperscan_guess = 2;
} else {
n_linesperscan_guess = IMultiple(n_linesperscan_guess,nlines);
n_linesperscan_guess = imin(n_linesperscan_guess,nlines);
}
int n_linesperscan_range = 1 - n_linesperscan_guess;
if(n_linesperscan_range == 0) {
n_linesperscan_range = 1;
}
double n_pointsperscan = double(n_linesperscan * npoints);
// Compute back
int int_time_guess = main_phase / iceil(sqrt(n_pointsperscan));
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int n_switch_on_guess = imax(int_time_guess / (2 * data_time_guess),1);
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
data_time_guess = imax(imin(5,int_time_guess / (2 * n_switch_on_guess)),datalimit);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// OFF phase
int data_time_off_guess = imin(imax(iceil(phaselengths{2}),datalimit),20);
int data_time_off_range = datalimit - data_time_off_guess;
if(data_time_off_range == 0) {
data_time_off_range = 1;
}
int n_switch_off_guess = imax(iceil(double(data_time_guess * n_switch_on_guess) * 0.67 * sqrt(n_pointsperscan) / (double(data_time_off_guess) * sqrt(phaselengths{3} / effResolution{1}))),1);
int n_switch_off_range = 1 - n_switch_off_guess;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"data_time_off",double(data_time_off_guess),double(data_time_off_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)},{"n_linesperscan",double(n_linesperscan_guess),double(n_linesperscan_range)}];
return retvalues;
}
/////////////////////////////////////////////////////////////////
// Spectral scan in frequency switch with OFF calibration
//
{string,double,double}[] procedure HifiSScanProcFSwitchSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
double raoff = 0.0; // RA coordinate of the OFF position
double decoff = 0.0; // DEC coordinate of the OFF position
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4 in [1,12]; // Frequency scan redundancy
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} effResolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool wbs1Used = true; // whether WBS1 is used
bool wbs2Used = true; // whether WBS2 is used
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int data_time_off = 4 in [1,20]; // data dump interval on OFF
int n_switch_on = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_switch_off = 1 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles on OFF
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int n_cycles = 1 in [1,600]; // Number of half OFF-ON-ON-OFF cycles at one frequency
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,imin(data_time,data_time_off));
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// Get frequency grid characteristic parameters
{double,int,double} gfref = GetFReference(band,lo_freq,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,"fs");
int n_freq_point_guess = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
// Now general part of Frequency switch modes
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
// spectral scans always use the full bandwidth for reference
bool narrowReference = false;
{double,double,double,double} phaselengths = FSwitchPhaseLengths(band,reffreq,effResolution,narrowReference);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(phaselengths{1}),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// How much time for single ON phase
int n_switch_on_guess = iceil(phaselengths{0}) / (n_freq_point_guess * 2 * data_time_guess) + 1;
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// OFF phase
int data_time_off_guess = imin(imax(iceil(phaselengths{2}),datalimit),20);
int data_time_off_range = datalimit - data_time_off_guess;
if(data_time_off_range == 0) {
data_time_off_range = 1;
}
int n_switch_off_guess = imax(iceil(double(data_time_guess * n_switch_on_guess) / (double(data_time_off_guess) * sqrt(phaselengths{3} / effResolution{1}))),1);
int n_switch_off_range = 1 - n_switch_off_guess;
if(n_switch_off_range == 0) {
n_switch_off_range = 1;
}
// Additional constraint of compatibility of group size with load period
int loadperiod = LoadPeriod(band,reffreq,effResolution{1});
// 80% margin
int periodlimit = loadperiod * 4 / 5;
// elements of cycle - compute cycle duration
int tunedelay = LOSettlingTime(band,reffreq / 1000.0,false,true);
tunedelay = 2 * tunedelay;
int load_datatime = imax(data_time_guess,data_time_off_guess);
int loadlength = duration(SScanDoubleLoadMeasurement(band,reffreq,reffreq,freq_throw,true,effResolution{0},load_datatime,backendreadoutparms));
int perfreqtime = 2 * (data_time_guess * n_switch_on_guess + data_time_off_guess * n_switch_off_guess + tunedelay);
int cycle = perfreqtime * n_freq_point_guess + loadlength;
if(cycle > periodlimit) {
n_freq_point_guess = imax((periodlimit - loadlength) / perfreqtime,1);
}
int n_freq_point_range = 1 - n_freq_point_guess;
if(n_freq_point_range == 0) {
n_freq_point_range = 1;
}
// Construct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"data_time_off",double(data_time_off_guess),double(data_time_off_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)},{"n_switch_off",double(n_switch_off_guess),double(n_switch_off_range)},{"n_freq_point",double(n_freq_point_guess),double(n_freq_point_range)}];
return retvalues;
}
{int,double,double,double,double,double} obs HifiMappingModeFastDBSCross {
string modeName = "cross";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
OpenMessages("HIFI Mapping - DBS Cross Map fastChop",{data_time,0,n_switch_on,n_int_on,0,0,n_pointsperscan,0,n_cycles,load_interval},true);
ChopMessages(true,data_time,n_int_on);
RasterSizeMessages({0.0,0.0},stepsize,2,npoints,true);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = FastDBSRaster_pre_timing(2,npoints,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
{int,int,int,string,int,double,double,bool,double,double,double,double[],double[],int[],double,double,int,int,int,int,int,int} tpar = DBSCross_telescope(naifid,onPosition,stepsize,npoints,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = custom_map_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21});
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} post_timing = DBSCross_post_timing(pre_timing,telescopetimes,npoints,n_switch_on,n_cycles,load_interval,true);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
tpar = DBSCross_telescope(naifid,onPosition,stepsize,npoints,band,lo_freq,"",post_timing{1},n_cycles);
telescopetimes = custom_map_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21});
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
int scansize = post_timing{1}{10};
int initlength = post_timing{1}{11};
int dangling = post_timing{1}{12};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
FastDBSRaster_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_cycles,scansize,n_loadinterval,n_load,final_load,startobs,telescopetimes,loadlength,true);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = FastDBSRaster_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_load,scansize,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBSRaster_performance(band,lo_freq,effResolution,noisevalues,timeTaken,2,npoints,n_cycles,n_seq * n_int_on * imax(n_load,1),tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Correct for double counting of central point
// The central point is returned only
double multiplier = sqrt(0.5);
noisevalues{0} = noisevalues{0} * multiplier;
noisevalues{1} = noisevalues{1} * multiplier;
noisevalues{2} = noisevalues{2} * multiplier;
noisevalues{3} = noisevalues{3} * multiplier;
noisevalues{4} = noisevalues{4} / multiplier;
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
//////////////////////////////////////////////////////////////////////
// Procedure to display performance parameters of the observing mode
procedure PositionSwitch_performance {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{double,double,double,double,double} noisevalues = {1.0,1.0,1.0,1.0,0.0}; // Noise values from noisecomputer
int totaltime = 200; // Total observing time
int n_cycles = 1; // Number of map coverages
double tscan = 60.0; // Total average duration of one scan
double tdead = 10.0; // Average dead time in one slew
}{
double inttime = (tscan - tdead) / 2.0;
// Integration time per pointing phase
// Get performance of ideal instrument for comparison
{int,double,double,double,double,double} idealvalues = IdealInstrument(band,lo_freq,eff_resolution,totaltime);
double idealnoise = idealvalues{1} * idealvalues{1};
double obsnoise = noisevalues{0} * noisevalues{0};
double efficiency = idealnoise / obsnoise;
// Compute integration time
double posinttime = inttime * double(n_cycles);
double timeefficiency = 2.0 * posinttime / double(totaltime);
// Drift noise contribution
double relnoise = noisevalues{4} / (1.0 + noisevalues{4});
// General messages
PerformanceMessages(band,lo_freq,eff_resolution,noisevalues,totaltime,posinttime,posinttime,timeefficiency,efficiency,relnoise,false);
}
/////////////////////////////////////////////////////////////////
// Spectral scan in load-chop without OFF calibration
//
{string,double,double}[] procedure HifiSScanProcLoadChopNoRefSequencerInit {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4 in [1,12]; // Frequency scan redundancy
{double,double} effResolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool wbs1Used = true; // whether WBS1 is used
bool wbs2Used = true; // whether WBS2 is used
/* Sequence parameters */
int data_time = 4 in [1,20]; // data dump interval limited by the data rate/stability
int n_cycles = 2 in [1,900]; // number of half nu1-nu2-nu2-nu1 cycles per frequency and pointing
int n_freq_point = 1 in [1,12]; // Number of frequency steps before pointing to second phase
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
// First get the backend configuration
{{bool,int,double[],bool[]},{bool,int,double[],bool[]},{bool,int[][]},{bool,int[][]}} backends = SScanBackendSettings(band,redundancy,wbs1Used,wbs2Used,data_time);
{bool,int,double[],bool[]} hr1 = backends{0};
{bool,int,double[],bool[]} hr2 = backends{1};
{bool,int[][]} wb1 = backends{2};
{bool,int[][]} wb2 = backends{3};
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hr1{0},hr1{1},hr1{3}},{hr2{0},hr2{1},hr2{3}},wb1,wb2};
// Get frequency grid characteristic parameters
{double,int,double} gfref = GetFReference(band,lo_freq,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,"lchop");
int n_freq_point_guess = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
// inherit from fs-noref mode
// spectral scans always use the full bandwidth for reference
bool narrowReference = false;
{string,double,double}[] retvalues = HifiPointProcLoadChopNoRefSequencerInit(naifid,ra,dec,band,reffreq,effResolution,narrowReference,hr1,hr2,wb1,wb2,data_time,n_cycles,load_interval,docommands);
// Additional constraint of compatibility of group size with load period
int loadperiod = LoadPeriod(band,reffreq,effResolution{1});
// 80% margin
int periodlimit = loadperiod * 4 / 5;
// elements of cycle - compute cycle duration
int tunedelay = LOSettlingTime(band,reffreq / 1000.0,false,true);
int load_datatime = iceil(retvalues[0]{1});
int loadlength = duration(SScanLoadMeasurement(band,reffreq,reffreq,true,effResolution{0},load_datatime,backendreadoutparms));
int perfreqtime = 2 * load_datatime + tunedelay;
int cycle = perfreqtime * n_freq_point_guess + loadlength;
if(cycle > periodlimit) {
n_freq_point_guess = imax((periodlimit - loadlength) / perfreqtime,1);
}
int n_freq_point_range = 1 - n_freq_point_guess;
if(n_freq_point_range == 0) {
n_freq_point_range = 1;
}
retvalues[1] = {"n_freq_point",double(n_freq_point_guess),double(n_freq_point_range)};
return retvalues;
}
// Routine to compute the periodic HK parameters
{string,int,double,double,double,double} procedure PeriodicHKParms {
string speed = "normal" in ["fast","normal","slow"]; // Select HK rate
}{
// HK rate value accoring to IFSI/OBS/MA/2005-001
int ratevalue = ifloor(dlookup("datarates",speed + "_hkrate_value","value"));
// Assign
// No exception handling here - CUS internals only
string[] allowedvalues = ["1_pkt_per_5_s","1_pkt_per_10_s","1_pkt_per_s","1_pkt_per_3_s","1_pkt_per_4_s"];
int[] allowedperiods = [5,10,1,3,4];
string hk_string = allowedvalues[ratevalue];
int hk_period = allowedperiods[ratevalue];
// Get all relevant parameters
int pmax = ifloor(dlookup("datarates","maxbuspackets","value"));
int per_hkpackets = iceil(dlookup("datarates","periodic_hkpackets","value"));
int per_hksize = iceil(dlookup("datarates","periodic_hksize","value"));
int ess_hkpackets = iceil(dlookup("datarates","ess_hkpackets","value"));
int ess_hksize = iceil(dlookup("datarates","ess_hksize","value"));
int osize = ifloor(dlookup("datarates","packetoverhead","value"));
// Compute rates
double per_packetrate = double(per_hkpackets) / double(hk_period);
double per_datarate = double(per_hkpackets * (per_hksize + osize)) / double(hk_period);
double ess_packetrate = double(ess_hkpackets) / double(hk_period);
double ess_datarate = double(ess_hkpackets * (ess_hksize + osize)) / double(hk_period);
// return everything
return {hk_string,hk_period,per_packetrate,per_datarate,ess_packetrate,ess_datarate};
}
procedure SError {
string errormessage = "Bad sequence parameters."; // Error message
}{
string fullmessage = "Invalid sequence parameter combination:
" + errormessage + "
Rerun the sequencer to obtain a valid observing request.";
error(fullmessage);
}
// Get maximum delay needed for backend readout after SlowChopSpectroscopy
int procedure SlowChopReadoutDelay {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used, channel windows}
}{
// Currently the delay applies independent from the spectrometer selection
// if (backendreadoutparms{2}{0} || backendreadoutparms{3}{0}) {
double[] dead = CalibrationReader("slowchopreadout",["slowchopreadout"],band,lo_freq);
// }
return iceil(dead[0]);
}
/////////////////////////////////////////////////////////////////
// Procedure to compute the detailed frequency grid for a
// spectral scan
{int,double,double[],int[][],int,bool} procedure MakeFreqGrid {
string band = "4a"; // HIFI band
double lo_freq_low = 978200.0; // Lower LO frequency limit in MHz
double lo_freq_up = 979600.0; // Upper LO frequency limit in MHz
int redundancy = 4; // Frequency scan redundancy
string refmode = "dbs" in ["dbs","fs","lchop"]; // reference scheme to use
double freq_throw = 0.0; // Frequency throw in case of FSW observations
int grouplen = 1; // Number of frequency steps before pointing to second phase
}{
// First check validity of frequencies
CheckLOFrequencies(band,lo_freq_low,lo_freq_up);
// Rigid check - not needed as scan will be reduced below
// CheckLOFrequencies(band,lo_freq_low+min(freq_throw,0.0),
// lo_freq_up+max(freq_throw,0.0));
// Get frequency grid characteristic parameters
// Perform the check for the redundancy
{double,int,double} gfref = GetFReference(band,lo_freq_low,lo_freq_up);
double reffreq = gfref{0};
int stdredun = gfref{1};
double stdstep = gfref{2};
int increment = stdredun / redundancy;
// Check that redundancy is allowed
if(redundancy * increment != stdredun) {
IError("The selected redundancy is no factor of " + stdredun + "!");
}
// Perform check for allowed group size
double nocaliblen = GetFNoCalibLength(band,reffreq,refmode);
int maxgrouplen = ifloor(nocaliblen / (stdstep * double(increment)) + 1.0);
if(grouplen > maxgrouplen) {
SError("The group size exceeds the frequency range possible without recalibration.");
}
// We set up the frequency grid in four steps
// Separate edges and main part of spectral scan
{int,double,double} edgeampl = GetEdgeEnhance(redundancy,band);
int highredun = edgeampl{0};
int inchigh = stdredun / highredun;
// Check that redundancy is allowed
if(highredun * inchigh != stdredun) {
IError("The required redundancy at the band edges cannot be satisfied!");
}
double nu1 = lo_freq_low;
double nu2 = lo_freq_low + edgeampl{1};
double nu3 = lo_freq_up - edgeampl{1};
double nu4 = lo_freq_up;
// Check for very small scans
if(nu2 > nu4) {
nu2 = nu4;
}
if(nu3 < nu1) {
nu3 = nu1;
}
// Get frequency grid indices
{int,int} ffindex = GetFScanBoundaries(band,freq_throw);
{int,int} gfindex_lo = GetFIndex(band,nu1,nu2);
{int,int} gfindex_up = GetFIndex(band,nu3,nu4);
int index1 = gfindex_lo{0};
int index2 = gfindex_lo{1};
int index3 = gfindex_up{0};
int index4 = gfindex_up{1};
// Make frequency grid self-consistent and monotoneous
// Shift if needed by frequency switch
if(index1 < ffindex{0}) {
index2 = index2 + ffindex{0} - index1;
index1 = ffindex{0};
}
if(index4 > ffindex{1}) {
index3 = index3 + ffindex{1} - index4;
index4 = ffindex{1};
}
// Check again for very small scans
if(index2 > index4) {
index2 = index4;
}
if(index3 < index1) {
index3 = index1;
}
//
// lower frequency end with high redundancy
int nstep1 = (index2 - index1 + inchigh - 1) / inchigh;
index2 = index1 + nstep1 * inchigh;
// Check again that we do not exceed the band boundary in this step
if(index2 > ffindex{1}) {
// No check here, we cannot exceed both boundaries
index1 = index1 - index2 + ffindex{1};
index2 = ffindex{1};
}
// upper end with high redundancy
// Exception handling for small scans
int nstep3 = imax((index4 - imax(index3,index2) + inchigh - 1) / inchigh - 1,0);
index3 = index4 - nstep3 * inchigh;
// main part inbetween, edges already covered
int nstep2 = imax((index3 - index2 + increment - 1) / increment - 1,0);
int index5 = index2 + nstep2 * increment;
// Number of points
int nfreq = nstep1 + nstep2 + nstep3 + 1;
// Now we can construct the frequency grid from the index markers
double[] freqgrid = GetFScanPoints(band,index1,index2,inchigh);
// Consistency check
if(nstep1 + 1 != length(freqgrid)) {
CError("Frequency grid error. First frequency steps inconsistent.");
}
double[] addpoints = GetFScanPoints(band,index2,index5,increment);
// Consistency check
if(nstep2 + 1 != length(addpoints)) {
CError("Frequency grid error. Main frequency steps inconsistent.");
}
for(int ia2 = 1 .. nstep2) {
freqgrid[nstep1 + ia2] = addpoints[ia2];
}
addpoints = GetFScanPoints(band,index3,index4,inchigh);
// Consistency check
if(nstep3 + 1 != length(addpoints)) {
CError("Frequency grid error. Last frequency steps inconsistent.");
}
if(nstep3 > 0) {
for(int ia3 = 1 .. nstep3) {
freqgrid[nstep1 + nstep2 + ia3] = addpoints[ia3];
}
}
// Initial definition of the frequency grid finished
// adjust reference frequency to be within the grid
gfref = GetFReference(band,freqgrid[0],freqgrid[nfreq - 1]);
reffreq = gfref{0};
// Check vs. system temperature and attenuators - modify if required
double tsys = InterpolateTsys(band,reffreq);
double[] tsysarray = GetAllTsys(band,freqgrid);
// Search for frequencies with too high tsys
double tsyslimit = GetTsysVariationLimit(band,reffreq);
tsyslimit = tsys * tsyslimit;
bool[] hightsys = [];
int nadd = 0;
for(int in1 = 0 .. nfreq - 1) {
hightsys[in1] = tsysarray[in1] > tsyslimit;
if(hightsys[in1]) {
nadd = nadd + 1;
}
}
// Add some integrations to make the total number of points an
// integer multiple of the group size
int groupnumber = (nfreq + nadd + grouplen - 1) / grouplen;
int nrest = groupnumber * grouplen - nfreq - nadd;
// add integrations at points of highest system temperature not yet covered
for(int ng = 1 .. nrest) {
int curmax = -1;
double tsysmax = 0.0;
for(int in2 = 0 .. nfreq - 1) {
// dont duplicate points which are already duplicated
if(!hightsys[in2]) {
// search for maximum
if(tsysarray[in2] > tsysmax) {
curmax = in2;
tsysmax = tsysarray[in2];
}
}
}
if(curmax >= 0) {
// Add point
hightsys[curmax] = true;
} else {
// Giving up
string obscure = "Perfect observation! You managed to set up the " + "observation that will explain life, the universe, and everything. " + "However, as this would drastically lower future research funding, " + "the observation is rejected. ";
// Throw message
IError(obscure + "Please, increase frequency interval or reduce redundancy!");
}
}
// Actually expand frequency grid
int newindex = 0;
double[] newgrid = [];
for(int in3 = 0 .. nfreq - 1) {
newgrid[newindex] = freqgrid[in3];
newindex = newindex + 1;
if(hightsys[in3]) {
newgrid[newindex] = freqgrid[in3];
newindex = newindex + 1;
}
}
// Consistency check
nfreq = nfreq + nadd + nrest;
if(nfreq != length(newgrid)) {
CError("Frequency grid error. Expanded frequency grid inconsistent.");
}
// Information about frequency grid
message("Actually covered frequency range: " + newgrid[0] / 1000.0 + " - " + newgrid[nfreq - 1] / 1000.0 + "GHz.
");
// Summary message
message("Total number of LO settings: " + nfreq + "
");
message("Frequency used for noise computation: " + reffreq / 1000.0 + "GHz.
");
// Create index for frequency stepping within a group
int[][] grouporder = GetFrequencyGroupSteps(grouplen);
// Check for very small scans
if(lo_freq_up - lo_freq_low >= edgeampl{1} + edgeampl{2}) {
bool dsb = true;
int nfreq_if = redundancy;
} else {
if(lo_freq_up - lo_freq_low >= edgeampl{2}) {
dsb = false;
nfreq_if = highredun;
} else {
dsb = false;
nfreq_if = nfreq;
}
}
// Return all frequency parameters
return {groupnumber,reffreq,newgrid,grouporder,nfreq_if,dsb};
}
//Set LOU to nominal, procedure
//Set LOU in nominal mode with no channel selected
procedure Set_LO_Nominal_proc_aot {
}{
{double,string}[] result = ConfigurationReader("name_delays",["set_to_nominal_delay"],"0",0.0);
int set_to_nominal_delay = iround(result[0]{0});
//
Hifi_HIFI_HL_Normal($BBID);
delay(set_to_nominal_delay);
//
}
// Compute minimum nod time in a nod used for loads
// Used only in case of scansize > 1
int procedure GetMinLoadNod {
int[] telescopetimes = [300,180,20,0,21,0,4,10,10,10];
int scansize = 2; // Number of points measured in one scan
int n_cycles = 1; // Number of half OFF-ON-ON-OFF pointing cycles
int n_loadinterval = 1; // Number of nods to include loads
}{
// Use telescope return parameters
int numpoints = telescopetimes[6];
// Scan return field
int n_scans = numpoints / (2 * scansize);
int n_loadnods = n_scans / n_loadinterval;
int longslew = 180;
// guarantee that all nods are shorter
int theindex = 0;
for(int i = 0 .. n_cycles - 1) {
for(int i1 = 0 .. n_loadnods - 1) {
theindex = theindex + n_loadinterval * 2 * scansize;
if(theindex < numpoints) {
longslew = imin(longslew,telescopetimes[theindex + 6]);
}
}
}
return longslew;
}
// Get the standard chop angle difference from calibration file
double[] procedure GetSkyChopThrow {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
string throw = ""; // Identifier for chop throw, empty is standard
}{
string lstring = throw + "length";
string astring = throw + "angle";
// We chop now from plusZ tu minusZ, i.e. in negative direction
// The nodding has to go into the opposite direction
double[] nodpatt = CalibrationReader("skychopthrow",[lstring,astring],band,lo_freq);
// restrict to allowed range
double patt = (nodpatt[1] + 360.0) % 360.0;
return [nodpatt[0],patt];
}
//////////////////////////////////////////////////////////////////////////
// Procedure to generate the telescope command inherited from DBS mode
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure FastDBS_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 10 in [4,80]; // data dump interval
int n_int = 20; // number chop cycles to integrate in ICU before transfer
int n_seq = 1; // Number of continuous data transfer cycles
int n_load = 0; // additional load measurements in one pointing phase
int n_loadinterval = 10; // number of nods before a load measurement
bool end_load = false; // Need for load after each pointing phase
bool final_load = false; // Need for final load measurement
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,20,1,21,0]; // Timing of the observation from telescope
int loadlength = 21; // Load duration
int shiftlength = 10; // Shift of the loop start relative to the pointing
}{
// Auxiliary variables
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Fixed timings in the fast-chop mode
int load_datatime = GetStdLoadReadout(band,lo_freq);
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
int tnodslew = telescopetimes[2];
// slew dead time between points
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time / 2);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,true);
int readoutdead = FastChopReadoutDelay(band,lo_freq,backendreadoutparms);
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
int[] choppars = [2 * n_int,0];
bool runintostate = false;
while(state[0] >= 0) {
if(runintostate) {
state = next_state_no_check();
} else {
state = next_state();
}
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength + shiftlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
if(shiftlength > 0) {
runintostate = true;
} else {
runintostate = false;
}
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// First nodding position
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i1 = 1 .. n_load) {
HIFIFastChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFIFastChopOnIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Second phase in first nod position
// occurs for even cycle numbers
runintostate = false;
if(state[2] % 2 == 0) {
if(end_load) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// A nod slew follows - active HK if not used by load measurement
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 7) {
// second nod position
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i2 = 1 .. n_load) {
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
choppars = HIFIConfigureFastChopIntegration(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFIFastChopOffIntegration(data_time,n_seq,band,lo_freq,choppars,rates);
// First phase in second nod position
// occurs for odd cycle numbers
runintostate = false;
if(state[2] % 2 == 1) {
if(end_load) {
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = true;
}
} else {
// A nod slew follows - active HK if not used by load measurement
if(state[2] % n_loadinterval > 0) {
HIFIActiveHK("normal",tnodslew);
}
}
}
if(state[0] == 9) {
// Load nod
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
runintostate = false;
}
if(state[0] == 5) {
delay(readoutdead);
if(final_load) {
// Perform final load measurement
// ( Does not occur if end_load is set)
LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms);
}
runintostate = false;
HIFICloseObs();
}
}
}
////////////////////////////////////////
// Procedure to calculate the pre timing
//
{int,int,int,int,int,int,int,int,int,bool,int,int,int} procedure FastDBS_pre_timing {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 10 in [4,80]; // data dump interval
int n_int = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_data = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_cycles = 1 in [1,1200]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// First check validity of frequencies
CheckLOFrequencies(band,lo_freq,lo_freq);
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Fixed timings in the fast-chop mode
int load_datatime = GetStdLoadReadout(band,lo_freq);
// It should be investigated wehther we can use fast-chop on loads as well
// Perform consistency checks
int single_data = data_time / 2;
// Check chunk size given by the data rates
CheckDataTaking(backendreadoutparms,single_data);
// Check chopper frequency
CheckFastChopFrequency(band,lo_freq,data_time,n_int,n_data);
// Telescope-instrument communication jitter
int jitterdead = GetMaxTimeJitter(band,lo_freq);
// Compute parameters for the instrument timing
int readouttime = data_time;
int inttime = data_time * n_data;
// compute load integration time
int loadlength = duration(LoadMeasurement(band,lo_freq,eff_resolution{0},load_datatime,backendreadoutparms));
int readoutdead = FastChopReadoutDelay(band,lo_freq,backendreadoutparms);
loadlength = loadlength + readoutdead;
// For double phases I can use the added jitterdead in both phases for load
int halfloadlength = (loadlength - jitterdead + 1) / 2;
// Compare load interval and nodding interval
// This determines the order of the loops
int load_spacing = CheckedLoadSpacing(load_interval - loadlength,8);
if(load_spacing < data_time) {
SError("Load period shorter than backend readout period.");
}
int n_load = inttime / load_spacing;
if(load_spacing > 2 * inttime) {
int n_seq = n_data;
bool end_load = false;
int pointing = inttime + jitterdead;
int shiftlength = 0;
} else {
n_seq = n_data / (n_load + 1);
if(n_seq < 1) {
SError("Transfer cycle too long relative to load period.");
}
end_load = true;
inttime = n_seq * (n_load + 1) * data_time;
pointing = inttime + halfloadlength + n_load * loadlength + jitterdead;
shiftlength = halfloadlength;
}
// Duration of initial set up
// determine exact duration only in case of full commanding
if(docommands) {
int initlength = duration(HIFIInitObs());
initlength = initlength + duration(TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal"));
// Add time for HK readout
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,true);
initlength = initlength + hkduration;
} else {
initlength = GetRoughInitLength(band,lo_freq,false);
}
initlength = initlength + loadlength;
// Compute the overall cycle length
// First estimate of the load interval
int n_loadinterval = imax(load_interval / (2 * pointing),1);
// dangling time given by readout dead time
int dangling = readoutdead;
// Return all the times needed for telescope call and post_timing processing
return {inttime,pointing,readouttime,loadlength,jitterdead,load_spacing,n_load,n_loadinterval,n_seq,end_load,shiftlength,initlength,dangling};
}
//////////////////////////////////////////////////////////////////////////
// Procedure to generate the telescope command is inherited from load chop
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure FSwitchNoRef_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double freq_throw = -40.0; // throw of frequency switch in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // data dump interval limited by the data rates
int n_per_on = 1; // number of half load-sky-sky-load cycles on ON
int n_load_on = 0; // additional load measurements in ON pointing phase
bool end_load_on = false; // Need for load after ON pointing phase
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,0]; // Timing of observation from telescope
int loadlength = 50; // Load duration
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFIFsw(band,lo_freq,freq_throw,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// ON integration
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i1 = 1 .. n_load_on) {
HIFIFSwitchOnIntegration(data_time,n_per_on,band,lo_freq,rates);
// Perform load calibration
delay(readoutdead);
DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms);
HIFIConfigureFSwitchIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFIFSwitchOnIntegration(data_time,n_per_on,band,lo_freq,rates);
}
if(state[0] == 5) {
delay(readoutdead);
if(end_load_on) {
// Perform final load measurement
DoubleLoadMeasurement(band,lo_freq,freq_throw,eff_resolution{0},data_time,backendreadoutparms);
}
HIFICloseObs();
}
}
}
// get HRS efficiency
double procedure GetHrsEfficiency {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] resol = CalibrationReader("backendresolution",["hrs_efficiency"],band,lo_freq);
return resol[0];
}
/////////////////////////////////////////////////////////////////
// Auxiliary routine to determine the two loop phase durations for all
// DBS modes
{double,double} procedure DBSPhaseLengths {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
}{
// Get the drift parameters to compute the drift noise
if(continuumDetection) {
double[] allanparms = InterpolateTpAllan(band,lo_freq,oneGHzReference);
} else {
allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
}
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// Differential Allan variance
if(continuumDetection) {
allanparms = InterpolateTpChopAllan(band,lo_freq,oneGHzReference);
} else {
allanparms = InterpolateSpecChopAllan(band,lo_freq,oneGHzReference);
}
// rescale to frequency resolution
double dalpha = allanparms[1];
binningexp = 1.0 / allanparms[2];
double dallan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// phase lengths
double main_phase = 0.3 * dallan_time_lores;
double chop_phase = 0.3 * allan_time_lores;
// Constrain by load period
int loadper = LoadPeriod(band,lo_freq,effResolution{0});
main_phase = min(main_phase,0.4 * double(loadper));
return {main_phase,chop_phase};
}
// Get main beam size for message
double procedure GetTsysVariationLimit {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] fwhm = CalibrationReader("tsysvariation",["tsysvariation"],band,lo_freq);
return fwhm[0];
}
// Perform frequency-switch integration at ON position
block HIFIFSwitchOnIntegration HIFI 6038 {
int data_time = 4; // Integration time between two data readouts
int n_cycle = 1; // chop cycle number
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
double[] rates = [120.0,1.0,2.0]; // Data rates between and during integrations
}{
HIFI_Spectr_fswitch_proc_aot(data_time,n_cycle,band,lo_freq,rates);
}
//////////////////////////////////////////////////////////////////////////////
// routines from ILT not used in observing modes
//////////////////////////////////////////////////////////////////////////////
//Configure LCU in nominal mode at frequency of interest
procedure ConfigureLOUnominal {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
}{
LCU_config_nominal_proc_aot(band,lo_freq / 1000.0);
}
//////////////////////////////////////////////////////////////////////
// Procedure to display performance parameters of the observing mode
procedure SScanChopNoRef_performance {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
int nfreq = 4; // Number of frequency points per IF
bool dsb = true; // Both sidebands covered
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
{double,double,double,double,double} noisevalues = {1.0,1.0,1.0,1.0,0.0}; // Noise values from noisecomputer
int totaltime = 200; // Total observing time
int n_cycles = 1; // Number of chop cycles
int freqsteps = 4; // Total number of frequencies
bool fs = false; // whether frequency switch used
double tscan = 10.0; // Total average duration of one scan
double tdead = 0.05; // Average dead time in one chop cycle
}{
// Get performance of ideal instrument for comparison
{int,double,double,double,double,double} idealvalues = IdealInstrument(band,lo_freq,eff_resolution,totaltime);
// Use DSB noise for long spctral scans
if(dsb) {
double idealnoiselsb = idealvalues{1} * idealvalues{1};
double idealnoiseusb = idealvalues{3} * idealvalues{3};
double idealnoise = idealnoiselsb * idealnoiseusb / (idealnoiselsb + idealnoiseusb);
} else {
idealnoise = idealvalues{1} * idealvalues{1};
}
double obsnoise = noisevalues{0} * noisevalues{0};
// rescale for range coverage
double accumulation = double(freqsteps) / double(nfreq);
idealnoise = idealnoise * accumulation;
double efficiency = idealnoise / obsnoise;
// Compute the actual integration time
double inttime = (tscan - tdead) / 2.0;
double posinttime = double(n_cycles) * 2.0 * inttime * double(freqsteps);
double posofftime = 0.0;
int instrumenttime = iceil(double(freqsteps) * tscan);
// Check total integration time
double timeefficiency = (posinttime + posofftime) / double(totaltime);
// Noise contribution
double relnoise = noisevalues{4} / (1.0 + noisevalues{4});
// General messages
PerformanceMessages(band,lo_freq,eff_resolution,noisevalues,totaltime,posinttime,posofftime,timeefficiency,efficiency,relnoise,true);
}
// Frequency of load measurements
// This is no longer computed, but tabulated as it does not depend
// on user parameters - deltanu is a dummy parameter
int procedure LoadPeriod {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
double deltanu = 1.0; // maximum effective resolution of the calibrated data
}{
// Get the stability parameters
double[] allanparms = CalibrationReader("loaddiff_stability",["tp_stability_time"],band,lo_freq);
int period = ifloor(allanparms[0]);
return period;
}
//Retune HIFI for frequency switch - keep magnet and backends
procedure HIFITuneFreqNoretuneFsw {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq_1 = 978200.0; //LO frequency for FSW1 phase
double lo_freq_2 = 978300.0; //LO frequency for FSW2 phase
}{
// Setting with no retune for first frequency, and store in FSW1 register
LCU_config_nominal_noretune_block_aot(band,lo_freq_1 / 1000.0,true);
//
// Second frequency setup, and stored in FSW2 register
LCU_config_nominal_noretune_block_aot(band,lo_freq_2 / 1000.0,true);
//
}
// LCU configuration into DISSIPATIVE mode, procedure
procedure LCU_config_dissipative_w_D2_proc_aot {
string band = "1a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
}{
//
//Fetch LO parameters
string name_configlo = "name_configlo_a";
string name_configlcu = "name_configlcu_a";
string name_confindex = "name_confindex_a";
if(band == "1b" || band == "2b" || band == "3b" || band == "4b" || band == "5b" || band == "6b" || band == "7b") {
name_configlo = "name_configlo_b";
name_configlcu = "name_configlcu_b";
name_confindex = "name_confindex_b";
}
//
double[] cresult = CalibrationReader("name_lcu_dissipative",["lo_freq"],band,0.0);
double lo_freq = cresult[0];
//
cresult = CalibrationReader("name_lcu_safe_values",["pl_c","m1_v","m2_v","m3_v","g1_v","g2_v","d1_v","d2_v"],band,lo_freq);
double plevel_v = cresult[0];
double m1_v = cresult[1];
double m2_v = cresult[2];
double m3_v = cresult[3];
double gate1_v = cresult[4];
double gate2_v = cresult[5];
double drain1_v = cresult[6];
double drain2_v = cresult[7];
//
cresult = CalibrationReader("name_lcu_dissipative",["d2_step","nx"],band,lo_freq);
int d2_step = iround(cresult[0]);
int freq_nx = ifloor(cresult[1]);
//
//Compute lsu_main and offset
int[] resu = ComputeLSU_A_M_R(band,lo_freq);
int lsu_main = resu[0];
int lsu_offset = resu[1];
//Get checksum
{double,string}[] result = ConfigurationReader("name_delays",["cus_checksum"],band,lo_freq);
int macro_checksum = iround(result[0]{0});
//
result = ConfigurationReader(name_configlo,["curlim1_v","curlim2_v"],band,lo_freq);
string curlim1_v = result[0]{1};
string curlim2_v = result[1]{1};
//
result = ConfigurationReader("name_delays",["switch_on_delay"],band,lo_freq);
int config_lo_delay = iround(result[0]{0});
//
//Send command: expect that we have already switched to NOMINAL
HIFI_Configure_LCU_dissipative_block_aot(band,lo_freq,freq_nx,lsu_main,lsu_offset,d2_step,plevel_v,m1_v,m2_v,m3_v,gate1_v,gate2_v,drain1_v,curlim1_v,drain2_v,curlim2_v,macro_checksum,config_lo_delay);
//
// Put heaters explicitly to 4 V
mois_step("Set heaters to normal mode value");
HL_heater_block_aot(band,"nominal");
//
//Configure to Dissipative
Set_LO_Dissipative_block_aot();
}
// messages giving gyro-calibration information
procedure GCPMessages {
int gcp_time = 15; // pointing time at GCP
int gcp_period = 500; // period for visiting the GCP
int tend = 0; // final decelleration time as indication for planet
}{
// Constants hard coded
int tend_fixed = 0;
int critical = 0;
int min_gcp_time = 15;
int max_gcp_period = 2000;
// close any previous messages
message("
");
message("Gyro-calibration
");
message("");
// Actual messages
if(gcp_time > critical) {
if(tend > tend_fixed) {
message("A-posteriori pointing improvement is not possible for " + "solar system objects.");
} else {
if(gcp_time >= min_gcp_time && gcp_period <= max_gcp_period) {
message("A-posteriori relative pointing improvement can be obtained " + "from a gyro-calibration taking " + gcp_time + "s every " + gcp_period + "s.");
} else {
message("The AOR is not optimized for gyro-calibration.");
message("It is not clear whether any a-posteriori relative " + "pointing improvement can be obtained from a " + "gyro-calibration taking " + gcp_time + "s every " + gcp_period + "s.");
}
}
} else {
message("No a-posteriori pointing improvement possible for this AOR.");
}
}
//Chopper rotation procedure. Reduced version without overshooting treatment
// Always one step
procedure RotateChopper {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency
string chop_target = "chop_cold"; //Targetted chopper position
}{
{bool,double,double} chopparms = GetChopVoltages(band,lo_freq,chop_target,chop_target);
bool isPrime = chopparms{0};
// Call command
if(isPrime) {
Hifi_HIFI_P_Chopper_Rot($BBID,chopparms{1});
} else {
Hifi_HIFI_R_Chopper_Rot($BBID,chopparms{1});
}
// No delays should be required here
}
// General version used in most observingmodes
procedure LoadMeasurement {
string band = "4a"; // HIFI band (needed to estimate stabilization)
double lo_freq = 978200.0; // LO frequency
double deltanu = 1.0; // minimum effective resolution of the calibrated data
int data_time = 4; // time between subsequent data readouts
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // Readout parameters for HRS1,HRS2, WBS1,WBS2
}{
// Call generic version with fixed parameters
SScanLoadMeasurement(band,lo_freq,lo_freq,true,deltanu,data_time,backendreadoutparms);
}
{string,double,double}[] procedure HifiMappingModeLoadChopOTFNoRefSequencerInit {
string modeName = "load-raster";
int goalTime = 180;
double goalNoise = 0.1;
bool doingTime = true;
double ra = 0.0;
double dec = 0.0;
double raoff = 0.0;
double decoff = 0.0;
bool refSelected = true;
int naifid = 0;
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
string spectrometer = "both";
bool hrsSeparatePol = false;
string hrsModeH = "Nominal";
string hrsModeV = "Nominal";
double fe_lof_0 = 978.2;
double fe_hrs1_h_0 = 0.0;
double fe_hrs2_h_0 = 0.0;
double fe_hrs3_h_0 = 0.0;
double fe_hrs4_h_0 = 0.0;
double fe_hrs1_v_0 = 0.0;
double fe_hrs2_v_0 = 0.0;
double fe_hrs3_v_0 = 0.0;
double fe_hrs4_v_0 = 0.0;
double fe_eff_res_min_0 = 1.1;
double fe_eff_res_max_0 = 1.1;
bool resolutionMhz = true;
bool singleWbs = false;
int redundancy = 4;
bool dbsContinuum = true;
bool oneGHzReference = true;
double lo_freq1 = 978.2;
double lo_freq2 = 979.6;
bool fullRange = true;
string fsThrow = "small-negative";
double flyX = 0.0;
double flyY = 0.0;
double flyAngle = 0.0;
bool flyNyquistSel = false;
double flyCrossStep = 10.0;
string crossStepSize = "jitter" in ["jitter","nyquist","halfbeam","10","20","40"];
/* HSPOT-only parameters beyond this line. */
bool dbsFast = true;
bool fastChop = true;
string frame = "LSR";
string redshiftFrame = "heliocentric";
string redshiftType = "redshift";
double redshift = 0.0;
string fe_wbs_line_0 = "-No Lines-";
string fe_wbs_trans_0 = "-No Lines-";
double fe_wbs_freq_0 = -1.0;
bool fe_wbs_usb_0 = true;
string fe_hrs1_h_line_0 = "-No Lines-";
string fe_hrs1_h_trans_0 = "-No Lines-";
double fe_hrs1_h_freq_0 = -1.0;
bool fe_hrs1_h_usb_0 = true;
string fe_hrs2_h_line_0 = "-No Lines-";
string fe_hrs2_h_trans_0 = "-No Lines-";
double fe_hrs2_h_freq_0 = -1.0;
bool fe_hrs2_h_usb_0 = true;
string fe_hrs3_h_line_0 = "-No Lines-";
string fe_hrs3_h_trans_0 = "-No Lines-";
double fe_hrs3_h_freq_0 = -1.0;
bool fe_hrs3_h_usb_0 = true;
string fe_hrs4_h_line_0 = "-No Lines-";
string fe_hrs4_h_trans_0 = "-No Lines-";
double fe_hrs4_h_freq_0 = -1.0;
bool fe_hrs4_h_usb_0 = true;
string fe_hrs1_v_line_0 = "-No Lines-";
string fe_hrs1_v_trans_0 = "-No Lines-";
double fe_hrs1_v_freq_0 = -1.0;
bool fe_hrs1_v_usb_0 = true;
string fe_hrs2_v_line_0 = "-No Lines-";
string fe_hrs2_v_trans_0 = "-No Lines-";
double fe_hrs2_v_freq_0 = -1.0;
bool fe_hrs2_v_usb_0 = true;
string fe_hrs3_v_line_0 = "-No Lines-";
string fe_hrs3_v_trans_0 = "-No Lines-";
double fe_hrs3_v_freq_0 = -1.0;
bool fe_hrs3_v_usb_0 = true;
string fe_hrs4_v_line_0 = "-No Lines-";
string fe_hrs4_v_trans_0 = "-No Lines-";
double fe_hrs4_v_freq_0 = -1.0;
bool fe_hrs4_v_usb_0 = true;
bool docommands = true; // Whether instrument commands are generated
/* Sequence parameters */
int data_time = 4 in [1,20]; // chunk size given by the data rates and optimum speed
int n_switch_on = 1 in [1,1800]; // Supersamplingfactor
int n_cycles = 1 in [1,1200]; // Number of map coverages
int load_interval = 1800 in [10,7200]; // load period defines number of lines between two loads
}{
// start Volkers list
{double,double} lineDistance = {0.0,0.0};
int nlines = 1;
double stepsize = 0.0;
int npoints = 1;
double lo_freq = 1000.0;
double lo_freq_up = 1000.0;
double av_lo_freq = 1000.0;
double freq_throw = 0.0;
double redundancy_C = 4.0;
{double,double} effResolution = {1.0,1.0};
bool continuumDetection = true;
{bool,int,double[],bool[]} hrs1 = {true,1,[1.0],[true]};
{bool,int,double[],bool[]} hrs2 = {true,1,[1.0],[true]};
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]};
// int data_time = 1 ;
// double data_chop = 0.0 ;
// int n_int_on = 1 ;
// int n_int_off = 1 ;
// int n_switch_on = 1 ;
// int n_switch_off = 1 ;
// int n_linesperscan = 1 ;
// int n_pointsperscan = 1 ;
// int n_freq_point = 1 ;
// int n_cycles = 1;
// int load_interval = 1 ;
// end of Volkers list
// start general definitions
{int,double,double,double,double,double} result = {1,0.0,0.0,0.0,0.0,0.0};
double degreesPerRadian = 57.2957795;
double degreesPerArcmin = 1.0 / 60.0;
double degreesPerArcsec = 1.0 / 3600.0;
double factorMHzPerGHz = 1000.0;
double factorMHzPerkHz = 0.0010;
double[] hrs1aux = [0.0];
double[] hrs2aux = [0.0];
double[] sortarr = [0.0];
// end general definitions
// start translation
// frequencies
lo_freq = fe_lof_0 * factorMHzPerGHz;
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
lo_freq = lo_freq1 * factorMHzPerGHz;
lo_freq_up = lo_freq2 * factorMHzPerGHz;
av_lo_freq = 0.5 * (lo_freq + lo_freq_up);
} else {
av_lo_freq = lo_freq;
lo_freq_up = lo_freq;
}
redundancy_C = double(redundancy);
freq_throw = GetTrueFsThrow(band,av_lo_freq,fsThrow);
// An additional function is needed here to compute the
// actual LO frequency from the redshift correction
// This needs to be provided by Mission Planning
// double lo_shift=function(redshift,frame,redshiftframe);
// pointing - get step sizes
stepsize = flyCrossStep * degreesPerArcsec;
if(flyNyquistSel) {
double[] s = CalibrationReader("beam",["nyquist"],band,av_lo_freq);
stepsize = s[0];
}
if(stepsize <= 0.0) {
s = CalibrationReader("beam",["halfbeam"],band,av_lo_freq);
stepsize = s[0];
}
// Setup for maps
if(modeName == "raster" || modeName == "cross" || modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
// line distance measured 90deg ccw to lines
lineDistance = {stepsize * cos(flyAngle / degreesPerRadian),stepsize * -sin(flyAngle / degreesPerRadian)};
nlines = imax(iceil(flyY * degreesPerArcmin / stepsize),1);
// extend map by rim for OTF
if(modeName == "fly" || modeName == "fs-raster" || modeName == "load-raster") {
npoints = imax(iceil((flyX * degreesPerArcmin + 1.1 * stepsize) / stepsize),2);
} else {
npoints = imax(iceil(flyX * degreesPerArcmin / stepsize),2);
}
// exception handling for raster maps
if(modeName == "raster") {
if(npoints > 32 || nlines > 32) {
IError("Map too large." + " Raster maps are restricted to <= 32x32 points.");
}
}
// special treatment for cross map mode
if(modeName == "cross") {
npoints = 3;
nlines = 2;
if(crossStepSize == "nyquist" || crossStepSize == "halfbeam") {
s = CalibrationReader("beam",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
} else {
s = CalibrationReader("crossstep",[crossStepSize],band,av_lo_freq);
stepsize = s[0];
}
}
} else {
npoints = 1;
nlines = 1;
}
// backends
// assume none used unless proven otherwise
hrs1{0} = false;
hrs2{0} = false;
wbs1{0} = false;
wbs2{0} = false;
if(spectrometer == "hrs" || spectrometer == "hrsFast" || spectrometer == "both") {
hrs1{0} = true;
hrs2{0} = true;
}
// no HRS in spectral scan modes - only serendipity backend
if(modeName == "fs-freq" || modeName == "freq" || modeName == "load-freq") {
hrs1{0} = false;
hrs2{0} = false;
// put minimum resolution explicitely to WBS resolution
fe_eff_res_min_0 = max(1.1,fe_eff_res_min_0);
}
double[] x = CalibrationReader("backendselect",["bestwbs"],band,av_lo_freq);
int bestWbs = iround(x[0]);
x = CalibrationReader("backendselect",["window1_lo","window1_up","window2_lo","window2_up","window3_lo","window3_up","window4_lo","window4_up"],band,av_lo_freq);
int[] stdWbsWindow1 = [iround(x[0]),iround(x[1])];
int[] stdWbsWindow2 = [iround(x[2]),iround(x[3])];
int[] stdWbsWindow3 = [iround(x[4]),iround(x[5])];
int[] stdWbsWindow4 = [iround(x[6]),iround(x[7])];
if(spectrometer == "wbs" || spectrometer == "both") {
if(!singleWbs) {
wbs1{0} = true;
wbs2{0} = true;
} else {
if(bestWbs == 1) {
wbs1{0} = true;
} else {
wbs2{0} = true;
}
}
}
// for spectral scans
bool wbs1Used = wbs1{0};
bool wbs2Used = wbs2{0};
string[] hrsModes = ["High","Nominal","Low","Wide"];
if(spectrometer == "hrsFast") {
bool[][] hrsUseMap = [[true,false,false,false],[true,false,false,false],[true,true,false,false],[true,true,false,false]];
int[] hrsUseBands = [1,1,2,2];
} else {
hrsUseMap = [[true,false,false,false],[true,true,false,false],[true,true,true,true],[true,true,true,true]];
hrsUseBands = [1,2,4,4];
}
hrs1{1} = -1;
hrs2{1} = -1;
for(int i = 0 .. 3) {
if(hrsModeH == hrsModes[i]) {
hrs1{1} = i;
}
if(hrsModeV == hrsModes[i]) {
hrs2{1} = i;
}
}
// Special treatment for band 6 due to weired definition in HSPOT
// Check whether IF is out of subband I
if(stdWbsWindow1[1] - stdWbsWindow1[0] == 0) {
double mix = 0.8;
// mixing point relative to Andrew's scale
hrs1aux = [mix - fe_hrs1_h_0,mix - fe_hrs2_h_0,mix - fe_hrs3_h_0,mix - fe_hrs4_h_0];
hrs2aux = [mix - fe_hrs1_v_0,mix - fe_hrs2_v_0,mix - fe_hrs3_v_0,mix - fe_hrs4_v_0];
} else {
hrs1aux = [fe_hrs1_h_0,fe_hrs2_h_0,fe_hrs3_h_0,fe_hrs4_h_0];
hrs2aux = [fe_hrs1_v_0,fe_hrs2_v_0,fe_hrs3_v_0,fe_hrs4_v_0];
}
// Order HRS subbands to assign USB frequencies to first subbands
sortarr = DSort(hrs1aux,hrsUseBands[hrs1{1}]);
for(int j1 = 0 .. 3) {
hrs1{2}[j1] = sortarr[j1] * factorMHzPerGHz;
}
sortarr = DSort(hrs2aux,hrsUseBands[hrs2{1}]);
for(int j2 = 0 .. 3) {
hrs2{2}[j2] = sortarr[j2] * factorMHzPerGHz;
}
hrs1{3} = hrsUseMap[hrs1{1}];
hrs2{3} = hrsUseMap[hrs2{1}];
wbs1{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
wbs2{1} = [stdWbsWindow1,stdWbsWindow2,stdWbsWindow3,stdWbsWindow4];
// resolution
effResolution = EffectiveResolution(band,av_lo_freq,{fe_eff_res_min_0,fe_eff_res_max_0},resolutionMhz,wbs1{0},wbs2{0},{hrs1{0},hrs1{1}},{hrs2{0},hrs2{1}});
continuumDetection = dbsContinuum;
// no need to translate any sequencer-determined values
// end of translation
// end of generic code
// Start of observing mode
// limit on data rate
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
int datalimit = dataparms{0};
// limits from noise section
// Get the drift parameters to compute the drift noise
// System Allan variance
double[] allanparms = InterpolateSpecAllan(band,lo_freq,oneGHzReference);
// rescale to frequency resolution
double alpha = allanparms[1];
double binningexp = 1.0 / allanparms[2];
double allan_time_lores = allanparms[0] * pow(1.0 / effResolution{1},binningexp);
// Compute derived quantities
int data_time_guess = imin(imax(iceil(0.3 * allan_time_lores),datalimit),20);
int data_time_range = datalimit - data_time_guess;
if(data_time_range == 0) {
data_time_range = 1;
}
// n_switch limited by load_interval - 2 lines should be possible
int n_switch_on_guess = load_interval / (4 * npoints * data_time_guess);
int n_switch_on_range = 1 - n_switch_on_guess;
if(n_switch_on_range == 0) {
n_switch_on_range = 1;
}
// Contruct return tuple
{string,double,double}[] retvalues = [{"data_time",double(data_time_guess),double(data_time_range)},{"n_switch_on",double(n_switch_on_guess),double(n_switch_on_range)}];
return retvalues;
}
//////////////////////////////////////////////////////////////////////
// Procedure to perform the noise level evaluation for the observing mode
{double,double,double,double,double} procedure SScanChopNoRef_noisecomputer {
string band = "4a"; // HIFI band
double reffreq = 978300.0; // Reference LO frequency in scan center
int nfreq = 4; // Number of frequency points per IF
bool dsb = true; // Both sidebands covered
{double,double} eff_resolution = {1.1,1.1}; // Minimum and maximum goal resolution of the calibrated data in MHz
int n_cycles = 1; // Number of map coverages
bool fs = false; // whether frequency switch used
double tscan = 60.0; // Total average duration of one scan
double tdead = 10.0; // Average dead time in one slew
}{
// spectral scans always use the full bandwidth for reference
bool oneGHzReference = false;
// Call position switch noise computer
{double,double,double,double,double} noisevalues = PositionSwitch_noisecomputer(band,reffreq,eff_resolution,oneGHzReference,n_cycles,tscan,tdead);
// Combined sideband scaling
double[] gssb = InterpolateGssb(band,reffreq);
double avgainfac = 0.5 / gssb[0] + 0.5 / gssb[1];
double rescalefac = gssb[1] * avgainfac;
// Correct for multiple frequencies and signal in both phases in case of FSW
if(fs) {
double multiplier = sqrt(0.5 / double(nfreq));
} else {
multiplier = sqrt(1.0 / double(nfreq));
}
noisevalues{0} = noisevalues{0} * gssb[0] * multiplier;
noisevalues{1} = noisevalues{1} * gssb[0] * multiplier;
// Check for double sideband coverage
if(dsb) {
// Combine LSB-USB noise
// In spectral scans we have only a combined noise temperature for both
// sidebands, so that the USB/LSB separation is not used
double decnoise_lores = noisevalues{0} / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double decnoise_hires = noisevalues{1} / sqrt(gssb[0] * gssb[0] + gssb[1] * gssb[1]);
double indnoise_lores = noisevalues{2} * rescalefac;
double indnoise_hires = noisevalues{3} * rescalefac;
} else {
// Get single sideband noise equivalent
decnoise_lores = noisevalues{0} * avgainfac;
decnoise_hires = noisevalues{1} * avgainfac;
indnoise_lores = noisevalues{2} * rescalefac;
indnoise_hires = noisevalues{3} * rescalefac;
}
// Return noise values and the maximum ratio of drift to radiometric noise
return {decnoise_lores,decnoise_hires,indnoise_lores,indnoise_hires,noisevalues{4}};
}
// Get dead time for chopper motion
double procedure GetSkyChopDeadTime {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency
}{
double[] dead = CalibrationReader("chop_deadtime",["skychop"],band,lo_freq);
return dead[0];
}
////////////////////////////////////
// Fast chop DBS raster observing mode - Engineering version with half throw
//
// The timing is defined as WBS timing, the HRS takes more data during
// the WBS read out, but this is ignored in the computations here.
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiEngHalfThrowFastDBSRaster {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,100]; // Number of rows in the map
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the raster line
int npoints = 10 in [2,100]; // Number of points per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Engineering - DBS Raster Map halfThrow fastChop",{data_time,0,n_int_on,n_switch_on,0,0,n_pointsperscan,0,n_cycles,load_interval},true);
ChopMessages(true,data_time,n_int_on);
RasterSizeMessages(lineDistance,stepsize,nlines,npoints,false);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = FastDBSRaster_pre_timing(nlines,npoints,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
// Check for NoddingInRaster or NoddingOfRaster
int scansize = pre_timing{10};
if(scansize > 1) {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,double,double,int,int,int,int,int} tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_of_raster_pointing(false,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,int,double,double,int,int,int,double,double,int,int,int,int} tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",pre_timing,n_cycles);
telescopetimes = nodding_raster_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} post_timing = DBSRaster_post_timing(pre_timing,telescopetimes,nlines,npoints,n_switch_on,n_cycles,load_interval,true);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
if(scansize > 1) {
tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_of_raster_pointing(true,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"half",post_timing{1},n_cycles);
telescopetimes = nodding_raster_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
int initlength = post_timing{1}{11};
int dangling = post_timing{1}{12};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
HalfFastDBSRaster_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_cycles,scansize,n_loadinterval,n_load,final_load,startobs,telescopetimes,loadlength,false);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = FastDBSRaster_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_load,scansize,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBSRaster_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints,n_cycles,n_seq * n_int_on * imax(n_load,1),tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
///////////////////////////////////////////////////////////////////
// Procedure to compute detailed post timing for the version of the
// load-chop and frequency-switch modes with baseline measurement
//
{int,{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int},int,bool,double,double} procedure DoubleChop_post_timing {
{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int} pre_timing = {16,16,16,16,21,11,1800,32,2,2,0,0,false,false,50,0}; // pre_timing parameter list
int[] telescopetimes = [300,180,20,1,21,0];
int n_cycles = 1; // Number of half OFF-ON-ON-OFF calibration cycles
}{
// Get all values from the pre_timing section
int on_inttime = pre_timing{0};
int off_inttime = pre_timing{1};
int on_pointing = pre_timing{2};
int off_pointing = pre_timing{3};
int loadlength = pre_timing{4};
int jitterdead = pre_timing{5};
int load_spacing = pre_timing{6};
int n_loadinterval = pre_timing{7};
int n_per_on = pre_timing{8};
int n_per_off = pre_timing{9};
int n_load_on = pre_timing{10};
int n_load_off = pre_timing{11};
bool end_load_on = pre_timing{12};
bool end_load_off = pre_timing{13};
int initlength = pre_timing{14};
int dangling = pre_timing{15};
// Use all values from the telescope section
int telinit = telescopetimes[1];
// Initial slew time
int slewtime = telescopetimes[2];
// Slew time to OFF
int pointwaittime = telescopetimes[3];
// Idle time between two phases
int longslew = telescopetimes[4];
// Actual slew time for load slew
int tend = telescopetimes[5];
// Final deceleration time
// If load is performed between the cycles use pointwaittime for load
int halfloadlength = (loadlength - jitterdead + 1) / 2;
int effhalfloadlength = (loadlength - jitterdead - pointwaittime + 1) / 2;
if(end_load_on) {
on_pointing = on_pointing - (halfloadlength - effhalfloadlength);
int shiftlength_on = effhalfloadlength;
} else {
shiftlength_on = 0;
}
if(end_load_off) {
off_pointing = off_pointing - (halfloadlength - effhalfloadlength);
int shiftlength_off = effhalfloadlength;
} else {
shiftlength_off = 0;
}
// treat remaining pointwaittime like an additional slew dead time in cycles
slewtime = slewtime + pointwaittime;
longslew = longslew + pointwaittime;
// Now we can compute the true scan time
int scan_time = on_pointing + off_pointing + slewtime;
// Finally I can compute the load interval
n_loadinterval = imax((load_spacing + slewtime) / scan_time,1);
// Exception handling for very uneven phases
if(end_load_on || end_load_off) {
n_loadinterval = 1;
}
// Variables for the noise computer
// Compute duration of measurement and average scan length
// Compute total dead time in one pointing cycle including load overhead
int scan_time_long = on_pointing + off_pointing + longslew;
int n_long = n_cycles / n_loadinterval;
// Determine need for final load measurement
double rest = double(n_cycles % n_loadinterval) + 0.5;
bool final_load = rest > 0.5001 * double(n_loadinterval);
int looplength = (n_cycles - n_long) * scan_time + n_long * scan_time_long;
double tscan = double(looplength) / double(n_cycles);
// Get pointing dead time, instrument dead time is added later
double tdead = tscan - double(off_inttime + on_inttime);
int initshiftlength = shiftlength_off;
// Check the last pointing cycle, repeated on the telescope procedure
if(n_cycles % 2 == 0) {
int lastshiftlength = shiftlength_off;
} else {
lastshiftlength = shiftlength_on;
}
// Add dangling load time
if(lastshiftlength > 0) {
dangling = loadlength - lastshiftlength;
}
if(final_load) {
dangling = loadlength;
}
int closelength = duration(HIFICloseObs());
dangling = imax(dangling + closelength - tend,0);
// Compute total duration
initlength = initlength - initshiftlength;
// The initial time is no longer contained in the total time
// Compute total duration, remove pointwaittime for last slew
int totaltime = looplength + dangling - pointwaittime + tend;
// show gyro-propagation messages
GCPMessages(off_pointing,2 * scan_time_long,tend);
// Return all the times needed in the telescope and instrument modules
return {totaltime,{on_inttime,off_inttime,on_pointing,off_pointing,loadlength,jitterdead,load_spacing,n_loadinterval,n_per_on,n_per_off,n_load_on,n_load_off,end_load_on,end_load_off,initlength,dangling},initshiftlength,final_load,tscan,tdead};
}
/////////////////////////////////////////////////////////////////
// Procedure to compute total dead times for the mode
//
{double,double,double} procedure OTFmap_deadtimes {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // chunk size given by the data rates and optimum speed
int n_supersample = 1; // Supersamplingfactor
int n_linesperscan = 1; // Number of lines between two OFFs
int n_intoff = 3; // Number of data dumps for the OFF integration time
int n_pp = 10; // Number of data dumps per line
double tdead = 10.0; // Dead time from telescope
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// Dead time in OFF
{double,double} tinst = GetInstDeadSlowChop(data_time,n_intoff,"tp",band,lo_freq,backendreadoutparms);
// dead time within OFF
double tdeadint = double(data_time * n_intoff) - tinst{0};
// total dead time from OFF
double tdead_tot = tdead + tdeadint;
double tintoff = tinst{0};
// Dead time in one line
tinst = GetInstDeadSlowChop(data_time,n_pp,"tp",band,lo_freq,backendreadoutparms);
// Dead time for each line
tdeadint = double(data_time * n_pp) - tinst{0};
tdead_tot = tdead_tot + double(n_linesperscan) * tdeadint;
double tintpoint = tinst{0} / double(n_pp) * double(n_supersample);
// Return total dead time and actual integration times
return {tdead_tot,tintpoint,tintoff};
}
////////////////////////////////////////////////////////////////////////////
// Procedure to generate the instrument commands for the observing mode
procedure LoadChopNoRef_commanding {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4; // data dump interval limited by the data rates
int n_per_on = 2; // number of half load-sky-sky-load cycles on ON
int n_load_on = 0; // additional load measurements in ON pointing phase
bool end_load_on = false; // Need for load after ON pointing phase
int startobs = 0; // Actual starting time of observation
int[] telescopetimes = [300,180,0]; // Timing of observation from telescope
int loadlength = 21; // Load duration
}{
//////////////////////////////////////////////////////////////////////
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// get time values from the telescope structure
int tinitslew = telescopetimes[1];
// Initial slew time
////////////////////////////////////////////////////////////////////////
// Instrument Initialization: The instrument tuning is done as early as
// possible, the load calibration as late as possible
//
// Clustering is currently not implemented in MPS - switched off here
int clustered = 0;
// data rates
{int,double[]} dataparms = DataTaking(backendreadoutparms,data_time);
double[] rates = dataparms{1};
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
////////////////////////////////////////////////////////////////////////
// start state machine
int[] state = [0];
while(state[0] >= 0) {
state = next_state();
if(state[0] == 1) {
// Initialization
if(clustered != 1) {
HIFIInitObs();
TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal");
}
delay(tinitslew - (time() - startobs) - loadlength - hkduration);
// First load measurement
HIFISetHK("normal",false);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
//////////////////////////////////////////////////////////////////////
// States for actual observations
if(state[0] == 3) {
// ON integration
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
// Loop for load cycles
for(int i1 = 1 .. n_load_on) {
HIFILoadChopOnIntegration(data_time,n_per_on,band,lo_freq,rates);
// Perform load calibration
delay(readoutdead);
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
HIFIConfigureLoadChopIntegration(data_time,n_per_on,band,lo_freq,backendreadoutparms);
}
// Last cycle - no load
HIFILoadChopOnIntegration(data_time,n_per_on,band,lo_freq,rates);
}
if(state[0] == 5) {
delay(readoutdead);
if(end_load_on) {
// Perform final load measurement
LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms);
}
HIFICloseObs();
}
}
}
/////////////////////////////////////////////////////////////////
// Get limiting frequencies
{double,double} procedure GetBandLimits {
string band = "4a"; // HIFI band
}{
// read master file
string calibfile = slookup("frequencystep_masterfile",band,"tablefile");
double[] allfpoints = dcolumn(calibfile,"stepfrequency");
// get table size
int iindex1 = length(allfpoints);
double firstlo = allfpoints[1];
double lastlo = allfpoints[iindex1 - 2];
return {firstlo,lastlo};
}
////////////////////////////////////
// Fast chop DBS raster observing mode
//
// The timing is defined as WBS timing, the HRS takes more data during
// the WBS read out, but this is ignored in the computations here.
//
// Combination of four modules implementing the new structure
//
// Return time and noise levels
{int,double,double,double,double,double} obs HifiMappingProcFastDBSRaster {
/* Setup parameters */
int naifid = 0; // Tracking object ID
double ra = 0.0; // RA coordinate of the source
double dec = 0.0; // DEC coordinate of the source
{double,double} lineDistance = {0.0050,0.0050}; // Distance between subsequent rows
int nlines = 1 in [1,100]; // Number of rows in the map
double stepsize = 0.0050 in [5.5556E-4,0.13333]; // Distance between subsequent points in the raster line
int npoints = 10 in [2,100]; // Number of points per row
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} effResolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data in MHz
bool continuumDetection = false; // Whether timing is for total-power level
bool oneGHzReference = true; // 1GHz reference bandwith instead of full IF
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[36,2012],[36,2012],[36,2012],[36,2012]]}; // WBS2 parameters ={used, channel windows}
/* Sequence parameters */
int data_time = 10 in [4,80]; // data dump interval
int n_int_on = 20 in [1,640]; // number chop cycles to integrate in ICU before transfer
int n_switch_on = 1 in [1,1800]; // number of data transfer cycles per pointing
int n_pointsperscan = 1 in [1,1024]; // Number of points measured before moving to the second pointing phase
int n_cycles = 1 in [1,32]; // Number of half OFF-ON-ON-OFF pointing cycles
int load_interval = 1800 in [10,7200]; // load period = f(band,lo_freq,effResolution{1})
bool docommands = true; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// Start of observing mode
OpenMessages("HIFI Mapping - DBS Raster Map fastChop",{data_time,0,n_switch_on,n_int_on,0,0,n_pointsperscan,0,n_cycles,load_interval},true);
ChopMessages(true,data_time,n_int_on);
RasterSizeMessages(lineDistance,stepsize,nlines,npoints,false);
// Call first part of the timing computer
{int,int,int,int,int,int,int,int,int,int,int,int,int} pre_timing = FastDBSRaster_pre_timing(nlines,npoints,band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_switch_on,n_pointsperscan,n_cycles,load_interval,docommands);
//////////////////////////////////////////////////////////////////////
// Prepare telescope command
{double,double} onPosition = {ra,dec};
// Check for NoddingInRaster or NoddingOfRaster
int scansize = pre_timing{10};
if(scansize > 1) {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,double,double,int,int,int,int,int} tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"",pre_timing,n_cycles);
// Dummy call to spacecraft command
int[] telescopetimes = nodding_of_raster_pointing(false,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
{int,int,int,string,int,double,double,bool,double,double,double,int,int,double,double,int,int,int,double,double,int,int,int,double,double,int,int,int,int} tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"",pre_timing,n_cycles);
telescopetimes = nodding_raster_pointing(false,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
//////////////////////////////////////////////////////////////////////
// Call second part of timing computer using results
// from telescope command
{int,{int,int,int,int,int,int,int,int,int,int,int,int,int},bool,double,double} post_timing = DBSRaster_post_timing(pre_timing,telescopetimes,nlines,npoints,n_switch_on,n_cycles,load_interval,true);
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the telescope
// Prepare telescope command
if(scansize > 1) {
tmpar = DBSMultiRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"",post_timing{1},n_cycles);
// Call telescope command
telescopetimes = nodding_of_raster_pointing(true,tmpar{0},tmpar{1},tmpar{2},tmpar{3},tmpar{4},tmpar{5},tmpar{6},tmpar{7},tmpar{8},tmpar{9},tmpar{10},tmpar{11},tmpar{12},tmpar{13},tmpar{14},tmpar{15},tmpar{16},tmpar{17},tmpar{18},tmpar{19},tmpar{20},tmpar{21},tmpar{22},tmpar{23});
} else {
tpar = DBSRaster_telescope(naifid,onPosition,lineDistance,stepsize,nlines,npoints,band,lo_freq,"",post_timing{1},n_cycles);
telescopetimes = nodding_raster_pointing(true,tpar{0},tpar{1},tpar{2},tpar{3},tpar{4},tpar{5},tpar{6},tpar{7},tpar{8},tpar{9},tpar{10},tpar{11},tpar{12},tpar{13},tpar{14},tpar{15},tpar{16},tpar{17},tpar{18},tpar{19},tpar{20},tpar{21},tpar{22},tpar{23},tpar{24},tpar{25},tpar{26},tpar{27},tpar{28});
}
// Consistency check
int totaltime = post_timing{0};
if(totaltime != telescopetimes[0]) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " telescope time of " + telescopetimes[0] + "s detected.");
}
}{
//////////////////////////////////////////////////////////////////////
// Instrument section
// Get all values from post_timing needed in the following
int loadlength = post_timing{1}{3};
int n_load = post_timing{1}{6};
int n_loadinterval = post_timing{1}{7};
int n_seq = post_timing{1}{8};
int initlength = post_timing{1}{11};
int dangling = post_timing{1}{12};
bool final_load = post_timing{2};
double tscan = post_timing{3};
double tdead = post_timing{4};
//////////////////////////////////////////////////////////////////////
// Now the observation starts for the instrument
// Initialize time
sync();
int startobs = time();
// Call instrument commands
///////////////////////////////////////////////////////////////////////
// Don't do anything if docommand=false
//
if(docommands) {
FastDBSRaster_commanding(band,lo_freq,effResolution,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_cycles,scansize,n_loadinterval,n_load,final_load,startobs,telescopetimes,loadlength,false);
} else {
delay(telescopetimes[0] + telescopetimes[1]);
}
// Second consistency check
int timeTaken = time() - startobs - telescopetimes[1];
if(timeTaken != totaltime) {
CError("Mismatch between instrument time of " + totaltime + "s and" + " command duration of " + timeTaken + "s detected.");
}
//////////////////////////////////////////////////////////////////////
// Compute the noise
//
// First get additional dead times from instrument
{double,double,double} tact = FastDBSRaster_deadtimes(band,lo_freq,hrs1,hrs2,wbs1,wbs2,data_time,n_int_on,n_seq,n_load,scansize,tdead);
//
// Call noise computer
{double,double,double,double,double} noisevalues = DBS_noisecomputer(band,lo_freq,effResolution,continuumDetection,oneGHzReference,n_cycles,tscan,tact);
// Evaluate performance
DBSRaster_performance(band,lo_freq,effResolution,noisevalues,timeTaken,nlines,npoints,n_cycles,n_seq * n_int_on * imax(n_load,1),tact);
// Final message to check for both polarizations
PolarizationMessage(hrs1{0},hrs2{0},wbs1{0},wbs2{0});
// Return everything
noise_level([noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3}]);
// Auxiliary construct for HSPOT - return total time and noise values
// Also return the maximum ratio of drift to radiometric noise
return {timeTaken,noisevalues{0},noisevalues{1},noisevalues{2},noisevalues{3},noisevalues{4}};
}
// Configuration for fast-chop integration
int[] block HIFIConfigureFastChopIntegration HIFI 6040 {
int data_time = 4; // Integration time between two data readouts
int n_int = 20; // number chop cycles to integrate in ICU before transfer
int n_seq = 1; // Number of continuous data transfer cycles
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{true,1,[true,true,true,true]},{true,1,[true,true,true,true]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]},{true,[[0,2048],[0,2048],[0,2048],[0,2048]]}}; // HRS1/2 {used,resolution,subbands used}, WBS1/2 {used, channel windows}
}{
// Call procedure doing the work
{int,int} fchop = FastConfigureSpectroscopy(data_time,n_int,n_seq,band,lo_freq,backendreadoutparms);
// Return data rates for command
return [fchop{0},fchop{1}];
}
/////////////////////////////////////////////////////////////////
// get reference frequency, resolution, redundancy
{double,int,double} procedure GetFReference {
string band = "4a"; // HIFI band
double lo_freq1 = 978200.0 in [480000.0,1950000.0]; // LO frequency
double lo_freq2 = 979600.0 in [480000.0,1950000.0]; // LO frequency
}{
// first step: read master file
double referencefreq = ComputeReferenceFreq(band,lo_freq1,lo_freq2);
int redundancy = ilookup("frequencystep_masterfile",band,"redundancy");
double stdstep = dlookup("frequencystep_masterfile",band,"stdstep");
return {referencefreq,redundancy,stdstep};
}
/////////////////////////////////////////////////////////////////
// Procedure to compute detailed timing for the mode
//
{int,int,int,int,int,int,int,int,int,int,int,int,bool,bool,int,int} procedure PositionSwitch_pre_timing {
string band = "4a"; // HIFI band
double lo_freq = 978200.0; // LO frequency in MHz
{double,double} eff_resolution = {1.0,1.0}; // Minimum and maximum goal resolution of the calibrated data
{bool,int,double[],bool[]} hrs1 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS1 parameters={used,resolution,frequency offsets, subbands used}
{bool,int,double[],bool[]} hrs2 = {true,1,[-110.0,110.0,0.0,0.0],[true,true,true,true]}; // HRS2 parameters={used,resolution,frequency offsets, subbands used}
{bool,int[][]} wbs1 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS1 parameters ={used, channel windows}
{bool,int[][]} wbs2 = {true,[[0,2048],[0,2048],[0,2048],[0,2048]]}; // WBS2 parameters ={used, channel windows}
int data_time = 4 in [1,5]; // data dump interval limited by the data rates
int n_int = 3 in [2,1800]; // number of data dumps for integration per phase
int load_interval = 1800 in [10,7200]; // load period in seconds
bool docommands = false; // Whether instrument command loop is executed
}{
//////////////////////////////////////////////////////////////////////
// First check validity of frequencies
CheckLOFrequencies(band,lo_freq,lo_freq);
// Create a composite readout structure for simpler handling
{{bool,int,bool[]},{bool,int,bool[]},{bool,int[][]},{bool,int[][]}} backendreadoutparms = {{hrs1{0},hrs1{1},hrs1{3}},{hrs2{0},hrs2{1},hrs2{3}},wbs1,wbs2};
// First perform consistency checks
// Check chunk size given by the data rates
CheckDataTaking(backendreadoutparms,data_time);
// Compute parameters for the instrument timing
int jitterdead = GetMaxTimeJitter(band,lo_freq);
int inttime = n_int * data_time;
// Resulting integer integration time
int pointing = inttime + jitterdead;
// Pointing time
// compute load integration time
int loadlength = duration(LoadMeasurement(band,lo_freq,eff_resolution{0},data_time,backendreadoutparms));
int readoutdead = SlowChopReadoutDelay(band,lo_freq,backendreadoutparms);
loadlength = loadlength + readoutdead;
int halfloadlength = (loadlength - jitterdead + 1) / 2;
int load_spacing = CheckedLoadSpacing(load_interval - loadlength,2 * inttime);
// Duration of initial set up
// determine exact duration only in case of full commanding
if(docommands) {
int initlength = duration(HIFIInitObs());
initlength = initlength + duration(TuneHIFI(band,lo_freq,hrs1,hrs2,wbs1{0},wbs2{0},"normal"));
// Add time for HK readout
int hkduration = HkReadoutTime(band,lo_freq,backendreadoutparms,false);
initlength = initlength + hkduration;
} else {
initlength = GetRoughInitLength(band,lo_freq,false);
}
initlength = initlength + loadlength;
// Compute the load period
// First estimate of the load interval
int n_loadinterval = imax(load_interval / (2 * pointing),1);
// Dangling load not known yet at this point
bool final_load = false;
int dangling = readoutdead;
// pseudo parameters which are notneeded here, but used for a
// unified treatment of all modes using the same pointing command
int n_seq = 1;
int n_load = 0;
// Return all the times needed for telescope call and post_timing processing
return {inttime,inttime,pointing,pointing,loadlength,halfloadlength,load_spacing,n_loadinterval,n_seq,n_seq,n_load,n_load,final_load,final_load,initlength,dangling};
}
/////////////////////////////////////////////////////////////////
// Get all frequency points in interval
double[] procedure GetFScanPoints {
string band = "4a"; // HIFI band
int firstindex = 1; // Index of first frequency point
int lastindex = 2; // Index of last frequency point
int increment = 1; // Index increment
}{
// first step: read master file
string calibfile = slookup("frequencystep_masterfile",band,"tablefile");
double[] allfpoints = dcolumn(calibfile,"lo_frequency");
// Initialize field
int nstep = (lastindex - firstindex + 2 * increment - 1) / increment;
double[] fpoints = [];
// Loop for reading
for(int i = 0 .. nstep - 1) {
int counter = firstindex + i * increment;
fpoints[i] = allfpoints[counter];
}
return fpoints;
}
//Tune HIFI at frequency of interest for 2 frequencies (FSW)
procedure HIFITuneFsw {
string band = "4a" in ["1a","1b","2a","2b","3a","3b","4a","4b","5a","5b","6a","6b","7a","7b"]; // HIFI band
double lo_freq_1 = 978200.0; //LO frequency for FSW1 phase
double lo_freq_2 = 978300.0; //LO frequency for FSW2 phase
bool hrs1used = true; // HRS1 parameter =used
bool hrs2used = true; // HRS2 parameter
bool wbs1used = true; // WBS1 parameter =used
bool wbs2used = true; // WBS2 parameter
string target_name = "normal"; // Name of target level
}{
//
//LO power tuning: could use either H or V polar
{double,string}[] result = ConfigurationReader("name_confpolar4lotune",[band],band,lo_freq_1);
double x = result[0]{0};
string tuningbackend = "H";
if(iround(x) == 2) {
tuningbackend = "V";
} else {
tuningbackend = "H";
}
// All tuning for first frequency, and store in FSW1 register
double lo_freq_setting = 0.5 * (lo_freq_1 / 1000.0 + lo_freq_2 / 1000.0);
LO_tuning_block_aot(band,lo_freq_1 / 1000.0,lo_freq_setting,tuningbackend,true,true,true,true);
//
//Magnet tuning: use either HRS or WBS, not for bands 1,2,6,7 (SCR-2380)
if(band == "3a" || band == "3b" || band == "4a" || band == "4b" || band == "5a" || band == "5b") {
// Currently only the HRS is used
string magnettuningbackend = "HRS";
Magnet_tuning_block_aot(band,lo_freq_1 / 1000.0,magnettuningbackend);
}
//
//Spectrometer attenuator tuning on HBB
if(wbs1used || wbs2used) {
WBS_attenuators_block(band,lo_freq_1 / 1000.0,target_name,false);
}
if(hrs1used || hrs2used) {
HRS_tune_block_aot(band);
}
// Second frequency setup, and stored in FSW2 register
// Extra stabilization only for HEB bands
if(band == "6a" || band == "6b" || band == "7a" || band == "7b") {
LO_tuning_block_aot(band,lo_freq_2 / 1000.0,lo_freq_setting,tuningbackend,false,true,true,true);
} else {
LO_tuning_block_aot(band,lo_freq_2 / 1000.0,lo_freq_setting,tuningbackend,false,true,true,false);
}
//
}
// Last message of an observing mode - check for polarizations, close message body
procedure PolarizationMessage {
bool hrs1used = true;
bool hrs2used = true;
bool wbs1used = true;
bool wbs2used = true;
}{
// Check whether both polarizations are used in at least one spectrometer system
if(hrs1used && hrs2used || wbs1used && wbs2used) {
message("