Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
IPSL
LMD
InTro
RoutingPP
Commits
0e973277
Commit
0e973277
authored
Oct 24, 2020
by
POLCHER Jan
🚴🏾
Browse files
Adds location names and types to the graph file.
parent
6b0de4bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
15 deletions
+39
-15
Locations.py
Locations.py
+39
-15
No files found.
Locations.py
View file @
0e973277
...
...
@@ -2,6 +2,7 @@
#
import
numpy
as
np
from
netCDF4
import
Dataset
from
netCDF4
import
stringtochar
,
chartostring
,
stringtoarr
import
sys
import
codecs
#
...
...
@@ -77,8 +78,8 @@ class Locations :
self
.
lat
.
append
(
g
.
variables
[
"lat"
][
i
])
self
.
upstream
.
append
(
g
.
variables
[
"area"
][
i
])
self
.
ltype
.
append
(
"gauging station"
)
# Proper information to be added later.
self
.
lname
.
append
(
"GRDCName"
)
self
.
lname
.
append
(
str
(
chartostring
(
g
.
variables
[
"name"
][
i
,:])))
#
g
.
close
()
return
nb
#
...
...
@@ -99,6 +100,7 @@ class Locations :
self
.
lat
=
np
.
array
(
self
.
lat
)[
l
]
self
.
upstream
=
np
.
array
(
self
.
upstream
)[
l
]
self
.
ltype
=
np
.
array
(
self
.
ltype
)[
l
]
self
.
lname
=
np
.
array
(
self
.
lname
)[
l
]
self
.
ij
=
np
.
array
(
self
.
ij
)[
l
]
self
.
ib
=
np
.
array
(
self
.
ib
)[
l
]
self
.
cost
=
np
.
array
(
self
.
cost
)[
l
]
...
...
@@ -172,14 +174,15 @@ class Locations :
gl
=
part
.
gather
(
procgrid
.
landscatter
(
locmap
,
order
=
'F'
))
gc
=
part
.
gather
(
procgrid
.
landscatter
(
costmap
,
order
=
'F'
))
#
htumon
=
np
.
zeros
((
self
.
htumonmax
,
part
.
njg
,
part
.
nig
),
dtype
=
int
)
htumon
[:,:,:]
=
-
1
monnb
=
np
.
zeros
((
part
.
njg
,
part
.
nig
),
dtype
=
int
)
locationlist
=
np
.
zeros
((
5
,
self
.
nblocated
),
dtype
=
int
)
#
# Eliminate locations with lower cost
#
if
part
.
rank
==
0
:
#
htumon
=
np
.
zeros
((
self
.
htumonmax
,
part
.
njg
,
part
.
nig
),
dtype
=
int
)
htumon
[:,:,:]
=
-
1
monnb
=
np
.
zeros
((
part
.
njg
,
part
.
nig
),
dtype
=
int
)
locationlist
=
np
.
zeros
((
5
,
self
.
nblocated
),
dtype
=
int
)
#
u
,
n
=
np
.
unique
(
gl
[
~
np
.
isnan
(
gl
)],
return_counts
=
True
)
# Go through all IDs which are not unique
for
lid
in
u
[
np
.
where
(
n
>
1
)[
0
]]
:
...
...
@@ -206,27 +209,48 @@ class Locations :
locationlist
[
2
,
i
]
=
f
[
2
][
0
]
+
1
locationlist
[
3
,
i
]
=
f
[
1
][
0
]
+
1
locationlist
[
4
,
i
]
=
imon
+
1
else
:
htumon
=
None
monnb
=
None
locationlist
=
np
.
array
([[
0
],[
0
]])
#
# Add to NetCDF file
#
gtypes
=
part
.
gathermergelist
(
list
(
self
.
lid
),
list
(
self
.
ltype
),
list
(
locationlist
[
0
,:]))
gnames
=
part
.
gathermergelist
(
list
(
self
.
lid
),
list
(
self
.
lname
),
list
(
locationlist
[
0
,:]))
if
part
.
rank
==
0
:
for
t
in
gnames
:
print
(
"XXXXX got type : "
,
t
)
if
part
.
rank
==
0
:
# Create new dimension
monmax
=
np
.
max
(
monnb
)
strlen
=
60
if
monmax
>
0
:
moncoord
=
(
'htumon'
,)
outnf
.
createDimension
(
moncoord
[
0
],
monmax
)
infocoord
=
(
'locinfo'
,)
outnf
.
createDimension
(
infocoord
[
0
],
5
)
monaxe
=
(
'htumon'
,)
outnf
.
createDimension
(
monaxe
[
0
],
monmax
)
infoaxe
=
(
'locinfo'
,)
outnf
.
createDimension
(
infoaxe
[
0
],
5
)
outnf
.
createDimension
(
'str'
,
strlen
)
# Create variable for the list of stations
locvar
=
outnf
.
createVariable
(
locname
,
vtyp
,
info
coord
+
loccoord
)
locvar
.
titl
e
=
loctitle
locvar
=
outnf
.
createVariable
(
locname
,
vtyp
,
info
axe
+
loccoord
)
locvar
.
long_nam
e
=
loctitle
locvar
.
units
=
locunits
locvar
.
description
=
"ID, i-index, j-index, HTU-index, monitoring-index"
locvar
[:,:]
=
locationlist
# Create variable for the indices of the HTU to monitor
monvar
=
outnf
.
createVariable
(
monname
,
vtyp
,
mon
coord
+
spacecoord
)
monvar
.
titl
e
=
montitle
monvar
=
outnf
.
createVariable
(
monname
,
vtyp
,
mon
axe
+
spacecoord
)
monvar
.
long_nam
e
=
montitle
monvar
.
units
=
monunits
monvar
[:,:,:]
=
htumon
[
0
:
monmax
,:,:]
# Variable for type of station
loctype
=
outnf
.
createVariable
(
"LocationType"
,
'c'
,
loccoord
+
(
'str'
,))
loctype
.
long_name
=
"Type of location"
for
it
,
t
in
enumerate
(
gtypes
)
:
loctype
[
it
,:]
=
stringtoarr
(
t
,
strlen
)
# Variable for type of station names
locnames
=
outnf
.
createVariable
(
"LocationName"
,
'c'
,
loccoord
+
(
'str'
,))
locnames
.
long_name
=
"Name of location"
for
it
,
t
in
enumerate
(
gnames
)
:
locnames
[
it
,:]
=
stringtoarr
(
t
,
strlen
)
return
#
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment