tacknowledge.py - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
 (HTM) git clone git://src.adamsgaard.dk/pism
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tacknowledge.py (2944B)
       ---
            1 #!/usr/bin/env python3
            2 
            3 header = """
            4 ..
            5    DO NOT EDIT: This file was automatically generated by running doc/acknowledge.py
            6 
            7    Edit doc/acknowledge.py, doc/funding.csv, and doc/citing-pism.bib
            8 """
            9 
           10 acknowledgement = """
           11 Acknowledging PISM funding sources
           12 ----------------------------------
           13 
           14 If you use PISM in a publication then we ask for an acknowledgement of funding and a
           15 citation. However, unless PISM developers are involved in the preparation of the
           16 publication at the usual co-author level, we do not expect co-authorship on PISM-using
           17 papers.
           18 
           19 To acknowledge PISM funding please include the statement:
           20 """
           21 
           22 citing = """
           23 Citing
           24 ------
           25 
           26 To cite PISM please use at least one of Bueler and Brown (2009) or Winkelmann et al.
           27 (2011), below, as appropriate to the application.
           28 
           29 If your results came from source code modifications to PISM then we request that your
           30 publication say so explicitly.
           31 
           32 If your study relies heavily on certain PISM sub-models (such as hydrology, calving,
           33 fracture mechanics, thermodynamics) please contact the corresponding author/developer for
           34 information on additional citations.
           35 
           36 .. code::
           37 """
           38 
           39 import csv
           40 import time
           41 import sys
           42 import argparse
           43 
           44 parser = argparse.ArgumentParser()
           45 parser.description = '''Generate a funding acknowledgment string.'''
           46 parser.add_argument("--manual", action="store_true")
           47 options = parser.parse_args()
           48 
           49 year = time.gmtime(time.time())[0]
           50 funding = {}
           51 
           52 with open("funding.csv", "r") as f:
           53     reader = csv.reader(f, skipinitialspace=True, quoting=csv.QUOTE_ALL)
           54 
           55     funding = {}
           56     for row in reader:
           57         start_year, end_year, agency, number, _ = row
           58 
           59         try:
           60             start_year = int(start_year)
           61             end_year = int(end_year)
           62         except:
           63             continue
           64 
           65         if start_year <= year and year <= end_year:
           66             try:
           67                 funding[agency].append(number)
           68             except:
           69                 funding[agency] = [number]
           70 
           71 
           72 def join(strings):
           73     assert len(strings) > 0
           74     if len(strings) == 1:
           75         return strings[0]
           76     elif len(strings) == 2:
           77         return "{} and {}".format(strings[0], strings[1])
           78     else:
           79         return join(["{}, {}".format(strings[0], strings[1]),
           80                      join(strings[2:])])
           81 
           82 
           83 grants = []
           84 for k, v in funding.items():
           85     grant = "grant"
           86     if len(v) > 1:
           87         grant = "grants"
           88 
           89     grants.append("{agency} {grant} {number}".format(agency=k,
           90                                                      grant=grant,
           91                                                      number=join(v)))
           92 
           93 if options.manual:
           94     print(header)
           95     print("""
           96 Development of PISM is supported by {grants}.""".format(grants=join(grants)))
           97 else:
           98     print(header)
           99     print(acknowledgement)
          100     print("""
          101     Development of PISM is supported by {grants}.
          102 """.format(grants=join(grants)))
          103     print(citing)
          104     with open("citing-pism.bib") as f:
          105         for line in f:
          106             sys.stdout.write("   {}".format(line))