Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toargridding
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
esde
toar-public
toargridding
Commits
8397c4b3
Commit
8397c4b3
authored
1 year ago
by
Carsten Hinz
Browse files
Options
Downloads
Patches
Plain Diff
TimeSample: resolved TODO on restricted selection of values for sampling
added first documentation to classes and their methods
parent
e551d40b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Creation of first beta release version
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
toargridding/metadata.py
+38
-7
38 additions, 7 deletions
toargridding/metadata.py
toargridding/toar_rest_client.py
+5
-0
5 additions, 0 deletions
toargridding/toar_rest_client.py
with
43 additions
and
7 deletions
toargridding/metadata.py
+
38
−
7
View file @
8397c4b3
...
...
@@ -5,7 +5,7 @@ from dataclasses import dataclass
import
numpy
as
np
import
pandas
as
pd
from
toargridding.toarstats_constants
import
STATISTICS_LIST
from
toargridding.toarstats_constants
import
STATISTICS_LIST
,
ALLOWED_SAMPLING_VALUES
from
toargridding.static_metadata
import
global_cf_attributes
,
TOARVariable
date_created
=
datetime
.
utcnow
().
strftime
(
"
%Y-%m-dT%H:%M:%SZ
"
)
...
...
@@ -21,26 +21,57 @@ Variables = Enum("Variables", [*DATA_VARIABLES, *COORDINATE_VARIABLES])
TIME_FREQUENCIES
=
{
"
daily
"
:
"
D
"
,
"
monthly
"
:
"
M
"
,
"
yearly
"
:
"
Y
"
}
# TODO test
# TODO allow only valid sampling strings
@dataclass
class
TimeSample
:
"""
Sampling in time
provides conversion into different formats
"""
start
:
datetime
end
:
datetime
sampling
:
str
def
as_datetime_index
(
self
):
@property
def
sampling
(
self
)
->
str
:
# TODO make better
"""
sampling for data request
Sampling, i.e. the period used for the calculation of a parameters within the TOAD DB
Allows only a limited number of supported sampling durations see toargridding.toarstats_constants.ALLOWED_SAMPLING_VALUES
"""
return
self
.
_sampling
@sampling.setter
def
sampling
(
self
,
sampling
:
str
):
if
sampling
not
in
ALLOWED_SAMPLING_VALUES
:
raise
ValueError
(
f
"
sampling:
{
sampling
}
is not in the list of supported samplings for toargridding.
"
)
self
.
_sampling
=
sampling
def
as_datetime_index
(
self
)
->
pd
.
DatetimeIndex
:
"""
Conversion to array with all sampled time points
"""
return
pd
.
period_range
(
self
.
start
,
self
.
end
,
freq
=
self
.
frequency
).
to_timestamp
()
@property
def
daterange_option
(
self
):
def
daterange_option
(
self
)
->
str
:
"""
Conversion of range to a string
Range is given as start<=incuded days < end
"""
end_with_padding
=
self
.
end
+
timedelta
(
1
)
return
f
"
{
self
.
start
.
isoformat
()
}
,
{
end_with_padding
.
isoformat
()
}
"
@property
def
frequency
(
self
):
def
frequency
(
self
)
->
str
:
"""
Converts sampling argument from TOAR to Pandas
"""
return
TIME_FREQUENCIES
[
self
.
sampling
]
def
as_cf_index
(
self
):
def
as_cf_index
(
self
)
->
np
.
array
:
"""
conversion to netCDF Climate and Forecast (CF) Metadata Convertions
Calculates the duration in days relative to start time point.
"""
n_days
=
(
self
.
end
-
self
.
start
).
days
return
np
.
arange
(
n_days
+
1
)
...
...
This diff is collapsed.
Click to expand it.
toargridding/toar_rest_client.py
+
5
−
0
View file @
8397c4b3
...
...
@@ -32,6 +32,9 @@ class QueryOptions:
@staticmethod
def
from_metadata
(
metadata
:
Metadata
):
"""
Creation from Metadata object
"""
return
QueryOptions
(
daterange
=
metadata
.
time
.
daterange_option
,
variable_id
=
str
(
metadata
.
variable
.
toar_id
),
...
...
@@ -41,6 +44,8 @@ class QueryOptions:
@property
def
cache_key
(
self
):
"""
creation to identify the request in the cache of known request.
"""
return
""
.
join
(
asdict
(
self
).
values
())
...
...
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