Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FINAM
finam
Commits
71f1401d
Commit
71f1401d
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
fix for importing opensimplex, add to dependencies
parent
e1ea978a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!131
Simplex noise generator
Pipeline
#123558
passed with stages
Stage: test
Stage: build
in 2 minutes and 58 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
src/finam/modules/noise.py
+35
-34
35 additions, 34 deletions
src/finam/modules/noise.py
with
36 additions
and
34 deletions
pyproject.toml
+
1
−
0
View file @
71f1401d
...
...
@@ -44,6 +44,7 @@ dependencies = [
"cf_xarray>
=
0.7
.
4
",
"pyproj>
=
3.4
",
"pandas>
=
1.3
",
"opensimplex>
=
0.4
",
]
[project.urls]
...
...
This diff is collapsed.
Click to expand it.
src/finam/modules/noise.py
+
35
−
34
View file @
71f1401d
...
...
@@ -2,6 +2,7 @@
import
datetime
as
dt
import
numpy
as
np
import
opensimplex
as
ox
from
finam.data.grid_spec
import
NoGrid
,
UnstructuredGrid
from
finam.data.tools
import
Info
...
...
@@ -106,17 +107,15 @@ class SimplexNoise(Component):
if
not
self
.
_is_ready
:
return
None
import
opensimplex
as
ox
ox
.
seed
(
self
.
_seed
)
grid
=
self
.
_info
.
grid
t
=
(
time
-
dt
.
datetime
(
1900
,
1
,
1
)).
total_seconds
()
if
isinstance
(
grid
,
UnstructuredGrid
):
func
=
self
.
_generate_unstructured
func
=
_generate_unstructured
else
:
func
=
self
.
_generate_structured
func
=
_generate_structured
amp
=
1.0
max_amp
=
0.0
...
...
@@ -125,9 +124,9 @@ class SimplexNoise(Component):
for
i
in
range
(
self
.
_octaves
):
if
i
==
0
:
data
=
func
(
grid
,
t
*
freq_t
,
freq
,
ox
)
data
=
func
(
grid
,
t
*
freq_t
,
freq
)
else
:
data
+=
amp
*
func
(
grid
,
t
*
freq_t
,
freq
,
ox
)
data
+=
amp
*
func
(
grid
,
t
*
freq_t
,
freq
)
max_amp
+=
amp
amp
*=
self
.
_persistence
freq
*=
2.0
...
...
@@ -138,36 +137,38 @@ class SimplexNoise(Component):
return
data
def
_generate_structured
(
self
,
grid
,
t
,
freq
,
ox
):
if
grid
.
dim
==
1
:
data
=
ox
.
noise2array
(
grid
.
data_axes
[
0
]
*
freq
,
np
.
asarray
([
t
]))
if
grid
.
dim
==
2
:
data
=
ox
.
noise3array
(
grid
.
data_axes
[
0
]
*
freq
,
grid
.
data_axes
[
1
]
*
freq
,
np
.
asarray
([
t
])
)
if
grid
.
dim
==
3
:
data
=
ox
.
noise4array
(
grid
.
data_axes
[
0
]
*
freq
,
grid
.
data_axes
[
1
]
*
freq
,
grid
.
data_axes
[
2
]
*
freq
,
np
.
asarray
([
t
]),
)
return
data
[
0
,
...].
T
def
_generate_structured
(
grid
,
t
,
freq
):
if
grid
.
dim
==
1
:
data
=
ox
.
noise2array
(
grid
.
data_axes
[
0
]
*
freq
,
np
.
asarray
([
t
]))
if
grid
.
dim
==
2
:
data
=
ox
.
noise3array
(
grid
.
data_axes
[
0
]
*
freq
,
grid
.
data_axes
[
1
]
*
freq
,
np
.
asarray
([
t
])
)
if
grid
.
dim
==
3
:
data
=
ox
.
noise4array
(
grid
.
data_axes
[
0
]
*
freq
,
grid
.
data_axes
[
1
]
*
freq
,
grid
.
data_axes
[
2
]
*
freq
,
np
.
asarray
([
t
]),
)
return
data
[
0
,
...].
T
def
_generate_unstructured
(
self
,
grid
,
t
,
freq
,
ox
):
points
=
grid
.
data_points
data
=
np
.
full
((
grid
.
point_count
,),
0.0
,
dtype
=
float
)
def
_generate_unstructured
(
grid
,
t
,
freq
):
if
grid
.
dim
==
1
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise2
(
p
[
0
]
*
freq
,
t
)
elif
grid
.
dim
==
2
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise3
(
p
[
0
]
*
freq
,
p
[
1
]
*
freq
,
t
)
elif
grid
.
dim
==
3
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise4
(
p
[
0
]
*
freq
,
p
[
1
]
*
freq
,
p
[
2
]
*
freq
,
t
)
points
=
grid
.
data_points
data
=
np
.
full
((
grid
.
point_count
,),
0.0
,
dtype
=
float
)
return
data
if
grid
.
dim
==
1
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise2
(
p
[
0
]
*
freq
,
t
)
elif
grid
.
dim
==
2
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise3
(
p
[
0
]
*
freq
,
p
[
1
]
*
freq
,
t
)
elif
grid
.
dim
==
3
:
for
i
,
p
in
enumerate
(
points
):
data
[
i
]
=
ox
.
noise4
(
p
[
0
]
*
freq
,
p
[
1
]
*
freq
,
p
[
2
]
*
freq
,
t
)
return
data
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