Repository navigation
Improve treatment of solar spectrum - #39
James Manners (mo-jmanners) wants to merge 11 commits into
Conversation
…7, WHI and Lyman-alpha data; Fix issues with the interpretation of the solar spectrum in the correlated-k code so that sub-band irradiance is interpolated correctly and the long wavelength tail uses a full Planck function rather than a Rayleigh-Jeans approximation; Extend functionality for solar spectral variability allowing variations at lower spectral resolution than spectral file sub-bands by merging in the high-res (sub-band) solar spectrum; Significant decrease in memory usage for spectrum type.
…ot have an extended file
Dr Stephan Havemann (Petzi1)
left a comment
There was a problem hiding this comment.
I am happy with the changes and additions.
Pierre Siddall (Pierre-siddall)
left a comment
There was a problem hiding this comment.
Hi James Manners (@mo-jmanners), I'm afraid I have quite a large laundry list of issues on this PR. But this feels to me like a case of a few mistakes which have been propogated throughout the rest of the PR. For future reference it would be useful to revisit the coding standards these will help you to avoid a long list of actions from a PR in future. If my comments have missed any context from a scientific perspective please feel free to let me know and I'd be happy to discuss with you.
| linenum = 0 | ||
| scale_wv=1.0 | ||
| scale_irr=1.0 | ||
| with open(filename1, 'r') as file: |
There was a problem hiding this comment.
These set of operation on a file could do with some comments explaining what the operations are doing.
| dataend = linenum | ||
|
|
||
| datalen = dataend-datastart-1 | ||
| if (l_binned): |
There was a problem hiding this comment.
Similarly here comments on why the wavelength and irradiance are multiplied by 2 when the line data is binned would be helpful to future developers.
| irradiance1 = np.zeros(datalen) | ||
|
|
||
| total_irradiance=0.0 | ||
| with open(filename1) as file: |
There was a problem hiding this comment.
Comments on this set of file operations would be helpful.
|
|
||
| l_sub_bands = False | ||
| if (len(sys.argv) > 2): | ||
| with open(filename2, 'r') as file: |
There was a problem hiding this comment.
Similary, this also needs some documentation or comments added.
| if (l_sub_bands): | ||
| band = np.zeros(datalen, dtype=int) | ||
| kterm = np.zeros(datalen, dtype=int) | ||
| with open(filename2) as file: |
There was a problem hiding this comment.
Comments would also be helpful here.
| ! Scale to get the flux at 1 AU. | ||
| planck_tail = planck_tail * (Sol%radius/astronomical_unit)**2 | ||
|
|
||
| END FUNCTION planck_tail |
There was a problem hiding this comment.
| END FUNCTION planck_tail | |
| END SUBROUTINE planck_tail |
|
|
||
|
|
||
| ! Dummy arguments. | ||
| INTEGER, Intent(IN) :: iu_solar |
There was a problem hiding this comment.
The casing needs to be kept the same here.
| INTEGER, Intent(IN) :: iu_solar | |
| INTEGER, INTENT(IN) :: iu_solar |
| ! Dummy arguments. | ||
| INTEGER, Intent(IN) :: iu_solar | ||
| ! Unit number for the solar spectrum | ||
| INTEGER, Intent(INOUT) :: ierr |
There was a problem hiding this comment.
| INTEGER, Intent(INOUT) :: ierr | |
| INTEGER, INTENT(INOUT) :: ierr |
| ! Unit number for the solar spectrum | ||
| INTEGER, Intent(INOUT) :: ierr | ||
| ! Error flag | ||
| TYPE (StrSolarSpec), Intent(OUT) :: SolarSpec |
There was a problem hiding this comment.
| TYPE (StrSolarSpec), Intent(OUT) :: SolarSpec | |
| TYPE (StrSolarSpec), INTENT(OUT) :: SolarSpec |
|
Thanks Pierre, I think I've dealt with all your comments apart from the ones I've replied to above. I also haven't removed any of the stop statements. The exit statement is not equivalent and not generally appropriate. These routines are stand-alone Socrates programs that are not run in a parallel environment and are not part of LFRic / UM builds. James |
Hi James, thanks for flagging this, I'll have a further chat about the stop statements with the SSD team tommorow as your right in saying that stop will have no effect on the code if not part of the UM/LFRIC builds. However,my concern is more to do with maintaining the same standards across all the code respositories and maintainability in the future should this become part of the UM/LFRIC builds for whatever reason and my gut feeling is this might still be a no I'm afraid but I'll see what I can do. |
|
Hi James Manners (@mo-jmanners), regarding the use of stop staments I have consulted with the working practices again and the rest of the SSD team and I think the verdict is if you could report the error via the |
…MetOffice#44 and replace stop statements with ereport calls.
|
Thanks Pierre Siddall (@Pierre-siddall), I've introduced a socrates_ereport module as part of a longer term plan to disentangle the modules_core routines from their UM versions. This work will continue in #44 to properly replace ereport with socrates_ereport throughout the socrates code. For now, this lets me provide a cleaner stop message for 'usage' errors for these stand-alone programs. |
Hi James Manners (@mo-jmanners) , another SSSE has explained the usage of stop statements to me futher and how to handle them in socrates in the future. Apologies again for my confusion regarding the strong wording on our documentation. I'm happy that I understand this is the way to procced now. |
Pierre Siddall (Pierre-siddall)
left a comment
There was a problem hiding this comment.
I'm happy that the changes now make sense within the context of socrates and hence this PR is good to be tested, apologies again James Manners (@mo-jmanners) for my confusion on this, this has definetly been a learning experience for me on future socrates tickets.
PR Summary
Improve treatment of solar spectrum
Sci/Tech Reviewer: Dr Stephan Havemann (@Petzi1)
Code Reviewer: Pierre Siddall (@Pierre-siddall)
New scripts are introduced to create a merged high-resolution solar spectrum, in particular: examples/solar/mk_solar_cmip7_cyc23_whi_lya
Fixes are made in src/general/solar_intensity_nu.f90 (previously solar_intensity_90.f90) to properly interpolate a binned solar spectrum with constant solar flux over the defined bins. The longwave tail is now also fitted with a Planck function rather than a Rayleigh-Jeans approximation.
Spectral variability files made with src/general/make_block_17.f90 will now give variations on a smaller number of "var" bands that will then be mapped to the higher-resolution spectral file sub-bands.
The data type for holding the spectral file information once it is read in has been optimised to reduce memory usage. The most significant changes involve removing high-dimensional arrays that are sparsely filled and replacing them with nested defined types that can be allocated to hold only the required data. These optimisations affect the routines: def_spectrum, read_spectrum, map_sub_bands_mod, radiance_calc, inter_k, out_spectrum and make_block_5.
Code Quality Checklist
(Some checks are automatically carried out via the CI pipeline)
Testing
Socrates stand-alone quick_tests and slow_tests all pass with changes to KGOs when creating block 2 of spectral files (solar spectrum fraction):
LFRic Apps trac.log
Developer LFRic Apps tests all pass (no lfric_apps changes required):
Test Suite Results - lfric_apps - lfric_apps_socrates38_solar/run3
Suite Information
Task Information
✅ succeeded tasks - 1216
UM trac.log
UM tests require a linked UM change for broadcast of the changes to the spectral type: MetOffice/um#143
Test Suite Results - um - um_socrates38_solar/run24
Suite Information
Approvals
Code Owners
Config Owners
No UM Config Owners Required
Task Information
❌ failed tasks - 1
⌛ waiting tasks - 1
Security Considerations
Performance Impact
AI Assistance and Attribution
Documentation
Sci/Tech Review
Please alert the code reviewer via a tag when you have approved the SR
Code Review