Skip to content
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

sflux time shifts if it's not hour 00 based #141

Open
SorooshMani-NOAA opened this issue Nov 13, 2024 · 1 comment
Open

sflux time shifts if it's not hour 00 based #141

SorooshMani-NOAA opened this issue Nov 13, 2024 · 1 comment

Comments

@SorooshMani-NOAA
Copy link
Contributor

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:

dst['time'].base_date = (
nc_start_date.year,
nc_start_date.month,
nc_start_date.day,
0)
dst['time'][:] = [
(localize_datetime(x) - nc_start_date) / timedelta(days=1)
for x in variable.datetime_array]

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:

def read(cls, path, sflux_1_glob="*_1.*", sflux_2_glob="*_2.*"):
path = pathlib.Path(path)
sflux_2 = list(path.glob(sflux_2_glob))
return cls(
sflux_1=SfluxDataset(list(path.glob(sflux_1_glob))),
sflux_2=SfluxDataset(sflux_2) if len(sflux_2) > 0 else None,
)

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.

@josephzhang8
Copy link
Member

It's a potential trap for users for sure and I've been thinking about removing the 'hour' in base_date, because it's actually not read in; see:

https://schism-dev.github.io/schism/master/input-output/sflux.html

Instead the hour offset is specified in param.nml (utc_start).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants