Compare two ProDiMo models

This module provides several routines to compare two ProDiMo models.

Currently only certain output fields are compared. In each comparison a certain tolerance is considered. Those values depend on which quantity is compared (e.g. temperatures, abundances).

Currently it is possible to compare full (standard) ProDiMo models and molecular cloud (0D chemistry) models.

This module is mainly used for automatic tests. However, it is also useful during development to compare two models with one simple command.

Source documentation

# .. inheritance-diagram:: prodimopy.compare.Compare prodimopy.compare.CompareMc

class prodimopy.compare.CompareAbs[source]

An “abstract” class for comparing some kind of ProDiMo model.

A subclass of this class needs to implement the necessary compare routine(s). (example see Compare)

Todo

  • make tolerances configurable via config file (see punit checkModels).

diffArrayRel(a, aref, diff)[source]

Checks the relative difference between two arrays.

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • diff (float) – if the values of the arrays differe only by <diff they are considered as equal.

diffArray(a, aref, rtol=0.001, atol=0.0, nlimfrac=0.0, mask=None)[source]

Checks the difference between two arrays using the np.isclose routine but additionally allows to set a limit for how many elements can be different in the arrays to still be considered as equal (or similar).

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • rtol (float) – Relative tolerance as used in numpy.iclose().

  • atol (float) – Absolute tolerance as used in numpy.iclose().

  • nlimfrac (float) – Relative limit of elements that are allowed to be not equal. If less than nlim * len(aref) elements are different, the arrays are still considered as equal.

  • mask (mask for the array) – Mask for the elements that should not be included in the evaluation. Those elements are set to True in any case.

diff(val, valref, rtol=1e-10, atol=0.0)[source]

Checks the relative difference between two values. FIXME: is not inconsisten with diffArr

Parameters:
  • a (float) – a value.

  • aref (float) – the reference value

  • diff (float) – if the two values differe only by <diff the are considered as equal.

diffFile(fname)[source]

Compares the file with the name given by fname (a file produced by ProDiMo) for the the two models.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

diffFitsFile(fname, atol=0.0, rtol=2e-07)[source]

Compares two fits Files using the astropy routines.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

doAll()[source]

Utility function to call all compare* method.

Prints out what function failed and the errors.

Assume a naming convention. The method needs to start with compare. If the compare method uses the diffFile(), the method name should start with compareFile.

class prodimopy.compare.Compare(model, modelref)[source]

Class for comparing to ProDiMo models of type Data_ProDiMo

Every compare Function returns true or false, and the relative differences (in case of arrays these are arrays).

Can be used in e.g. automatic testing routines or in simple command line tools to compare ProDiMo model results.

Parameters:
  • model (Data_mc) – The model one wants to compare.

  • modelref (Data_mc) – The reference model to compare with.

m

Data_ProDiMo: The model one wants to compare.

mref

Data_ProDiMo: The reference model agains which model is compared..

tolerances

dict: A dictionary of tolerances. The naming convention has to follow the naming of the compare Function. e.g. If one wants to provide tolerances for compareAbundances the key names are Abundances.rtol and Abundances.atol.

FIXME: This is still experimental and not implemented for all compare routines. FIXME: This should be something that is in CompareAbs

getTols(atol=None, rtol=None, nlimfrac=None)[source]

Get the tolerance values from the self.tolerances dictionary

Returns:

dict

Return type:

containing {“atol”: value, “rtol”: value } if set. Can also be empty

compareX()[source]

Compares the x grid points.

compareZ()[source]

Compares the z grid points.

compareLineFluxes()[source]

Compares the line fluxes Currently assumes that both models include the same lines in the same order.

compareLineEstimates()[source]

Compares the fluxes from the line estimates Currently assumes that both models include the same lines in the same order.

Todo

  • it might be worth to make this smarter and compare the individual line estimates. currently the comparison fails if e.g. there are more level for one line … but the rest is fine

compareSED()[source]

Compares the SEDs

compareContinuumImages()[source]

Compares some of the continuum images.

compareCdnmol()[source]

checks the vertical column densities only the outermost points (e.g. total column density) are checked

compareRcdnmol()[source]

Checks the radial column densities. Only the outermost points are checked (i.e. the total radial column density)

compareSolved_chem()[source]

Compares the solved_chem field. The flag for the quality of the chemical solution.

compareAbundances()[source]

Compare the abundances.

compareElements()[source]

Compares the numbers from the Elemenst.out file.

compareSpecies()[source]

Compares the numbers from the Species.out file.

compareDustOpacEnv()[source]

Compares the dust opacities for an envelope model (optional output).

compareDustOpac()[source]

Compares the dust opacities.

compareStarSpec()[source]

Compares the input Stellar spectrum, from X-rays to mm

compareNHtot()[source]

checks the total hydrogen number density

compareRhog()[source]

checks the gas density

compareVelocity()[source]

checks the velocity structure. If in one of the models velocity is None it is assumed it is an old model and the comparison returns Tru

compareRhod()[source]

checks the dust density

compareD2g()[source]

checks the resulting dust to gass mass ratio

compareDamean()[source]

checks the resulting dust to gass mass ratio

compareTg()[source]

checks the gas temperature

compareTd()[source]

checks the dust temperature

compareRadFields()[source]

checks the radiation fields

compareZetaCR()[source]

checks the cosmic ray ionisation rate

compareZetaX()[source]

checks the Xray ionisation rate

compareHX()[source]

checks the Xray energy deposition rate

compareChemnet()[source]

Compare the chemical network. Uses the compare routine from ReactionNetwork

compareFileCheckNetworkLog()[source]

Makes a file comparison with CheckNetwork.log

compareFileCheckChemLog()[source]

Makes a file comparison with CheckChem.log

compareFitsFileRestart()[source]

Makes a fits file comparison with restart.fits.gz

compareFitsFileMie()[source]

Makes a fits file comparison with Mie.fits.gz

compareFitsFileFLiTs()[source]

Makes a fits file comparison with ProDiMoForFLits.fits

compareFitsFileLineCubes()[source]

Makes a fits file comparison with for all line cubes (LINE_3D_*)

diff(val, valref, rtol=1e-10, atol=0.0)

Checks the relative difference between two values. FIXME: is not inconsisten with diffArr

Parameters:
  • a (float) – a value.

  • aref (float) – the reference value

  • diff (float) – if the two values differe only by <diff the are considered as equal.

diffArray(a, aref, rtol=0.001, atol=0.0, nlimfrac=0.0, mask=None)

Checks the difference between two arrays using the np.isclose routine but additionally allows to set a limit for how many elements can be different in the arrays to still be considered as equal (or similar).

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • rtol (float) – Relative tolerance as used in numpy.iclose().

  • atol (float) – Absolute tolerance as used in numpy.iclose().

  • nlimfrac (float) – Relative limit of elements that are allowed to be not equal. If less than nlim * len(aref) elements are different, the arrays are still considered as equal.

  • mask (mask for the array) – Mask for the elements that should not be included in the evaluation. Those elements are set to True in any case.

diffArrayRel(a, aref, diff)

Checks the relative difference between two arrays.

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • diff (float) – if the values of the arrays differe only by <diff they are considered as equal.

diffFile(fname)

Compares the file with the name given by fname (a file produced by ProDiMo) for the the two models.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

diffFitsFile(fname, atol=0.0, rtol=2e-07)

Compares two fits Files using the astropy routines.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

doAll()

Utility function to call all compare* method.

Prints out what function failed and the errors.

Assume a naming convention. The method needs to start with compare. If the compare method uses the diffFile(), the method name should start with compareFile.

class prodimopy.compare.CompareMc(model, modelref)[source]

Class for comparing two ProDiMo models of type Data_mc

Every compare Function returns true or false, and the relative differences (in case of arrays these are arrays).

Can be used in e.g. automatic testing routines or in simple command line tools to compare ProDiMo model results.

Parameters:
  • model (Data_mc) – The model one wants to compare.

  • modelref (Data_mc) – The reference model to compare with.

m

Data_mc: The model one wants to compare.

mref

Data_mc: The reference model to compare with.

compareAbundances()[source]

Compares the abundances of two molecular cloud (0D chemistry) models.

Assumes that both models used the same number of ages and species in the same order.

compareRatecoefficients()[source]

Compares the rate coefficients of two molecular cloud (0D chemistry) models.

Assumes that both models have exactly the same chemical reactions in the same order.

diff(val, valref, rtol=1e-10, atol=0.0)

Checks the relative difference between two values. FIXME: is not inconsisten with diffArr

Parameters:
  • a (float) – a value.

  • aref (float) – the reference value

  • diff (float) – if the two values differe only by <diff the are considered as equal.

diffArray(a, aref, rtol=0.001, atol=0.0, nlimfrac=0.0, mask=None)

Checks the difference between two arrays using the np.isclose routine but additionally allows to set a limit for how many elements can be different in the arrays to still be considered as equal (or similar).

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • rtol (float) – Relative tolerance as used in numpy.iclose().

  • atol (float) – Absolute tolerance as used in numpy.iclose().

  • nlimfrac (float) – Relative limit of elements that are allowed to be not equal. If less than nlim * len(aref) elements are different, the arrays are still considered as equal.

  • mask (mask for the array) – Mask for the elements that should not be included in the evaluation. Those elements are set to True in any case.

diffArrayRel(a, aref, diff)

Checks the relative difference between two arrays.

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • diff (float) – if the values of the arrays differe only by <diff they are considered as equal.

diffFile(fname)

Compares the file with the name given by fname (a file produced by ProDiMo) for the the two models.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

diffFitsFile(fname, atol=0.0, rtol=2e-07)

Compares two fits Files using the astropy routines.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

doAll()

Utility function to call all compare* method.

Prints out what function failed and the errors.

Assume a naming convention. The method needs to start with compare. If the compare method uses the diffFile(), the method name should start with compareFile.

class prodimopy.compare.CompareSlab(model, modelref)[source]

Class for comparing two ProDiMo SLAB models of type slab_data

Every compare Function returns true or false, and the relative differences (in case of arrays these are arrays).

Can be used in e.g. automatic testing routines or in simple command line tools to compare ProDiMo model results.

Parameters:
  • model (slab_data) – The model one wants to compare.

  • modelref (slab_data) – The reference model to compare with.

diff(val, valref, rtol=1e-10, atol=0.0)

Checks the relative difference between two values. FIXME: is not inconsisten with diffArr

Parameters:
  • a (float) – a value.

  • aref (float) – the reference value

  • diff (float) – if the two values differe only by <diff the are considered as equal.

diffArray(a, aref, rtol=0.001, atol=0.0, nlimfrac=0.0, mask=None)

Checks the difference between two arrays using the np.isclose routine but additionally allows to set a limit for how many elements can be different in the arrays to still be considered as equal (or similar).

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • rtol (float) – Relative tolerance as used in numpy.iclose().

  • atol (float) – Absolute tolerance as used in numpy.iclose().

  • nlimfrac (float) – Relative limit of elements that are allowed to be not equal. If less than nlim * len(aref) elements are different, the arrays are still considered as equal.

  • mask (mask for the array) – Mask for the elements that should not be included in the evaluation. Those elements are set to True in any case.

diffArrayRel(a, aref, diff)

Checks the relative difference between two arrays.

If the arrays do not have the same shape they are considered as inequal (return False).

Parameters:
  • a (array_like(float,ndim=whatever)) – an array.

  • aref (array_like(float,ndim=same as a)) – the reference array for comparison.

  • diff (float) – if the values of the arrays differe only by <diff they are considered as equal.

diffFile(fname)

Compares the file with the name given by fname (a file produced by ProDiMo) for the the two models.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

diffFitsFile(fname, atol=0.0, rtol=2e-07)

Compares two fits Files using the astropy routines.

Parameters:

fname (str) – the Filename to compare, (must exist for both models)

doAll()

Utility function to call all compare* method.

Prints out what function failed and the errors.

Assume a naming convention. The method needs to start with compare. If the compare method uses the diffFile(), the method name should start with compareFile.

m

slab_data: The model one wants to compare.

mref

slab_data: The reference model to compare with.

compareLbLFluxes()[source]

Compares the FNLTE and FLTE of the linedata for all the models in line-by-line mode If number of models is not the same return false.

Assumes that both models used the same number of species in the same order.

compareLbLTau()[source]

Compares the FNLTE and FLTE of the linedata for all the models in line-by-line mode If number of models is not the same return false.

Assumes that both models used the same number of species in the same order.

compareLbLPop()[source]

Compares the LTE and NLTE level populations of the linedata for all the models in line-by-line mode If number of models is not the same return false.

Assumes that both models used the same number of species in the same order.

prodimopy.compare.eval_model_type(modelDir)[source]

Try to guess the model type (e.g. mc, full prodimo etc.). Default is always prodimo.

Possible types:

prodimo …. full prodimo model (prodimopy.read.Data_ProDiMo)

mc ……… molecular cloud model (prodimopy.read_mc.Data_mc)

Return type:

str either prodimo, prodiomTD, slab or mc

FIXME: this is maybe not the best place for this routine FIXME: provide constants for the values (what’s the best way to do this in pyhton?) FIXME: this is just a quick hack, it would be better to use the parameters in Parameter.in