shakelib.conversions.convert_imc

class shakelib.conversions.convert_imc.ComponentConverter[source]

Bases: ABC

Base class for implementing conversions between components.

checkUnknown()[source]

Checks if imc_in or imc_out is an unknown type.

If of an unknown type, it is automatically set to GEOMETRIC_MEAN.

convertAmps(imt, amps, rrups=None, mag=None)[source]

Return an array of amps converted from one IMC to another.

Note: This can be used to perform chained conversions.

Parameters:
  • imt (OpenQuake IMT) – The intensity measure type of the input ground motions. Valid IMTs are PGA, PGV, and SA.

  • amps (array) – A numpy array of the (logged) ground motions to be converted.

  • rrups (array) – A numpy array of the same shape as amps, containing the rupture distances of the ground motions. Default is None.

  • mag (float) – The earthquake magnitude. Default is None.

Returns:

A numpy array of converted ground motions.

Return type:

array

abstract convertAmpsOnce(imt, amps, rrups=None, mag=None)[source]

Return an array of amps converted from one IMC to another.

Note: This does not implement chained conversions.

Parameters:
  • imt (OpenQuake IMT) – The intensity measure type of the input ground motions. Valid IMTs are PGA, PGV, and SA.

  • amps (array) – A numpy array of the (logged) ground motions to be converted.

  • rrups (array) – A numpy array of the same shape as amps, containing the rupture distances of the ground motions.

  • mag (float) – The earthquake magnitude.

Returns:

A numpy array of converted ground motions.

Return type:

array

convertSigmas(imt, sigmas)[source]

Return an array of standard deviations converted from one IMC to another.

Note: This can be used to perform chained conversions.

Parameters:
  • imt (OpenQuake IMT) – The intensity measure type of the input ground motions. Valid IMTs are PGA, PGV, and SA.

  • sigmas (array) – A numpy array of the standard deviations of the logged ground motions.

Returns:

A numpy array of converted standard deviations.

Return type:

array

abstract convertSigmasOnce(imt, sigmas)[source]

Return an array of standard deviations converted from one IMC to another.

Note: This does not implement chained conversions.

Parameters:
  • imt (OpenQuake IMT) – The intensity measure type of the input ground motions. Valid IMTs are PGA, PGV, and SA.

  • sigmas (array) – A numpy array of the standard deviations of the logged ground motions.

Returns:

A numpy array of converted standard deviations.

Return type:

array

static pathSearch(graph, imc_in, imc_out)[source]

Helper method to create a “path” to convert one IMC to another.

This can be used for chain conversions

Parameters:
  • graph (Dictionary) – Dictionary of sets describing possible conversions between IMCs.

  • imc_in (IMC) – OpenQuake IMC type of the input amp array.

  • imc_out (IMC) – Desired OpenQuake IMC type of the output amps.

Returns:

IMCs as a path for to convert one IMC to another.

Return type:

list

getShortestPath(graph, imc_in, imc_out)[source]

Create a “path” to convert one IMC to another.

This can be used for chain conversions

Parameters:
  • graph (Dictionary) – Dictionary of sets describing possible conversions between IMCs.

  • imc_in (IMC) – OpenQuake IMC type of the input amp array.

  • imc_out (IMC) – Desired OpenQuake IMC type of the output amps.

Returns:

IMCs as a path for to convert one IMC to another.

Return type:

list

Raises:

ValueError if no path is found.

imc_from_str(imcstring)[source]

Convert a string to one of the OQ IMC types. Return None if the string does not match any of the strings in the Enum.

Parameters:

imcstring (str) – A string corresponding to one of the OQ IMC types.

Returns:

One of the OQ IMC types. Returns None if nothing matches.

Return type:

IMC