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
a1b607eb
Commit
a1b607eb
authored
Jul 04, 2017
by
LAMBERT Jean-charles
Browse files
improve c2dplot, warning on py_unstools import missing
parent
2ca5dafa
Changes
8
Hide whitespace changes
Inline
Side-by-side
py/mains/script_analysis.txt
View file @
a1b607eb
...
...
@@ -2,15 +2,18 @@
"""
This script is called by external python script through execfile() call
"""
import matplotlib
matplotlib.use('Agg') # for offscreen rendering
from simulations.ccod import *
from simulations.ccom import *
from simulations.crectify import *
from simulations.cmovie import *
run_cod=1
run_com=1
run_rectify=1
run_movie=1
run_cod=0
run_com=0
run_rectify=0
run_movie=0
run_2dplot=1
##
## COD
##
...
...
@@ -62,7 +65,22 @@ if run_movie:
movie.smartAnalysis()
##
## MOVIE2
##
if run_2dplot:
data.lock_id=4
data.movie_dir="ANALYSIS/"+data.simname+"/movie2"
#data.movie_select syntax: component # propertie # percen # newradius # extdir
data.movie_select="gas,stars,halo"
mergers="@"+data.sim_info['name']
cmap="gas:jet,stars:Paired,halo:Accent"
if data.first:
movie=C2dplot(analysis=data,verbose_debug=True) # initialyze MOVIE analysis
movie.smartAnalysis(component=data.movie_select,xrange=20.,mergers=mergers,cmap=cmap,contour=False,noxz=False)
movie.smartAnalysis(component=data.movie_select,xrange=20.,mergers=mergers,cmap=cmap,contour=True,noxz=False)
##
data.first=False #MANDATORY
...
...
py/mains/uns_2dplot.py
View file @
a1b607eb
...
...
@@ -5,10 +5,8 @@ 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
*
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
#from IPython import embed
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
...
...
@@ -21,14 +19,14 @@ def commandLine():
parser
.
add_argument
(
'snapshot'
,
help
=
"uns input snapshot"
,
default
=
None
)
parser
.
add_argument
(
'component'
,
help
=
"selected component"
,
default
=
None
)
parser
.
add_argument
(
'--out'
,
help
=
"if blank display on screen, else on given file "
,
default
=
""
,
type
=
str
)
parser
.
add_argument
(
'--range'
,
help
=
"plot range
(X or -A:B)
"
,
default
=
35
,
type
=
str
)
parser
.
add_argument
(
'--mergers'
,
help
=
"file to center, or @sim to get file automatically "
,
default
=
None
,
type
=
str
)
parser
.
add_argument
(
'--range'
,
help
=
"plot range"
,
default
=
20
,
type
=
str
)
parser
.
add_argument
(
'--mergers'
,
help
=
"file to
re-
center, or @sim
(ex; @mdf648)
to get file automatically
from simulation
"
,
default
=
""
,
type
=
str
)
parser
.
add_argument
(
'--sigma'
,
help
=
"gaussian sigma "
,
default
=
6.
,
type
=
float
)
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
(
'--c
b
'
,
help
=
"
display color bar (1:True, 0:False
)"
,
default
=
0
,
type
=
int
)
parser
.
add_argument
(
'--cmap'
,
help
=
"color map (see mathplotlib colormap)"
,
default
=
"
je
t"
)
parser
.
add_argument
(
'--
noxz
'
,
help
=
'no XZ projection'
,
dest
=
"noxz"
,
action
=
"store_true
"
,
default
=
False
)
parser
.
add_argument
(
'--
contour
'
,
help
=
'toggle contour display'
,
dest
=
"contour"
,
action
=
"store_true
"
,
default
=
False
)
parser
.
add_argument
(
'--
nc
'
,
help
=
'#levels contour'
,
default
=
20
,
type
=
int
)
parser
.
add_argument
(
'--c
pt
'
,
help
=
"
index of the image (out.cpt.jpg
)"
,
default
=
0
,
type
=
int
)
parser
.
add_argument
(
'--cmap'
,
help
=
"color map (see mathplotlib colormap)"
,
default
=
"
gas:jet,stars:Paired,halo:Accen
t"
)
parser
.
add_argument
(
'--verbose'
,
help
=
'verbose mode'
,
dest
=
"verbose"
,
action
=
"store_true"
,
default
=
False
)
# parse
...
...
@@ -40,13 +38,24 @@ def commandLine():
# -----------------------------------------------------
# process, is the core function
def
process
(
args
):
# select matplotlib backend
if
args
.
out
!=
""
:
# non interactive
import
matplotlib
matplotlib
.
use
(
'Agg'
)
# we import this modules here because
# matplotlib.use() must be done before importing matplotlib.pyplot
import
simulations.c2dplot
as
c2d
import
simulations.csnapshot
as
csnap
try
:
cpt
=
0
uns
=
CSnapshot
(
args
.
snapshot
,
args
.
component
,
verbose_debug
=
args
.
verbose
)
cpt
=
args
.
cpt
uns
=
csnap
.
CSnapshot
(
args
.
snapshot
,
args
.
component
,
verbose_debug
=
args
.
verbose
)
#ok=uns.nextFrame("")
while
(
uns
.
nextFrame
(
""
)):
c
=
C2dplot
(
verbose_debug
=
args
.
verbose
)
c
.
fullProcess
(
uns
=
uns
,
out
=
args
.
out
,
component
=
args
.
component
,
xrange
=
int
(
args
.
range
),
sigma
=
args
.
sigma
,
mergers
=
args
.
mergers
,
cmap
=
args
.
cmap
,
cpt
=
cpt
)
c
=
c2d
.
C2dplot
(
verbose_debug
=
args
.
verbose
)
c
.
fullProcess
(
uns
=
uns
,
out
=
args
.
out
,
component
=
args
.
component
,
xrange
=
int
(
args
.
range
),
sigma
=
args
.
sigma
,
mergers
=
args
.
mergers
,
cmap
=
args
.
cmap
,
cpt
=
cpt
,
noxz
=
args
.
noxz
,
contour
=
args
.
contour
,
nc
=
args
.
nc
)
cpt
=
cpt
+
1
# else:
# print ("[%s] is not a UNS snapshot ..."%(simname))
...
...
py/modules/simulations/c2dpgplot.py
View file @
a1b607eb
...
...
@@ -2,8 +2,12 @@
from
__future__
import
print_function
from
uns_simu
import
*
from
csnapshot
import
*
import
sys
try
:
import
py_unstools
# rectify swig
except
ImportError
:
print
(
"WARNING !!!, failed to import module [py_unstools]"
,
file
=
sys
.
stderr
)
import
py_unstools
# rectify swig
from
multiprocessing
import
Lock
import
time
...
...
py/modules/simulations/ccod.py
View file @
a1b607eb
...
...
@@ -368,154 +368,6 @@ class CCod:
if
(
ss
==
comp
+
"_%d"
%
(
i
)):
return
True
,
comp
,
i
-
1
return
False
,
None
,
None
#
# ----
#
# try to read model_param.txt file in SIMULATION directory and fill up an array with #particles per galaxy/halo
def
__getHaloParticlesNumber
(
self
,
model_param
=
"model_param.txt"
):
ok
=
False
infile
=
self
.
__r
[
'dir'
]
+
"/"
+
model_param
if
os
.
path
.
exists
(
infile
):
print
(
"Model file exist :"
,
infile
,
file
=
sys
.
stderr
)
fh
=
open
(
infile
)
for
line
in
fh
:
line
=
line
.
strip
()
if
line
.
find
(
'_halo_nbody'
)
>=
0
:
ok
=
True
sline
=
line
.
split
()
ind
=
int
(((
sline
[
0
].
split
(
"_"
))[
0
].
split
(
"l"
))[
1
])
print
(
sline
,
ind
,
type
(
self
.
__halo_part
),
file
=
sys
.
stderr
)
self
.
__halo_part
[
ind
-
1
]
=
int
(
sline
[
1
])
self
.
__halo_part
=
self
.
__halo_part
[
np
.
where
(
self
.
__halo_part
>
0
)]
print
(
self
.
__halo_part
,
self
.
__halo_part
.
size
,
file
=
sys
.
stderr
)
return
ok
#
# ----
# Compute mering time between two halos galaxy
def
computeMergingTime
(
self
,
halo_1
=
None
,
halo_2
=
None
,
simname
=
None
,
outdir
=
"./"
,
txtfile
=
"merging_time.txt"
,
pngfile
=
"merging_time.png"
,
dmax
=
1.0
,
seger
=
False
,
plot
=
True
):
merging_time
=-
1
if
halo_1
is
None
:
# we are in a simulation
if
self
.
__cod_file_base
is
None
:
# no cod computation ?
return
0
else
:
if
not
seger
:
c_halo_1
=
self
.
__cod_file_base
+
"/"
+
self
.
simname
+
".halo_1.cod"
c_halo_2
=
self
.
__cod_file_base
+
"/"
+
self
.
simname
+
".halo_2.cod"
outdir
=
self
.
__cod_file_base
simname
=
self
.
simname
else
:
# seger
c_halo_1
=
self
.
__cod_file_base
+
"/../seger.analysis/g1g2_center/g1_halo.cod0.01.txt"
c_halo_2
=
self
.
__cod_file_base
+
"/../seger.analysis/g1g2_center/g2_halo.cod0.01.txt"
outdir
=
None
simname
=
self
.
simname
+
"(seger)"
else
:
c_halo_1
=
halo_1
c_halo_2
=
halo_2
simname
=
"None"
if
self
.
__vdebug
:
print
(
"c_halo_1 [%s]
\n
c_halo_2 [%s]
\n
"
%
(
c_halo_1
,
c_halo_2
),
file
=
sys
.
stderr
)
if
os
.
path
.
isfile
(
c_halo_1
)
and
os
.
path
.
isfile
(
c_halo_2
):
# load files in numpy arrays
data1
=
np
.
loadtxt
(
c_halo_1
,
dtype
=
np
.
float32
)
data2
=
np
.
loadtxt
(
c_halo_2
,
dtype
=
np
.
float32
)
# sort according time
time1_sort
=
data1
[:,
0
].
argsort
()
time2_sort
=
data2
[:,
0
].
argsort
()
n
=
min
(
time1_sort
.
size
,
time2_sort
.
size
)
# get minimum in case of #lines
time1_sort
=
time1_sort
[
0
:
n
]
time2_sort
=
time2_sort
[
0
:
n
]
# compute distance
x2
=
(
data1
[
time1_sort
][:,
1
]
-
data2
[
time2_sort
][:,
1
])
**
2
y2
=
(
data1
[
time1_sort
][:,
2
]
-
data2
[
time2_sort
][:,
2
])
**
2
z2
=
(
data1
[
time1_sort
][:,
3
]
-
data2
[
time2_sort
][:,
3
])
**
2
distance
=
np
.
sqrt
(
x2
+
y2
+
z2
)
# select times only when distance > dmax
a
=
(
distance
>=
dmax
)
x
=
np
.
where
(
a
)
if
x
[
0
].
size
==
0
:
print
(
"
\n\n\n
NO MERGING TIME FOUND
\n\n\n
"
,
file
=
sys
.
stderr
)
return
-
1
id_merge
=
x
[
0
][
-
1
]
+
1
# id matching to merging time
merging_time
=
data1
[
id_merge
][
0
]
print
(
"Merging time ="
,
merging_time
,
"
\n
merging distance ="
,
distance
[
id_merge
],
"
\n
max distance from merging="
,
distance
[
data1
[
time1_sort
][:,
0
]
>
merging_time
].
max
(),
file
=
sys
.
stderr
)
if
txtfile
is
not
None
and
outdir
is
not
None
:
m_txt
=
outdir
+
"/"
+
txtfile
print
(
"Saving txt "
,
m_txt
,
file
=
sys
.
stderr
)
f
=
open
(
m_txt
,
"w"
)
f
.
write
(
str
(
merging_time
)
+
"
\n
"
)
f
.
close
()
if
plot
:
# plot
# first plot: plot distance between 2 halos on whole simulation
plt
.
subplot
(
211
)
plt
.
plot
(
data1
[
time1_sort
][:,
0
],
distance
[
time1_sort
],
'b'
)
plt
.
axvline
(
merging_time
,
color
=
'g'
,
dashes
=
(
10
,
3
),
label
=
"merging"
)
plt
.
title
(
'Distance between 2 Halos : '
+
simname
)
plt
.
xlabel
(
'Gyears'
)
plt
.
ylabel
(
'Kpc'
)
ax
=
plt
.
axis
()
# get axis coordinates
plt
.
text
(
merging_time
+
0.01
,(
ax
[
3
]
-
ax
[
2
])
/
2
,
"%.3f"
%
(
merging_time
))
# print merging time
#plt.show()
# second plot: plot distance between 2 halos from merging time
plt
.
subplot
(
212
)
#plt.title('Distance between 2 Halos')
plt
.
xlabel
(
'Gyears'
)
plt
.
ylabel
(
'Kpc'
)
select_t
=
(
data1
[
time1_sort
][:,
0
]
>
merging_time
)
plt
.
plot
(
data1
[
time1_sort
[
select_t
]][:,
0
],
distance
[
time1_sort
[
select_t
]],
'b'
)
plt
.
axvline
(
merging_time
,
color
=
'g'
,
dashes
=
(
10
,
3
))
ax
=
plt
.
axis
()
# get axis coordinates
plt
.
text
(
merging_time
+
0.01
,(
ax
[
3
]
-
ax
[
2
])
/
2
,
"%.3f"
%
(
merging_time
))
# print merging time
plt
.
tight_layout
()
if
pngfile
is
not
None
and
outdir
is
not
None
:
img_png
=
outdir
+
"/"
+
pngfile
print
(
"Saving plot :"
,
img_png
,
file
=
sys
.
stderr
)
plt
.
savefig
(
img_png
)
else
:
plt
.
show
()
return
merging_time
#
#
#
def
getMergingTime
(
self
,
txtfile
=
"merging_time.txt"
):
"""
Get merging time from file
"""
ok
=
False
mtime
=-
1
if
self
.
__cod_file_base
is
None
:
# no cod computation ?
return
ok
,
-
1
mtf
=
self
.
__cod_file_base
+
"/"
+
txtfile
if
os
.
path
.
isfile
(
mtf
):
f
=
open
(
mtf
,
"r"
)
try
:
mtime
=
float
(
f
.
readline
())
ok
=
True
except
EOFError
:
print
(
"Unable to read file <%s>
\n
"
%
(
mtf
),
file
=
sys
.
stderr
)
pass
print
(
"File <%s> does not exist
\n
"
%
(
mtf
),
file
=
sys
.
stderr
)
return
ok
,
mtime
#
# isMultipleHalo
#
...
...
@@ -817,7 +669,8 @@ class CCod:
ok
=
False
infile
=
self
.
__r
[
'dir'
]
+
"/"
+
model_param
if
os
.
path
.
exists
(
infile
):
print
(
"Model file exist :"
,
infile
,
file
=
sys
.
stderr
)
if
self
.
__vdebug
:
print
(
"Model file exist :"
,
infile
,
file
=
sys
.
stderr
)
fh
=
open
(
infile
)
for
line
in
fh
:
line
=
line
.
strip
()
...
...
@@ -825,12 +678,13 @@ class CCod:
ok
=
True
sline
=
line
.
split
()
ind
=
int
(((
sline
[
0
].
split
(
"_"
))[
0
].
split
(
"l"
))[
1
])
print
(
sline
,
ind
,
type
(
self
.
__halo_part
),
file
=
sys
.
stderr
)
if
self
.
__vdebug
:
print
(
sline
,
ind
,
type
(
self
.
__halo_part
),
file
=
sys
.
stderr
)
self
.
__halo_part
[
ind
-
1
]
=
int
(
sline
[
1
])
self
.
__halo_part
=
self
.
__halo_part
[
np
.
where
(
self
.
__halo_part
>
0
)]
print
(
self
.
__halo_part
,
self
.
__halo_part
.
size
,
file
=
sys
.
stderr
)
if
self
.
__vdebug
:
print
(
self
.
__halo_part
,
self
.
__halo_part
.
size
,
file
=
sys
.
stderr
)
return
ok
...
...
py/modules/simulations/cfalcon.py
View file @
a1b607eb
#!/usr/bin/python
from
__future__
import
print_function
import
py_unstools
import
numpy
as
np
import
sys
try
:
import
py_unstools
except
ImportError
:
print
(
"WARNING !!!, failed to import module [py_unstools]"
,
file
=
sys
.
stderr
)
class
CFalcon
:
"""methods imported from FalcON engine"""
...
...
py/modules/simulations/cmovie.py
View file @
a1b607eb
...
...
@@ -3,7 +3,13 @@ from __future__ import print_function
from
uns_simu
import
*
from
csnapshot
import
*
from
c2dplot
import
*
import
py_unstools
# rectify swig
import
sys
try
:
import
py_unstools
# rectify swig
except
ImportError
:
print
(
"WARNING !!!, failed to import module [py_unstools]"
,
file
=
sys
.
stderr
)
import
subprocess
from
multiprocessing
import
Lock
,
cpu_count
...
...
py/modules/simulations/crectify.py
View file @
a1b607eb
...
...
@@ -2,8 +2,12 @@
from
__future__
import
print_function
from
uns_simu
import
*
from
csnapshot
import
*
import
sys
import
py_unstools
# rectify swig
try
:
import
py_unstools
# rectify swig
except
ImportError
:
print
(
"WARNING !!!, failed to import module [py_unstools]"
,
file
=
sys
.
stderr
)
from
multiprocessing
import
Lock
import
time
...
...
@@ -15,7 +19,7 @@ import glob
#
class
CRectify
:
"""
compute Center Of Mass on
UNS snapshots
Rectify
UNS snapshots
"""
__analysis
=
None
#
...
...
@@ -137,7 +141,7 @@ class CRectify:
#
def
smartAnalysis
(
self
,
analysis
=
None
):
"""
Main core function to compute RECTIFY on current snapshot store in data_analysis
Main core function to compute RECTIFY on current snapshot store
d
in data_analysis
"""
if
analysis
is
None
:
data
=
self
.
__analysis
...
...
py/modules/simulations/ctree.py
View file @
a1b607eb
from
__future__
import
print_function
import
py_unstools
as
ut
# import py_unstools package
import
sys
try
:
import
py_unstools
as
ut
# import py_unstools package
except
ImportError
:
print
(
"WARNING !!!, failed to import module [py_unstools]"
,
file
=
sys
.
stderr
)
import
numpy
as
np
from
cfalcon
import
*
from
py_unsio
import
*
...
...
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