コード例 #1
0
ファイル: main.py プロジェクト: easyDiffraction/CoDE
def calculator_test():
    """
    Test the calculator(s)
    """
    # instantiate default Calculator object
    # and define initial state
    calc = Calculator(structure=dna, wavelength=1.2)

    # calculate XRD for the structure, using defined engine
    #data_out = calc.calculateXRD(structure=diamond, engine="ASE")

    # calculate XRD for the structure, using default engine
    data_out = calc.calculateXRD()

    # create a chart object
    chart = Chart()

    # add powder data to the chart. This needs to be made such that
    # setData doesn't need a type (setData1D/setDataCrystal) but rather
    # gets set depending on the type of the argument passed
    chart.setData1D(data_out)

    # create MPL representation of the Chart object
    #mpl_chart = chart.getMplChart()
    #mpl_chart.show()

    # or just show it directly
    chart.show()
コード例 #2
0
def year_distribution(start, end):
    os.mkdir(chart_path) if not os.path.exists(chart_path) else ''
    pubs_per_year = [0 for x in range(start, end)]
    citation_per_year = [0 for x in range(start, end)]
    # print(pubs_per_year)
    year_labels = [str(x) for x in range(start, end)]
    docs = copy.find({}, {'pubs': 1})
    for doc in docs:
        for pub in doc['pubs']:
            if pub['year'] == '':
                continue
            year = int(pub['year'])
            index = year - start
            if 0 > index or index >= end - start:
                continue
            try:
                pubs_per_year[index] += 1
                if pub['citation'].isdigit():
                    citation_per_year[index] += int(pub['citation'])
            except Exception as e:
                print(pub['citation'])
                print(len(pub['citation']))
                print(index)
                sys.exit()

    # pubs_per_year = [year/1000 for year in pubs_per_year]
    chart = Chart(50, 50)
    chart.bar(citation_per_year,
              end - start,
              year_labels,
              'publication number per year',
              'year',
              'number',
              log=False,
              fontsize=10)
    # chart.bar(pubs_per_year,end-start,year_labels,'publication number per year','year','number',log=False,fontsize=10)
    chart.save('pub_per_year', format='png')
    chart.show()