#!/usr/bin/env python
# Copyright (C) 2012 Nathan Charles
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#from numpy import *
import matplotlib
import pv
import json
import sys
import pathfinder
import expedite

if __name__ == "__main__":
    import argparse
    matplotlib.use('Agg')
    parser = argparse.ArgumentParser(description='Model a PV system. annual and daily output')
    parser.add_argument('-f', '--file',help='json system description',required=True)
    parser.add_argument('-s', '--shade',help='Solar Pathfinder Horizon file')
    args = vars(parser.parse_args())
    try:
        #start program
        plant = pv.jsonToSystem(json.loads(open(args['file']).read()))
        if args['shade']:
            plant.horizon = pathfinder.horizon('example.hor')
        
        expedite.string_notes(plant)
        print ""
        output  = plant.model()
        output.summary()
        output.plot().savefig('%s_output_%s.pdf' % (plant.systemName, plant.zipcode),format='pdf')

    except (KeyboardInterrupt, SystemExit):
        sys.exit(1)
    except:
        raise
