Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Refactoring: Esmlab's TimeManager class #139

Closed
andersy005 opened this issue Jun 9, 2019 · 2 comments
Closed

Refactoring: Esmlab's TimeManager class #139

andersy005 opened this issue Jun 9, 2019 · 2 comments
Assignees
Labels
1 - urgent Urgent priority enhancement New feature or request help wanted Extra attention is needed

Comments

@andersy005
Copy link
Contributor

andersy005 commented Jun 9, 2019

It's become obvious that we need to reintroduce the TimeManager back into esmlab due to all complications that arise when dealing with time operations. Having a dedicated TimeManager class will make both maintenance and extending existing functionality easier.

Currently, all time operations are handled by EsmlabAccessor in esmlab/core.py. This approach has some disadvantages due to xarray's accessor limitations. For instance, because xarray's accessors only accept one argument, which is an xarray.Dataset in our case, it's not possible to pass additional attributes/arguments to this class during instantiation. To resolve this issue, I added a somewhat unpleasant hack ds.esmlab.set_time() to allow passing attributes such as year_offset, time_coord_name duringEsmlabAccessor class instantiation.

EsmlabAccessor class has the following:

Properties

  • time_attrs: Get the attributes of the time coordinate.
  • time_bound_attrs: Get the attributes of the time bounds coordinate.

Time Bounds Methods

  • compute_time_bound_diff: Compute the difference between time bounds
  • infer_time_bound_var: Infer time_bound variable in a dataset

Time Methods

  • compute_time: Get the attributes of the time coordinate.
  • compute_time_var: Compute the time coordinate of a dataset
  • decode_arbitrary_time: Decode an arbitrary time var of type number
  • get_time_decoded: Return time decoded
  • get_time_undecoded
  • infer_time_coord_name: Infer name for time coordinate in a dataset
  • isdecoded
  • sel_time: Return dataset truncated to specified time range.
  • set_time: store the original time and time_bound data from the dataset;
    ensure that time_bound, if present, is not decoded.
  • time_year_to_midyeardate: Set the time coordinate to the mid-point of the year.
  • uncompute_time_var: Return time coordinate from object to float.
  • compute_resample_times: Computes time values for resample operations

Miscellaneous Methods

  • get_original_metadata
  • get_variables
  • restore_dataset: Return the original time variable to decoded or undecoded state.
  • update_metadata

Ideally, the new/refactored implementation will address a list of issues that have popped up over time: #128, #116, #118, #126, #111

Comments would be helpful from @matt-long, @kmpaul and any others regarding how to approach this refactoring.

@dcherian
Copy link

passing attributes such as year_offset, time_coord_name

These seem like dataset attributes. Can you not assign these to the Dataset and/or the time DataArray when creating the Dataset and read them when needed?

@andersy005 andersy005 added 1 - urgent Urgent priority enhancement New feature or request help wanted Extra attention is needed and removed feature labels Jul 31, 2019
@andersy005 andersy005 self-assigned this Dec 16, 2019
@maboualidev
Copy link

Sounds good. We should take this up and finish it

@kmpaul kmpaul closed this as completed Jun 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 - urgent Urgent priority enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants