Example #1
0
    aggregateOutTable = tableDict.fromTextFile(aggregateOut, width = 20, prec = 10)
    aggregateOutTable.keep(['age', 'owner'])
    aggregateOutTable.rename('owner', 'thOwnership')
    empOwnershipTable = tableDict.fromTextFile(empOwnershipFile, width = 20, prec = 10)
    empOwnershipTable.rename('PrOwnership', 'empOwnership')
    print empOwnershipTable
#    print empOwnershipTable.cellFormat

    ownershipTable = aggregateOutTable.merged(empOwnershipTable, 'age')
    print ownershipTable
#    print ownershipTable.cellFormat

    yVars = ['thOwnership', 'empOwnership']
    # add the individual simulations
    for profile in [ '1', '2', '3' ]:
        profileOwnershipFile = os.path.join(output_dir, 'simulation_' + profile + '.out')
        if not os.path.exists(profileOwnershipFile): continue
        profileOwnershipTable = tableDict.fromTextFile(profileOwnershipFile, width = 20, prec = 10)
        profileOwnershipTable.keep(['age', 'owner'])
        profileOwnershipTable.rename('owner', 'thOwnership_' + profile)
        ownershipTable.merge(profileOwnershipTable, 'age')
        ownershipTable.drop('_merge') 
print ownershipTable
f = open(ownershipTableFile, 'w')
print >> f, ownershipTable
f.close()
plotSimulation(table = ownershipTableFile, xVar = 'age', yVars = yVars, yVarRange = (0., 1.), figureFile = os.path.join(output_dir, 'ownership.png'), verb = 'CRITICAL')
# make plot of life-cycle simulation (all variables)
makeAggregatePlot(output_dir)

Example #2
0
    ownershipTable = aggregateOutTable.merged(empOwnershipTable, 'age')
    print ownershipTable
    #    print ownershipTable.cellFormat

    yVars = ['thOwnership', 'empOwnership']
    # add the individual simulations
    for profile in ['1', '2', '3']:
        profileOwnershipFile = os.path.join(output_dir,
                                            'simulation_' + profile + '.out')
        if not os.path.exists(profileOwnershipFile): continue
        profileOwnershipTable = tableDict.fromTextFile(profileOwnershipFile,
                                                       width=20,
                                                       prec=10)
        profileOwnershipTable.keep(['age', 'owner'])
        profileOwnershipTable.rename('owner', 'thOwnership_' + profile)
        ownershipTable.merge(profileOwnershipTable, 'age')
        ownershipTable.drop('_merge')
print ownershipTable
f = open(ownershipTableFile, 'w')
print >> f, ownershipTable
f.close()
plotSimulation(table=ownershipTableFile,
               xVar='age',
               yVars=yVars,
               yVarRange=(0., 1.),
               figureFile=os.path.join(output_dir, 'ownership.png'),
               verb='CRITICAL')
# make plot of life-cycle simulation (all variables)
makeAggregatePlot(output_dir)
Example #3
0
    def terminated(self):
        """
        Analyze the retrieved output, with a threefold purpose:

        - work around a bug in ARC where the output is stored in a
          subdirectory of the output directory.

        - make plots for post-analysis
        """
        output_dir = self.output_dir
        # if files are stored in `output/output/`, move them one level up
        if os.path.isdir(os.path.join(output_dir, 'output')):
            wrong_output_dir = os.path.join(output_dir, 'output')
            for entry in os.listdir(wrong_output_dir):
                dest_entry = os.path.join(output_dir, entry)
                if os.path.isdir(dest_entry):
                    # backup with numerical suffix
                    gc3libs.utils.backup(dest_entry)
                os.rename(os.path.join(wrong_output_dir, entry), dest_entry)
            try:
                os.rmdir(wrong_output_dir)
            except:
                logger.warning('could not delete wront output dir = %s' %
                               wrong_output_dir)

        ## set the exitcode based on postprocessing the main output file
        #aggregateOut = os.path.join(output_dir, 'aggregate.out')
        #genParametersFile = os.path.join(os.getcwd(), 'localBaseDir', 'input', 'genParameters.in')
        #ctry =       getParameter(genParametersFile, 'ctry', 'space-separated')
        #if ctry == 'us':
        #curPanel = 'PSID'
        #elif ctry == 'de':
        #curPanel = 'SOEP'
        #elif ctry == 'uk':
        #curPanel = 'BHPS'
        #else:
        #logger.critical('unknown profile %s' % profile)
        #os.exit(1)
        #empOwnershipFile = os.path.join(os.path.split(output_dir)[0], 'input', curPanel + 'OwnershipProfilealleduc.out')
        #ownershipTableFile = os.path.join(output_dir, 'ownershipTable.out')
        #if os.path.exists(aggregateOut):
        #self.execution.exitcode = 0
        ## make plot of predicted vs empirical ownership profile
        #aggregateOutTable = tableDict.fromTextFile(aggregateOut, width = 20, prec = 10)
        #aggregateOutTable.keep(['age', 'owner'])
        #aggregateOutTable.rename('owner', 'thOwnership')
        #empOwnershipTable = tableDict.fromTextFile(empOwnershipFile, width = 20, prec = 10)
        #empOwnershipTable.rename('PrOwnership', 'empOwnership')
        #ownershipTable = aggregateOutTable.merged(empOwnershipTable, 'age')
        #ownershipTable.drop('_merge')
        #yVars = ['thOwnership', 'empOwnership']
        ## add the individual simulations
        #for profile in [ '1', '2', '3' ]:
        #profileOwnershipFile = os.path.join(output_dir, 'simulation_' + profile + '.out')
        #if not os.path.exists(profileOwnershipFile): continue
        #profileOwnershipTable = tableDict.fromTextFile(profileOwnershipFile, width = 20, prec = 10)
        #profileOwnershipTable.keep(['age', 'owner'])
        #profileOwnershipTable.rename('owner', 'thOwnership_' + profile)
        #ownershipTable.merge(profileOwnershipTable, 'age')
        #ownershipTable.drop('_merge')
        #yVars.append('thOwnership_' + profile)
        #f = open(ownershipTableFile, 'w')
        #print >> f, ownershipTable
        #f.close()
        #try:
        #plotSimulation(table = ownershipTableFile, xVar = 'age', yVars = yVars, yVarRange = (0., 1.), figureFile = os.path.join(self.output_dir, 'ownership.png'), verb = 'CRITICAL')
        #except:
        #logger.debug('couldnt make ownershipTableFile')

        #try:
        #self.execution.exitcode = plotOwnerProfiles(path2input = os.path.join(os.getcwd(), 'localBaseDir', 'input'),
        #path2output = output_dir, simuFileName = 'aggregate.out')
        #except:
        #logger.debug('couldnt make ownerprofile plot. plotOwnerProfiles crashed, couldnt even set exitcode. ')
        # make plot of life-cycle simulation (all variables)
            try:
                makeAggregatePlot(self.output_dir)


#                plotSimulation(table = os.path.join(output_dir, 'aggregate.out'), xVar = 'age', yVars = ['wealth', 'theta1', 'theta2', 'theta3', 'theta4', 'theta5', 'cons', 'income'], figureFile = os.path.join(self.output_dir, 'aggregate.png'), verb = 'CRITICAL' )
            except:
                logger.debug('coulndt make aggregate.out plot')
            #if os.path.exists('ownershipThreshold_1.out'):
            #plotSimulation(path = os.path.join(output_dir, 'ownershipThreshold_1.out'), xVar = 'age', yVars = [ 'Yst1', 'Yst4' ], figureFile = os.path.join(self.output_dir, 'ownershipThreshold_1.eps'), verb = 'CRITICAL' )
            #plotSimulation(path = os.path.join(output_dir, 'ownershipThreshold_1.out'), xVar = 'age', yVars = [ 'yst1', 'yst4' ], figureFile = os.path.join(self.output_dir, 'normownershipThreshold_1.eps'), verb = 'CRITICAL' )
        else:
            # no `simulation.out` found, signal error
            self.execution.exitcode = 2
Example #4
0
    def terminated(self):
        """
        Analyze the retrieved output, with a threefold purpose:

        - work around a bug in ARC where the output is stored in a
          subdirectory of the output directory.

        - make plots for post-analysis
        """
        output_dir = self.output_dir
        # if files are stored in `output/output/`, move them one level up
        if os.path.isdir(os.path.join(output_dir, "output")):
            wrong_output_dir = os.path.join(output_dir, "output")
            for entry in os.listdir(wrong_output_dir):
                dest_entry = os.path.join(output_dir, entry)
                if os.path.isdir(dest_entry):
                    # backup with numerical suffix
                    gc3libs.utils.backup(dest_entry)
                os.rename(os.path.join(wrong_output_dir, entry), dest_entry)
            try:
                os.rmdir(wrong_output_dir)
            except:
                logger.warning("could not delete wront output dir = %s" % wrong_output_dir)

            ## set the exitcode based on postprocessing the main output file
            # aggregateOut = os.path.join(output_dir, 'aggregate.out')
            # genParametersFile = os.path.join(os.getcwd(), 'localBaseDir', 'input', 'genParameters.in')
            # ctry =       getParameter(genParametersFile, 'ctry', 'space-separated')
            # if ctry == 'us':
            # curPanel = 'PSID'
            # elif ctry == 'de':
            # curPanel = 'SOEP'
            # elif ctry == 'uk':
            # curPanel = 'BHPS'
            # else:
            # logger.critical('unknown profile %s' % profile)
            # os.exit(1)
            # empOwnershipFile = os.path.join(os.path.split(output_dir)[0], 'input', curPanel + 'OwnershipProfilealleduc.out')
            # ownershipTableFile = os.path.join(output_dir, 'ownershipTable.out')
            # if os.path.exists(aggregateOut):
            # self.execution.exitcode = 0
            ## make plot of predicted vs empirical ownership profile
            # aggregateOutTable = tableDict.fromTextFile(aggregateOut, width = 20, prec = 10)
            # aggregateOutTable.keep(['age', 'owner'])
            # aggregateOutTable.rename('owner', 'thOwnership')
            # empOwnershipTable = tableDict.fromTextFile(empOwnershipFile, width = 20, prec = 10)
            # empOwnershipTable.rename('PrOwnership', 'empOwnership')
            # ownershipTable = aggregateOutTable.merged(empOwnershipTable, 'age')
            # ownershipTable.drop('_merge')
            # yVars = ['thOwnership', 'empOwnership']
            ## add the individual simulations
            # for profile in [ '1', '2', '3' ]:
            # profileOwnershipFile = os.path.join(output_dir, 'simulation_' + profile + '.out')
            # if not os.path.exists(profileOwnershipFile): continue
            # profileOwnershipTable = tableDict.fromTextFile(profileOwnershipFile, width = 20, prec = 10)
            # profileOwnershipTable.keep(['age', 'owner'])
            # profileOwnershipTable.rename('owner', 'thOwnership_' + profile)
            # ownershipTable.merge(profileOwnershipTable, 'age')
            # ownershipTable.drop('_merge')
            # yVars.append('thOwnership_' + profile)
            # f = open(ownershipTableFile, 'w')
            # print >> f, ownershipTable
            # f.close()
            # try:
            # plotSimulation(table = ownershipTableFile, xVar = 'age', yVars = yVars, yVarRange = (0., 1.), figureFile = os.path.join(self.output_dir, 'ownership.png'), verb = 'CRITICAL')
            # except:
            # logger.debug('couldnt make ownershipTableFile')

            # try:
            # self.execution.exitcode = plotOwnerProfiles(path2input = os.path.join(os.getcwd(), 'localBaseDir', 'input'),
            # path2output = output_dir, simuFileName = 'aggregate.out')
            # except:
            # logger.debug('couldnt make ownerprofile plot. plotOwnerProfiles crashed, couldnt even set exitcode. ')
            # make plot of life-cycle simulation (all variables)
            try:
                makeAggregatePlot(self.output_dir)
            #                plotSimulation(table = os.path.join(output_dir, 'aggregate.out'), xVar = 'age', yVars = ['wealth', 'theta1', 'theta2', 'theta3', 'theta4', 'theta5', 'cons', 'income'], figureFile = os.path.join(self.output_dir, 'aggregate.png'), verb = 'CRITICAL' )
            except:
                logger.debug("coulndt make aggregate.out plot")
            # if os.path.exists('ownershipThreshold_1.out'):
            # plotSimulation(path = os.path.join(output_dir, 'ownershipThreshold_1.out'), xVar = 'age', yVars = [ 'Yst1', 'Yst4' ], figureFile = os.path.join(self.output_dir, 'ownershipThreshold_1.eps'), verb = 'CRITICAL' )
            # plotSimulation(path = os.path.join(output_dir, 'ownershipThreshold_1.out'), xVar = 'age', yVars = [ 'yst1', 'yst4' ], figureFile = os.path.join(self.output_dir, 'normownershipThreshold_1.eps'), verb = 'CRITICAL' )
        else:
            # no `simulation.out` found, signal error
            self.execution.exitcode = 2