Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and apply in-flight calibration factors to counts using simulated data #893

Open
Tracked by #892
tech3371 opened this issue Oct 1, 2024 · 2 comments · May be fixed by #1267
Open
Tracked by #892

Read and apply in-flight calibration factors to counts using simulated data #893

tech3371 opened this issue Oct 1, 2024 · 2 comments · May be fixed by #1267
Assignees
Labels
Ins: SWE Related to the SWE instrument
Milestone

Comments

@tech3371
Copy link
Contributor

tech3371 commented Oct 1, 2024

From document
/*
** APPLY ELECTRON CALIBRATION FACTORS
**
** These factors are used to account for changes in gain with time.
**
** They are derived from the weekly electron calibration data.
** The procedure is to compare the counts obtained at the operating CEM
** level (step 2 of the cal run) to the counts are the next higher CEM
** level (step 3 of the cal run). We assume that the next higher
** level is correct, and use this ratio to scale the counts.
**
*/

cal_factor = electron_cal(mystruct.sct);

for (i=0; i<N_ENERGIES; i++){
  for (j=0; j<N_CEMS; j++){
for (k=0; k<N_PHI; k++){
              counts[i][j][k] = ccounts[i][j][k] * cal_factor[j];
}
  }
}

/*****************
** electron_cal ** given an S/C time, return interpolated electron cals
****************/
float *
electron_cal(uint32 sct)
{
int i;
static int last_i; /
value of i at previous iteration */
static float factor[7];

/*
** First time through? Read in the calibration data
*/
if (cal == NULL) init_electron_cal();

/*
** Iterate over all points, until we find ourselves within this range.
**
** When we do, return a linear interpolation of the factors at the
** two measured points.
**
** NOTE: since the cal data file is in sequential order, and the only
** code that invokes us also does so in sequence, we can optimize a
** step by preserving last_i and assuming we will never be invoked for
** a time prior to the last one.
*/
for (i=last_i; i < npoints-1; i++){
if (cal[i].sct <= sct && sct < cal[i+1].sct) {
int j;
int run = cal[i+1].sct - cal[i].sct;
int tdif= sct - cal[i].sct;

  last_i = i;

  for (j=0; j<7; j++) {
float slope = (cal[i+1].factor[j] - cal[i].factor[j]) / run;

factor[j] = cal[i].factor[j] + slope * tdif;
  }
  return factor;
}

}

printf("cannot extrapolate beyond last cal\n");
exit(1);
}

@tech3371 tech3371 self-assigned this Dec 11, 2024
@tech3371 tech3371 added the Ins: SWE Related to the SWE instrument label Dec 11, 2024
@tech3371 tech3371 added this to IMAP Dec 11, 2024
@tech3371 tech3371 added this to the Jan 2025 milestone Dec 11, 2024
@tech3371
Copy link
Contributor Author

tech3371 commented Jan 8, 2025

From Ruth:

For in-flight calibration - I first note that this is another place where the process will be different from the heritage instruments. There really are two steps to this process: 1) obtaining the calibration data and calculating the calibration factors, and 2) applying the calibration factors.
For now, assuming we focus just on step 2, attached is a file containing electron calibration factors from the ACE/SWEPAM instrument. This instrument also has 7 CEM detectors. Each line has 8 numbers, with the first being a time stamp (I think in seconds since some arbitrary date), and the next 7 being the factors for the 7 detectors. For SWEPAM, the calibration points are roughly a week apart. To calculate the factors for any given time, we simply do a linear interpolation between the two points surrounding the time of interest, as shown in the SWE algorithms document. I’m sure the IMAP timestamps will be some completely different format, but I’m also sure you know how to handle that.
(And an aside, just for your knowledge. If you look at the sample data file, you can see that the factors generally increase with time, as the detector gains decrease with age and we need to correct by a larger amount. However, there are also times where you see the factors all decrease, and those are times when we turned up the voltage on the detectors, making them more sensitive.)
Soon (but not today) we’ll have to get to back to step 1 and determine these factors. For ACE/SWEPAM Step 1 was done outside of the processing code, as it required me to look at the data by hand. For SWE, this will probably also require a human in the loop. For ACE/SWEPAM, the process was made easier by the calibration data being tagged with a “Calibration Mode” label. For SWE, we will need to be more clever about identifying these times, although it should be straightforward.
The assumption at launch will be that the cal_factor values are all equal to 1.0. You can either define values of 1.0 to start, or can make the code apply cal_factors only after some time, with the time to be determined later based on in-flight observations.

@tech3371
Copy link
Contributor Author

tech3371 commented Jan 8, 2025

Example data
4944931 1.045670 1.087874 1.100443 1.043955 1.074945 1.031638 1.041656 7608371 1.151423 1.681108 1.675211 1.418572 1.410090 1.117653 1.113883 7866803 1.027960 1.061101 1.064915 1.039616 1.045498 1.020982 1.022698 8727987 1.036081 1.123971 1.137029 1.083515 1.079056 1.047497 1.033264 16675667 1.264092 1.901397 1.791956 1.532835 1.546491 1.273017 1.162437 17276947 1.250342 1.795031 1.735279 1.567255 1.579045 1.341641 1.156612 17886163 1.264816 2.002724 1.860664 1.642952 1.694609 1.389691 1.182828 18509267 1.337568 2.008272 1.877477 1.749571 1.754070 1.480939 1.177816 19092691 1.357293 2.227281 1.985637 1.818376 1.842406 1.539557 1.208733 19695955 1.416493 2.802722 2.477755 2.158766 2.165989 1.687427 1.243318 20325011 1.494244 2.623787 2.345025 2.249632 2.273543 1.873648 1.298826 20901715 1.546746 3.162000 2.517506 2.377272 2.350183 1.880439 1.292290 20902931 1.006269 1.023805 1.020336 1.011127 1.020895 1.008487 1.009387 21518099 1.010843 1.070874 1.073926 1.054237 1.039873 1.045534 1.000000 21879699 1.006657 1.025136 1.025257 1.012237 1.014889 1.000000 1.000000 22123859 1.006536 1.040294 1.029717 1.017456 1.000000 1.012943 1.015307 22725139 1.030550 1.079994 1.067328 1.047905 1.040284 1.037894 1.014964 23324435 1.021971 1.078435 1.071664 1.055182 1.042652 1.046517 1.017898 23931667 1.022119 1.069561 1.040190 1.014045 1.017634 1.051313 1.019832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ins: SWE Related to the SWE instrument
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

1 participant