Wednesday, June 15, 2016

Plot LST

Just a code to plot LST
Lat  = double(hdfread(filewant,  'Latitude' ));
Lon  =  double(hdfread(filewant,  'Longitude' ));
LST = 0.02* double(hdfread(filewant,  'LST' ));
LST(LST==0)=NaN;
figure

load coast
latlim=[floor(min(min(Lat))),ceil(max(max(Lat))) ]; lonlim=[floor(min(min(Lon))),ceil(max(max(Lon))) ];
ax = worldmap(latlim, lonlim);
surfacem(Lat, Lon, LST);
geoshow(lat, long,'Color', 'black' )
colormap; set(gcf,'Color','white')
map2 = colormap; map2( 1, : ) = 0; colormap(map2);
colorbar % saveas(gcf, 'plotHDF.png', 'png') close all
caxis([ 290 330])

Tuesday, June 14, 2016

Chrome: Add keyboard shortcut to your favorite website


This trick works on Google chrome. 
  • Right click on the address bar
  • Edit Search Engines
  • Scroll to the bottom of the list
  • Give the name, keyword (eg. gs: for google scholar), then URL.
You can put %s in place of query.



Monday, June 13, 2016

Matlab Colorbar: LST

I think I found a good one! (Sorry intensity, no one prints grayscale pics these days... they just read on-screen).
r1 = [1 0];
g1 = [0 0];
b1 =  [1 1];
rgb1 = [r1; g1; b1]';
rgba = interp1([1 2],rgb1, linspace(1,2,16 ));
r1 = [0 0];
g1 = [0 1];
b1 =  [1 1];
rgb1 = [r1; g1; b1]';
rgbb = interp1([1 2],rgb1, linspace(1,2,11 ));

r1 = [0 0];
g1 = [1 1];
b1 =  [1 0];
rgb1 = [r1; g1; b1]';
rgbc = interp1([1 2],rgb1, linspace(1,2,10));

r1 = [0 1];
g1 = [1 1];
b1 =  [0 0];
rgb1 = [r1; g1; b1]';
rgbd = interp1([1 2],rgb1, linspace(1,2,11 ));

r1 = [ 1 1];
g1 = [1 0];
b1 =  [0 0];
rgb2 = [r1; g1; b1]';
rgbe= interp1([1 2],rgb2, linspace(1,2,16));

newNDVI = [rgba;rgbb;rgbc;rgbd;rgbe];

newNDVI= interp1( newNDVI, linspace(1,64,256));


%
figure
plot([1:256],newNDVI(:,1), 'ro-'); hold on
plot([1:256],newNDVI(:,2), 'g*-');
plot([1:256],newNDVI(:,3), 'bd-.');
xlim([1 256])

colormap(newNDVI );
cmap = colormap; % cmap nicely puts colormap into 3 col data
% colorbar
caxis([0 1])
hc = colorbar('southoutside');
set(hc, 'FontSize', 16)

 axis off; set(gcf,'Color','White')


I can append white and or black at the end for distinction, if needed.

Wednesday, June 1, 2016

Insert the date and time into the google docs

This first appeared here ... http://ajabgajab.blogspot.com/2015/01/insert-date-and-time-into-google-docs.html 
This is how you insert the date and time to the google docs

1. Go to the Google document/new document.
2. Go to the Tools/Script Editor, and insert the following script at the bottom of the scripts.
This will create a new menu. You can modify the code to change the appearance of the month/date.
3. See the end note to add automated date entry!

The code is available below/ at pastebin.
http://pastebin.com/QFpTRQ3h




function onOpen() {
  var ui = DocumentApp.getUi();
  // Or FormApp or SpreadsheetApp.
  ui.createMenu('Insert Date')
      .addItem('Insert Date', 'insertDate')
      .addToUi();

}

function insertDate() {
  var cursor = DocumentApp.getActiveDocument().getCursor();
  if (cursor) {
      // Attempt to insert text at the cursor position. If insertion returns null,
      // then the cursor's containing element doesn't allow text insertions.
      var d = new Date();
      var dd = d.getDate();
      var hrs = d.getHours();
      var min = d.getMinutes();
      dd = pad(dd, 2)
      var mm = d.getMonth() + 1; //Months are zero based
      mm = pad(mm, 2)
      var yyyy = d.getFullYear();
    var date =  "Date: "+mm + "-" +dd + "-" + yyyy+ "::"+hrs+":"+min +"\n";
      var element = cursor.insertText(date);
      if (element) {
        element.setBold(true);
      } else {
        DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
      }
    } else {
      DocumentApp.getUi().alert('Cannot find a cursor in the document.');
  }

}
function pad (str, max) {
  str = str.toString();
  return str.length < max ? pad("0" + str, max) : str;
}

--- 
--> 

Note:
If you add the following function call inside the onOpen() function:
  insertDate();
Then you will get automated insertion of date and time. Great for logging the daily notes!!!




function onOpen() {
  var ui = DocumentApp.getUi();
  // Or FormApp or SpreadsheetApp.
  ui.createMenu('Insert Date')
      .addItem('Insert Date', 'insertDate')
      .addToUi();

  insertDate();

}

Friday, May 27, 2016

Colormap for NDVI

Setting up NDVI colorbar can be tricky! You want a nice representation of the vegetation and bare surfaces in the map.

1. I found an easy way would be to flip the default matlab summer color bar upside down!
colormap('summer')
map2 = (colormap);
map2 = flipud(map2);
colormap(map2);
cmap = colormap;
It looks like:
However, the negatives are not treated nicely. For the first approximation, I could set x<0 == 0.

2. Found a nice one:
https://publiclab.org/notes/cfastie/08-26-2014/new-ndvi-colormap
The colorbar is nice, but, I was not much happy with the squeezed RBG dance!


3. Having seen them, I wanted to create my own.
I combined the inverted summer with the graded b/w scheme.  The idea is to set inverted summer for x > 0 with  the gray image for x < 0!
So, I wrote this small piece!

r1 = [0 1];
g1 = [0 1];
b1 =  [0 1];
rgb1 = [r1; g1; b1]';
rgbt = interp1([1 2],rgb1, linspace(1,2,32 ));

r1 = [ 1 0];
g1 = [1 0.5];
b1 =  [0.4 0.4];
rgb2 = [r1; g1; b1]';
rgbb= interp1([1 2],rgb2, linspace(1,2,32 ));

newNDVI = [rgbt;rgbb];

figure
colormap(newNDVI );
cmap = colormap; % cmap nicely puts colormap into 3 col data
% colorbar
caxis([-1 1])
hc = colorbar('southoutside');
set(hc, 'FontSize', 16)

 axis off; set(gcf,'Color','White')
You can set that linspace limit to 128, and make 256x3 colormap, making a smooth colorbar.
The new NDVI colorbar looks like:

The color scheme looks like:

For the first half, it goes from dark to bright, and then smoothly to green from yellow at the center!

Try it! and let me know if you like this scheme for NDVI!
Here is a small preview. I changed the lower rgbb matrix to 224x3 arrays which nicely set yellow limit at ~0.2! (some info on NDVI for the cusious minds: http://earthobservatory.nasa.gov/Features/MeasuringVegetation/measuring_vegetation_2.php)






Forcing Matlab colorbar to display climits

Matlab sometimes can not register the upper and lower limits of the color bar when the figures are saved (eg with export_fig). 

I found a way around it:
instead of setting caxis limit at the exact values, increase/decrease the upper/lower limit
caxis([0.94 0.99] )
to >> caxis([0.94 0.99001] )

This worked for me!