Changeset 19157


Ignore:
Timestamp:
02/26/15 09:07:32 (10 years ago)
Author:
bdef
Message:

NEW: adding cluster (pfe) launch ability in python

Location:
issm/trunk-jpl/src/m
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/model.py

    r19048 r19157  
    2929from toolkits import toolkits
    3030from generic import generic
     31from pfe import pfe
     32from greenplanet import greenplanet
    3133from balancethickness import balancethickness
    3234from stressbalance import stressbalance
  • issm/trunk-jpl/src/m/contrib/netCDF/export_netCDF.py

    r19097 r19157  
    1 from netCDF4 import Dataset
     1from netCDF4 import Dataset, stringtochar
    22import numpy
    33import time
     
    3434        Dimension3=NCData.createDimension('Dimension3',numpy.shape(md.mesh.elements)[1])
    3535        Dimension4=NCData.createDimension('Dimension4',StepNum)
    36         Dimension5=NCData.createDimension('Dimension5',2)
     36        Dimension5=NCData.createDimension('Dimension5',40)
     37        Dimension6=NCData.createDimension('Dimension6',2)
    3738
    3839        DimDict = {len(Dimension1):'Dimension1',
     
    4041                                                 len(Dimension3):'Dimension3',
    4142                                                 len(Dimension4):'Dimension4',
    42                                                  len(Dimension5):'Dimension5'}
     43                                                 len(Dimension5):'Dimension5',
     44                                                 len(Dimension6):'Dimension6'}
    4345
    4446        #get all model classes and create respective groups
     
    114116        elif val_type==list:
    115117                dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime)
    116                 ncvar = Group.createVariable(str(field),str,dimensions,zlib=True)
     118                ncvar = Group.createVariable(str(field),'S1',dimensions,zlib=True)
     119                charvar=stringtochar(numpy.array(var))
     120                print charvar
     121                print charvar.shape
    117122                for elt in range(0,val_dim):
    118123                        try:
    119                                 ncvar[elt] = var[elt]
     124                                ncvar[elt] = charvar[elt]
    120125                        except IndexError:
    121126                                ncvar[0]= " "
     
    123128        elif val_type=='bool':
    124129                dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime)
    125                 ncvar = Group.createVariable(str(field),str,dimensions,zlib=True)
     130                ncvar = Group.createVariable(str(field),'S1',dimensions,zlib=True)
    126131                for elt in range(0,val_shape[0]):
    127132                        ncvar[elt] = str(var[elt])
     
    129134        elif val_type==collections.OrderedDict:
    130135                dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime)
    131                 ncvar = Group.createVariable(str(field),str,dimensions,zlib=True)
     136                ncvar = Group.createVariable(str(field),'S1',dimensions,zlib=True)
    132137                for elt in range(0,val_dim):
    133138                        ncvar[elt,0]=dict.keys(var)[elt]
     
    169174def GetDim(NCData,var,shape,DimDict,i,istime):
    170175        output=[]
     176        #grab type
     177        try:
     178                val_type=str(var.dtype)
     179        except AttributeError:
     180                val_type=type(var)
     181        #grab dimension
    171182        for dim in range(0,i): #loop on the dimensions
    172183                if type(shape[0])==int:
     
    187198                                NewDim=NCData.createDimension('Dimension'+str(index),numpy.shape(shape)[0])
    188199                                DimDict[len(NewDim)]='Dimension'+str(index)
    189                                 output=[str(DimDict[numpy.shape(dict.keys(var))[0]])]+['Dimension5']
     200                                output=[str(DimDict[numpy.shape(dict.keys(var))[0]])]+['Dimension6']
    190201                                print 'Defining dimension ' +'Dimension'+str(index)
    191202                        break
    192203        if istime:
    193204                output=output+['Dimension4']
     205        #dealing with char and not string as we should so we need to had a string length
     206        if val_type=='bool' or val_type==collections.OrderedDict or val_type==list:
     207                charvar=stringtochar(numpy.array(var))
     208                stringlength=charvar.shape[charvar.ndim-1]
     209                try:
     210                        output=output+[str(DimDict[stringlength])] #test if the dimension allready exist
     211                except KeyError: #if not create it
     212                        if (shape[dim])>1:
     213                                index=len(DimDict)+1
     214                                NewDim=NCData.createDimension('Dimension'+str(index),(stringlength))
     215                                DimDict[len(NewDim)]='Dimension'+str(index)
     216                                output=output+[str(DimDict[stringlength])]
     217                                print 'Defining dimension ' +'Dimension'+str(index)
    194218        return tuple(output), DimDict
  • issm/trunk-jpl/src/m/contrib/netCDF/read_netCDF.m

    r19096 r19157  
    2121                                subclass = netcdf.getAtt(subgroupIDs(j),netcdf.getConstant('NC_GLOBAL'),'classtype');
    2222                                self.results=setfield(self.results,subclass,struct);
    23                                 [ndims nvar natts]=netcdf.inq(groupIDs(j));
     23                                [ndims nvar natts]=netcdf.inq(subgroupIDs(j));
    2424                                varIDs=netcdf.inqVarIDs(subgroupIDs(j));
    2525                                %first loop on group atributes
     
    2727                                        attname = netcdf.inqAttName(subgroupIDs(j),netcdf.getConstant('NC_GLOBAL'),k-1);
    2828                                        [xtype,attlen] = netcdf.inqAtt(subgroupIDs(j),netcdf.getConstant('NC_GLOBAL'),attname);
    29                                         %disp(sprintf('In %s, Treating attribute %s of type %i',subclass,attname,xtype));
     29                                        disp(sprintf('In %s, Treating attribute %s of type %i',subclass,attname,xtype));
    3030                                        %classtype have done is job, no need to keep it any more
    3131                                        if ~strcmp(attname,'classtype'),
     
    4343                                for k=1:length(varIDs),
    4444                                        [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(subgroupIDs(j),varIDs(k));
    45                                         %disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));
     45                                        disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));
    4646                                        %time dimension seems to be last in our construction
    4747                                        for l=1:length(varDimIDs),
     
    6868                        varID=netcdf.inqVarIDs(groupIDs(i));
    6969                        [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(groupIDs(i),varID);
    70                         %disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));
     70                        disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));
    7171                        [dimname,numoffields] = netcdf.inqDim(ncid,varDimIDs(end));
    7272                        self.(groupName)=eval(whichclass);
     
    9797                                attname = netcdf.inqAttName(groupIDs(i),netcdf.getConstant('NC_GLOBAL'),j-1);
    9898                                [xtype,attlen] = netcdf.inqAtt(groupIDs(i),netcdf.getConstant('NC_GLOBAL'),attname);
    99                                 %disp(sprintf('In %s, Treating attribute %s of type %i',whichclass,attname,xtype));
     99                                disp(sprintf('In %s, Treating attribute %s of type %i',whichclass,attname,xtype));
    100100                                %classtype have done is job, no need to keep it any more
    101101                                if ~strcmp(attname,'classtype'),
     
    113113                        for j=1:length(varIDs),
    114114                                [varname, xtype, varDimIDs, varAtts] =netcdf.inqVar(groupIDs(i),varIDs(j));
    115                                 %disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));                     
     115                                disp(sprintf('In %s, Treating variable %s of type %i',whichclass,varname,xtype));                       
    116116                                %if the value is a single string, we need to transpose it (cross check with python file is necessary)
    117117                                if xtype==2
  • issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m

    r19104 r19157  
    112112                        %check which field is a real result and print
    113113                        for k=1:num_of_fields
    114                                 if ((numel(sol_struct{j}(timestep).(fieldnames{k})))== ...
    115                                                 num_of_points);
     114                                if ((numel(sol_struct{j}(timestep).(fieldnames{k})))==num_of_points);
    116115                                        %paraview does not like NaN, replacing
    117116                                        nanval=find(isnan(sol_struct{j}(timestep).(fieldnames{k})));
  • issm/trunk-jpl/src/m/dev/devpath.py

    r17230 r19157  
    11#!/usr/bin/env python
    2 
    32import os,sys
     3import warnings
    44
    55#Recover ISSM_DIR and USERNAME
    6 ISSM_DIR=os.getenv('ISSM_DIR')
    7 USERNAME =os.getenv('USER')
     6ISSM_DIR = os.getenv('ISSM_DIR')
     7USERNAME = os.getenv('USER')
     8JPL_SVN  = os.getenv('JPL_SVN')
    89if(ISSM_DIR==None):
    910        raise NameError('"ISSM_DIR" environment variable is empty! You should define ISSM_DIR in your .cshrc or .bashrc!')
     11if(JPL_SVN==None):
     12        warnings.warn('"JPL_SVN" environment variable is empty! add it to your .cshrc or .bashrc if you want to do distant computing')
    1013
    1114#Go through src/m and append any directory that contains a *.py file to PATH
     
    2124sys.path.append(ISSM_DIR + '/lib')
    2225sys.path.append(ISSM_DIR + '/src/wrappers/python/.libs')
     26# If using clusters, we need to have the path to the cluster settings directory
     27if(JPL_SVN!=None):
     28        if os.path.exists(JPL_SVN + '/usr/' + USERNAME):
     29                sys.path.append(JPL_SVN + '/usr/' + USERNAME)
     30        else:
     31                raise NameError ('cluster settings should be in, '+ JPL_SVN +'/usr/' + USERNAME)
    2332
    2433#Manual imports for commonly used functions
  • issm/trunk-jpl/src/m/io/structtonc.m

    r15106 r19157  
    2828%Double vector
    2929elseif isa(field,'double') & size(field,2)==1,
    30         if step==1,
     30
     31if step==1,
    3132                dim_id          = netcdf.defDim(ncid,[fieldname '_size1'],size(field,1));
    3233                var_id(counter) = netcdf.defVar(ncid,fieldname,'NC_DOUBLE',dim_id);
  • issm/trunk-jpl/src/m/os/issmscpin.py

    r17480 r19157  
    5555                        #just use standard unix scp
    5656                        #string to copy multiple files using scp:
    57                         if len(packages)==1:
    58                                 string=packages[0]
     57                        string='\{'+','.join([str(x) for x in packages])+'\}'
     58                       
     59                        if port:
     60                                subprocess.call('scp -P %d %s@localhost:%s %s/. ' % (port,login,os.path.join(path,string),os.getcwd()),shell=True)
    5961                        else:
    60                                 string='{'
    61                                 for package in packages:
    62                                         string+=packages[i]+','
    63                                 string=string[:-1]+'}'
    64 
    65                         if port:
    66                                 subprocess.call('scp -P %d %s@localhost:%s %s' % (port,login,os.path.join(path,string),os.getcwd),shell=True)
    67                         else:
    68                                 subprocess.call('scp %s@%s:%s %s' % (login,host,os.path.join(path,string),os.getcwd),shell=True)
     62                                subprocess.call('scp %s@%s:%s %s/.' % (login,host,os.path.join(path,string),os.getcwd()),shell=True)
    6963               
    7064                        #check scp worked
  • issm/trunk-jpl/src/m/solve/loadresultsfromcluster.py

    r17480 r19157  
    3535        #erase the log and output files
    3636        if md.qmu.isdakota:
    37                 os.remove(os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name+'.outlog'))
    38                 os.remove(os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name+'.errlog'))
     37                filename=os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name)
    3938        else:
    40                 os.remove(md.miscellaneous.name+'.outlog')
    41                 os.remove(md.miscellaneous.name+'.errlog')
    42                 os.remove(md.miscellaneous.name+'.outbin')
    43                 if not m.ispc():
    44                         os.remove(md.private.runtimename+'.tar.gz')
     39                filename=md.miscellaneous.name
    4540
    46         #erase input file if run was carried out on same platform.
     41        TryRem('.errlog',filename)
     42        TryRem('.outlog',filename)
     43       
     44        if not m.ispc():
     45                TryRem('.tar.gz',md.private.runtimename)
     46                if not md.qmu.isdakota:
     47                        TryRem('.outbin',filename)
     48
     49                        #erase input file if run was carried out on same platform.
    4750        hostname=socket.gethostname()
    4851        if m.strcmpi(hostname,cluster.name):
    4952                if md.qmu.isdakota:
    50                         os.remove(os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name+'.bin'))
    51                         os.remove(os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name+'.queue'))
     53                        filename=os.path.join('qmu'+str(os.getpid()),md.miscellaneous.name)
     54                        TryRem('.queue',filename)
    5255                else:
    53                         os.remove(md.miscellaneous.name+'.bin')
    54                         os.remove(md.miscellaneous.name+'.toolkits')
     56                        filename=md.miscellaneous.name
     57                        TryRem('.toolkits',filename)
    5558                        if not m.ispc():
    56                                 os.remove(md.miscellaneous.name+'.queue')
     59                                TryRem('.queue',filename)
    5760                        else:
    58                                 os.remove(md.miscellaneous.name+'.bat')
     61                                TryRem('.bat',filename)
     62
     63                TryRem('.bin',filename)
    5964
    6065        return md
    6166
     67def TryRem(extension,filename):
     68        try:   
     69                os.remove(filename+extension)
     70        except OSError:
     71                print 'WARNING, no '+extension+'  is present for run '+filename
Note: See TracChangeset for help on using the changeset viewer.