def build(self, variable, ftp): """Build initial dataset.""" # We need to build these three files paths = self.get_paths(variable) # Retrieve rasters self.get_rasters(variable, ftp) # Reproject for area calculations for file in glob(os.path.join(self.tif_folder, "*tif")): self.reproject(file) # Convert originals to NetCDF file files = glob(os.path.join(self.tif_folder, variable + "*tif")) toNetCDF(tfiles=files, ncfiles=None, savepath=paths["original"], index=variable, proj=4326, year1=1895, month1=1, year2=TODAYS_DATE.year - 2, month2=12, wmode="w", percentiles=False) # Convert projected files to NetCDF file files = glob(os.path.join(self.tif_folder, "proj_*tif")) toNetCDFAlbers(tfiles=files, ncfiles=None, savepath=paths["albers"], index=variable, proj=PROJ, year1=1895, month1=1, year2=TODAYS_DATE.year - 2, month2=12, wmode="w", percentiles=False) # Create a percentile dataset toNetCDFPercentile(paths["original"], paths["percentile"]) # Clear temp folder self._clear_tif()
ncfiles=None, savepath=nc_path, index=index, proj=4326, year1=1980, month1=1, year2=todays_date.year, month2=12, wmode='w', percentiles=False) toNetCDFAlbers(tfiles=tfiles_proj, ncfiles=None, savepath=nc_path_proj, index=index, proj=proj, year1=1980, month1=1, year2=todays_date.year, month2=12, wmode='w', percentiles=False) # Now lets get the percentile values pc_path = os.path.join(data_path, "data/droughtindices/netcdfs/" + "percentiles", index + ".nc") toNetCDFPercentile(nc_path, pc_path) # Close connection with FTP server ftp.quit()
percentiles=False) # We are also including percentiles, so lets build another dataset pc_path = os.path.join(data_path, 'data/droughtindices/netcdfs/percentiles', index_map[index] + '.nc') print("Calculating Percentiles...") toNetCDFPercentile(nc_path, pc_path) # Now create the alber's netcdf toNetCDFAlbers(tfiles_proj, ncfiles, nc_path_proj, index, proj=proj, year1=1895, month1=1, year2=todays_date.year, month2=todays_date.month, wmode='w', percentiles=False) # We use a pre-made min/max value data frame to set color scales print("Downloads and transformations complete, establishing index ranges...") index_paths = [ os.path.join(data_path, 'data/droughtindices/netcdfs', i + '.nc') for i in local_indices ] maxes = {} mins = {} for i in tqdm(range(len(index_paths)), position=0):
ncfiles=None, savepath=original_path, index=variable, proj=4326, year1=1895, month1=1, year2=todays_date.year, month2=12, wmode='w', percentiles=False) toNetCDFAlbers(tfiles=tfiles_proj, ncfiles=None, savepath=albers_path, index=variable, proj=proj, year1=1895, month1=1, year2=todays_date.year, month2=12, wmode='w', percentiles=False) toNetCDFPercentile(original_path, percentile_path) # Empty tif folder for t in glob(os.path.join(tif_folder, '*')): os.remove(t) # One last thing, we only have min and max vapor pressure deficit meanNC(minsrc='data/droughtindices/netcdfs/albers/vpdmin.nc', maxsrc='data/droughtindices/netcdfs/albers/vpdmax.nc', dst='data/droughtindices/netcdfs/albers/vpdmean.nc')