コード例 #1
0
ファイル: test_output.py プロジェクト: mikecampagna/gwlf-e
    def test_generated_output_matches_static_output(self):
        """
        Test generated output using the sample GMS, input_4.gms
        versus static output generated using the same file.
        """
        input_file = open('test/input_4.gms', 'r')
        z = parser.GmsReader(input_file).read()
        generated_output = gwlfe.run(z)

        static_output = json.load(open('test/input_4.output', 'r'))

        self.assertEqual(generated_output, static_output)
コード例 #2
0
ファイル: run.py プロジェクト: mikecampagna/gwlf-e
def main():
    log = logging.getLogger('gwlfe')
    log.setLevel(logging.DEBUG)

    ch = logging.StreamHandler()
    log.addHandler(ch)

    gms_filename = sys.argv[1]

    fp = open(gms_filename, 'r')
    z = parser.GmsReader(fp).read()
    result = gwlfe.run(z)
    print(json.dumps(result, indent=4))
コード例 #3
0
ファイル: test_output.py プロジェクト: mikecampagna/gwlf-e
    def test_gms_writer(self):
        """
        Test that GmsWriter is able to replicate the sample GMS created
        from MapShed.
        """
        input_file = open('test/input_4.gms', 'r')
        z = parser.GmsReader(input_file).read()

        output = StringIO()
        writer = parser.GmsWriter(output)
        writer.write(z)

        input_file.seek(0)
        output.seek(0)

        self.assertGmsEqual(input_file, output)
コード例 #4
0
ファイル: tasks.py プロジェクト: mibowser/model-my-watershed
def run_gwlfe(model_input, inputmod_hash):
    """
    Given a model_input resulting from a MapShed run, converts that dictionary
    to an intermediate GMS file representation, which is then parsed by GWLF-E
    to create the final data model z. We run GWLF-E on this final data model
    and return the results.

    This intermediate GMS file representation needs to be created because most
    of GWLF-E logic is written to handle GMS files, and to support dictionaries
    directly we would have to replicate all that logic. Thus, it is easier to
    simply create a GMS file and have it read that.
    """
    output = to_gms_file(model_input)

    reader = parser.GmsReader(output)
    z = reader.read()

    result = gwlfe.run(z)
    result['inputmod_hash'] = inputmod_hash

    return result
コード例 #5
0
ファイル: main.py プロジェクト: rajadain/mmw-gwlfe-comparison
        timing['read_input_file'] = default_timer()

        # Round Areas
        mapshed_areas = [round(a, 1) for a in mapshed_data['Area']]
        mapshed_data['Area'] = mapshed_areas

        # Prepare input GMS
        pre_z = parser.DataModel(mapshed_data)
        output = StringIO()
        writer = parser.GmsWriter(output)
        writer.write(pre_z)
        output.seek(0)
        timing['prepare_input_gms'] = default_timer()

        # Read input GMS
        reader = parser.GmsReader(output)
        z = reader.read()
        timing['read_input_gms'] = default_timer()

        # Run the model
        result = gwlfe.run(z)
        timing['run_gwlfe'] = default_timer()

        # Write to file
        outpath = os.path.abspath(
            os.path.join(__file__, '../output/', filename))

        with open(outpath, 'w') as outfile:
            json.dump(result, outfile)
            timing['write_output_file'] = default_timer()