Skip to content

Handling cftime objects #50

@florianboergel

Description

@florianboergel

I am currently using this package to analyze SST data from 950 to 1800. Hence, I need to use cftime objects. Without fixing possible errors with the calendar I came across a problem with the function add_doy().

I'd simply propose a new branch called cftime first that removes

        not_leap_year = ~t.dt.is_leap_year
        doy = doy_original + (not_leap_year & march_or_later)

and adds

        not_leap_year = xr.apply_ufunc(cftime.is_leap_year,
                                       t.dt.year,
                                       input_core_dims=[[]],
                                       output_core_dims=[[]],
                                       kwargs={'calendar': "standard",
                                               "has_year_zero":None},
                                       dask="allowed",
                                       vectorize=True)
        doy = doy_original + (~not_leap_year & march_or_later)

One could also just catch the type of the DatetimeIndex and choose between those two methods. The problem with cftime objects is that they do not have the function is_leap_year. cftime.is_leap_year only takes integers, therefore I needed to use apply_ufunc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions