def CopyRequiredFilesToGitRepository(ObjectsDirectory,DriverDirectory,TargetDirectory): # Ensure the directories exist ObjectsDirectory,DriverDirectory,TargetDirectory,TargetDriverDirectory = CheckFileStructuresForCopy(ObjectsDirectory,DriverDirectory,TargetDirectory) # Now get the required files print "\n\n\n=================================" required_files_noduplicates = GetRequiredFilesFromFolder(DriverDirectory) print "The required files are: " print required_files_noduplicates print "=================================" # loop through these files, collecting the filenames and directory names # first you need to know what directory level the driver files are in print "\n\n\n======================================" n_level_of_driver_directory = LSDost.GetPathLevel(DriverDirectory) for FileName in required_files_noduplicates: # you need to know what level the file is ThisPath = LSDost.GetPath(FileName) ThisLevel = LSDost.GetPathLevel(ThisPath) #if it is the same level as the driver directory, it is in the driver directory! if ThisLevel == n_level_of_driver_directory: CopyDirectory = TargetDriverDirectory CopyFileName = LSDost.GetFileNameNoPath(FileName) CopyFileNameWithPath = CopyDirectory+CopyFileName else: CopyDirectory = TargetDirectory CopyFileName = LSDost.GetFileNameNoPath(FileName) CopyFileNameWithPath = CopyDirectory+CopyFileName print "The filename is: " + FileName print "The copy filename is: " + CopyFileNameWithPath shutil.copy(FileName, CopyFileNameWithPath) # now copy the files over print "=============================================="
def TranslateToReducedGeoJSON(self, FileName): # Parse a delimited text file of volcano data and create a shapefile import osgeo.ogr as ogr import osgeo.osr as osr # set up the shapefile driver driver = ogr.GetDriverByName("GeoJSON") # Get the path to the file this_path = LSDOst.GetPath(FileName) DataName = self.FilePrefix FileOut = this_path + DataName + ".geojson" print "The filename will be: " + FileOut # delete the existing file if os.path.exists(FileOut): driver.DeleteDataSource(FileOut) # create the data source data_source = driver.CreateDataSource(FileOut) # create the spatial reference, in this case WGS84 (which is ESPG 4326) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) print "Creating the layer" # create the layer layer = data_source.CreateLayer("CRNData", srs, ogr.wkbPoint) #print "Adding the field names" # Add the fields we're interested in field_name = ogr.FieldDefn("SampleName", ogr.OFTString) field_name.SetWidth(48) layer.CreateField(field_name) field_region = ogr.FieldDefn("Nuclide", ogr.OFTString) field_region.SetWidth(48) layer.CreateField(field_region) layer.CreateField(ogr.FieldDefn("Latitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("Longitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("EffERate", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("EffERateU", ogr.OFTReal)) sample_name = self.GetSampleName() nuclide = self.GetNuclide() Latitude = self.GetLatitude() Longitude = self.GetLongitude() ERateU = self.GetErosionRatesUncert() ERate = self.GetErosionRates() #print "lengths are: " #print "SN: " + str(len(sample_name)) #print "N: " + str(len(Latitude)) #print "Lat: " + str(len(nuclide)) #print "Long: " + str(len(Longitude)) #print "Erate: " + str(len(ERate)) #print "ErateU: " + str(len(ERateU)) # Process the text file and add the attributes and features to the shapefile for index, name in enumerate(sample_name): # create the feature feature = ogr.Feature(layer.GetLayerDefn()) # Set the attributes using the values from the delimited text file feature.SetField("SampleName", name) feature.SetField("Nuclide", nuclide[index]) feature.SetField("Latitude", Latitude[index]) feature.SetField("Longitude", Longitude[index]) feature.SetField("EffERate", ERate[index]) feature.SetField("EffERateU", ERateU[index]) # create the WKT for the feature using Python string formatting wkt = "POINT(%f %f)" % (float( Longitude[index]), float(Latitude[index])) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # Destroy the data source to free resources data_source.Destroy()
def TranslateToReducedGeoJSON(self, FileName): # Parse a delimited text file of volcano data and create a shapefile import osgeo.ogr as ogr import osgeo.osr as osr # set up the shapefile driver driver = ogr.GetDriverByName("GeoJSON") # Get the path to the file this_path = LSDOst.GetPath(FileName) DataName = self.FilePrefix FileOut = this_path + DataName + ".geojson" print "The filename will be: " + FileOut # delete the existing file if os.path.exists(FileOut): driver.DeleteDataSource(FileOut) # create the data source data_source = driver.CreateDataSource(FileOut) # create the spatial reference, in this case WGS84 (which is ESPG 4326) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) print "Creating the layer" # create the layer layer = data_source.CreateLayer("PointData", srs, ogr.wkbPoint) #print "Adding the field names" # Add the field names for index, name in enumerate(self.VariableList): print "The variable name is " + name + " and the type is: " + str( self.DataTypes[index]) if self.DataTypes[index] is int: layer.CreateField(ogr.FieldDefn(name, ogr.OFTInteger)) elif self.DataTypes[index] is float: layer.CreateField(ogr.FieldDefn(name, ogr.OFTReal)) elif self.DataTypes[index] is str: print "Making a sting layer for layer " + name layer.CreateField(ogr.FieldDefn(name, ogr.OFTString)) else: layer.CreateField(ogr.FieldDefn(name, ogr.OFTReal)) # Process the text file and add the attributes and features to the shapefile for index, lat in enumerate(self.Latitude): # create the feature feature = ogr.Feature(layer.GetLayerDefn()) for name in self.VariableList: feature.SetField(name, self.PointData[name][index]) # create the WKT for the feature using Python string formatting wkt = "POINT(%f %f)" % (float( self.Longitude[index]), float(self.Latitude[index])) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # Destroy the data source to free resources data_source.Destroy()
def PlotERateErrorsRefined(self, CRONUSFileName): import matplotlib.pyplot as plt from matplotlib import rcParams from matplotlib.gridspec import GridSpec #from scipy.stats import gaussian_kde label_size = 18 axis_size = 26 # Set up fonts for plots rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size #safi = 1 # Save figures as png (1 to save, otherwise 0): #zoom = 1 # zoom in plots activated if value is 1 # Check if you've got the CONUS data: don't read the file if you've already got it if (self.HaveCRONUSData != True): self.ReadCRONUSData(CRONUSFileName) # now get the errors self.GetErrorsBetweenMethods() self.GetErrorsBetweenCRONUS() # FIGURE 1 = ERATE COMPARED TO ERATE Fig1 = plt.figure(1, facecolor='white', figsize=(12, 9)) # generate a 120,90 grid. gs = GridSpec(90, 120, bottom=0.1, left=0.1, right=0.95, top=0.95) Error_string_CR_BERC = '($\epsilon_{CR}$-$\epsilon_{BERC}$)/$\epsilon_{BERC}$ g cm$^{-2}$ yr$^{-1}$' Error_string_CC_BERC = '($\epsilon_{CC}$-$\epsilon_{BERC}$)/$\epsilon_{BERC}$ g cm$^{-2}$ yr$^{-1}$' # get the lengths #print "The lengths are: " #print len(self.CRNData['AvgProdScaling']) #print len(self.CRNData['Error_CR']) #print len(self.CRNData['basin_relief']) ########################################## # Plot 1 = comparison new_code / cosmocalc ############################################ ## ax = Fig1.add_subplot(gs[0:40, 0:50]) #plt.plot(self.CRNData['AvgProdScaling'],self.CRNData['Error_CR'],"o", markersize=8 ) cax = plt.scatter(self.CRNData['erate_g_percm2_peryr'], self.CRNData['Error_CR'], c=self.CRNData['AverageCombinedScaling'], s=50, edgecolor='', cmap=plt.get_cmap("summer")) cbar = plt.colorbar(cax) cbar.set_label('Combined Scaling') # the basin relief data is in self.CRNData['basin_relief'] #plt.plot(self.CRNData['AvgProdScaling'],self.CRNData['Error_CR'],color=cmap(self.CRNData['basin_relief']),"o", markersize=8 ) #plt.errorbar(datazz['erate_cosmocalc']*10, datazz['erate_cmperkyr']*10, xerr=datazz['error_cosmocalc'], yerr=datazz['error_newcode'], fmt='o',color = cmap(colo)) ax.spines['top'].set_linewidth(2.5) ax.spines['left'].set_linewidth(2.5) ax.spines['right'].set_linewidth(2.5) ax.spines['bottom'].set_linewidth(2.5) # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=2.5, pad=2) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(10) plt.xlabel('Erosion rate in g cm$^{-2}$ yr$^{-1}$', fontsize=axis_size - 2, verticalalignment='bottom') plt.ylabel('($\epsilon_{CR}$-$\epsilon_{BERC}$)/$\epsilon_{BERC}$', fontsize=axis_size - 4) # this aligns the labels. # The transform=ax.transAxes means that the coordinate system is the axis coordinate system # where x = 0.5 is the centre of the x axis ax.xaxis.set_label_coords(0.5, -0.22, transform=ax.transAxes) ########################################## # Plot 2 = comparison new_code / cosmocalc ############################################ ## ax = Fig1.add_subplot(gs[0:40, 70:120]) cax = plt.scatter(self.CRNData['AverageCombinedScaling'], self.CRNData['Error_CR'], c=self.CRNData['AverageShielding'], s=50, edgecolor='', cmap=plt.get_cmap("hot")) cbar = plt.colorbar(cax) cbar.set_label('Average shielding') ax.spines['top'].set_linewidth(2.5) ax.spines['left'].set_linewidth(2.5) ax.spines['right'].set_linewidth(2.5) ax.spines['bottom'].set_linewidth(2.5) # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=2.5, pad=2) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(10) plt.xlabel('Average shielding', fontsize=axis_size - 2) plt.ylabel('($\epsilon_{CR}$-$\epsilon_{BERC}$)/$\epsilon_{BERC}$', fontsize=axis_size - 4) ########################################## # Plot 3 = comparison new_code / cosmocalc ############################################ ## ax = Fig1.add_subplot(gs[50:90, 0:50]) cax = plt.scatter(self.CRNData['AverageCombinedScaling'], self.CRNData['Error_CR_em'], c=self.CRNData['erate_g_percm2_peryr'], s=50, edgecolor='', cmap=plt.get_cmap("YlGnBu")) cbar = plt.colorbar(cax) cbar.set_label('Erosion rate (g cm$^{-2}$ yr$^{-1}$)') ax.spines['top'].set_linewidth(2.5) ax.spines['left'].set_linewidth(2.5) ax.spines['right'].set_linewidth(2.5) ax.spines['bottom'].set_linewidth(2.5) # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=2.5, pad=2) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(10) plt.xlabel('Average combined scaling', fontsize=axis_size - 2, verticalalignment='bottom') plt.ylabel('($\epsilon_{CC}$-$\epsilon_{BERC}$)/$\epsilon_{BERC}$', fontsize=axis_size - 4) # this aligns the labels. # The transform=ax.transAxes means that the coordinate system is the axis coordinate system # where x = 0.5 is the centre of the x axis ax.xaxis.set_label_coords(0.5, -0.22, transform=ax.transAxes) ########################################## # Plot 4 = comparison new_code / cosmocalc ############################################ ## ax = Fig1.add_subplot(gs[50:90, 70:120]) linetest = np.arange( 0, np.max(self.CRNData['erate_g_percm2_peryr'] + np.max(self.CRNData['total_uncert'])), 0.01) print "Here is the line" print linetest print "max: " print np.max(self.CRNData['erate_g_percm2_peryr'] + np.max(self.CRNData['total_uncert'])) #print "err: " #print CRONUS_err = self.CRNData['CRONUS_total_uncert'] BERC_err = self.CRNData['total_uncert'] ax.errorbar(self.CRNData['erate_g_percm2_peryr'], self.CRNData['CRONUS_erate_g_percm2_peryr'], yerr=CRONUS_err, xerr=BERC_err, fmt='.', zorder=1) cax = ax.scatter(self.CRNData['erate_g_percm2_peryr'], self.CRNData['CRONUS_erate_g_percm2_peryr'], c=self.CRNData['AverageCombinedScaling'], s=50, edgecolor='', cmap=plt.get_cmap("summer"), zorder=10) ax.plot(linetest, linetest, '-k', linewidth=2, zorder=5) cbar = plt.colorbar(cax) cbar.set_label('Combined Scaling') # the basin relief data is in self.CRNData['basin_relief'] axlims = ax.get_xlim() ax.set_xlim(0, axlims[1]) # This makes all the spines thick so you can see them ax.spines['top'].set_linewidth(2.5) ax.spines['left'].set_linewidth(2.5) ax.spines['right'].set_linewidth(2.5) ax.spines['bottom'].set_linewidth(2.5) # This gets all the ticks, and pads them away from the axis so that the corners don't overlap ax.tick_params(axis='both', width=2.5, pad=2) for tick in ax.xaxis.get_major_ticks(): tick.set_pad(10) plt.xlabel('$\epsilon_{BERC}$ g cm$^{-2}$ yr$^{-1}$', fontsize=axis_size - 2) plt.ylabel('$\epsilon_{CR}$ g cm$^{-2}$ yr$^{-1}$', fontsize=axis_size - 4) figname = LSDOst.GetPath(CRONUSFileName) + 'Erate_comparison.pdf' plt.savefig(figname, format='pdf')