MCPcopy Index your code
hub / github.com/pydata/xarray / _random_day_of_year

Function _random_day_of_year

xarray/coding/calendar_ops.py:257–275  ·  view source on GitHub ↗

Return a day of year in the new calendar. Removes Feb 29th and five other days chosen randomly within five sections of 72 days.

(time, target_calendar, use_cftime)

Source from the content-addressed store, hash-verified

255
256
257def _random_day_of_year(time, target_calendar, use_cftime):
258 """Return a day of year in the new calendar.
259
260 Removes Feb 29th and five other days chosen randomly within five sections of 72 days.
261 """
262 year = time.dt.year[0]
263 source_calendar = time.dt.calendar
264 new_doy = np.arange(360) + 1
265 rm_idx = np.random.default_rng().integers(0, 72, 5) + 72 * np.arange(5)
266 if source_calendar == "360_day":
267 for idx in rm_idx:
268 new_doy[idx + 1 :] = new_doy[idx + 1 :] + 1
269 if _days_in_year(year, target_calendar) == 366:
270 new_doy[new_doy >= 60] = new_doy[new_doy >= 60] + 1
271 elif target_calendar == "360_day":
272 new_doy = np.insert(new_doy, rm_idx - np.arange(5), -1)
273 if _days_in_year(year, source_calendar) == 366:
274 new_doy = np.insert(new_doy, 60, -1)
275 return new_doy[time.dt.dayofyear - 1]
276
277
278def _convert_to_new_calendar_with_new_day_of_year(

Callers

nothing calls this directly

Calls 2

_days_in_yearFunction · 0.85
arangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…