@@ -196,22 +191,60 @@ class maskAndFuntionality (BASE, WIDGET):
...
@@ -196,22 +191,60 @@ class maskAndFuntionality (BASE, WIDGET):
#expand all the data
#expand all the data
self.tree_data.expandAll()
self.tree_data.expandAll()
ncFile.close()#close the file
#we close the netCDF file
defsetMapData(self):
ncFile.close()
"""This function sets the entities, time, scenarios and metrics in the QComboBox"""
#we get the path from the text space
path=self.text_set.text()
ncFile=nc.Dataset(path,'r',format='NETCDF4')
metrics=list(ncFile.groups.keys())#we get the metrics (name of the groups)
scenarios=list(ncFile.groups[metrics[0]].groups.keys())#we get the scenarios(name of the groups of the groups)
#set scenario and metric in the QComboBox
#if there ist just group in the file we set it in the cbox_metric and if there is groups of the groups we set the first group in the cbox_scenario
iflen(metrics)==1:#if there is just one group
self.cbox_metric.addItems(metrics)
eliflen(metrics)>1:#if there is more than one group
self.cbox_scenarios.addItems(scenarios)
self.cbox_metric.addItems(metrics)
#here we are gonna get the entities and the time of the netCDF file and set them into a QComboBox if the top level is clicked
#we get the time of the netCDF file
time=ncFile.variables['time']
timeUnits=time.units
timeCalendar=time.calendar
time=nc.num2date(time[:],timeUnits,timeCalendar)
#we set the time into the QComboBox
self.cbox_time.clear()
self.cbox_time.addItems([str(i)foriintime])
#we get the entities
self.cbox_entity.clear()
entities=ncFile.variables['entity']
entityScope=entities.ebv_entity_scope.split(',')
numberOfEntities=len(entities)
#we set the entity_scope and the number of the entity into the QComboBox
#self.cbox_entity.addItems([entityScope[i] + " " + str(i) for i in range(numberOfEntities)])
#we set the entities into the QComboBox
self.cbox_entity.addItems(entityScope)
#we close the netCDF file
ncFile.close()
defshowInfo(self):
defshowInfo(self):
"""this function shows first the name of the file and the global attributes and then if a varible is clicked delete the info and add the attributes of the selected variable"""
"""this function shows first the name of the file and the global attributes and then if a varible is clicked delete the info and add the attributes of the selected variable"""
self.text_info.clear()
self.text_info.clear()
#we get the path from the text space
#we get the path from the text space
path=self.text_set.text()
path=self.text_set.text()
#we load the netCDF file
ncFile=nc.Dataset(path,'r',format='NETCDF4')
ncFile=nc.Dataset(path,'r',format='NETCDF4')
#we get the name of the netCDF file to show it in the GUI
ncFileName=os.path.basename(path)
ncFileName=os.path.basename(path)
#We get the title of the netCDF file
ncFileTitle=ncFile.title
ncFileTitle=ncFile.title
#we get the global attributes of the netCDF file
ncFileGlobalAttributes=list(ncFile.ncattrs())
ncFileGlobalAttributes=list(ncFile.ncattrs())
#when we click on the top level item we show the name of the file, title and the global attributes
#when we click on the top level item we show the name of the file, title and the global attributes
...
@@ -244,110 +277,92 @@ class maskAndFuntionality (BASE, WIDGET):
...
@@ -244,110 +277,92 @@ class maskAndFuntionality (BASE, WIDGET):
nameOfRasterLayer=ncFileName+"_entity: "+self.cbox_entity.currentText()+"_time: "+self.cbox_time.currentText()#we get the name of the raster layer
#we get the time of the netCDF file
#time
#we get the time
time=ncFile.variables['time']
time=ncFile.variables['time']
#we have to get the units of the time
timeUnits=time.units
timeUnits=time.units
#get the calendar of the time
timeCalendar=time.calendar
timeCalendar=time.calendar
#we get the time of the netCDF file
time=nc.num2date(time[:],timeUnits,timeCalendar)
time=nc.num2date(time[:],timeUnits,timeCalendar)
#we get the time selected in the QComboBox
time=[str(i)foriintime]#we have to convert the time into a string
max_time=len(time)#we get the length of the time
#time selected in the QComboBox
timeSelected=self.cbox_time.currentText()
timeSelected=self.cbox_time.currentText()
#we get the index of the time selected
timeIndex=time.index(timeSelected)#we get the index of the time selected
timeIndex=[str(i)foriintime].index(timeSelected)
#Entity
#we get the entities
#we get the entities
#we get the entities of the netCDF file
entity=ncFile.variables['entity']
entities=ncFile.variables['entity']
entityScope=entity.ebv_entity_scope.split(',')#we get the name of the entities
#we get the name of the entities
entityScope=entities.ebv_entity_scope.split(',')
#entity selected in the QComboBox
#we get the entity selected in the QComboBox
entitySelected=self.cbox_entity.currentText()
entitySelected=self.cbox_entity.currentText()
#we get the index of the entity selected
entityIndex=entityScope.index(entitySelected)#we get the index of the entity selected
entityIndex=entityScope.index(entitySelected)
#from the groups and the groups of the groups we get the ebv_cube variable
foriinrange(len(ncFile.groups)):#we go through the groups
if'ebv_cube'inncFile.groups[list(ncFile.groups.keys())[i]].variables:#if we find the ebv_cube variable
ebvCube=ncFile.groups[list(ncFile.groups.keys())[i]].variables['ebv_cube']#we get the ebv_cube variable
break#we break the loop
else:#if we don't find the ebv_cube variable
forjinrange(len(ncFile.groups[list(ncFile.groups.keys())[i]].groups)):#we go through the groups of the groups
if'ebv_cube'inncFile.groups[list(ncFile.groups.keys())[i]].groups[list(ncFile.groups[list(ncFile.groups.keys())[i]].groups.keys())[j]].variables:#if we find the ebv_cube variable
ebvCube=ncFile.groups[list(ncFile.groups.keys())[i]].groups[list(ncFile.groups[list(ncFile.groups.keys())[i]].groups.keys())[j]].variables['ebv_cube']#we get the ebv_cube variable
break#we break the loop
#we get the data of the ebv_cube variable
ebvCubeData=ebvCube[timeIndex,entityIndex,:,:]
#we get the importat attributes from the CRS varible of the ncFile file
crs=ncFile.variables['crs']
crsName=crs.grid_mapping_name#we get the name of the CRS
crsProj4=crs.spatial_ref#we get the proj4 string of the CRS
#time to set the attributes from the CRS variable to the QgsCoordinateReferenceSystem
crs=QgsCoordinateReferenceSystem()
crs.createFromProj4(crsProj4)
crs.createFromOgcWmsCrs(crsName)
#if the ebv_cube is a masked array we have to convert it to a normal array
#we have to get the scenarios and the metrics from the interface
ifisinstance(ebvCubeData,np.ma.MaskedArray):
ebvCubeData=ebvCubeData.filled(np.nan)
#if we click on the ebv_cube item in the QTreeWidget we get the name group and the group of the group and turn the row grey