Commit 37d2c3b0 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles

add docstrings + rc4

parent a7a6a534
......@@ -8,7 +8,11 @@ import unsio
# class CSsnapshot
#
class CUNS_IN:
"""Input Operations on UNS snapshots"""
"""Input Operations on UNS snapshots
This class provide methods for loading data stored in an UNS compatible snapshots
"""
__uns=None
__verbose=False
__float32=True
......@@ -19,6 +23,43 @@ class CUNS_IN:
# constructor
#
def __init__(self,simname,select="all",times="all",float32=True,verbose=False,verbose_debug=False):
"""
The Constructor for CUNS_IN class
example :
- instantiate an object to load components gas and stars of snapshot "mysnap"
with double precision
import unsio.input as uns_in
my_in=uns_in.CUNS_IN("mysnap","gas,stars",float32=False)
Args:
simname (str) : snapshot's file name or simulation's name
select (str) : selected components to be loaded. It's a list of components
separated with coma ",".
Known components are: disk,gas,halo,bndry,bulge,all
example :
select="gas,disk"
select="halo"
(default: all)
times (str) : specify on which range of time data must be loaded.
example :
times="100" (load time 100)
times="0:10" (load 0<=time<=10)
times="all" (load all times)
(default: all)
float32 (bool): load data in float value or double value.
example:
float32=True (load in float)
float32=False (load in double)
(default: True)
"""
#select=select.encode('ascii')
#times=times.encode('ascii')
self.__verbose=verbose
......@@ -51,14 +92,22 @@ class CUNS_IN:
def nextFrame(self,bits=""):
"""
Load the next snapshot. Data retreival depend from bits (array selected) and
components selected during instanciation
components selected during instanciation.
Args :
bits (str) : It's a based string variable which control which arrays will be loaded according to components selected
Each characters of the string represents a different arrays.
Argument :
for bits explanation, please visit :
https://projets.lam.fr/projects/unsio/wiki/UnsioVariablesUtilisation#How-to-select-data-at-loading
example :
bits="mxv" will load masses (m), positions(x) and velocities(v)
bits="xRH" will load postions(x), densities(R) and hsml(H)
for a complete bits explanation, please visit :
https://projets.lam.fr/projects/unsio/wiki/UnsioVariablesUtilisation#How-to-select-data-at-loading
(default: all)
Return :
1 if success, 0 otherwise
int: 1 success (something has been loaded), 0 otherwise
"""
if not self.__uns.isValid():
......@@ -72,6 +121,8 @@ class CUNS_IN:
# close
#
def close(self):
"""close opened snapshot"""
if not self.__uns.isValid():
raise RuntimeError("UNS not valid")
self.__uns.close()
......@@ -79,6 +130,8 @@ class CUNS_IN:
# kill
#
def kill(self):
"""close opened snapshot"""
if not self.__uns.isValid():
raise RuntimeError("UNS not valid")
self.close()
......@@ -86,9 +139,8 @@ class CUNS_IN:
# getInterfaceType
#
def getInterfaceType(self):
"""
return uns snapshot's Interface type
"""
"""return uns snapshot's Interface type"""
if not self.__uns.isValid():
raise RuntimeError("UNS not valid")
return self.__uns.getInterfaceType()
......@@ -96,9 +148,8 @@ class CUNS_IN:
# getFileStructure
#
def getFileStructure(self):
"""
return uns snapshot's File structure
"""
"""return uns snapshot's File structure"""
if not self.__uns.isValid():
raise RuntimeError("UNS not valid")
return self.__uns.getFileStructure()
......@@ -106,9 +157,8 @@ class CUNS_IN:
# getFileName
#
def getFileName(self):
"""
return uns snapshot's File name
"""
"""return uns snapshot's File name"""
if not self.__uns.isValid():
raise RuntimeError("UNS not valid")
return self.__uns.getFileName()
......@@ -117,13 +167,29 @@ class CUNS_IN:
#
def getData(self,select,tag=None,data_type=np.float32):
"""
General method to get Data from uns snapshot
General method to get Data Array/Value respecting to components
example :
- to get positions from gas component
status,pos=obj.getData("gas","pos")
- to get concatened positions from gas and stars component
status,pos=obj.getData("gas,stars","pos")
- to get simulation Time
status,time=obj.getData("time")
Argument:
- select : component or list of components (ex: gas or gas,stars)
- tag : pos,vel,mass,rho...etc see https://projets.lam.fr/projects/unsio/wiki/GetDataDescription
Args:
select (str) : component or list of components separeted with a coma
example :
select="gas"
select="gas,stars"
tag (str) : array to get
example :
tag="pos"
tag="acc"
pos,vel,mass,rho...etc see https://projets.lam.fr/projects/unsio/wiki/GetDataDescription
IMPORTANT : if 'tag' is None, then 'select' is treated as 'tag' (see above)
IMPORTANT : if 'tag' is None, then 'select' is treated as 'tag' (see above)
Return :
status,numpy_array (if tag is not None)
......
......@@ -8,7 +8,11 @@ import unsio
# class CSsnapshot
#
class CUNS_OUT:
"""Output Operations on UNS snapshots"""
"""Output Operations on UNS snapshots
This class provide methods for saving data in an UNS compatible snapshots
"""
__uns=None
__verbose=False
__verbose_debug=False
......@@ -25,7 +29,27 @@ class CUNS_OUT:
#
def __init__(self,outfile, uns_type, float32=True, verbose=False, verbose_debug=False):
"""
The Constructor for CUNS_OUT class
example :
- instantiate an object to save file "mysnap" in gadget3 with float precision
import unsio.output as uns_out
my_out=uns_out.CUNS_OUT("mysnap","gadget3")
Args:
outfile (str) : output file name
uns_type(str) : UNS file format
available format for saving are :
- gadget2, gadget3(hdf5), nemo
float32 (bool): save data in float value or double value.
example:
float32=True (save in float)
float32=False (save in double)
(default: True)
"""
self.__float32 = float32
self.__outfile = outfile
......@@ -48,12 +72,25 @@ class CUNS_OUT:
#
def setData(self,data_array,select,tag=None):
"""
General method to set Data to uns snapshot
General method to set Data Array/Value respecting to components to an uns snapshot
example:
- set numpy array pos as positions for gas component
status=obj.setData(pos,"gas","pos")
- set float value timex as simulation time
status=obj.setData(timex,"time")
Args:
data_array (array|float) : 1D numpy_array or single value
select (str) : component gas,stars,disk,halo,bndry or bulge
Argument:
- data_array : 1D numpy_array or single value to save
- select : component or list of components (ex: gas or gas,stars)
- tag : pos,vel,mass,rho...etc see https://projets.lam.fr/projects/unsio/wiki/GetDataDescription
tag (str) : array to set
example :
tag="pos"
tag="acc"
pos,vel,mass,rho...etc see https://projets.lam.fr/projects/unsio/wiki/GetDataDescription
IMPORTANT : if 'tag' is None, then 'select' is treated as 'tag' (see above)
......@@ -86,6 +123,7 @@ class CUNS_OUT:
# save
#
def save(self):
"""save data presumbly set on file"""
if not self.__is_valid:
raise RuntimeError("CUNS_OUT is not valid")
......@@ -95,6 +133,7 @@ class CUNS_OUT:
# close
#
def close(self):
"""close open file"""
if not self.__is_valid:
raise RuntimeError("CUNS_OUT is not valid")
......
......@@ -48,7 +48,7 @@ class build_py(_build_py, object):
#
MAJOR = '0'
MINOR = '9'
MICRO = '3rc3'
MICRO = '3rc4'
VERSION = '%s.%s.%s' % (MAJOR, MINOR, MICRO)
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment