Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GeoPEAS
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
Container registry
Model registry
Operate
Environments
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-data
GeoPEAS
Commits
4f4184f4
Commit
4f4184f4
authored
5 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
can pass additional options for allowed agg functions in View inits
parent
93e2fc7e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
climatic_zones/views.py
+2
-1
2 additions, 1 deletion
climatic_zones/views.py
utils/extraction_tools.py
+5
-4
5 additions, 4 deletions
utils/extraction_tools.py
utils/views_commons.py
+19
-4
19 additions, 4 deletions
utils/views_commons.py
with
26 additions
and
9 deletions
climatic_zones/views.py
+
2
−
1
View file @
4f4184f4
...
...
@@ -26,7 +26,8 @@ class ClimateView(APIView, CommonViews):
def
__init__
(
self
):
CommonViews
.
__init__
(
self
)
self
.
keep_only_given_agg_allowed
(
dict
(
maxclass
=
most_common_value
,
frequency
=
relative_frequency
))
frequency
=
relative_frequency
),
frequency
=
dict
(
bins
=
13
))
def
_extract
(
self
,
lat
,
lon
,
radius
,
agg
,
direction
,
by_direction
):
"""
perform actual extraction of desired quantity
"""
...
...
This diff is collapsed.
Click to expand it.
utils/extraction_tools.py
+
5
−
4
View file @
4f4184f4
...
...
@@ -256,9 +256,10 @@ def extract_value_stats(lonvec, latvec, data, lon=-999., lat=-999.,
radius
,
dlon
,
dlat
,
min_valid
=
min_valid
,
max_valid
=
max_valid
,
min_angle
=
min_angle
,
max_angle
=
max_angle
)
# apply statistics
if
agg
is
relative_frequency
:
res
=
relative_frequency
(
subset
,
bins
=
max_valid
+
1
)
else
:
#if agg is relative_frequency:
# res = relative_frequency(subset, bins=max_valid+1)
#else:
# res = agg(subset)
res
=
agg
(
subset
)
if
res
is
None
:
res
=
default_value
...
...
This diff is collapsed.
Click to expand it.
utils/views_commons.py
+
19
−
4
View file @
4f4184f4
...
...
@@ -23,6 +23,7 @@ import numpy as np
from
functools
import
partial
import
toar_location_services.settings
as
settings
from
utils.geoutils
import
Directions
import
inspect
class
CommonViews
:
...
...
@@ -41,9 +42,23 @@ class CommonViews:
def
update_agg_allowed
(
self
):
self
.
AGG_ALLOWED
=
list
(
self
.
STATS
.
keys
())
+
[
'
NN%-ile
'
,
'
NN-percentile
'
]
def
add_agg_allowed
(
self
,
name
,
func
,
update
=
True
):
def
load_kwargs
(
self
,
args_dict
,
func
):
# check kwargs for usage
args
=
{}
for
k
,
v
in
args_dict
.
items
():
if
inspect
.
getargspec
(
func
):
args
[
k
]
=
v
def
add_agg_allowed
(
self
,
name
,
func
,
update
=
True
,
**
kwargs
):
# add only if not already present
if
str
(
name
)
not
in
self
.
STATS
.
keys
():
if
name
not
in
kwargs
.
keys
():
self
.
STATS
[
str
(
name
)]
=
func
else
:
self
.
STATS
[
str
(
name
)]
=
partial
(
func
,
**
kwargs
[
name
])
# if len(args.keys()) == 0:
# self.STATS[str(name)] = func
if
update
:
self
.
update_agg_allowed
()
...
...
@@ -53,12 +68,12 @@ class CommonViews:
if
update
:
self
.
update_agg_allowed
()
def
keep_only_given_agg_allowed
(
self
,
agg_dict
):
def
keep_only_given_agg_allowed
(
self
,
agg_dict
,
**
kwargs
):
for
name
in
list
(
self
.
STATS
.
keys
()):
if
name
not
in
agg_dict
.
keys
():
self
.
remove_agg_allowed
(
name
,
update
=
False
)
for
name
,
func
in
agg_dict
.
items
():
self
.
add_agg_allowed
(
name
,
func
,
update
=
False
)
self
.
add_agg_allowed
(
name
,
func
,
update
=
False
,
**
kwargs
)
self
.
update_agg_allowed
()
def
get_agg_param
(
self
,
params
):
...
...
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