pyschism icon indicating copy to clipboard operation
pyschism copied to clipboard

`sflux` time shifts if it's not hour `00` based

Open SorooshMani-NOAA opened this issue 11 months ago • 1 comments

While working on setting up sflux ensemble based on HAFS and GEFS I realized that if the sflux "input" files (e.g. what I generate from HAFS or GEFS) then pyschism incorrectly shifts the time vector:

https://github.com/schism-dev/pyschism/blob/00b1137d2a87366d41fc7aa93ddc3af31776c03b/pyschism/forcing/nws/nws2/sflux.py#L331-L338

This is because the schism sflux time hour 00 based, but the vector differences for sflux_*.nc file are calculated based on the actual input .nc file's base time. So for example if I have the following time vector in my custom input nc file:

array(['2023-08-14T18:00:00.000000000', '2023-08-15T00:00:00.000000000',
       '2023-08-15T06:00:00.000000000', '2023-08-15T12:00:00.000000000',
       '2023-08-15T18:00:00.000000000', '2023-08-16T00:00:00.000000000',
       '2023-08-16T06:00:00.000000000', '2023-08-16T12:00:00.000000000',
       '2023-08-16T18:00:00.000000000', '2023-08-17T00:00:00.000000000',
       '2023-08-17T06:00:00.000000000', '2023-08-17T12:00:00.000000000',
       '2023-08-17T18:00:00.000000000', '2023-08-18T00:00:00.000000000',
       '2023-08-18T06:00:00.000000000', '2023-08-18T12:00:00.000000000',
       '2023-08-18T18:00:00.000000000', '2023-08-19T00:00:00.000000000',
       '2023-08-19T06:00:00.000000000', '2023-08-19T12:00:00.000000000',
       '2023-08-19T18:00:00.000000000', '2023-08-20T00:00:00.000000000',
       '2023-08-20T06:00:00.000000000', '2023-08-20T12:00:00.000000000',
       '2023-08-20T18:00:00.000000000', '2023-08-21T00:00:00.000000000',
       '2023-08-21T06:00:00.000000000', '2023-08-21T12:00:00.000000000',
       '2023-08-21T18:00:00.000000000', '2023-08-22T00:00:00.000000000',
       '2023-08-22T06:00:00.000000000', '2023-08-22T12:00:00.000000000',
       '2023-08-22T18:00:00.000000000', '2023-08-23T00:00:00.000000000',
       '2023-08-23T06:00:00.000000000', '2023-08-23T12:00:00.000000000',
       '2023-08-23T18:00:00.000000000', '2023-08-24T00:00:00.000000000',
       '2023-08-24T06:00:00.000000000'], dtype='datetime64[ns]')

then I get the following time in the final sflux file sflux_air_1.0001.nc written by pyschism:

array(['2023-08-14T00:00:00.000000000', '2023-08-14T06:00:00.000000000',
       '2023-08-14T12:00:00.000000000', '2023-08-14T18:00:00.000000000',
       '2023-08-15T00:00:00.000000000', '2023-08-15T06:00:00.000000000',
       '2023-08-15T12:00:00.000000000', '2023-08-15T18:00:00.000000000',
       '2023-08-16T00:00:00.000000000', '2023-08-16T06:00:00.000000000',
       '2023-08-16T12:00:00.000000000', '2023-08-16T18:00:00.000000000',
       '2023-08-17T00:00:00.000000000', '2023-08-17T06:00:00.000000000',
       '2023-08-17T12:00:00.000000000', '2023-08-17T18:00:00.000000000',
       '2023-08-18T00:00:00.000000000', '2023-08-18T06:00:00.000000000',
       '2023-08-18T12:00:00.000000000', '2023-08-18T18:00:00.000000000',
       '2023-08-19T00:00:00.000000000', '2023-08-19T06:00:00.000000000',
       '2023-08-19T12:00:00.000000000', '2023-08-19T18:00:00.000000000',
       '2023-08-20T00:00:00.000000000', '2023-08-20T06:00:00.000000000',
       '2023-08-20T12:00:00.000000000', '2023-08-20T18:00:00.000000000',
       '2023-08-21T00:00:00.000000000', '2023-08-21T06:00:00.000000000',
       '2023-08-21T12:00:00.000000000', '2023-08-21T18:00:00.000000000',
       '2023-08-22T00:00:00.000000000', '2023-08-22T06:00:00.000000000',
       '2023-08-22T12:00:00.000000000', '2023-08-22T18:00:00.000000000',
       '2023-08-23T00:00:00.000000000', '2023-08-23T06:00:00.000000000',
       '2023-08-23T12:00:00.000000000'], dtype='datetime64[ns]')

I know that I'm using custom input .nc file as SfluxDataset, but still I'm not sure if this is intentional (i.e. I need to make sure my input .nc file dates are 00 based) or a bug!

Note that I call this function to read the custom .nc file I generate from HAFS or GEFS: https://github.com/schism-dev/pyschism/blob/00b1137d2a87366d41fc7aa93ddc3af31776c03b/pyschism/forcing/nws/nws2/nws2.py#L35-L41

Is this not meant to be used on a generic .nc file? My .nc file has all the required variables, it just doesn't have hour 00 based time.

SorooshMani-NOAA avatar Nov 13 '24 21:11 SorooshMani-NOAA