DoseNet Workshop (ワークショップ)

==========================================================================

ノートブックをセットアップし、必要なすべてのPythonライブラリをインポートする


In [8]:
# Setup notebook and import all needed python libraries
# Embed plots in the body of the notebook
%matplotlib inline
%config InlineBackend.figure_formats=['svg']

# Standard csv and file io python libraries
import csv
import io
import os

# Library for loading data from a webpage (Python 2 and 3 compatible)
from future.standard_library import install_aliases
install_aliases()
from urllib.request import urlopen, Request

# Main python library for mathematical calculations
import numpy as np
import statistics
from math import log10, floor
from scipy.stats.stats import pearsonr, spearmanr

# Plotting related python libraries
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

# Python libraries for manipulating dates and times as objects
import time
import datetime as dt
from matplotlib.dates import date2num

Method for selecting data within a specified time range

指定された時間範囲内のデータを選択する方法


In [6]:
def SelectDataTimeRange(start_time,stop_time,data,times):
    dataarray = np.array(data)
    timesarray = np.array(times)

    indices = np.where((timesarray>=start_time)&(timesarray<=stop_times))
    subdata  = dataarray[indices]
    subdatatimes = timesarray[indices]
   
    return subdata, subdatatimes

In [ ]:
# import data from weather station for all isotopes
date = []
Bi214 = []
K40 = []
Cs134 = []
Cs137 = []
line = 0
url = 'https://radwatch.berkeley.edu/sites/default/files/pictures/rooftop_tmp/weather.csv'
response = urlopen(url)

reader = csv.reader(response, delimiter=",")
for row in reader:
    # skip meta-data
    if line == 0:
        print('')
        print(", ".join(row))
    else:
        date.append(datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S'))
        Bi214.append(float(row[1]))
        K40.append(float(row[2]))
        Cs134.append(float(row[3]))
        Cs137.append(float(row[4]))
    line += 1

print 'collected data between ', date[0], ' and ', date[-1]