Conversion to julian date of cycle dates

Hi there. Our code mostly works with julian dates and starting from the cycle date, I need to set environment variables for start and end of each of each cycle in julian date format. What would be the best way to do this?
Cheers!
Gaby

Is this Julian dates as used in astronomy?

Using the formula from Wikipedia

(1461 ร— (Y + 4800 + (M โˆ’ 14)/12))/4 +(367 ร— (M โˆ’ 2 โˆ’ 12 ร— ((M โˆ’ 14)/12)))/12 โˆ’ (3 ร— ((Y + 4900 + (M - 14)/12)/100))/4 + D โˆ’ 32075

Iโ€™d say the best way to do this might be using a python script and the isodatetime library

Quick script to illustrate; made with assistance of GitHub Copilot; Iโ€™ve not tested this:

from metomi.isodatetime.datetimeoper import DateTimeOperator

cycle_point, _ = DateTimeOperator().date_parse('ref')  # uses $CYLC_TASK_CYCLE_POINT

julian_date = (
    1461 * (
        cycle_point.year + 4800 + (cycle_point.month_of_year - 14) // 12
    )
) // 4 + (
    367 * (
        cycle_point.month_of_year - 2 - 12 * ((cycle_point.month_of_year - 14) // 12)
    )
) // 12 - (
    3 * ((cycle_point.year + 4900 + (cycle_point.month_of_year - 14) // 12) // 100)
) // 4 + cycle_point.day_of_month - 32075

You could make a pull request to the open source Metomi-Isodatetime library used by Cylc to add a Julian Cycling mode. Effectively just some data inputting at isodatetime/metomi/isodatetime/data.py at master ยท metomi/isodatetime ยท GitHub

Oh and I guess I missed this out: you should be able to import the script in Jinja2 in the workflow in order to set the environment variables. See Jinja2 โ€” Cylc 8.3.0 documentation

Ha, I will need to figure out which kind of Julian date they are taking about. Apparently there are different versions being used :dizzy_face:, but thanx for the tip about using a script

1 Like