CWorthy-ocean / roms-tools

Tools for creating input files for UCLA-ROMS simulations
https://roms-tools.readthedocs.io
Apache License 2.0
11 stars 5 forks source link

Weird time values for bry forcing #94

Closed dafyddstephenson closed 3 months ago

dafyddstephenson commented 3 months ago

ROMS actually likes the bgc bry file! 🎉

start_time=dt.datetime(2012,1,1,0,0,0)
end_time=dt.datetime(2012,3,1,0,0,0)
roms_bry = rt.BoundaryForcing(
    grid=roms_grd,
    start_time=start_time,
    end_time=end_time,
    physics_source={"name": "GLORYS", "path": datadir+'GLORYS/mercatorglorys*.nc'},
    bgc_source={"name": "CESM_REGRIDDED",
                "path": datadir+"CESM-climatology_lowres_regridded.nc",
                "climatology": True}
)

... however the values for bry_time look off to me, I assume related to climatology=True? My run is supposed to be in january 2012, but

bds=roms_bry.ds["bgc"].to_dataset()
[dt.datetime(2000,1,1,0,0,0)+dt.timedelta(seconds=float(bds['bry_time'].values[i]*1e-9)) for i in range(len(bds.bry_time))]

returns

[datetime.datetime(2000, 1, 16, 0, 0),
 datetime.datetime(2000, 2, 15, 0, 0),
 datetime.datetime(2000, 3, 15, 0, 0),
 datetime.datetime(2000, 4, 15, 0, 0),
 datetime.datetime(2000, 5, 15, 0, 0),
 datetime.datetime(2000, 6, 15, 0, 0),
 datetime.datetime(2000, 7, 15, 0, 0),
 datetime.datetime(2000, 8, 15, 0, 0),
 datetime.datetime(2000, 9, 15, 0, 0),
 datetime.datetime(2000, 10, 15, 0, 0),
 datetime.datetime(2000, 11, 15, 0, 0),
 datetime.datetime(2000, 12, 15, 0, 0)]

meanwhile for physics:

pds=roms_bry.ds["physics"].to_dataset()
[dt.datetime(2000,1,1,0,0,0)+dt.timedelta(seconds=float(pds['bry_time'].values[i]*1e-9)) for i in range(len(bds.bry_time))]

returns:

[datetime.datetime(2012, 1, 1, 12, 0),
 datetime.datetime(2012, 1, 2, 12, 0),
 datetime.datetime(2012, 1, 3, 12, 0),
 datetime.datetime(2012, 1, 4, 12, 0),
 datetime.datetime(2012, 1, 5, 12, 0),
 datetime.datetime(2012, 1, 6, 12, 0),
 datetime.datetime(2012, 1, 7, 12, 0),
 datetime.datetime(2012, 1, 8, 12, 0),
 datetime.datetime(2012, 1, 9, 12, 0),
 datetime.datetime(2012, 1, 10, 12, 0),
 datetime.datetime(2012, 1, 11, 12, 0),
 datetime.datetime(2012, 1, 12, 12, 0)]

as expected.

So all of the bgc bry values are in 2000, when my run is in 2012, and there doesn't appear to be anything in the metadata telling ROMS that this is a special case. I would expect ROMS to error out on initialisation in this case, but it doesn't. I'm not sure the behaviour that follows within ROMS is expected, just that there isn't an error. Could you explain? Thanks!

NoraLoose commented 3 months ago

The bry_time variable has an attribute cycle_length that is filled with the value 365.25. If cycle_length is present, ROMS will just cycle through these dates (iteratively adding cycle_length) until the dates hit the actual range of the run.

In case of a climatology (as here), bry_time will just hold the year 2000 values, or whatever is closest to the reference time. If this is confusing, I can change it to year 2012 values or whatever is the first covered year of the simulation (based on start_time).

By the way, instead of doing

bds=roms_bry.ds["bgc"].to_dataset()
[dt.datetime(2000,1,1,0,0,0)+dt.timedelta(seconds=float(bds['bry_time'].values[i]*1e-9)) for i in range(len(bds.bry_time))]

you could have just looked at roms_bry.ds["bgc"]["abs_time"], which should hold the same values. ;)

dafyddstephenson commented 3 months ago

abs_time and bry_time output the same thing for me!

xarray.DataArray
'abs_time'

    bry_time: 12

    array([ 1296000000000000,  3888000000000000,  6393600000000000,
            9072000000000000, 11664000000000000, 14342400000000000,
           16934400000000000, 19612800000000000, 22291200000000000,
           24883200000000000, 27561600000000000, 30153600000000000],
          dtype='timedelta64[ns]')

    Coordinates:
        abs_time
        (bry_time)
        timedelta64[ns]
        15 days 45 days ... 349 days
        bry_time
        (bry_time)
        timedelta64[ns]
        15 days 45 days ... 349 days
NoraLoose commented 3 months ago

Oh true, in the case of a climatology... Sorry!

NoraLoose commented 3 months ago

Can this issue be closed @dafyddstephenson? Or what do you think about this:

In case of a climatology (as here), bry_time will just hold the year 2000 values, or whatever is closest to the reference time. If this is confusing, I can change it to year 2012 values or whatever is the first covered year of the simulation (based on start_time).

dafyddstephenson commented 3 months ago

It can be closed, though I'd maybe suggest an attribute that indicates it's a climatology in a more human-readable format, and for abs_time to be formatted differently in this case - What do you think?

NoraLoose commented 3 months ago

Both good ideas! I will work on those.

NoraLoose commented 3 months ago

The attribute should maybe be global, rather than one of bry_time?