Open sunt05 opened 1 year ago
The interesting exploration by @DanLi-BU does reminds me of the coupling work we did a while ago for WRF-SUEWS.
- But then when there is indeed valid NUDAPT data (as we did in previous weeks), how does
real.exe
"pass"STDH_URB2D
, as well asHGT_URB2D
, to wrf.exe throughwrfinput_d0x
? Does this have anything to do with thisgrid%
? Interesting...
And it's right - the custom variables in wrfinput
are indeed loaded via the grid%xx
derived type - see here
So we will need to tweak the related part in module_first_rk_step_part1.F
to get this working (hopefully...).
This is the modified wrfinput_d04. I changed STDH_URB2D
but there are no effects.
This is the namelist.
Please upload all input files so I can run this case at my side.
wrfinput_d01.zip wrfinput_d02.zip wrfinput_d03.zip wrfinput_d04.zip
wrfinput_d01_mod.nc.zip wrfinput_d02_mod.nc.zip wrfinput_d03_mod.nc.zip wrfinput_d04_mod.nc.zip
wrfbdy_d01 1.zip.001.zip wrfbdy_d01 1.zip.002.zip wrfbdy_d01 1.zip.003.zip wrfbdy_d01 1.zip.004.zip wrfbdy_d01 1.zip.005.zip wrfbdy_d01 1.zip.006.zip
This is the code I used to modify the wrfinputs
_Now we've resolved an issue with the STDH_URB2D
variable, which lost its metadata during a Python-based modification process - just wanted to write down the interesting debugging journey that might help fellow WRF users/coders._
🔍 Initial Search & Dead Ends
STDH_URB2D
was loaded from within the WRF input files.STDH_URB2D
, but no clear reason why it showed zeros instead of expected values after running WRF.💡 Breakthrough with Compilation Files
Turned our attention to intermediate .f90
files generated during compilation.
Used VSCode and its Fortran plugin, which made locating references easier.
Found key insights in share/mediation_wrfmain.F
:
https://github.com/DanLi-BU/WRF/blob/b9a794dfa12806d60de24714d1a7a0203896a37c/share/mediation_wrfmain.F#L70
Further details were hidden behind macros here: https://github.com/DanLi-BU/WRF/blob/b9a794dfa12806d60de24714d1a7a0203896a37c/share/mediation_wrfmain.F#L76
🛠️ Debugging Steps Taken
Implemented some debug lines using the existing code structure:
WRITE ( message , FMT = '("processing wrfinput file (stream 0) for domain ",I8)' ) grid%id
CALL wrf_debug ( 100 , message )
Remember to adjust the debug_level
in your namelist.input
!
Added checks right after reading the NetCDF file revealed unexpected all-zero values for grid%stdh_urb2d
.
🕵️♂️ Comparing Variables
Checked another urban-related variable, frc_urb2d
, which loaded correctly – indicating an isolated issue with just one variable.
✅ Solution Identified
A few lines of quick xarray
code pinpointed that while modifying values, we didn't preserve attributes (attrs
).
The fix? Modify only the necessary variable values rather than replacing entire objects.
This is the code I used to modify the wrfinputs
Below is the core part of the zipped ipynb
:
Updated version:
The following is drafted by @DanLi-BU with light edits by @sunt05
OK, now at least I think I can elaborate my questions clearly. Here they are:
wrfinput_d04
(attached), there is a variable calledBUILD_HEIGHT
, which corresponds toHGT_URB2D
in the WRF code according to this line inRegistry.EM_COMMON
:https://github.com/DanLi-BU/WRF/blob/3dd1546ba425b5e77d682dd92253738416b3cb0a/Registry/Registry.EM_COMMON#L813
HGT_URB2D
/BUILD_HEIGHT
is one of the key variables in NUDAPT. IfHGT_URB2D
is larger than 0, it will trigger using NUDAPT, see https://ral.ucar.edu/sites/default/files/public/product-tool/NUDAPT_44_Documentation.pdf This is also corroborated by looking at the functionurban_var_init
inmodule_sf_urban.F
Here is the question. If I manually modified
BUILD_HEIGHT
inwrfinput_d04
, say make it 10 m everywhere, and save it asBUILD_HEIGHT
inwrfinput_d04
. This has NO effect on my WRF results. Well, now that I think about it more, I start to understand why, because WRF actually never has a variable calledBUILD_HEIGHT
(or never reads in a variable calledBUILD_HEIGHT
fromwrfinput_d0x
). The variable name in the code isHGT_URB2D
, even thoughBUILD_HEIGHT
is the variable name inwrfinput_d04
.Similarly (but also not exactly), there is a variable called
STDH_URB2D
inwrfinput_d04
(again see attached), which is also called STDH_URB2D in the WRF code.https://github.com/DanLi-BU/WRF/blob/3dd1546ba425b5e77d682dd92253738416b3cb0a/Registry/Registry.EM_COMMON#L815
But when I modified it, there was again no effect on the WRF outputs.
STDH_URB2D
in all.F
files and here is what I got:My understanding is that
STDH_URB2D
is created after run real.exe (the line of code highlighted earlier, also see here, but there was never a place where the WRF model "reads in" the variableSTDH_URB2D
fromwrfinput_d04
. So it makes sense that modifying it does not affect the simulation results.But then when there is indeed valid NUDAPT data (as we did in previous weeks), how does
real.exe
"pass"STDH_URB2D
, as well asHGT_URB2D
, to wrf.exe throughwrfinput_d0x
? Does this have anything to do with thisgrid%
? Interesting...