cmor icon indicating copy to clipboard operation
cmor copied to clipboard

warning on timesteps written

Open larsbuntemeyer opened this issue 1 year ago • 6 comments

I think this is just a minor issue, but i get a misleading warning when i write several timesteps with cmor.write. For example, using the python5 example, i get the warning:

!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Warning: while closing variable 0 (htovgyre, table Omon)
! we noticed you wrote 0 time steps for the variable,
! but its time axis 0 (time) has 2 time steps
!
!!!!!!!!!!!!!!!!!!!!!!!!!

However, it seems that everything is written correctly and i figured out that i don't get the warning when i pass the number of timesteps explictily, e.g.

cmor.write(cmorVar, data, ntimes_passed=time.size)

However, the documentation states that if omitted, the number will be assumed to be the size of the time dimension of the data (if there is a time dimension). So, this warning is a little misleading because ntimes_passed=time.size should be the default. Just wanted to document it here since it took me some time to figure it out.

larsbuntemeyer avatar Mar 07 '23 10:03 larsbuntemeyer

@mauzey1 this seems like a trivial update, I'll label this against the 3.9.0 milestone as it would be useful to cleanup if there is a sensible solution

@taylor13 ping

durack1 avatar Apr 07 '24 16:04 durack1

Not sure how trivial, but should be corrected, I think. Could be a problem between python and C???

taylor13 avatar May 06 '24 19:05 taylor13

I think this issue might be originating from the following section of the function cmor_write_var_to_file. This is the section that writes the time and time bound values from the axis if ntimes_passed is set to zero. Is it assuming that it is writing data for all of the timesteps in the time axis? If the bounds value of the time axis are not null, then it will set the start of the time values to zero otherwise it will be set to the ntimes_written value of the variable. What is the reasoning for this behavior? Shouldn't the start be set to zero for this case whether or not the bounds are not null?

https://github.com/PCMDI/cmor/blob/7714266a456ecf6b5edf3b826d8e78919c0b9494/Src/cmor_variables.c#L3162-L3248

Near the end of the function outside of the conditional statement for whether ntimes_passed is zero, the ntimes_passed value is added to the variable's ntimes_written value. Should the length of the time axis be added to the ntimes_written value, or should the ntimes_written value be set to the length of the time axis?

https://github.com/PCMDI/cmor/blob/7714266a456ecf6b5edf3b826d8e78919c0b9494/Src/cmor_variables.c#L3277

mauzey1 avatar May 13 '24 19:05 mauzey1

Thanks, Chris, for this nice analysis. I'll try to take a look tomorrow at the. coding and hope to understand how we had hoped to handle this situation. If you don't hear back in a couple of days, could you please ping me? thanks. Karl

taylor13 avatar May 13 '24 23:05 taylor13

I really don't know C well enough to be sure, but I think ntimes_written should actually keep track of how many times have been written to the file. In the case that times_passed is missing, then it should be set within the function (and not remain at a default value of 0. I would simply insert after line 3248 something like ntimes_written = counts[0] (if counts[0] is the number of time written in this call to the function).

By the way a basic question: If an optional integer argument is missing in a call to a function, does it's value get set to 0?

I'll also try to answer one of your other questions:

** Is it assuming that it is writing data for all of the timesteps in the time axis?

I don't think so ... I think it can write some of the time-steps and then add more timesteps on a later call to the function.

** If the bounds value of the time axis are not null, then it will set the start of the time values to zero otherwise it will be set to the ntimes_written value of the variable. What is the reasoning for this behavior? Shouldn't the start be set to zero for this case whether or not the bounds are not null?

I don't know.

Let me know if you think my suggestion above is consistent with your reasoning.

taylor13 avatar May 15 '24 20:05 taylor13

@taylor13

By the way a basic question: If an optional integer argument is missing in a call to a function, does it's value get set to 0?

For the C function of cmor_write, you cannot omit the ntimes_passed parameter from the function call. You must set it to zero if you are using the time dimension size for the number of times passed.

For Fortran and Python, omitting this parameter will set it to a default of zero. The length of the time_vals parameter will be used if it is passed without the ntimes_passed parameter.

mauzey1 avatar May 16 '24 19:05 mauzey1