Changeset 1837 in lmdz_wrf
- Timestamp:
- Mar 22, 2018, 3:39:20 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1794 r1837 1483 1483 got an extra dependency... 1484 1484 >>> variables_values('WRFght') 1485 ['z', 'geopotential_height', 0.0, 80000.0, 'geopotential|height', 'm2s-2', 'rainbow', ] 1485 ['z', 'geopotential_height', 0.0, 80000.0, 'geopotential|height', 'm2s-2', 1486 'rainbow', '$z$', 'z'] 1486 1487 """ 1487 1488 import subprocess as sub -
trunk/tools/nc_var_tools.py
r1836 r1837 22492 22492 return 22493 22493 22494 22495 22494 def compute_WRFtime_bnds(timewrfv, period, kindWRFt='begperiod', \ 22496 22495 refdate='19491201000000', tunitsval='minutes'): … … 22671 22670 22672 22671 #onc.close() 22672 22673 def CFmorzization(values, ncfile, variable): 22674 """ Function to provide a CF-compilation version of a variable within a file 22675 See further details at: 22676 - Christensen, Gutowski, Nikulin, and Legutke; 2013. CORDEX Archive Design 22677 (http://cordex.org/publications/report-and-document-archives/) 22678 - Taylor, K., and C. Doutriaux, 2011. âCMIP5 Model Output Requirements: File 22679 Contents and Format, Data Structure and Meta Dataâ 22680 (http://cmip-pcmdi.llnl.gov/cmip5/output_req.html#metadata) 22681 22682 values=[dimvarns]:[globattrfile] 22683 [dimvarns]: ',' separated list for identification of axes, dimensions and 22684 variable-dimensions as '[AXIS]|[dimn]|[vardimn]' 22685 [AXIS]: axis of the file: 'X', 'Y', 'Z', or 'T' 22686 [dimn]: name of the current name of the dimension of the given axis 22687 [vardimn]: name of the current name of the variable-dimension of the 22688 given axis 22689 [globattrfilen]: name of ASCII file with the given metadata to be added as global attributes 22690 with a line per attribute [attrname] [value] it has to have at least (underparenthesis for description) 22691 use '#' for comments: 22692 institute_id [value, use '!' for spaces] (CV) 22693 institution [value] 22694 model_id [value] (CORDEX starts with <institute_id>-) 22695 experiment_id [value] (same CV as CMIP5 with "evaluation" in addition) 22696 experiment [value] (long version of "experiment_id") 22697 contact [value] ([Name], [email] of contact person) 22698 product [value] (single value: "output") 22699 Conventions [value] (later than CF1.4 if present / single value: "CF-1.4") 22700 creation_date [YYYY-MM-DDTHH:MM:SSZ] (format according to UNIDATA conventions, same in CMIP5 & CORDEX) 22701 frequency [value] (same CV as CMIP5 with "sem" in addition; 3hr highest freq. in CORDEX; no "yr") 22702 driving_model_id [value] (CMIP5 institute_id, <CMIP5 institute_id>-<member in CMIP5 CV list of model_id>) 22703 driving_model_ensemble_member [value] (CMIP5 CV, e.g. "r1i1p1") 22704 driving_experiment_name [value] ("evaluation" or <member in CMIP5 CV list of experiment_id >) 22705 driving_experiment [value] ("<driving_model_id>,<driving_experiment_name>,<driving_model_ensemble_member>", 22706 members of the CMIP5 list of forcing agents are not necessarily forcing agents of RCM (besides implicitly 22707 in driving_experimnt) 22708 rcm_version_ID [value] (<free text string>; valid characters only indicates model modifs during the project 22709 e.g.: parameterizations, small upgrades) 22710 project_id [value] (single value) 22711 CORDEX_domain [value] ((e.g.: "AFR-44", "AFR-44i", includes resolution acronym) 22712 tracking_id [value] (not required or explained in ADD; it is, however, strongly recommended to include it 22713 as prescribed CMIP5.) 22714 basetime [value] (reference time "1949-12-01T00:00:00Z" formatted acording to UNIDATA conventions) 22715 calendar [value] (CF conventions as in driving model) 22716 grid [value] (according to CF conventions 22717 ncfile= netCDF file to use 22718 variable= ',' list of variables to CF transform ('all' for all variables). A separated file will be created 22719 for each variable 22720 NOTE: CF values will be taken from 'variables_values.dat' 22721 """ 22722 fname = 'CFmorzization' 22723 22724 if values == 'h': 22725 print fname + '_____________________________________________________________' 22726 print CFmorzizarion.__doc__ 22727 quit() 22728 22729 expectargs = '[dimvarns]:[globattrfilen]' 22730 gen.check_arguments(fname, values, expectargs, ':') 22731 22732 dimvarns = values.split(':')[0].split(',') 22733 globalattrfilen = values.split(':')[1] 22734 22735 # CF Mandatory global attributes 22736 mangattr = ['institute_id', 'institution', 'model_id', 'experiment_id', \ 22737 'experiment', 'contact', 'product', 'Conventions', 'creation_date','frequency',\ 22738 'driving_model_id', 'driving_model_ensemble_member', 'driving_experiment_name',\ 22739 'driving_experiment', 'rcm_version_ID', 'project_id', 'CORDEX_domain', \ 22740 'tracking_id', 'basetime', 'calendar', 'grid'] 22741 22742 # Getting axes information 22743 axisinf = {} 22744 for dvn in dimvarns: 22745 axis = dvn.split('|')[0] 22746 dimn = dvn.split('|')[1] 22747 dimvn = dvn.split('|')[2] 22748 axisinf[axis] = [dimn, dimvn] 22749 22750 # Getting global attributes 22751 if not os.path.isfile(globalattrfilen): 22752 print errormsg 22753 print ' '+fname+ "': ASCII file with global attributes '" + globalattrfilen \ 22754 + "' does not exist !!" 22755 quit(-1) 22756 22757 gattr = {} 22758 ogatrf = open(globalattrfilen, 'r') 22759 for line in ogatrf: 22760 if line[0:1] != '#' and len(line) > 1: 22761 linevals = line.replace('\n','').replace('\t','').split(' ') 22762 gattr[linevals[0]] = linevals[1].replace('!',' ') 22763 ogatrf.close() 22764 # Checking for presence of mandatory attributes 22765 for mgattr in mangattr: 22766 if not gattr.has_key(mgattr): 22767 print errormsg 22768 print ' '+fname+ "': ASCII file with global attributes does not " + \ 22769 "contain attribute '" + mgattr + "' !!" 22770 quit(-1) 22771 22772 # Getting variables to process 22773 onc = NetCDFFile(ncfile,'r') 22774 if variable == 'all': 22775 Varns = onc.variables 22776 # Removing axis variables 22777 for axis in axisinf.keys: 22778 dimvn = axis[axis][1] 22779 if gen.searchInlist(Varns, dimvn): Varns.remove(dimvn) 22780 else: 22781 Varns = gen.str_list(variable, ',') 22782 22783 # Creation of new file name 22784 # This will done following CORDEX rules (getting information from the ASCII 22785 # global attributes and variable): 22786 # Institution: institude_id 22787 # VariableName: from `variables_values.dat' 22788 # Domain: CORDEX_domain 22789 # GCMModelName: driving_model_id 22790 # CMIP5ExperimentName: driving_experiment_name 22791 # CMIP5EnsembleMember: driving_model_ensemble_member 22792 # RCMModelName: model_id 22793 # RCMVersionID: rcm_version_id 22794 # Frequency: frequency 22795 # StartTime-EndTime: (not allowed if <frequency>=fx) 22796 # filen = Institution_VariableName_Domain_GCMModelName_CMIP5ExperimentName_ 22797 # CMIP5EnsembleMember_RCMModelName_RCMVersionID_Frequency_StartTime-EndTime.nc 22798 22799 for vn in varns: 22800 # getting CF information 22801 varinf = gen.variables_values(vn) 22802 cfvarn = varinf[0] 22803 stdvarn = varinf[1] 22804 longvarn = varinf[4].replace('|', ' ') 22805 22806 if not onc.variables.has_key(vn): 22807 print errormsg 22808 print ' '+fname+ "': netcdf file '" + ncfile + "' does not contain " + \ 22809 "variable '" + vn + "' !!" 22810 onc.close() 22811 quit(-1) 22812 22813 filen = gattr['institude_id'] + '_' + cfvarn + '_' + gattr['CORDEX_domain'] +\ 22814 '_' + gattr['driving_model_id'] + '_' + gattr['driving_experiment_name'] + \ 22815 '_' + gattr['driving_model_ensemble_member'] + '_' + gattr['model_id'] + \ 22816 '_' + gattr['rcm_version_id'] + '_' + Sfrequency + '_' StartTime-EndTime + \ 22817 '.nc' 22818 22819 onc.close() 22820 return 22821 22673 22822 #quit()
Note: See TracChangeset
for help on using the changeset viewer.