Exemplo n.º 1
0
 def test_calc_area(self):
     self.assertEqual(3, calc_area(1))
     self.assertEqual(196350, calc_area(250))
     self.assertEqual(0, calc_area(0))
     self.assertEqual(31416, calc_area(100))
     self.assertEqual(7, calc_area(1.5))
     self.assertEqual(314159265, calc_area(10000))
     self.assertTrue(isinstance(calc_area(1.5), int))
Exemplo n.º 2
0
def budget_anc(netCDF, word):
    var=word
    ncbase=netCDF
    data = ncbase.variables[var]		# kg.m-2.-1
    lat = np.array(ncbase.variables['latitude'],dtype=np.float64)[:]
    lon = np.array(ncbase.variables['longitude'],dtype=np.float64)[:]
    area=calc_area.calc_area(lon,lat)		# m2.gridcell-1
    budget=int(round(np.sum(np.mean(data*area, axis=0))*3600*24*360*1E-9))			# Tg.yr-1
    unit = r'$\mathbf{\ Tg\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 3
0
def budget_anc(netCDF, word):
    var = word
    ncbase = netCDF
    data = ncbase.variables[var]  # kg.m-2.-1
    lat = np.array(ncbase.variables['latitude'], dtype=np.float64)[:]
    lon = np.array(ncbase.variables['longitude'], dtype=np.float64)[:]
    area = calc_area.calc_area(lon, lat)  # m2.gridcell-1
    budget = int(
        round(np.sum(np.mean(data * area, axis=0)) * 3600 * 24 * 360 *
              1E-9))  # Tg.yr-1
    unit = r'$\mathbf{\ Tg\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 4
0
def budget(netCDF, word):
    var=word
    ncbase=netCDF
    data = ncbase.variables[var]
    if var=='ch4_oh_rxn_flux':
        budget = int(round(np.sum(np.mean(data, axis=0)*16)*3600*24*360*1E-12))
    elif var=='ch4_ems' :
        lat = np.array(ncbase.variables['latitude'],dtype=np.float64)[:]
        lon = np.array(ncbase.variables['longitude'],dtype=np.float64)[:]
        area=calc_area.calc_area(lon,lat)	# m2.gridcell-1
        budget=int(round(np.sum(np.mean(data*area, axis=0))*3600*24*360*1E-9))			# Tg.yr-1
    unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 5
0
def yearly_budget(netCDF, word): 
    var=word
    ncbase=netCDF
    data = ncbase.variables[var]
    budget=[]
    for y in range(0,np.shape(data)[0]/12):
        if var=='ch4_oh_rxn_flux':
            budget.append(int(round(np.sum(np.mean(data[y*12:(y+1)*12], axis=0)*16)*3600*24*360*1E-12)))
        elif var=='ch4_ems':
            lat = np.array(ncbase.variables['latitude'],dtype=np.float64)[:]
            lon = np.array(ncbase.variables['longitude'],dtype=np.float64)[:]
            area=calc_area.calc_area(lon,lat)	# m2.gridcell-1
            budget=int(round(np.sum(np.mean(data*area[y*12:(y+1)*12], axis=0))*3600*24*360*1E-9))		# Tg.yr-1
    unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 6
0
def seasonal_budget(netCDF, word):
    var=word
    ncbase=netCDF
    season=seasonal_data.season(ncbase, var)
    budget=[]
    for i in range(0,4):
      if var=='ch4_oh_rxn_flux':
        budget.append(int(round(np.sum(season[i]*16)*3600*24*360*1E-12)))
      elif var=='ch4_ems':
        lat = np.array(ncbase.variables['latitude'],dtype=np.float64)[:]
        lon = np.array(ncbase.variables['longitude'],dtype=np.float64)[:]
        area=calc_area.calc_area(lon,lat)	# m2.gridcell-1
        budget.append(int(round(np.sum(season[i]*area)*3600*24*360*1E-9)))	# Tg.yr-1
      unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 7
0
def seasonal_budget(netCDF, word):
    var = word
    ncbase = netCDF
    season = seasonal_data.season(ncbase, var)
    budget = []
    for i in range(0, 4):
        if var == 'ch4_oh_rxn_flux':
            budget.append(
                int(round(np.sum(season[i] * 16) * 3600 * 24 * 360 * 1E-12)))
        elif var == 'ch4_ems':
            lat = np.array(ncbase.variables['latitude'], dtype=np.float64)[:]
            lon = np.array(ncbase.variables['longitude'], dtype=np.float64)[:]
            area = calc_area.calc_area(lon, lat)  # m2.gridcell-1
            budget.append(
                int(round(np.sum(season[i] * area) * 3600 * 24 * 360 *
                          1E-9)))  # Tg.yr-1
        unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 8
0
def budget(netCDF, word):
    var = word
    ncbase = netCDF
    data = ncbase.variables[var]
    if var == 'ch4_oh_rxn_flux':
        budget = int(
            round(
                np.sum(np.mean(data, axis=0) * 16) * 3600 * 24 * 360 * 1E-12))
    elif var == 'ch4_ems':
        lat = np.array(ncbase.variables['latitude'], dtype=np.float64)[:]
        lon = np.array(ncbase.variables['longitude'], dtype=np.float64)[:]
        area = calc_area.calc_area(lon, lat)  # m2.gridcell-1
        budget = int(
            round(
                np.sum(np.mean(data * area, axis=0)) * 3600 * 24 * 360 *
                1E-9))  # Tg.yr-1
    unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 9
0
def yearly_budget(netCDF, word):
    var = word
    ncbase = netCDF
    data = ncbase.variables[var]
    budget = []
    for y in range(0, np.shape(data)[0] / 12):
        if var == 'ch4_oh_rxn_flux':
            budget.append(
                int(
                    round(
                        np.sum(
                            np.mean(data[y * 12:(y + 1) * 12], axis=0) * 16) *
                        3600 * 24 * 360 * 1E-12)))
        elif var == 'ch4_ems':
            lat = np.array(ncbase.variables['latitude'], dtype=np.float64)[:]
            lon = np.array(ncbase.variables['longitude'], dtype=np.float64)[:]
            area = calc_area.calc_area(lon, lat)  # m2.gridcell-1
            budget = int(
                round(
                    np.sum(np.mean(data * area[y * 12:(y + 1) * 12], axis=0)) *
                    3600 * 24 * 360 * 1E-9))  # Tg.yr-1
    unit = r'$\mathrm{\ Tg(CH_{4})\ yr^{-1}}$'
    return budget, unit
Exemplo n.º 10
0
        writer = csv.writer(f, lineterminator='\n')
        writer.writerow(title)
        for i, file in enumerate(files, 721):
            if int(i) in delete:
                pass
            else:
                img = cv2.imread(file)
                # 画像のトリミング
                trimmed_img = img[600:1600, 1000:2000]
                cv2.imwrite(path + '/trimmed/' + str(i) + '_trimmed.png',
                            trimmed_img)
                # 明度の調整
                reg_img = reg_brightness(trimmed_img)
                cv2.imwrite(path + '/reg/' + str(i) + '_reg.png', reg_img)
                # 緑地面積の計算
                area = calc_area(reg_img)
                green_area = area[0]

                # pillowで緑地部分のみの切り抜き画像を作成
                cv2.imwrite(path + '/bw/' + str(i) + '_bw.png', area[1])
                src = Image.open(path + '/reg/' + str(i) + '_reg.png')
                mask = Image.open(path + '/bw/' + str(i) + '_bw.png')
                masked_src = src.copy()
                masked_src.putalpha(mask)
                masked_src.save(path + '/masked/' + str(i) + '_masked.png')

                # データ水増し
                masked_src.save(path + '/dataset/' + str(i) + '_dataset_0.png')
                masked_src.transpose(
                    Image.ROTATE_180).save(path + '/dataset/' + str(i) +
                                           '_dataset_1.png')