Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Detection eddies
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
IPSL
LMD
DPAO
Detection eddies
Commits
14ef373f
Commit
14ef373f
authored
2 years ago
by
Lionel GUEZ
Browse files
Options
Downloads
Patches
Plain Diff
Polish
parent
7360b14c
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
cost_function.py
+15
-15
15 additions, 15 deletions
cost_function.py
with
15 additions
and
15 deletions
cost_function.py
+
15
−
15
View file @
14ef373f
...
...
@@ -244,13 +244,13 @@ for n in g.vertices():
for
edge
in
g
.
edges
():
source_node
=
edge
.
source
()
target_node
=
edge
.
target
()
cf
=
-
10000
lat_for_conv
=
(
g
.
vp
.
pos_last
[
source_node
][
1
]
+
lat_for_conv
=
(
g
.
vp
.
pos_last
[
source_node
][
1
]
+
g
.
vp
.
pos_first
[
target_node
][
1
])
/
2
# latitude needed for conversion of degrees to kilometers
lat_for_conv
=
math
.
radians
(
lat_for_conv
)
# need to convert to radians
# because of the wrapping issue (360° wrapping incorrectly to 0°), we check for that here
lon_diff
=
abs
(
g
.
vp
.
pos_last
[
source_node
][
0
]
-
g
.
vp
.
pos_first
[
target_node
][
0
])
if
(
lon_diff
>
300
):
...
...
@@ -258,38 +258,38 @@ for edge in g.edges():
# calculate Delta_cent: numbers used for conversion obtained from:
# https://stackoverflow.com/questions/1253499/simple-calculations-for-working-with-lat-lon-and-km-distance
Delta_Cent
=
math
.
sqrt
((
lon_diff
*
111.32
*
math
.
cos
(
lat_for_conv
)
)
**
2
+
Delta_Cent
=
math
.
sqrt
((
lon_diff
*
111.32
*
math
.
cos
(
lat_for_conv
)
)
**
2
+
(
(
g
.
vp
.
pos_last
[
source_node
][
1
]
-
g
.
vp
.
pos_first
[
target_node
][
1
])
*
110.574
)
**
2
)
# calculate the first term
first_term
=
((
Delta_Cent
-
delta_cent_mean
)
/
delta_cent_std
)
**
2
# Rossbies:
# Rossbies:
if
(
g
.
vp
.
first_av_ros
[
target_node
]
and
g
.
vp
.
last_av_ros
[
source_node
]):
Delta_Ro
=
g
.
vp
.
last_av_ros
[
source_node
]
-
g
.
vp
.
first_av_ros
[
target_node
]
else
:
print
(
"
At least one of the rossbies is invalid.
"
)
#Delta_Ro = delta_ro_mean
Delta_Ro
=
0
# Calculate the second term
second_term
=
((
Delta_Ro
-
delta_ro_mean
)
/
delta_ro_std
)
**
2
# R_Vmax 1 and 2 already exist, just get the delta
Delta_R_Vmax
=
g
.
vp
.
last_av_rad
[
source_node
]
-
g
.
vp
.
first_av_rad
[
target_node
]
# Calculate the third term
third_term
=
((
Delta_R_Vmax
-
delta_r_mean
)
/
delta_r_std
)
**
2
#############################
# calculate the cost function
#############################
cf
=
math
.
sqrt
(
first_term
+
second_term
+
third_term
)
# assign as weight to the edge
g
.
ep
.
nl_cost_function
[
edge
]
=
cf
g
.
ep
.
nl_cost_function
[
edge
]
=
cf
################################
...
...
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