Showing posts with label data. Show all posts
Showing posts with label data. Show all posts
Friday, February 13, 2015
Reading binary data NSIDC Sea Ice Concentrations into GeoTIFF raster with Python
I need to read NSIDC sea ice concentration charts from Nimbus-7 SMMR and DMSP SSM/I-SSMIS Passive Microwave Data into a raster file. These files are according to the documentation "scaled, unsigned flat binary with one byte per pixel, and therefore have no byte order, or endianness. Data are stored as one-byte integers representing scaled sea ice concentration values.[...] The file format consists of a 300-byte descriptive header followed by a two-dimensional array of one-byte values containing the data."
The blog entry, which helped med finding out how to do this is this one but it had to be modified for my files.
Part One uses the Python struct command to unpack he binary file into a tuple

Read more »
The blog entry, which helped med finding out how to do this is this one but it had to be modified for my files.
Part One uses the Python struct command to unpack he binary file into a tuple
import struct, numpy, gdalThe "unpack_from" considers the offset of the header bytes and the tuple "z" contains now all the values in one long row of values -- this one-dimensional string of values is converted into an array and the reshaped according to the dimensions of the raster. Now I have my values in a two-dimensional array, the next part of the code writes it into a GeoTIFF file:
#Dimensions from https://nsidc.org/data/docs/daac/nsidc0051_gsfc_seaice.gd.html
height = 448
width = 304
#for this code, inspiration found at https://stevendkay.wordpress.com/category/python/
icefile = open(r"U:SSMI
t_20120101_f17_v01_n.bin", "rb")
contents = icefile.read()
icefile.close()
# unpack binary data into a flat tuple z
s="%dB" % (int(width*height),)
z=struct.unpack_from(s, contents, offset = 300)
nsidc = numpy.array(z).reshape((448,304))
nsidc = numpy.rot90(nsidc, 1)
#write the data to a GeotiffThis then is the resulting and imported image:
driver = gdal.GetDriverByName("GTiff")
outraster = driver.Create(C:UsersmaxDesktop\test4.tif, height, width, 1, gdal.GDT_Int16 )
raster = numpy.zeros((width, height), numpy.float)
outraster.GetRasterBand(1).WriteArray( raster )
outband = outraster.GetRasterBand(1)
#Write to file
outband.WriteArray(nsidc)
outband.FlushCache()
#Clear arrays and close files
outband = None
iceraster = None
outraster = None
outarray = None

Wednesday, February 11, 2015
Data Types in C
In some of our tutorials in the beginning, I told you about the three primary data types which are used in C language. Today I will introduce you to some variations in these primary data types in C. We can make unlimited data types as per our requirement in C. So C language is quite rich in data types.
What are 16 bit and 32 bit compilers?
Turbo C is a 16 bit compiler. After converting the C code into machine language, it will target that code to run on 16 bit processors like intel 8086.
On the other hand VC++ is a 32 bit compiler. It will target to run the code on 32 bit processors like intel Pentium processors.

Note: Here short and long are both keywords.
The range of both short and long are given below.
Range of long is -2147483648 to 2147483647.
Range of short is -32,768 to +32,767
New range will be 0 to 65535
By default normal int is also called signed int.
New range will be 0 to 255
If you want to increase this limit then you can also use double data type. It takes 8 bytes in the memory and it also provided a very big range to store values. Its range is -1.7e4932 to +1.7e4932.

int a;
unsigned int b;
long int c;
short int d;
unsigned short int e;
unsigned long int f;
char g;
unsigned char f;
float g;
double h;
Data Types in C
The primary data types which we have used till now has some limits. For example, we can only store values in the range of –32768 to 32767 for an int data type. Remember this range is for 16 bit compiler Turbo C. For 32 bit compiler like VC++ this range is –2147483648 to +2147483647. You can’t store more values which exceed this limit in int data type. To overcome those limits we have to use some extra keywords like unsigned, signed etc.What are 16 bit and 32 bit compilers?
Turbo C is a 16 bit compiler. After converting the C code into machine language, it will target that code to run on 16 bit processors like intel 8086.
On the other hand VC++ is a 32 bit compiler. It will target to run the code on 32 bit processors like intel Pentium processors.

short and long int
As I said earlier C language provides variation in its primary data types. short and long are such variations of integer data type. As its name suggests long has bigger range than int.Note: Here short and long are both keywords.
The range of both short and long are given below.
Range of long is -2147483648 to 2147483647.
Range of short is -32,768 to +32,767
signed and unsigned int
Generally it happened when we are confirmed that the value will not be negative in any case. So to utilize those conditions efficiently we often use unsigned int. With the use of unsigned keyword the range of int data type shifts from negative to positive.New range will be 0 to 65535
By default normal int is also called signed int.
signed and unsigned char
Range of normal char is -128 to +127. You must have known that char data type always stores the ASCII value of character. Many times we emerge in a condition when we have print or access the ASCII character who value is more than +127. So in that case we generally use unsigned char. Similar to int it also makes the range almost twice. Both signed and unsigned char occupies 1 byte in memory.New range will be 0 to 255
float and double
float variable occupies 4 bytes in memory and it also provides a good range to store values in it. It gives the range of -3.4e38 to +3.4e38.If you want to increase this limit then you can also use double data type. It takes 8 bytes in the memory and it also provided a very big range to store values. Its range is -1.7e4932 to +1.7e4932.

Declaration of all data types
Given below are declarations of all the data types which we have learned so far.int a;
unsigned int b;
long int c;
short int d;
unsigned short int e;
unsigned long int f;
char g;
unsigned char f;
float g;
double h;
Friday, January 16, 2015
PhoneGap Tutorial posting form data to MySql database Using PHP
Hi friends i am going to explain how to post mobile form data to MySql Database using PHP : Title : PhoneGap Tutorial - posting form data to MySql database Using PHP. Here is the html form source code , Requirements : PHP Server(you can install it in your local server or other wise you can use many free php webhosting servers online , I am using neq3.com for free control panel) Html5 JavaScript Css Here are the source files Html and JavaScript Files : Index.html
Here is the PHP Server file :
All Form data will be stored in mysql database like this
In my next tutorial i am going to explain how to convert this table data xml service or xml sothat it can be used as webservice.
Read more »
Insert title here
Ajax Form
$username="u462945266_sree";
$password="9963447141";
$database="u462945266_db";
$url = "mysql.neq3.com";
$category = $_POST[Category];
$website = $_POST[Website];
$title = $_POST[CouponTitle];
$description = $_POST[CouponDescription];
$code = $_POST[CouponCode];
$affiliatelink = $_POST[AffiliateLink];
$affiliateimage = $_POST[AffiliateImage];
mysql_connect($url,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO Coupons(Category,Website,CouponTitle,CouponDescription,CouponCode,AffiliateLink,AffiliateImage) VALUES ($category,$website,$title,$description,$code, $affiliatelink, $affiliateimage)";
mysql_query($query);
mysql_close();
echo "You successfully added your Coupon";
?>


Subscribe to:
Posts (Atom)