Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Climax
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
earth_observation_public
Climax
Commits
7584c276
Commit
7584c276
authored
3 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Vanilla implemenation of a PyTorch compliant NetCDF dataset.
parent
efa18e94
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
climax/core/dataset.py
+52
-0
52 additions, 0 deletions
climax/core/dataset.py
with
52 additions
and
0 deletions
climax/core/dataset.py
0 → 100644
+
52
−
0
View file @
7584c276
"""
Dataset classes compliant to the Pytorch standard.
"""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# externals
import
torch
import
numpy
as
np
class
EoDataset
(
torch
.
utils
.
data
.
Dataset
):
@staticmethod
def
to_tensor
(
x
,
dtype
):
"""
Convert ``x`` to :py:class:`torch.Tensor`.
Parameters
----------
x : array_like
The input data.
dtype : :py:class:`torch.dtype`
The data type used to convert ``x``.
The modified class labels.
Returns
-------
x : `torch.Tensor`
The input data tensor.
"""
return
torch
.
tensor
(
np
.
asarray
(
x
).
copy
(),
dtype
=
dtype
)
def
NetCDFDataset
(
EoDataset
):
def
__init__
(
self
,
X
,
y
,
dim
=
'
time
'
):
# NetCDF dataset containing predictor variables (ERA5)
self
.
X
=
X
# NetCDF dataset containing target variable (OBS)
self
.
y
=
y
# dimension along which to sample
self
.
dim
=
dim
def
__len__
(
self
):
return
len
(
self
.
X
[
self
.
dim
])
def
__getitem__
(
self
,
idx
):
return
(
self
.
to_tensor
(
self
.
X
.
isel
(
time
=
idx
),
dtype
=
torch
.
float32
),
self
.
to_tensor
(
self
.
y
.
isel
(
time
=
idx
),
dtype
=
torch
.
float32
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment