Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LAMBERT Jean-charles
uns_projects
Commits
37a43154
Commit
37a43154
authored
Apr 12, 2017
by
LAMBERT Jean-charles
Browse files
add wrapper to C2plot C++ class
parent
76ccb91a
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/mains/uns_c2dplot.py
0 → 100755
View file @
37a43154
#!/usr/bin/env python
from
__future__
import
print_function
import
numpy
as
np
import
os
,
time
import
sys
import
argparse
,
textwrap
sys
.
path
=
[
'/home/jcl/works/GIT/uns_projects/py/modules/'
,
'/home/jcl/works/GIT/uns_projects/py/modules/simulations'
]
+
sys
.
path
from
simulations.c2dplot
import
*
from
simulations.csnapshot
import
*
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def
commandLine
():
# help
parser
=
argparse
.
ArgumentParser
(
description
=
"Compute 2D image using uns_projects c2dplot engine"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
'snapshot'
,
help
=
"uns input snapshot"
,
default
=
None
)
parser
.
add_argument
(
'component'
,
help
=
"selected component"
,
default
=
None
)
parser
.
add_argument
(
'--range'
,
help
=
"plot range (X or -A:B) "
,
default
=
35
,
type
=
str
)
parser
.
add_argument
(
'--psort'
,
help
=
"sort particles according to properties"
,
default
=
0
,
type
=
int
)
parser
.
add_argument
(
'--prop'
,
help
=
"properties to plot (age,rho)"
,
default
=
""
,
type
=
str
)
parser
.
add_argument
(
'--pfname'
,
help
=
"print filename (1:True, 0:False)"
,
default
=
1
,
type
=
int
)
parser
.
add_argument
(
'--cb'
,
help
=
"display color bar (1:True, 0:False)"
,
default
=
0
,
type
=
int
)
parser
.
add_argument
(
'--cmap'
,
help
=
"color map (0:rainbow, 1:heat, 2:gray)"
,
default
=
0
,
type
=
int
)
parser
.
add_argument
(
'--dev'
,
help
=
"pgplot device"
,
default
=
"?"
)
parser
.
add_argument
(
'--verbose'
,
help
=
'verbose mode'
,
default
=
False
)
# parse
args
=
parser
.
parse_args
()
# start main funciton
process
(
args
)
# -----------------------------------------------------
# process, is the core function
def
process
(
args
):
try
:
uns
=
CSnapshot
(
args
.
snapshot
,
args
.
component
,
verbose_debug
=
args
.
verbose
)
ok
=
uns
.
nextFrame
(
""
)
if
ok
:
c
=
C2dplot
()
c
.
draw
(
uns_snap
=
uns
,
select
=
args
.
component
,
outdev
=
args
.
dev
,
rrange
=
args
.
range
,
\
prop
=
args
.
prop
,
psort
=
args
.
psort
,
pfname
=
args
.
pfname
,
cb
=
args
.
cb
,
cmap
=
args
.
cmap
)
else
:
print
(
"[%s] is not a UNS snapshot ..."
%
(
simname
))
except
Exception
as
x
:
print
(
x
.
message
)
# -----------------------------------------------------
# main program
if
__name__
==
'__main__'
:
commandLine
()
py/modules/simulations/c2dplot.py
0 → 100644
View file @
37a43154
#!/usr/bin/env python
from
__future__
import
print_function
from
uns_simu
import
*
from
csnapshot
import
*
import
py_unstools
# rectify swig
from
multiprocessing
import
Lock
import
time
import
os
#
# ----
#
class
C2dplot
:
"""
Draw 2d image using uns_project C2dplot engine
"""
#
# ----
#
# constructor
__analysis
=
None
dimx
=
1024
dimy
=
1024
pixel
=
20
gp
=
5.0
__c
=
None
def
__init__
(
self
,
analysis
=
None
,
dimx
=
1024
,
dimy
=
1024
,
pixel
=
20
,
gp
=
5.0
,
verbose
=
False
,
verbose_debug
=
False
):
"""
Constructor of CRectify class
- analysis : is a class object instantiate from CUnsAnalysis class
"""
self
.
__vdebug
=
verbose_debug
self
.
__verbose
=
verbose
self
.
dimx
=
dimx
self
.
dimy
=
dimy
self
.
pixel
=
pixel
self
.
gp
=
gp
self
.
__c
=
C2dplotF
(
1
,
self
.
pixel
,
self
.
dimx
,
self
.
dimy
,
self
.
gp
)
if
analysis
is
not
None
:
self
.
__analysis
=
analysis
self
.
__smartAnalysisInit
()
else
:
pass
#
# __smartAnalysisInit
#
def
__smartAnalysisInit
(
self
):
"""
start some initialisations
"""
data
=
self
.
__analysis
#
# draw
#
def
draw
(
self
,
uns_snap
,
select
,
outdev
,
prop
=
""
,
xy
=
True
,
xz
=
True
,
zy
=
False
,
com
=
True
,
\
hsml
=
False
,
cmap
=
0
,
title
=
"plot"
,
pfname
=
1
,
times
=
"all"
,
no
=
0
,
rrange
=
"35"
,
\
psort
=
0
,
itf
=
1
,
cb
=
0
):
"""
draw 2D image using uns_projects C2dplot engine
"""
# try to load positions
ok
,
pos
=
uns_snap
.
getData
(
select
,
"pos"
)
if
ok
:
# load time
ok
,
time
=
uns_snap
.
getData
(
"time"
)
# build range vector
nrange
=
np
.
empty
([
3
,
2
],
dtype
=
'f'
)
if
str
(
rrange
).
find
(
":"
)
!=-
1
:
left
,
right
=
str
(
rrange
).
split
(
":"
)
nrange
[:,
0
]
=
float
(
left
)
nrange
[:,
1
]
=
float
(
right
)
else
:
nrange
[:,
0
]
=-
float
(
rrange
)
nrange
[:,
1
]
=
float
(
rrange
)
nrange
=
np
.
reshape
(
nrange
,
nrange
.
size
)
#reshape in 1D
print
(
nrange
,
nrange
.
size
)
legend
=
""
comp_prop
=
select
weight
=
np
.
array
([],
dtype
=
'f'
)
# properties
if
prop
!=
""
:
ok
,
weight
=
uns_snap
.
getData
(
select
,
prop
)
if
not
ok
:
print
(
"No properties [%s] for the selection"
%
(
prop
))
else
:
if
prop
==
"age"
:
legend
=
"Time of birth "
else
:
comp_prop
=
comp_prop
+
" "
+
prop
else
:
pass
# sort
if
psort
:
legend
=
legend
+
"sort "
else
:
legend
=
legend
+
"add "
# image transfer function
sitf
=
[
"linear"
,
"log"
,
"square"
]
if
(
itf
>=
0
and
itf
<=
3
):
legend
=
legend
+
sitf
[
itf
]
# com
if
com
:
ok
,
mass
=
uns_snap
.
getData
(
select
,
"mass"
)
if
mass
.
size
<
1
:
mass
=
np
.
ones
(
pos
.
size
/
3
)
uns_snap
.
center
(
pos
,
None
,
mass
,
center
=
True
)
# print file name ?
if
pfname
:
filename
=
uns_snap
.
getFileName
()
else
:
filename
=
""
# color bar
if
cb
:
cb
=
True
else
:
cb
=
False
#weight=np.ones(pos.size/3,dtype="f")
hsml
=
np
.
array
([],
dtype
=
'f'
)
print
(
pos
.
size
,
outdev
,
no
,
weight
)
self
.
__c
.
compute_image
(
outdev
,
no
,
pos
,
nrange
,
title
,
comp_prop
,
filename
,
time
.
item
(),
xy
,
xz
,
zy
,
\
True
,
weight
,
psort
,
hsml
,
itf
,
cb
,
legend
,
cmap
)
else
:
print
(
"There is no position in snapshot..."
)
Write
Preview
Supports
Markdown
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