Changeset 1032 in lmdz_wrf
- Timestamp:
- Aug 19, 2016, 12:55:41 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/tools/model_graphics.py ¶
r1031 r1032 1613 1613 return 1614 1614 1615 def get_differences_var(vc,kdiff,db): 1616 """ Function to provide the operations to make for each variable from kdiff ('DIFFOP_' or 'DIFFVAR_') dictionary 1617 vc= kdiff dictionary, dictionary with all the parameters started with kdiff 1618 kdiff= kind of differences 'op' or 'var' 1619 """ 1620 fname = 'get_differences_var' 1621 1622 if kdiff == 'op': 1623 diffn = 'DIFFOP' 1624 elif kdiff == 'var': 1625 diffn = 'DIFFVAR' 1626 else: 1627 print errmsg 1628 print ' ' + fname + ": differences '" + kdiff + "' not ready !!" 1629 quit(-1) 1630 LD = len(diffn + '_') 1631 1632 iop = 1 1633 # list of operations by difference 1634 doopers = {} 1635 # operations by variable 1636 operationsvar = {} 1637 # individual operations by variable (not repeated) 1638 indivoperationsvar = {} 1639 1640 # Variables with a calculation whic requires vertical interpolation to all the 1641 # file (operations stating by [kdiff]'_pinterp') 1642 LVp = len(diffn + '_pinterp') 1643 varglobalp = [] 1644 1645 for oper in vc.keys(): 1646 Loper = len(oper) 1647 opn = oper[LD:Loper+1] 1648 vns = vc[oper].split(':') 1649 ops1 = opn.split('+') 1650 doopers[opn] = ops1 1651 for vn in vns: 1652 if not operationsvar.has_key(vn): 1653 operationsvar[vn] = [opn] 1654 indivoperationsvar[vn] = ops1 1655 else: 1656 opers = operationsvar[vn] 1657 opers.append(opn) 1658 operationsvar[vn] = opers 1659 opers1 = indivoperationsvar[vn] 1660 for op1 in ops1: 1661 if not gen.searchInlist(opers1, op1): 1662 opers1.append(op1) 1663 indivoperationsvar[vn] = opers1 1664 1665 if oper[0:LVp] == diffn + '_pinterp': 1666 for vn in vns: 1667 if not gen.searchInlist(varglobalp,vn): varglobalp.append(vn) 1668 1669 iop = iop + 1 1670 1671 if db: 1672 print ' operations to make _______' 1673 gen.printing_dictionary(doopers) 1674 print ' operations by variable _______' 1675 gen.printing_dictionary(operationsvar) 1676 print ' individual operations by variable _______' 1677 gen.printing_dictionary(indivoperationsvar) 1678 print ' variables with the vertical interpolation for all the file _______' 1679 print ' #', varglobalp 1680 1681 return doopers, operationsvar, indivoperationsvar, varglobalp 1682 1683 def diffvarop_listconstruct(config, mods, exps, odir, debug): 1684 """ Function to create the list of differences to compute and draw 1685 config= Configuration of the experiment 1686 mods= list with the models to use 1687 exps= list with the experiments to use 1688 odir= output differences folder 1689 """ 1690 fname='diffvarop_listconstruct' 1691 1692 diffop = gen.get_specdictionary_HMT(config, H='DIFFOP_') 1693 diffvar = gen.get_specdictionary_HMT(config, H='DIFFVAR_') 1694 1695 if debug: 1696 print " 'op' differences ________" 1697 gen.printing_dictionary(diffop) 1698 print " 'var' differences ________" 1699 gen.printing_dictionary(diffvar) 1700 1701 # Getting variable characteristics from each model/experiment 1702 idir1 = config['ofold'] + '/' + mods[0] + '/' + exps[0] 1703 idir2 = config['ofold'] + '/' + mods[1] + '/' + exps[1] 1704 1705 files1, testfiles1, allcompvar1, Nvar1= read_varcomp_file(idir1+'/varcompute.inf') 1706 files2, testfiles2, allcompvar2, Nvar2= read_varcomp_file(idir2+'/varcompute.inf') 1707 1708 # Getting 'op' differences characteristics 1709 doops, opvar, indivopvar, varglobalp = get_differences_var(diffop, 'op', debug) 1710 1711 diffops = {} 1712 Ndiffop = 0 1713 for vn in opvar.keys(): 1714 vnops = opvar[vn] 1715 for op in vnops: 1716 vnop = vn + '_' + op 1717 if not allcompvar1.has_key(vnop): 1718 print warnmsg 1719 print ' ' + fname + ": DIFFOP variable+operation '" + vnop + \ 1720 "' in '" + mods[0] + '/' + exps[0] + "' was not computed !!" 1721 print ' skipping it!' 1722 break 1723 if not allcompvar2.has_key(vnop): 1724 print warnmsg 1725 print ' ' + fname + ": DIFFOP variable+operation '" + vnop + \ 1726 "' in '" + mods[1] + '/' + exps[1] + "' was not computed !!" 1727 print ' skipping it!' 1728 break 1729 vals1 = allcompvar1[vnop] 1730 vals2 = allcompvar2[vnop] 1731 1732 headerf1 = vals1[0] 1733 headerf2 = vals2[0] 1734 1735 diffops[vnop] = [headerf1, headerf2] 1736 1737 Ndiffop = Ndiffop + 1 1738 1739 # Getting 'var' differences characteristics 1740 doops, opvar, indivopvar, varglobalp = get_differences_var(diffvar, 'var', debug) 1741 1742 diffvars = {} 1743 Ndiffvar = 0 1744 for vn in opvar.keys(): 1745 vnops = opvar[vn] 1746 for op in vnops: 1747 vnop = vn + '_' + op 1748 if not allcompvar1.has_key(vnop): 1749 print warnmsg 1750 print ' ' + fname + ": DIFFVAR variable+operation '" + vnop + \ 1751 "' in '" + mods[0] + '/' + exps[0] + "' was not computed !!" 1752 print ' skipping it!' 1753 break 1754 if not allcompvar2.has_key(vnop): 1755 print warnmsg 1756 print ' ' + fname + ": DIFFVAR variable+operation '" + vnop + \ 1757 "' in '" + mods[1] + '/' + exps[1] + "' was not computed !!" 1758 print ' skipping it!' 1759 break 1760 vals1 = allcompvar1[vnop] 1761 vals2 = allcompvar2[vnop] 1762 1763 headerf1 = vals1[0] 1764 headerf2 = vals2[0] 1765 1766 diffvars[vnop] = [headerf1, headerf2] 1767 1768 Ndiffvar = Ndiffvar + 1 1769 1770 Sopdiffs = gen.dictKeysVals_stringList(diffops) 1771 Svardiffs = gen.dictKeysVals_stringList(diffvars) 1772 1773 # Outwritting the op diffferences file to avoid next time (if it is not filescratch!) 1774 objf = open(odir + '/diffop.inf', 'w') 1775 objf.write('differences: ' + Sopdiffs + '\n') 1776 objf.write('Ndiff: ' + str(Ndiffop) + '\n') 1777 objf.close() 1778 1779 # Outwritting the var diffferences file to avoid next time (if it is not filescratch!) 1780 objf = open(odir + '/diffvar.inf', 'w') 1781 objf.write('differences: ' + Svardiffs + '\n') 1782 objf.write('Ndiff: ' + str(Ndiffvar) + '\n') 1783 objf.close() 1784 1785 return diffops, diffvars, Ndiffvar, Ndiffop 1786 1787 def read_diff_file(difffile): 1788 """ Function to read the file with the information about the differences 1789 difffile= file with the information 1790 """ 1791 fname = 'read_diff_file' 1792 1793 if not os.path.isfile(difffile): 1794 print errormsg 1795 print ' ' + fname + ": differences file '" + difffile + "' does not exist !!" 1796 quit(-1) 1797 1798 objf = open(difffile, 'r') 1799 for line in objf: 1800 if line[0:1] != '#' and len(line) > 1: 1801 values = line.split(' ') 1802 if values[0] == 'differences:': 1803 diffs = gen.stringList_dictKeysVals(values[1]) 1804 elif values[0] == 'Ndiff:': 1805 Ndiffs = int(values[1]) 1806 1807 objf.close() 1808 1809 return diffs, Ndiffs 1810 1615 1811 # Files with information about the configuration of the script 1616 1812 inffiles = ['varcompute.inf', 'all_computevars.inf', 'all_statsvars.inf'] … … 1788 1984 # Experiments loop 1789 1985 ## 1986 # There are two kind of differences: 1987 # DIFFop: differences between operations of each given variable. 1988 # Differences are computed directly from the last stage of the operation 1989 # DIFFvar: operations of differences between variables 1990 # First are computed the differences from the initial variable file 1991 # and then operations are made 1992 # NOTE: remember that: meanvar2 - meanvar1 = mean(var2 - var1) 1993 difffiles = ['diffop.inf', 'diffvar.inf'] 1994 1790 1995 Nexps = len(exps) 1791 1996 for exp1 in exps[0:Nexps-1]: … … 1795 2000 sout = sub.call('mkdir -p ' + owdir, shell=True) 1796 2001 1797 diffvarcompf = owdir + '/diffvarcompute.inf' 1798 if diffscratch: 1799 sub.call('rm -rf' + owdir +' >& /dev/null', shell=True) 1800 sub.call('rm ' + diffvarcompf +' >& /dev/null', shell=True) 1801 objf = open(owdir+'/all_diffcomputevars.inf','w') 1802 objf.write("## Computation and drawing of differences between '" + \ 1803 exp2 + "'-'" + exp1 + "'\n") 1804 objf.close() 1805 1806 if adddiffs: 1807 sub.call('rm ' + diffvarcompf +' >& /dev/null', shell=True) 1808 2002 # Removing files with list of differences if should be started from scratch or add differences 2003 for fdiff in difffiles: 2004 difff = owdir + '/' + fdiff 2005 if diffscratch: 2006 sub.call('rm -rf' + owdir +' >& /dev/null', shell=True) 2007 sub.call('rm ' + diffvarcompf +' >& /dev/null', shell=True) 2008 objf = open(owdir+'/all_' + fdiff,'w') 2009 objf.write("## Computation and drawing of differences " + \ 2010 "between '" + exp2 + "'-'" + exp1 + "'\n") 2011 objf.close() 2012 2013 if adddiffs: 2014 sub.call('rm ' + difff +' >& /dev/null', shell=True) 2015 2016 # op and var differences 2017 diffvarcompf = owdir + '/' + difffiles[0] 1809 2018 if not os.path.isfile(diffvarcompf): 1810 alldiff compvar, Ndiffs = diffcompvars_listconstruct(cnf, Modinf,\1811 allcompvar, owdir, dbg)2019 alldiffop, alldiffvar,Nopdiffs,Nvardiffs=diffvarop_listconstruct(cnf,\ 2020 [mod, mod], [exp1, exp2], owdir, dbg) 1812 2021 else: 1813 2022 print warnmsg 1814 print ' ' + main + ": getting differences to compute already from file !!" 1815 alldiffcompvar, Ndiffs = read_diffvarcomp_file(diffvarcompf) 2023 print ' ' + main + ": getting 'op' and 'var'differences to " + \ 2024 "compute already from file !!" 2025 alldiffop, Nopdiffops = read_diff_file(diffvarcompf) 2026 alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1]) 1816 2027 1817 2028 # End of avoiding to repeat all the experiment search … … 1822 2033 if dbg: 1823 2034 print 'Differences to compute _______' 1824 gen.printing_dictionary(alldiffcompvar) 2035 gen.printing_dictionary(alldiffop) 2036 gen.printing_dictionary(alldiffvar) 1825 2037 1826 2038 quit() -
TabularUnified trunk/tools/model_graphics_template.dat ¶
r1031 r1032 42 42 43 43 # Debug 44 debug = false44 debug = true 45 45 46 46 # Folder with the files … … 108 108 #varcombo = ta;pinterp@last@xmean:ua;pinterp@last@xmean:va;pinterp@last@xmean:hur;pinterp@last@xmean:ws;pinterp@turb@xmean:hus;pinterp@turb@xmean 109 109 110 vardiff = tas|last:tas|xmean:tas|tmean:wss|last:wss|xmean:wss|tmean:ua|pinterp@last@xmean:va|pinterp@last@xmean 110 # Differences to compute 111 # These differences will be computed among experiments and among models (and model-experiments) 112 # ':' separated list of [var]|[op] 113 # DIFFOP_[op]: differences of the [op] of [var]. NOTE: [op] must exist for each experiment 114 # Differences are computed directly from the last stage of the operation 115 # DIFFVAR_[op]: [op] of the [var] differences [var]. NOTE: [var] must exist for each experiment 116 # First are computed the differences from the initial variable file and then operations are made 117 # NOTE: remember that: meanvar2 - meanvar1 = mean(var2 - var1) 118 DIFFOP_last = hfls:hfss 119 DIFFOP_xmean = uas:vas 120 DIFFOP_tmean = hfss:hfls 121 DIFFOP_pinterp+tmean+xmean = ua:va 122 123 DIFFVAR_last = hfls:hfss 124 DIFFVAR_xmean = uas:vas 125 DIFFVAR_tmean = hfss:hfls 126 DIFFVAR_pinterp+tmean+xmean = ua:va 111 127 112 128 # Operations which attach a 'surname' at the end of the variable name
Note: See TracChangeset
for help on using the changeset viewer.