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
f3f1c003
Commit
f3f1c003
authored
3 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Implemented generic computation of anomalies on arbitrary time-scale.
parent
f5f984f4
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
+47
-0
47 additions, 0 deletions
climax/core/dataset.py
with
47 additions
and
0 deletions
climax/core/dataset.py
+
47
−
0
View file @
f3f1c003
...
...
@@ -6,6 +6,7 @@
# builtins
import
logging
import
pathlib
import
warnings
from
datetime
import
date
# externals
...
...
@@ -232,6 +233,52 @@ class EoDataset(torch.utils.data.Dataset):
return
dem_features
@staticmethod
def
anomalies
(
ds
,
timescale
=
'
time.dayofyear
'
,
standard
=
False
):
# group dataset by day of the year
LOGGER
.
info
(
'
Computing standardized anomalies ...
'
)
groups
=
ds
.
groupby
(
'
time.dayofyear
'
).
groups
# compute standardized anomalies for each day of the year over time
anomalies
=
{}
for
time
,
time_scale
in
groups
.
items
():
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
'
ignore
'
,
category
=
RuntimeWarning
)
# anomaly = (x(t) - mean(x, t))
anomalies
[
time
]
=
(
ds
.
isel
(
time
=
time_scale
)
-
ds
.
isel
(
time
=
time_scale
).
mean
(
dim
=
'
time
'
))
# standardized anomaly = (x(t) - mean(x, t)) / std(x, t)
if
standard
:
anomalies
[
time
]
=
(
anomalies
[
time
]
/
ds
.
isel
(
time
=
time_scale
).
std
(
dim
=
'
time
'
)
)
# concatenate anomalies and sort chronologically
anomalies
=
xr
.
concat
(
anomalies
.
values
(),
dim
=
'
time
'
)
anomalies
=
anomalies
.
sortby
(
anomalies
.
time
)
return
anomalies
@staticmethod
def
normalize
(
ds
,
dim
=
(
'
time
'
,
'
y
'
,
'
x
'
),
period
=
None
):
# normalize predictors to [0, 1]
LOGGER
.
info
(
'
Normalizing data to [0, 1] ...
'
)
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
'
ignore
'
,
category
=
RuntimeWarning
)
# whether to normalize using statistics for a specific period
# NOTE: this can result in values that are not in [0, 1]
if
period
is
not
None
:
ds
-=
ds
.
sel
(
time
=
period
).
min
(
dim
=
dim
)
ds
/=
ds
.
sel
(
time
=
period
).
max
(
dim
=
dim
)
# normalize using entire period: [0, 1]
else
:
ds
-=
ds
.
min
(
dim
=
dim
)
ds
/=
ds
.
max
(
dim
=
dim
)
return
ds
class
NetCDFDataset
(
EoDataset
):
...
...
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