Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dataset and data variable wrappers to apply common operations upon opening #80

Closed
6 tasks done
tomvothecoder opened this issue Jul 6, 2021 · 3 comments · Fixed by #81
Closed
6 tasks done
Assignees
Labels
type: enhancement New enhancement request

Comments

@tomvothecoder
Copy link
Collaborator

tomvothecoder commented Jul 6, 2021

Is your feature request related to a problem? If yes, Please describe

CDAT users commonly work on a single TransientVariable of a dataset, which is equivalent to a single xarray Dataset data variable of type DataArray. However, an xarray data variable does not link to other data variables. This means that the extracted data variable does not have access to any existing axis bounds (also data variables).

Describe your proposed solution

Acceptance Criteria

  1. Add open_dataset function to open a dataset and generate bounds if they don't exist.
    • Extensible for additional operations.
    • Add call to generate bounds if it doesn't exist
  2. Add open_variable function to open a data variable with axis bounds (passed from parent Dataset). Replicates CDAT TransientVariable.
    • Extensible for additional operations
    • Add DataArray accessor to add additional attributes to DataArray class (to store bounds info)
    • Show all attributes of accessor class (just use __dict__)
    • Take into account dataset's calendar (EDIT: not needed, but keep calendar type in encoding if available)
      • I don’t think the calendar type affects the algorithm for generating a date range. Non-CF units “months since…” or “years since…” don’t factor the number of days in a month.
      • pd.date_range() generates proleptic_gregorian datetime values

Describe alternatives solutions you've considered

  • On creation of the variable (easiest for the user): tas = ds.tas
    • Not possible because this is native xarray syntax, which requires extending via subclassing (not recommended) or xarray accessors.
  • On dataset open: ds = xcdat.load_dataset(filename) [this would embed the bounds in the relevant variables so that they are included in ds.tas]
    • Not possible, I found Dataset data variables don't preserve custom attributes via DataArray accessors

Additional context

@tomvothecoder tomvothecoder added the type: enhancement New enhancement request label Jul 6, 2021
@tomvothecoder tomvothecoder self-assigned this Jul 6, 2021
@tomvothecoder tomvothecoder changed the title Add open_dataset wrapper to apply common operations upon opening Add open_dataset wrapper to apply common operations initially Jul 6, 2021
@tomvothecoder
Copy link
Collaborator Author

Hey @pochedls, let me know if there are any other common operations that should be performed.

@pochedls
Copy link
Collaborator

pochedls commented Jul 6, 2021

@tomvothecoder - an issue that arose that inspired this ticket was that xarray does not read a pretty common time unit "months since." I'm wondering if open_dataset could be used to deal with issues like this (though perhaps not in the initial release)?

@tomvothecoder
Copy link
Collaborator Author

@pochedls Thanks, this ticket extracts the easier items from #77. I'll continue the conversation specific to that issue on #77.

@tomvothecoder tomvothecoder changed the title Add open_dataset wrapper to apply common operations initially Add wrapper to apply common operations initially Jul 7, 2021
@tomvothecoder tomvothecoder changed the title Add wrapper to apply common operations initially Add Dataset and data variable wrappers to apply common operations upon opening Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New enhancement request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants