def roi_mask_v2(self, roimask, contrast_data): filename = tempfile.mktemp(suffix='.png', dir=self.tmp_image_dir, prefix='roi_masks-') mask = cortex.db.get_mask('MNI', 'atlas') # a = b roimask = roimask * 1.0 roimask[mask == False] = np.nan roivol = cortex.Volume(roimask, 'MNI', 'atlas', mask=mask) # Create flatmap fig = cortex.quickflat.make_figure(cortex.Volume(contrast_data, 'MNI', 'atlas', vmin=0, vmax=1, cmap='Blues'), with_colorbar=False, with_curvature=True, bgcolor=None) # Add rois #if not contrast_data.isPmap: # add_hash_layer(fig, roivol, [255,255,255], [0,8,12]) add_hash_layer(fig, roivol, [10, 0, 0], [3, 8, 8]) dpi = 100 imsize = fig.get_axes()[0].get_images()[0].get_size() fig.set_size_inches(np.array(imsize)[::-1] / float(dpi)) fig.savefig(filename, transparent=True, dpi=dpi) fig.clf() pltclose(fig) return filename
def roi_mask_v2(self, roimask, contrast_data): # Create random filename prefix = 'group' if contrast_data.isPmap: print('This is a Pmap!') filename = '{0}_{1}_{2}_flatPmap.png'.format( prefix, contrast_data.contrast.experiment.name, contrast_data.contrast.contrast_name) else: print('This is a not a Pmap!') filename = '{0}_{1}_{2}_flatmap.png'.format( prefix, contrast_data.contrast.experiment.name, contrast_data.contrast.contrast_name) filename = os.path.join(self.path, filename) print filename mask = cortex.db.get_mask('MNI', 'atlas') # a = b roimask = roimask * 1.0 roimask[mask == False] = np.nan roivol = cortex.Volume(roimask, 'MNI', 'atlas', mask=mask) # print np.sum(np.isnan(roivol.data)) # Create flatmap #'YlGn' fig = cortex.quickflat.make_figure(contrast_data, with_colorbar=False, with_curvature=True, bgcolor='black') # Add rois if not contrast_data.isPmap: add_hash_layer(fig, roivol, [255, 255, 255], [0, 8, 12]) add_hash_layer(fig, roivol, [10, 0, 0], [3, 8, 8]) # add_hash_layer(fig, roivol, [10,10,0], [2,6,2]) #add_hash_layer(fig, roivol, [0,50,0], [0,6,4]) #add_hash_layer(fig, roivol, [10,10,0], [2,6,2]) #add_hash_layer(fig, roivol, [255,255,255], [4,6,2]) # Save flatmap dpi = 100 imsize = fig.get_axes()[0].get_images()[0].get_size() fig.set_size_inches(np.array(imsize)[::-1] / float(dpi)) # if bgcolor is None: fig.savefig(filename, transparent=True, dpi=dpi) # else: # fig.savefig(filename, facecolor=filename, transparent=False, dpi=dpi) fig.clf() pltclose(fig) # Create HTML pointing to flatmap html = "<img src='{filename}'/>".format(filename=filename) return html
def roi_mask_v2(self, roimask, contrast_data): # Create random filename prefix = contrast_data.ref_to_subject.pycortex_surface filename = '{0}_{1}_{2}_flatmap.png'.format( prefix, contrast_data.contrast.experiment.name, contrast_data.contrast.contrast_name) filename = os.path.join(self.path, filename) print filename mask = cortex.db.get_mask( contrast_data.ref_to_subject.pycortex_surface, contrast_data.ref_to_subject.pycortex_transform) # a = b roimask = roimask * 1.0 roimask = cortex.mni.transform_mni_to_subject( contrast_data.ref_to_subject.pycortex_surface, contrast_data.ref_to_subject.pycortex_transform, roimask.T, contrast_data.ref_to_subject.func_to_mni, template=default_template).get_data().T roimask[mask == False] = np.nan roivol = cortex.Volume(roimask, contrast_data.ref_to_subject.pycortex_surface, contrast_data.ref_to_subject.pycortex_transform, mask=mask) # print np.sum(np.isnan(roivol.data)) # Create flatmap contrast_data2 = ContrastDataS( contrast_data.thresholded_contrast_05.data, contrast_data.ref_to_subject.pycortex_surface, contrast_data.ref_to_subject.pycortex_transform, 0, #contrast_data.thresholded_contrast_05.vmin, 1.25, #contrast_data.thresholded_contrast_05.vmax, contrast_data.contrast, contrast_data.func_to_mni, contrast_data.ref_to_subject, cmap="Blues") #YlGn RdPu # print ContrastDataS.data.shape contrast_data2.data[contrast_data2.ref_to_subject._voxels_predicted == False] = np.nan fig = cortex.quickflat.make_figure(contrast_data2, with_colorbar=False, with_curvature=True, shadow=0, **self.quickflat_args) # bgcolor='black') # Add rois #add_hash_layer(fig, roivol, [0,10,255], [0,50000,50001], alpha = 0.5) #add_hash_layer(fig, roivol, [255,255,255], [0,8,12]) add_hash_layer(fig, roivol, [10, 0, 0], [0, 8, 8]) #add_hash_layer(fig, roivol, [10,0,0], [3,8,4]) #add_hash_layer(fig, roivol, [0,50,0], [4,8,2]) # add_hash_layer(fig, roivol, [10,10,0], [2,5,2]) # add_hash_layer(fig, roivol, [0,50,0], [0,5,2]) # add_hash_layer(fig, roivol, [10,10,0], [2,5,2]) # add_hash_layer(fig, roivol, [255,255,255], [4,5,2]) # Save flatmap dpi = 100 imsize = fig.get_axes()[0].get_images()[0].get_size() fig.set_size_inches(np.array(imsize)[::-1] / float(dpi)) # if bgcolor is None: fig.savefig(filename, transparent=True, dpi=dpi) # else: # fig.savefig(filename, facecolor=filename, transparent=False, dpi=dpi) fig.clf() pltclose(fig) # Create HTML pointing to flatmap html = "<img src='{filename}'/>".format(filename=filename) return html
def plotMeteogramFile(latitude=None, longitude=None, location=None, days=3, plotType="enhanced-hres"): print(latitude, longitude) print(plotType) if location: latitude, longitude, altitude, _ = getCoordinates([("--location", location)]) elif latitude is not None and longitude is not None: latitude = float(latitude) longitude = float(longitude) from altitude import ElevationService e = ElevationService('.cache/') altitude = e.get_elevation(latitude, longitude) if altitude is None: altitude = -999 else: latitude = 52.2646577 longitude = 10.5236066 altitude = 79 if days <= 10: allMeteogramData = getData(float(longitude), float(latitude), altitude, writeToFile=False) else: allMeteogramData = getData(float(longitude), float(latitude), altitude, writeToFile=False, meteogram="15days") tzName = tz.tzNameAt(latitude, longitude) today = datetime.utcnow() fromIndex, toIndex = getTimeFrame(allMeteogramData, today, today + timedelta(days)) fig = plotMeteogram(allMeteogramData, fromIndex, toIndex, tzName, plotType) filename = str(today) + str(latitude) + str(longitude) + "forecast.png" tmpSize = prop.get_size() prop.set_size(16) print(tmpSize) fig.suptitle(location + " " + str(np.round(latitude, decimals = 2)) +\ "°/" + str(np.round(longitude, decimals = 2)) +\ "°/" + str(altitude) + "m", fontproperties=prop) prop.set_size(tmpSize) if '2t' in allMeteogramData: #fig.text(0.1,0.03,allMeteogramData['2t']['date']+"-"+allMeteogramData['2t']['time'],fontproperties=prop) fig.text(0.2, 0.06, "Forecast from the European Weather Centre from " + allMeteogramData['2t']['date'] + " at " + allMeteogramData['2t']['time'][0:2] + ":" + allMeteogramData['2t']['time'][0:2] + " UTC", fontproperties=prop) if 'tp24' in allMeteogramData: fig.text(0.2, 0.06, "Forecast from the European Weather Centre from " + allMeteogramData['tp24']['date'] + " at " + allMeteogramData['tp24']['time'][0:2] + ":" + allMeteogramData['tp24']['time'][0:2] + " UTC", fontproperties=prop) #fig.text(0.1,0.03,allMeteogramData['tp24']['date']+"-"+allMeteogramData['tp24']['time'],fontproperties=prop) fig.savefig("/tmp/" + filename, dpi=300, bbox_inches='tight') pltclose(fig) return filename