Example #1
0
def make_dz_honshu(fname_subfaults, fname_dtopo, faultparams={}):
    """
    Creates a dtopo file over a region appropriate for the 11 March 2011
    Honshu quake.

    Improved from the above versions by choosing the mesh spacing to align
    properly with bathy grids (spacing 1 minute).
    
    Reads subfault model from fname_subfaults
    Output dtopo file as fname_dtopo

    """

    if faultparams == {}:
        # If this dictionary was not passed in, set default values:
        faultparams['mx'] = 241
        faultparams['my'] = 361  
        faultparams['xlower'] = 140
        faultparams['xupper'] = 144
        faultparams['ylower'] = 35
        faultparams['yupper'] = 41
    fm = subfaults.read_subfault_model(fname_subfaults)
    print "Making deformation file %s using Okada model" % fname_dtopo
    print "  with input %s" % fname_subfaults
    X,Y,dZ = subfaults.make_okada_dz(fm, faultparams)
    subfaults.write_dz(fname_dtopo, X,Y,dZ)
    return X,Y,dZ
  parser.add_argument('--config', required=1,
          help="file with grid parameters;\
                required values are mx, my, xlower, xupper, ylower and yupper;\
                parameter names and values should appear on the same single line seperated by a space")
  parser.add_argument('--subfaults', required=1, help="subfault file, a lot of files can be found at http://www.usgs.gov")  
  parser.add_argument('--outputFile', required=1, help="file where the computed grid will be placed")
  
  args=parser.parse_args()
    
    
  dtopo_fname=args.outputFile
  dtopo_cfg = args.config
  dtopo_subfaults =args.subfaults

  if os.path.exists(dtopo_fname):
    print "*** Not regenerating dtopo file (already exists): %s" % dtopo_fname
  elif not(os.path.exists(dtopo_cfg)):
    print "*** Config file missing: %s" %dtopo_cfg
  elif not(os.path.exists(dtopo_subfaults)):
      print "*** Subfaults file missing: %s" %dtopo_subfaults
  else:
    faultparams=okada.getfaultparams(dtopo_cfg)
    print(faultparams)
    subfault_model=subfaults.read_subfault_model(dtopo_subfaults)
    print "Creating deformation file %s using Okada model" %dtopo_fname
    print "  with input %s" % dtopo_subfaults
    
    X,Y,dZ = subfaults.make_okada_dz(subfault_model, faultparams)
    subfaults.write_dz(dtopo_fname, X,Y,dZ)
    print "Deformation file created."
        '--subfaults',
        required=1,
        help="subfault file, a lot of files can be found at http://www.usgs.gov"
    )
    parser.add_argument('--outputFile',
                        required=1,
                        help="file where the computed grid will be placed")

    args = parser.parse_args()

    dtopo_fname = args.outputFile
    dtopo_cfg = args.config
    dtopo_subfaults = args.subfaults

    if os.path.exists(dtopo_fname):
        print "*** Not regenerating dtopo file (already exists): %s" % dtopo_fname
    elif not (os.path.exists(dtopo_cfg)):
        print "*** Config file missing: %s" % dtopo_cfg
    elif not (os.path.exists(dtopo_subfaults)):
        print "*** Subfaults file missing: %s" % dtopo_subfaults
    else:
        faultparams = okada.getfaultparams(dtopo_cfg)
        print(faultparams)
        subfault_model = subfaults.read_subfault_model(dtopo_subfaults)
        print "Creating deformation file %s using Okada model" % dtopo_fname
        print "  with input %s" % dtopo_subfaults

        X, Y, dZ = subfaults.make_okada_dz(subfault_model, faultparams)
        subfaults.write_dz(dtopo_fname, X, Y, dZ)
        print "Deformation file created."