-
Notifications
You must be signed in to change notification settings - Fork 24
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
channel 4 BT to radiance conversion #57
Comments
Thanks for reporting this! I'll let @abhaydd look into this first then. |
Hi @mraspaud and @abhaydd, |
@carloshorn I understand your standpoint. But I think the code SHOULD depend on the coefficients. For climate applications, it is extremely important to be able to tag a particular version of PyGAC to a particular set of coefficients. It could easily happen that the files, from which we directly read the coefficients, will be misplaced or deleted by the user. Or it might get difficult to trace the history of the coefficients because the user might make some changes in those files later on, may they be deliberate or accidental. Also, which coefficient file format should PyGAC follow? What if the PATMOS-x changes its existing file format? So, in my opinion, the price to pay would be higher than trying to achieve some flexibility here. Maybe I am just missing something here or not understanding what you mean. Then please correct me. Thanks. |
Hi @abhaydd, |
How about having default coefs in the code but allow the user to replace it with a custom file, where a version number must be provided? |
@carloshorn I think your idea of reading calibration coefficients from the files (instead of having them hard-coded directly in the code) is good. But I just don't want PyGAC to depend on a particular file format to do that (e.g. PATMOS-x). If we were to have them in the separate files: 1) I would rather like to define our own format and let the users fill-in those coefficients. I agree that there will be a risk of making mistakes while copy-pasting, but the user has to bear then some responsibility. 2) And this next point is very important, each release of PyGAC should then also have the default calibration file tagged to it and stored on github as a part of that particular release. This is to ensure that a) we have a traceability for the climate applications and b) to help the users to use PyGAC without having to think about arranging those files. For example, when a satpy user calls pygac to just process/visualize few GAC orbits. In such low-demanding, but time-constrained cases, it would be too much to ask the user to define a calibration file. Having a default file would help. |
@mraspaud Ahhh...just saw your comment. Yes, pretty much what you said, but have everything in the files. User-defined as well as default ones. |
Some ideas:
|
I am not in a position nor do I have knowledge in this to comment your suggestions @mraspaud. I will only say this. We should try to keep it simple and avoid too many interdependencies. Would adding pyspectral make things easier or complex for a user? Can we guarantee that pyspectral in future will not diverge away in a fashion that would make dependency more complex (e.g. pyspectral may in future in turn depend on other additional packages that the user would have to think about)? To think about all of this just to read few cal-coefficients seems like a too much demand on a user. Or maybe nowadays anaconda will install and do everything smoothly. Don't know. |
pip and conda will take care of all the dependencies, so it's a non-issue imo. But it doesn't have to be linked to custom cal coefs, ie we can take this at another time. |
I agree with @abhaydd that adding another dependency for reading a hand full of coefficients would make it more complicated. Especially, because the user would then need to reference the version of pyspectral for the coefficients which would break the benefit of a single reference. |
Using import json
with tar.with_suffix('.json').open('w') as json_file:
json.dump(all_data, json_file, indent=4, sort_keys=True) at the end of above script, the json file looks much prettier, e.g.
This is just an example, how the json file could look like. In pygac, I think we do not use all parameters defined in patmos-x files. Furthermore, pygac has a different naming convention for these parameters, e.g. coeffs = {
'metopb': {'ah': np.array([0.166, 0.183, 0.201]),
'al': np.array([0.055, 0.061, 0.029]),
'bh': np.array([2.019, 1.476, 1.748]),
'bl': np.array([2.019, 1.476, 1.748]),
'ch': np.array([-0.201, -0.137, -0.033]),
'cl': np.array([-0.201, -0.137, -0.033]),
'c_dark': np.array([39.70, 40.00, 40.30]),
'c_s': np.array([501.12, 500.82, 501.32]),
'l_date': 2012.77,
... In any case, I would like to use some more self-explanatory names. Any suggestions or reference, where I could get some inspiration? If you are fine with json, I would start with the implementation. Naming convention can be updated later on. |
I'm good with that. Should the first step be to write a script to export the pygac values to json ? |
I started with a script that reads the patmos-x data, because the current pygac coefficients have been derived from them, see Lines 408 to 409 in 4c458ba
Now, I will write the mapping from patmos-x to pygac coefficients. This way, we avoid any typo issues or discrepancies to the original source. (I guess you have checked these numbers several times, but still another #49 could be hidden the hard coded values) . Of cause, I will compare the outcome to the current values and let you know if I find something. |
Thanks a lot @carloshorn that you have started with this. |
I did the comparison and found 16 deviating values, e.g. the last value of this arrays Lines 56 to 57 in 4c458ba
should be 1.224 instead of -0.016 according to avhrr_2_instr.dat, second column of line with comment "! ch3a low gain S0,S1,S2" and the following line. The following three scripts will reproduce my results: |
@abhaydd, beside the patmos-x web page, I would also like to give a scientific paper as reference to these coefficients. Some papers are listed at the end of patmos-x Solar Calibration documentation, which one would you cite as a reference, or is there a more recent paper for the 2017 data? |
@carloshorn Thanks. I think the citation of Heidinger et al (2010) is still valid for the original methodology. I am not sure if they have published the most recent update in a peer-reviewed journal yet. |
For the implementation, do you prefer to correct the 16 deviating coefficients in a separate step and compare/validate the results somehow, and in a later step change the pygac coefficient called 'a' according to the original issue and compare/validate again, or should I do both changes at once? |
@carloshorn I would suggest to wait till we evaluate and compare the existing calibration. Note that our version of coefficients may be different that what you see online there on patmos-x website. That doesn't mean it is incorrect. |
I started with the implementation. The current version simply exports the current coefficients as they are into a json file. Line 444 in 4c458ba
@abhaydd, do you have time this week for a short skype or webex meeting to talk about the usage of these coefficients. I feel like the mapping from patmos-x to pygac coefficients is not as "linear" as expected and includes some switches or so. @mraspaud, I did not start a PR yet, because I would like to know which flow you prefer. Do you like a separate PR for the export into json and another one for the change of coefficients, or is a single PR for both okay for you? |
@carloshorn Shall we try Skype on Friday morning say at 9:30? I will be on leave the next full week. |
Coming a bit late to the discussion (again...) but I very much like the idea of separating software and coefficients. Two examples:
Regarding the versioning: What if we create a DOI for each set of calibration coefficients? You can cite DOIs very easily, too. |
Oh and regarding pyspectral: @mraspaud was your idea to move the coefficients or the calibration methods to pyspectral? |
@sfinkens yes, DOI is good too. About pyspectral, I was thinking about the code, not the coeffs. But maybe pygac's calibration methods are too specific, I don't know. |
Hi, |
I think all patmos-x level-2 files even contain the coefficients, as global attributes, that were applied to that orbit. |
There is so much potential to improve pygac and make it more user friendly. If we four groups (eumetsat, dwd, uni bern and smhi) could work together unofficially, it would lift pygac to another level. I will try to spend some time on it during the online pytroll workshop. Also we could in future tackle the LAC component of it. |
@carloshorn Your boss mentioned that he has frequent contact to the patmos-x developers. Do you think he could ask them whether they would be willing to create a DOI for their coefficients? If there is already a paper describing the methods, it's hopefully not that much work (of course we can offer help). Then we would be able to cite that DOI in the pygac FDR documentation. |
Regarding pyspectral: I would be ok with moving the methods to pyspectral (if they are not too specific - I don't know either). It's an extra dependency, but it runs in the pytroll family ;) |
Hi all, @helgaweb brought me here. I am the guy she referenced as the one who built a tool to calculate and inject VIS calibration coefficients. I developed the tool in C for the UniBe AVHRR processing chain, over the years a ton of different coefficient sources were added as well as lots of code because every source / project uses different notations and approaches. Some months ago @helgaweb approached me because of the PATMOS coefficients. I collected all available coefficient sets from the PATMOS project, cleaned up their data files such that no values were missing and the files could be automatically processed, created a CSV file, and finally built a sqlite database of it. As I am trying to get into python I developed a proof of concept tool to read the coefficients from the database, however the output does not take into account the sensor degradation. @carloshorn I think the CSV file and / or the sqlite database would help you immensely for a start as you can probably derive the json data easily from it. |
Welcome @rsgb-neuhaus 😊 |
Hi all, |
Hi @rsgb-neuhaus ! Interesting project! Are you planning to publish this coefficient database? But I agree with @carloshorn that for the moment we should focus on moving the current coefficients to an external file with a well defined format. Once we have that sorted out, you would have a nice interface to pass any of the coefficient sets in your database to pygac. |
@carloshorn I am on skpye. Don't have your-id. Mine is: abhay.devasthale |
@abhaydd @carloshorn we're trying to organize a meeting on slack, check the #pygac channel |
Just started a project over at https://github.com/rsgb-neuhaus/viscal_db - time to teach an old svn dog some git tricks. I still need to figure out the license stuff for the scripts and of course the data; while I don't think that Andrew Heidinger as the author of the PATMOS coefficients will oppose to re-distributing the data I would like to get his permission first before I upload his data files. |
@rsgb-neuhaus Well done documentation! And I especially like that you accounted for more than one set of PATMOS-x coeffs per year! Would have made my work much easier earlier this year ;) |
Back to the original issue, I compared the coefficients of NOAA-15 in the code, the patmos-x coefficients and those from the KLM guide table (D.1-11) and found out, that there is actually a mistake in the pygac implementation. The pygac code follows the steps from 7.1.2.4 in the KLM guide, which lists the linear transformation using these coefficients as equation (7.1.2.4-3), which is implemented here: Line 549 in 2d7fbaf
The pygac coefficients coefficients for NOAA-15 are listed here: Lines 300 to 303 in 2d7fbaf
where the values of 'b' evaluate to [0.99801495, 0.99871864, 0.99902395]
The patmos-x values are:
which reveals that the pygac values for
The difference between the values in the KLM guide to the pygac values is exactly given by the division by The mistake in pygac might have originated from a side note that I found in the KLM guide
|
As mentioned before, I will open the PR to correct this issue after finishing #58. |
@carloshorn thank you for your excellent detective work!
Makes me think that it would be nice to have comments in the code referring to the equation numbers. For the rest, I'll let @abhaydd give the final word, but it indeed looks suspicious. |
Dear pygac team,
My colleagues Marie Doutriaux Boucher and Oliver Sus at EUMETSAT encountered a potential mistake in the conversion from brightness temperature to radiance in pygac.
The critical part is the linear temperature transformation in the exponent. The temperature in the equation is an effective brightness temperature. In order to use the measured brightness temperature, it is possible to re-define the constants of the linear equation.
It appears like the coefficient A has changed sign in pygac, but has not been divided by B. Since B is close to one, the results will not change dramatically. However, the differences accumulate when transforming back and forth.
Abhay Devasthale is already double checking the coefficients and comparing to patmos-x.
The text was updated successfully, but these errors were encountered: