Beispiel #1
0
 def __init__(self, date, sw_ds, wind_rds, res=500):
     datetime_list = []
     for hour in range(0, 24):
         datetime_list.append(datetime(date.year, date.month, date.day, hour))
     part_hourly_energy = partial(delta_swe_hourly_wrapper,
                                  shortwave_ds = sw_ds,
                                  wind_redistribution = wind_rds,
                                  res=500)
     pool = Pool(processes=cpu_count())
     daily_energy_list = pool.map(part_hourly_energy, datetime_list)
     pool.close()
     pool.join()
     self.daily_energy = 0.
     self.daily_precip_snow = 0.
     for i in range(0, len(daily_energy_list)):
         self.daily_energy += daily_energy_list[i][0]
         self.daily_precip_snow += daily_energy_list[i][1] / 1000.
     self.daily_energy[self.daily_energy < 0.] = 0.
     sca_fn = "SCA/" + str(date.year) + "/sca" + str(date.year) + \
              str(date.month).zfill(2) + str(date.day).zfill(2) + ".tif"
     self.FSCA = gdal.Open(sca_fn, GA_ReadOnly).ReadAsArray()
     self.FRA = gdal.Open("vegetation/amr_nlcd2011_500m.tif", GA_ReadOnly).ReadAsArray().astype(float)
     self.FRA[self.FRA >= 100.0] = 99.0
     self.FSCA = self.FSCA / (1.0 - self.FRA / 100.0)
     self.FSCA[self.FSCA > 1.0] = 1.0
     self.delta_swe = self.FSCA * self.daily_energy * 3600.0 / (343000.0 * 1000.0) - self.daily_precip_snow
     export_fn = "output/swe_change_reset_zero_hourly/" + str(date.year) + str(date.month).zfill(2) + \
                 str(date.day).zfill(2) + "delta_swe.tif"
     array2raster(sca_fn, export_fn, self.delta_swe, 0, 0)
     daily_energy_list = None
     self.daily_energy = None
     self.FSCA = None
     self.FRA = None
     self.delta_swe = None
     gc.collect()
Beispiel #2
0
def sum_daily_delta_swe(wy):
    end_month_list = [6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 4]
    end_day_list = [30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30]
    i = wy - 2001
    print "Start summing up year of", wy
    start_date = date(wy, 4, 1)
    end_date = date(wy, end_month_list[i], end_day_list[i])
    temp_date = end_date
    accumulate_swe = 0.
    while temp_date >= start_date:
        delta_swe_fn = "output/swe_change_reset_zero_hourly/" + str(temp_date.year) + str(temp_date.month).zfill(2) + \
                str(temp_date.day).zfill(2) + "delta_swe.tif"
        delta_swe = gdal.Open(delta_swe_fn, GA_ReadOnly).ReadAsArray()
        accumulate_swe += delta_swe
        export_fn = "output/swe_500m_reset_zero_hourly/" + str(wy) + "/" + str(wy) + str(temp_date.month).zfill(2) + \
                str(temp_date.day).zfill(2) + "_swe.tif"
        array2raster(delta_swe_fn, export_fn, accumulate_swe, 0., 0.)
        temp_date -= timedelta(days=1)