def create_correction_maps(self, date): ''' loads data to create the bias correction map ''' if mode == 'base': # to create base error maps filename_mean_error = 'analysis/mean_drifterror/SIPN2_error_{}{}.bin'.format( date[1], date[2]) filename_mean_error_extent = 'analysis/mean_drifterror_extent/SIPN2_error_{}{}.bin'.format( date[1], date[2]) elif mode == 'corrected': #to create error maps with drift correction filename_mean_error = 'analysis/mean_drifterror_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) filename_mean_error_extent = 'analysis/mean_drifterror_extent_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) mixmap_name = 'analysis/icedrift_correction/SIPN2_error_{}{}.bin'.format( date[1], date[2]) error_map = CryoIO.openfile(filename_mean_error, np.float16) / 100 error_map2 = CryoIO.openfile(filename_mean_error_extent, np.float16) / 100 mix_map = self.mix_errormaps(error_map, error_map2) export = np.array(mix_map * 100, dtype=np.float16) CryoIO.savebinaryfile(mixmap_name, export) self.errorshow(mix_map, 5, date, 'Correction Map') self.fig3.savefig('Images/Correction/Correction_Map_{}{}{}'.format( date[0], date[1], date[2]))
def calcMeanerrorgrid(): '''calculation for mean error grid''' datelist = dateloop() p = Pool(processes=22) data = p.map(spawnprocess_mean_calc, datelist) print(len(data)) p.close() CryoIO.csv_columnexport('analysis/mean_error.csv', [data])
def calc_difference(self, icepredict, iceobserve, filename_error): '''calculates the SIC error for a single day''' error_map = icepredict - iceobserve for x, y in enumerate(error_map): if self.regmaskf[x] > 10: error_map[x] = 0 error_map = np.array(error_map * 100, dtype=np.float16) CryoIO.savebinaryfile(filename_error, error_map) return
def masksload(self): ''' Loads NSIDC masks''' filename = 'X:/NSIDC_South/Masks/region_s_pure.msk' self.regmaskf = CryoIO.openfile(filename, np.uint8) filename = 'X:/NSIDC_South/Masks/pss25area_v3.dat' self.areamaskf = CryoIO.openfile(filename, np.int32) / 1000 filename = 'X:/NSIDC_South/Masks/pss25lats_v3.dat' self.latmaskf = CryoIO.openfile(filename, np.int32) / 100000 filename = 'X:/NSIDC_South/Masks/pss25lons_v3.dat' self.lonmaskf = CryoIO.openfile(filename, np.int32) / 100000
def masksload(self): ''' Loads NSIDC masks and Daily Solar Energy Data''' filename = 'X:/NSIDC_South/Masks/region_s_pure.msk' self.regmaskf = CryoIO.openfile(filename, np.uint8) filename = 'X:/NSIDC_South/Masks/pss25area_v3.dat' self.areamaskf = CryoIO.openfile(filename, np.int32) / 1000 filename = 'X:/NSIDC_South/Masks/pss25lats_v3.dat' self.latmaskf = CryoIO.openfile(filename, np.int32) / 100000 filename = 'X:/NSIDC_South/Masks/pss25lons_v3.dat' self.lonmaskf = CryoIO.openfile(filename, np.int32) / 100000 self.latitudelist = np.loadtxt( 'X:/NSIDC_South/Masks/Lattable_south_MJ_all_year.csv', delimiter=',') self.co2list = np.loadtxt('X:/NSIDC_South/Masks/Global_CO2.csv', delimiter=',')
def masksload(self): ''' Loads NSIDC masks and Daily Solar Energy Data''' filename = 'X:/NSIDC/Masks/Arctic_region_mask.bin' self.regmaskf = CryoIO.openfile(filename, np.uint32) filename = 'X:/NSIDC/Masks/psn25area_v3.dat' self.areamaskf = CryoIO.openfile(filename, np.uint32) / 1000 filename = 'X:/NSIDC/Masks/psn25lats_v3.dat' self.latmaskf = CryoIO.openfile(filename, np.uint32) / 100000 filename = 'X:/NSIDC/Masks/psn25lons_v3.dat' self.lonmaskf = CryoIO.openfile(filename, np.uint32) / 100000 self.latitudelist = np.loadtxt( 'X:/NSIDC/Masks/Lattable_MJ_all_year.csv', delimiter=',') self.co2list = np.loadtxt('X:/NSIDC/Masks/Global_CO2_forecast.csv', delimiter=',') self.templist = np.loadtxt('X:/NSIDC/Masks/DMI_Temp_80N.csv', delimiter=',')
def getvolume(self, thickness, daycount, day, month, year): ''' first day initialisation ''' self.daycount = daycount self.start = date(year, month, day) self.loopday = self.start self.year = year self.stringmonth = str(self.loopday.month).zfill(2) self.stringday = str(self.loopday.day).zfill(2) self.datestring = '{}{}{}'.format(self.year, self.stringmonth, self.stringday) lastday = '{}{}{}'.format(self.year, self.stringmonth, self.stringday) self.index = self.loopday.timetuple().tm_yday self.yearday = self.loopday.timetuple().tm_yday print(thickness, 'meter') self.CSVDatum = ['Date'] self.CSVVolume = [f'Volume_{year}'] self.CSVExtent = [f'Extent_{year}'] self.CSVArea = [f'Area_{year}'] filename = 'X:/NSIDC_south/DataFiles/NSIDC_{}_south.bin'.format( lastday) self.iceLastDate = CryoIO.openfile(filename, np.uint8) / 250 # Landmask initialisation for x in range(0, len(self.iceLastDate)): if self.regmaskf[x] > 7: self.iceLastDate[x] = 9 # thickness initialisation for x in range(0, len(self.iceLastDate)): if self.regmaskf[x] < 7: if 0.25 < self.iceLastDate[x] <= 1 and self.latmaskf[x] < -55: self.iceLastDate[x] = thickness * self.iceLastDate[x] elif 0.1 < self.iceLastDate[x] < 0.25 and self.latmaskf[ x] < -55: self.iceLastDate[ x] = thickness * self.iceLastDate[x] + 0.05 else: self.iceLastDate[x] = -1 if self.regmaskf[x] < 1: self.iceLastDate[x] = 0 # self.normalshow(self.iceLastDate,volume,area,'Mean') self.prediction() end = time.time() print(end - self.starttime) return self.CSVArea, self.CSVExtent
def compute_error(self): '''loads data for computation of SIC error and extent error of a single day''' filename_obs = 'X:/NSIDC_South/DataFiles/NSIDC_{}_south.bin'.format( self.datestring) filename_pre = 'analysis/predict/SIPN2_{}.bin'.format(self.datestring) if mode == 'base': filename_error = 'analysis/forecast/SIPN2_error_{}.bin'.format( self.datestring) filename_extent_error = 'analysis/forecast_extent/SIPN2_error_{}.bin'.format( self.datestring) elif mode == 'corrected': filename_error = 'analysis/drifterror_new/SIPN2_error_{}.bin'.format( self.datestring) filename_extent_error = 'analysis/extent_error_new/SIPN2_error_{}.bin'.format( self.datestring) iceobserve = CryoIO.openfile(filename_obs, np.uint8) / 250 iceforecast = CryoIO.openfile(filename_pre, np.uint8) / 250 #SIC error self.calc_difference(iceforecast, iceobserve, filename_error) #--------------------------- #extent error aaa = np.vectorize(self.calc_extent_error) error_map, extent_over, extent_under = aaa(iceforecast, iceobserve, self.regmaskf) export = np.array(error_map * 100, dtype=np.int8) CryoIO.savebinaryfile(filename_extent_error, export) extent_over = sum(extent_over) extent_under = sum(extent_under) extent_total = extent_over + extent_under self.extent_list_over.append(extent_over) self.extent_list_under.append(extent_under) self.extent_list_total.append(extent_total) self.CSVDatum.append(self.datestring)
def calc_error_of_mean_grid(self, date): '''calculates the error of the mean error maps''' if mode == 'base': # to create base error maps SIC_map = 'analysis/mean_drifterror/SIPN2_error_{}{}.bin'.format( date[1], date[2]) extent_map = 'analysis/mean_drifterror_extent/SIPN2_error_{}{}.bin'.format( date[1], date[2]) elif mode == 'corrected': #to create error maps with drift correction SIC_map = 'analysis/mean_drifterror_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) extent_map = 'analysis/mean_drifterror_extent_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) #--------------------------- #show mean error error_map1 = CryoIO.openfile(SIC_map, np.float16) / 100 aaa = np.vectorize(self.show_mean_error) error_map1, extent1 = aaa(error_map1, self.regmaskf) error_map2 = CryoIO.openfile(extent_map, np.float16) / 100 aaa = np.vectorize(self.show_mean_error) error_map2, extent2 = aaa(error_map2, self.regmaskf) #--------------------------- extent1 = sum(extent1) extent2 = sum(extent2) self.errorshow(error_map1, extent1, date, 'SIC Error') self.fig3.savefig('Images/SIC/SIC_{}{}{}'.format( date[0], date[1], date[2])) self.errorshow(error_map2, extent2, date, 'Extent Error') self.fig3.savefig('Images/SIE/SIE_{}{}{}'.format( date[0], date[1], date[2])) return '{}/{}/{}'.format(date[0], date[1], date[2]), extent1, extent2
def getvolume(self, thickness, daycount, day, month, year): ''' first day initialisation ''' self.daycount = daycount self.start = date(year, month, day) self.loopday = self.start self.year = year self.stringmonth = str(self.loopday.month).zfill(2) self.stringday = str(self.loopday.day).zfill(2) self.datestring = '{}{}{}'.format(self.year, self.stringmonth, self.stringday) self.index = self.loopday.timetuple().tm_yday self.meltmomentum = self.index print(thickness, 'meter') self.CSVDatum = ['Date'] self.CSVVolume = [f'Volume_{year}'] self.CSVExtent = [f'Extent_{year}'] self.CSVArea = [f'Area_{year}'] filename = 'X:/NSIDC/DataFiles/NSIDC_{}.bin'.format(self.datestring) self.iceLastDate = CryoIO.openfile(filename, np.uint8) / 250 self.sicmap = np.zeros(len(self.iceLastDate), dtype=np.uint8) # Landmask initialisation for x in range(0, len(self.iceLastDate)): if self.regmaskf[x] > 15: self.iceLastDate[x] = 9 self.sicmap[x] = 255 # thickness initialisation for x in range(0, len(self.iceLastDate)): if 1 < self.regmaskf[x] < 16: if self.iceLastDate[x] > 0.15: self.iceLastDate[x] = thickness * self.iceLastDate[x] * ( self.latmaskf[x] / 75) if self.regmaskf[x] < 2: self.iceLastDate[x] = 0 #SIT export for SIPN analysis # CryoIO.savebinaryfile('SIPN2_thickness_20200601.bin',self.iceLastDate) # self.normalshow(self.iceLastDate,volume,area,'Mean') self.prediction() # start dayloop end = time.time() print(end - self.starttime) # self.csvexport_by_forecasttype() # plt.show() return self.CSVArea, self.CSVExtent
def csvexport_by_measure(self): ''' Export values option 2 ''' exportpath = 'X:/Sea_Ice_Forecast/SIPN_north/' CryoIO.csv_columnexport( '{}__SIPN_forecast_Volume{}.csv'.format(exportpath, self.year), [ self.CSVDatum, self.CSVVolumeLow, self.CSVVolume, self.CSVVolumeHigh ]) CryoIO.csv_columnexport( '{}__SIPN_forecast_Area{}.csv'.format(exportpath, self.year), [self.CSVDatum, self.CSVAreaLow, self.CSVArea, self.CSVAreaHigh]) CryoIO.csv_columnexport( '{}__SIPN_forecast_Extent{}.csv'.format(exportpath, self.year), [ self.CSVDatum, self.CSVExtentLow, self.CSVExtent, self.CSVExtentHigh ]) CryoIO.csv_columnexport( '{}_SIPN_forecast_066_{}.csv'.format(exportpath, self.year), [self.CSVDatum, self.CSVAlaska])
def csvexport_by_forecasttype(self): ''' Exporting values option 1 ''' exportpathHigh = 'X:/Sea_Ice_Forecast/SIPN_north/' exportpath = 'X:/Sea_Ice_Forecast/SIPN_north/' exportpathLow = 'X:/Sea_Ice_Forecast/SIPN_north/' CryoIO.csv_columnexport( '{}_SIPN_forecast_002_{}.csv'.format(exportpath, self.year), [self.CSVDatum, self.CSVVolume, self.CSVArea, self.CSVExtent]) CryoIO.csv_columnexport( '{}_SIPN_forecast_003_{}.csv'.format(exportpathHigh, self.year), [ self.CSVDatum, self.CSVVolumeHigh, self.CSVAreaHigh, self.CSVExtentHigh ]) CryoIO.csv_columnexport( '{}_SIPN_forecast_001_{}.csv'.format(exportpathLow, self.year), [ self.CSVDatum, self.CSVVolumeLow, self.CSVAreaLow, self.CSVExtentLow ]) CryoIO.csv_columnexport( '{}_SIPN_forecast_066_{}.csv'.format(exportpath, self.year), [self.CSVDatum, self.CSVAlaska])
def create_mean_error_grid(self, date): ''''calculates a mean error map for the entire dataset''' data = [] data_extent = [] if mode == 'base': # to create base error maps filename_out = 'analysis/mean_drifterror/SIPN2_error_{}{}.bin'.format( date[1], date[2]) filename_out_extent = 'analysis/mean_drifterror_extent/SIPN2_error_{}{}.bin'.format( date[1], date[2]) elif mode == 'corrected': #to create error maps with drift correction filename_out = 'analysis/mean_drifterror_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) filename_out_extent = 'analysis/mean_drifterror_extent_new/SIPN2_error_{}{}.bin'.format( date[1], date[2]) for year in range(2001, 2021): if mode == 'base': filename_error = 'analysis/forecast/SIPN2_error_{}{}{}.bin'.format( year, date[1], date[2]) filename_error_extent = 'analysis/forecast_extent/SIPN2_error_{}{}{}.bin'.format( year, date[1], date[2]) elif mode == 'corrected': filename_error = 'analysis/drifterror_new/SIPN2_error_{}{}{}.bin'.format( year, date[1], date[2]) filename_error_extent = 'analysis/extent_error_new/SIPN2_error_{}{}{}.bin'.format( year, date[1], date[2]) ice = CryoIO.openfile(filename_error, np.float16) #int8 ice_extent = CryoIO.openfile(filename_error_extent, np.int8) #float16 data.append(ice) data_extent.append(ice_extent) ice = self.calcMean(data) ice_extent = self.calcMean(data_extent) export = np.array(ice, dtype=np.float16) export_extent = np.array(ice_extent, dtype=np.float16) CryoIO.savebinaryfile(filename_out, export) CryoIO.savebinaryfile(filename_out_extent, export_extent)
def calcsingleyearerror(): '''calculation for single year error grids''' datalist = [] for year in range(2000, 2021): datalist.append(year) p = Pool(processes=22) data = p.map(spawnprocess, datalist) print(len(data)) p.close() extent_under = [] extent_over = [] extent_total = [] for x in data: extent_under.append(x[0]) extent_over.append(x[1]) extent_total.append(x[2]) # action = NSIDC_analysis() CryoIO.csv_columnexport('analysis/extent_under.csv', extent_under) CryoIO.csv_columnexport('analysis/extent_over.csv', extent_over) CryoIO.csv_columnexport('analysis/extent_total.csv', extent_total)
def prediction(self): ''' Starts the day loop''' filepath = 'X:/NSIDC_South/DataFiles/' filename = 'NSIDC_{}{}{}_south.bin'.format(self.year, self.stringmonth, self.stringday) countmax = self.index + self.daycount iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 self.iceMean = np.array(self.iceLastDate, dtype=float) self.iceHigh = np.array(self.iceLastDate, dtype=float) self.iceLow = np.array(self.iceLastDate, dtype=float) for count in range(self.index, countmax, 1): filename = 'NSIDC_{}_south.bin'.format(self.datestring) filenameAvg = 'Mean_00_19/NSIDC_Mean_{}{}_south.bin'.format( self.stringmonth, self.stringday) filenameChange = 'Daily_change/NSIDC_SIC_Change_{}{}_south.bin'.format( self.stringmonth, self.stringday) filenameStdv = 'Stdv/NSIDC_Stdv_{}{}_south.bin'.format( self.stringmonth, self.stringday) filenameDrift_error = 'analysis/icedrift_correction/SIPN2_error_{}{}.bin'.format( self.stringmonth, self.stringday) #338ppm base value in 1980 co2listindex = (self.year - 1980) * 12 + self.loopday.month - 1 co2value = self.co2list[co2listindex][1] self.back_radiation = self.base_back_radiation - 2 * co2value / 338 self.bottommelt = self.base_bottommelt bottommelt = self.bottommelt bottommeltHigh = self.bottommelt * 0.9 bottommeltLow = self.bottommelt * 1.2 driftcorrection = self.icedrift_sim * 1 driftcorrectionLow = self.icedrift_sim * 0.9 driftcorrectionHigh = self.icedrift_sim * 1.1 icedrift_error = CryoIO.openfile(filenameDrift_error, np.float16) / 100 icedrift_error = icedrift_error #normal dtype:uint8 , filenameChange:int8 , filenameStdv: np.float16 if count <= 336: #change date of year to last available date iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 # self.early_recalibrate(iceforecast) self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecast, icedrift_error, self.iceMean, bottommelt, driftcorrection) self.iceHigh, sicmapHigh, extentHigh, areaHigh, calcvolumeHigh = self.meltcalc( iceforecast, icedrift_error, self.iceHigh, bottommeltHigh, driftcorrectionHigh) self.iceLow, sicmapLow, extentLow, areaLow, calcvolumeLow = self.meltcalc( iceforecast, icedrift_error, self.iceLow, bottommeltLow, driftcorrectionLow) else: icechange = CryoIO.openfile( os.path.join(filepath, filenameChange), np.int8) / 250 iceAvg = CryoIO.openfile(os.path.join(filepath, filenameAvg), np.uint8) / 250 iceStdv = CryoIO.openfile(os.path.join(filepath, filenameStdv), np.float16) / 250 iceforecast = iceforecast + icechange np.clip(iceforecast, 0, 1) iceforecastMean = (2 * iceforecast + iceAvg) / 3 iceforecastHigh = np.array(iceforecastMean + iceStdv * 0.22) iceforecastLow = np.array(iceforecastMean - iceStdv * 0.30) iceforecastMean[iceforecastMean > 1] = 1 iceforecastHigh[iceforecastHigh > 1] = 1 iceforecastLow[iceforecastLow > 1] = 1 iceforecastMean[iceforecastMean < 0] = 0 iceforecastHigh[iceforecastHigh < 0] = 0 iceforecastLow[iceforecastLow < 0] = 0 self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecastMean, icedrift_error, self.iceMean, bottommelt, driftcorrection) self.iceHigh, sicmapHigh, extentHigh, areaHigh, calcvolumeHigh = self.meltcalc( iceforecastHigh, icedrift_error, self.iceHigh, bottommeltHigh, driftcorrection) self.iceLow, sicmapLow, extentLow, areaLow, calcvolumeLow = self.meltcalc( iceforecastLow, icedrift_error, self.iceLow, bottommeltLow, driftcorrection) self.CSVVolume.append(int(calcvolume)) self.CSVExtent.append(round(int((extent)) / 1e6, 4)) self.CSVArea.append(round(int((area)) / 1e6, 4)) self.CSVVolumeHigh.append(int(calcvolumeHigh)) self.CSVExtentHigh.append(round(int((extentHigh)) / 1e6, 4)) self.CSVAreaHigh.append(round(int((areaHigh)) / 1e6, 4)) self.CSVVolumeLow.append(int(calcvolumeLow)) self.CSVExtentLow.append(round(int((extentLow)) / 1e6, 4)) self.CSVAreaLow.append(round(int((areaLow)) / 1e6, 4)) # visualize.thicknessshow(self.iceMean,int(calcvolume),int(extent),'Mean',self.datestring) # visualize.concentrationshow(sicmap,int(area),int(extent),'Mean',self.datestring) #save last date as arrary in mm # if count >= (countmax-15): # if count >330: # visualize.thicknessshow(self.iceMean,int(calcvolume),int(extent),'Mean',self.datestring) # visualize.concentrationshow(sicmap,int(area),int(extent),'Mean',self.datestring) # visualize.fig2.savefig('Images/{}'.format(self.datestring)) # ============================================================================= # # SIPN_analysis_south.thicknessshow(self.iceHigh,int(calcvolumeHigh),int(extentHigh),'High') # SIPN_analysis_south.concentrationshow(sicmapHigh,int(areaHigh),int(extentHigh),'High') # # # SIPN_analysis_south.thicknessshow(self.iceLow ,int(calcvolumeLow),int(extentLow),'Low') # SIPN_analysis_south.concentrationshow(sicmapLow,int(areaLow),int(extentLow),'Low') # ============================================================================= # convert SIT for binary export iceLastDateMean = self.iceMean iceLastDateMean = np.array(iceLastDateMean, dtype=np.float16) iceLastDateHigh = self.iceHigh iceLastDateHigh = np.array(iceLastDateHigh, dtype=np.float16) iceLastDateLow = self.iceLow iceLastDateLow = np.array(iceLastDateLow, dtype=np.float16) # save binary SIT maps exportpath = 'X:/Sea_Ice_Forecast/SIPN_south/2020-21_Submission/' CryoIO.savebinaryfile( '{}001/SIPN2_SIT_001_{}.bin'.format(exportpath, self.datestring), iceLastDateLow) CryoIO.savebinaryfile( '{}002/SIPN2_SIT_002_{}.bin'.format(exportpath, self.datestring), iceLastDateMean) CryoIO.savebinaryfile( '{}003/SIPN2_SIT_003_{}.bin'.format(exportpath, self.datestring), iceLastDateHigh) # save binary SIC maps exportpath = 'X:/Sea_Ice_Forecast/SIPN_south/2020-21_Submission/' CryoIO.savebinaryfile( '{}001/SIPN2_SIC_001_{}.bin'.format(exportpath, self.datestring), sicmapLow) CryoIO.savebinaryfile( '{}002/SIPN2_SIC_002_{}.bin'.format(exportpath, self.datestring), sicmap) CryoIO.savebinaryfile( '{}003/SIPN2_SIC_003_{}.bin'.format(exportpath, self.datestring), sicmapHigh) # ============================================================================= # #SIC export for error analysis # CryoIO.savebinaryfile('analysis/predict/SIPN2_{}.bin'.format(self.datestring),sicmap) # ============================================================================= self.CSVDatum.append('{}/{}/{}'.format(self.year, self.stringmonth, self.stringday)) print(self.year, self.yearday, self.latitudelist[150][self.yearday]) # print(count) if count < countmax: self.advanceday(1)
def prediction(self): ''' Starts the day loop''' filepath = 'X:/NSIDC/DataFiles/' filename = 'NSIDC_{}.bin'.format(self.datestring) countmax = self.index + self.daycount iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 self.iceMean = np.array(self.iceLastDate, dtype=float) self.iceHigh = np.array(self.iceLastDate, dtype=float) self.iceLow = np.array(self.iceLastDate, dtype=float) for count in range(self.index, countmax, 1): filename = 'NSIDC_{}.bin'.format(self.datestring) filenameAvg = 'X:/NSIDC/DataFiles/Forecast_Manual/NSIDC_Mean_{}{}.bin'.format( self.stringmonth, self.stringday) filenameChange = 'X:/NSIDC/DataFiles/Forecast_SIC_change/NSIDC_SIC_Change_{}{}.bin'.format( self.stringmonth, self.stringday) filenameStdv = 'X:/NSIDC/DataFiles/Forecast_Stdv/NSIDC_Stdv_{}{}.bin'.format( self.stringmonth, self.stringday) filenameDrift_error = 'analysis/icedrift_correction/SIPN2_error_{}{}.bin'.format( self.stringmonth, self.stringday) #338ppm base value in 1980 co2listindex = (self.year - 1980) * 12 + self.loopday.month - 1 co2value = self.co2list[co2listindex][1] self.back_radiation = self.base_back_radiation - 2 * co2value / 338 self.air_temp = (self.templist[count] - 273) * self.airtemp_mod self.bottommelt = self.base_bottommelt * self.meltmomentum / 180 bottommelt = self.bottommelt * 1 bottommeltHigh = self.bottommelt * 0.9 bottommeltLow = self.bottommelt * 1.1 driftcorrection = self.icedrift_sim * 1 driftcorrectionLow = self.icedrift_sim * 0.9 driftcorrectionHigh = self.icedrift_sim * 1.1 icedrift_error = CryoIO.openfile(filenameDrift_error, np.float16) / 100 icedrift_error = icedrift_error #fileformats: normal dtype:uint8 , filenameChange:int8 , filenameStdv: np.float16 if count <= 224: #change date of year to last available date iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 if 220 <= count <= 224: self.august_recalibrate(iceforecast) self.iceMean, sicmap, extent, area, calcvolume, alaska = self.meltcalc( iceforecast, icedrift_error, self.iceMean, count, bottommelt, driftcorrection) self.iceHigh, sicmapHigh, extentHigh, areaHigh, calcvolumeHigh, alaskaHigh = self.meltcalc( iceforecast, icedrift_error, self.iceHigh, count, bottommeltHigh, driftcorrectionHigh) self.iceLow, sicmapLow, extentLow, areaLow, calcvolumeLow, alaskaLow = self.meltcalc( iceforecast, icedrift_error, self.iceLow, count, bottommeltLow, driftcorrectionLow) else: #load statistical data icechange = CryoIO.openfile(filenameChange, np.int8) / 250 iceAvg = CryoIO.openfile(filenameAvg, np.uint8) / 250 iceStdv = CryoIO.openfile(filenameStdv, np.float16) / 250 iceforecast = iceforecast + icechange iceforecastMean = (3 * iceforecast + iceAvg) / 4 iceforecastHigh = np.array(iceforecastMean + iceStdv * 0.1) iceforecastLow = np.array(iceforecastMean - iceStdv * 0.3) iceforecastMean[iceforecastMean > 1] = 1 iceforecastHigh[iceforecastHigh > 1] = 1 iceforecastLow[iceforecastLow > 1] = 1 iceforecastMean[iceforecastMean < 0] = 0 iceforecastHigh[iceforecastHigh < 0] = 0 iceforecastLow[iceforecastLow < 0] = 0 self.iceMean, sicmap, extent, area, calcvolume, alaska = self.meltcalc( iceforecastMean, icedrift_error, self.iceMean, count, bottommelt, driftcorrection) self.iceHigh, sicmapHigh, extentHigh, areaHigh, calcvolumeHigh, alaskaHigh = self.meltcalc( iceforecastHigh, icedrift_error, self.iceHigh, count, bottommeltHigh, driftcorrectionHigh) self.iceLow, sicmapLow, extentLow, areaLow, calcvolumeLow, alaskaLow = self.meltcalc( iceforecastLow, icedrift_error, self.iceLow, count, bottommeltLow, driftcorrectionLow) self.CSVVolume.append(int(calcvolume)) self.CSVExtent.append(int(extent) / 1e6) self.CSVArea.append(int(area) / 1e6) self.CSVVolumeHigh.append(int(calcvolumeHigh)) self.CSVExtentHigh.append(int(extentHigh) / 1e6) self.CSVAreaHigh.append(int(areaHigh) / 1e6) self.CSVVolumeLow.append(int(calcvolumeLow)) self.CSVExtentLow.append(int(extentLow) / 1e6) self.CSVAreaLow.append(int(areaLow) / 1e6) self.CSVAlaska.append((int(alaska) / 1e6)) if count > (countmax - 82): # visualize.thicknessshow(self.iceMean,int(calcvolume),int(extent),'Mean',self.datestring) visualize.concentrationshow(sicmap, int(area), int(extent), 'Mean', self.datestring) visualize.fig2.savefig('Images/{}'.format(self.datestring)) # ============================================================================= # #save last date as arrary in mm # if count == (countmax-15): # # if count >210: # # SIPN_analysis.thicknessshow(self.iceMean,int(calcvolume),int(extent),'Mean') # SIPN_analysis.concentrationshow(sicmap,int(area),int(extent),'Mean') # # # SIPN_analysis.thicknessshow(self.iceHigh,int(calcvolumeHigh),int(extentHigh),'High') # SIPN_analysis.concentrationshow(sicmapHigh,int(areaHigh),int(extentHigh),'High') # # # SIPN_analysis.thicknessshow(self.iceLow ,int(calcvolumeLow),int(extentLow),'Low') # SIPN_analysis.concentrationshow(sicmapLow,int(areaLow),int(extentLow),'Low') # ============================================================================= # ============================================================================= # # convert SIT into millimeter # iceLastDateMean = self.iceMean*1000 # iceLastDateMean = np.array(iceLastDateMean,dtype=np.uint16) # iceLastDateHigh = self.iceHigh*1000 # iceLastDateHigh = np.array(iceLastDateHigh,dtype=np.uint16) # iceLastDateLow = self.iceLow*1000 # iceLastDateLow = np.array(iceLastDateLow,dtype=np.uint16) # ============================================================================= # ============================================================================= # # save SIT maps # exportpath = 'X:/Sea_Ice_Forecast/Data_Dump/' # CryoIO.savebinaryfile('{}001/SIPN2_Thickness_Mean_{}.bin'.format(exportpath,self.datestring),iceLastDateMean) # CryoIO.savebinaryfile('{}002/SIPN2_Thickness_midHigh_{}.bin'.format(exportpath,self.datestring),iceLastDateHigh) # CryoIO.savebinaryfile('{}003/SIPN2_Thickness_midLow_{}.bin'.format(exportpath,self.datestring),iceLastDateLow) # ============================================================================= # save SIC maps exportpath = 'X:/Sea_Ice_Forecast/SIPN_north/' CryoIO.savebinaryfile( '{}001/SIPN2_SIC_001_{}.bin'.format(exportpath, self.datestring), sicmapLow) CryoIO.savebinaryfile( '{}002/SIPN2_SIC_002_{}.bin'.format(exportpath, self.datestring), sicmap) CryoIO.savebinaryfile( '{}003/SIPN2_SIC_003_{}.bin'.format(exportpath, self.datestring), sicmapHigh) self.CSVDatum.append('{}/{}/{}'.format(self.year, self.stringmonth, self.stringday)) print(self.year, count) # print(self.meltmomentum) # ============================================================================= # # optional image export # if count == (countmax-1): # # SIPN_analysis.thicknessshow(self.iceMean,int(calcvolume),int(extent),'Mean') # SIPN_analysis.concentrationshow(sicmap,int(area),int(extent),'Mean') # # SIPN_analysis.fig.savefig('X:/Sea_Ice_Forecast/Data_Dump/SIPN_{}.png'.format(self.datestring)) # SIPN_analysis.fig2.savefig('X:/Sea_Ice_Forecast/Data_Dump/SIPN_SIC_{}.png'.format(self.datestring)) # # SIPN_analysis.ax.clear() # SIPN_analysis.ax2.clear() # ============================================================================= # model value adjustment over time if count < countmax: self.advanceday(1) self.icedrift_sim = 6 + count / 150 if count < 245: self.meltmomentum += 1.5 elif 245 <= count <= 250: self.meltmomentum -= 22 elif 252 <= count <= 278: self.meltmomentum -= 12 if count == 182: self.airtemp_mod = 0.25 elif count == 270: self.airtemp_mod = 1.11 elif count == 280: self.airtemp_mod = 1.33
def prediction(self): ''' Starts the day loop''' filepath = 'X:/NSIDC/DataFiles/' filename = 'NSIDC_{}.bin'.format(self.datestring) countmax = self.index + self.daycount iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 # icedrift_error = np.zeros(len(self.regmaskf)) self.iceMean = np.array(self.iceLastDate, dtype=float) for count in range(self.index, countmax, 1): filename = 'NSIDC_{}.bin'.format(self.datestring) filenameAvg = 'X:/NSIDC/DataFiles/Forecast_Mean/NSIDC_Mean_{}{}.bin'.format( self.stringmonth, self.stringday) filenameChange = 'X:/NSIDC/DataFiles/Forecast_SIC_change/NSIDC_SIC_Change_{}{}.bin'.format( self.stringmonth, self.stringday) filenameDrift_error = 'analysis/icedrift_correction/SIPN2_error_{}{}.bin'.format( self.stringmonth, self.stringday) #338ppm base value in 1980 co2listindex = (self.year - 1980) * 12 + self.loopday.month - 1 co2value = self.co2list[co2listindex][1] self.back_radiation = self.base_back_radiation - 2 * co2value / 338 self.air_temp = (self.templist[count] - 273) * self.airtemp_mod self.bottommelt = self.base_bottommelt * self.meltmomentum / 180 bottommelt = self.bottommelt self.MJ_adjust = bottommelt - self.back_radiation + self.air_temp icedrift_error = CryoIO.openfile(filenameDrift_error, np.float16) / 100 icedrift_error = icedrift_error #fileformats: normal dtype:uint8 , filenameChange:int8 , filenameStdv: np.float16 if count <= 161: #change date of year to last available date, 161==10th June iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecast, icedrift_error, self.iceMean, count) else: #load statistical data icechange = CryoIO.openfile(filenameChange, np.int8) / 250 iceAvg = CryoIO.openfile(filenameAvg, np.uint8) / 250 iceforecast = iceforecast + icechange iceforecastMean = (3 * iceforecast + iceAvg) / 4 self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecastMean, icedrift_error, self.iceMean, count) self.CSVVolume.append(int(calcvolume)) self.CSVExtent.append(int(extent) / 1e6) self.CSVArea.append(int(area) / 1e6) #SIC export for error analysis CryoIO.savebinaryfile( 'analysis/predict/SIPN2_{}.bin'.format(self.datestring), sicmap) self.CSVDatum.append('{}/{}/{}'.format(self.year, self.stringmonth, self.stringday)) print(self.year, count) # model value adjustment over time if count < countmax: self.advanceday(1) self.icedrift_sim = 6 + count / 150 if count < 245: self.meltmomentum += 1.5 elif 245 <= count <= 250: self.meltmomentum -= 22 elif 252 <= count <= 278: self.meltmomentum -= 12 if count == 182: self.airtemp_mod = 0.25 elif count == 270: self.airtemp_mod = 1.1 elif count == 280: self.airtemp_mod = 1.25
def prediction(self): ''' Starts the day loop''' filepath = 'X:/NSIDC_South/DataFiles/' filename = 'NSIDC_{}{}{}_south.bin'.format(self.year, self.stringmonth, self.stringday) countmax = self.index + self.daycount iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 icedrift_error = np.zeros(len(self.regmaskf)) self.iceMean = np.array(self.iceLastDate, dtype=float) for count in range(self.index, countmax, 1): filename = 'NSIDC_{}_south.bin'.format(self.datestring) filenameAvg = 'Mean_00_19/NSIDC_Mean_{}{}_south.bin'.format( self.stringmonth, self.stringday) filenameChange = 'Daily_change/NSIDC_SIC_Change_{}{}_south.bin'.format( self.stringmonth, self.stringday) filenameDrift_error = 'analysis/icedrift_correction/SIPN2_error_{}{}.bin'.format( self.stringmonth, self.stringday) #338ppm base value in 1980 co2listindex = (self.year - 1980) * 12 + self.loopday.month - 1 co2value = self.co2list[co2listindex][1] self.back_radiation = self.base_back_radiation - 2 * co2value / 338 self.bottommelt = self.base_bottommelt bottommelt = self.bottommelt driftcorrection = self.icedrift_sim icedrift_error = CryoIO.openfile(filenameDrift_error, np.float16) / 100 icedrift_error = icedrift_error #fileformats: normal dtype:uint8 , filenameChange:int8 , filenameStdv: np.float16 if count <= 161: #change date of year to last available date iceforecast = CryoIO.openfile(os.path.join(filepath, filename), np.uint8) / 250 self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecast, icedrift_error, self.iceMean, bottommelt, driftcorrection) else: icechange = CryoIO.openfile( os.path.join(filepath, filenameChange), np.int8) / 250 iceAvg = CryoIO.openfile(os.path.join(filepath, filenameAvg), np.uint8) / 250 iceforecast = iceforecast + icechange np.clip(iceforecast, 0, 1) iceforecastMean = (2 * iceforecast + iceAvg) / 3 iceforecastMean[iceforecastMean > 1] = 1 iceforecastMean[iceforecastMean < 0] = 0 self.iceMean, sicmap, extent, area, calcvolume = self.meltcalc( iceforecastMean, icedrift_error, self.iceMean, bottommelt, driftcorrection) self.CSVVolume.append(int(calcvolume)) self.CSVExtent.append(round(int((extent)) / 1e6, 4)) self.CSVArea.append(round(int((area)) / 1e6, 4)) #SIC export for error analysis CryoIO.savebinaryfile( 'analysis/predict/SIPN2_{}.bin'.format(self.datestring), sicmap) self.CSVDatum.append('{}/{}/{}'.format(self.year, self.stringmonth, self.stringday)) print(self.year, self.yearday, self.latitudelist[150][self.yearday]) # print(count) if count < countmax: self.advanceday(1)
for year in range(2005, 2021): datalist.append([year, thickness]) x += 1 p = Pool(processes=20) data = p.map(spawnprocess, datalist) print(len(data)) p.close() area = [] extent = [] for x in data: area.append(x[0]) extent.append(x[1]) CryoIO.csv_columnexport('area.csv', area) CryoIO.csv_columnexport('extent.csv', extent) # ============================================================================= # visualize = SIPN_analysis.NSIDC_analysis() # #visualize.thickmap_create() # visualize.conmap_create() # ============================================================================= ''' Values are coded as follows: 0-250 ice concentration 251 pole hole 252 unused 253 coastline 254 landmask 255 NA
def csvexport_by_forecasttype(self): ''' Exporting values ''' exportpath = 'X:/Sea_Ice_Forecast/SIPN_north/' CryoIO.csv_columnexport( '{}_SIPN_forecast_002_{}.csv'.format(exportpath, self.year), [self.CSVDatum, self.CSVVolume, self.CSVArea, self.CSVExtent])