JASMES Tutorial
 How to convert JASMES MODIS data to GeoTiFF (Python sample script)

This tutorial shows how to convert MODIS data in binary format provided by JASMES service to GeoTiFF.
By converting from binary format to GeoTiFF, data can be viewed, edited, analyzed, using QGIS.

Note

JASMES data must be downloaded before the tutorial, and user registration is required to use JASMES data.

The sample scripts use Python3.
The tutorial shows an example of execution under Linux, but the sample scripts can also be used under Windows.
For details, please refer to "1. How to use the sample scripts" in this tutorial.

JAXA is not responsible for any actions taken by users using the contents of this website (including scripts).

Please refer to the following page for details of JASMES user registration. JASMES users can use all data published in JASMES services.
In this tutorial, as an example, we will create GeoTiFF that converts MODIS data(filename : '*_le') to physical quantity. JASMES User Registration JASMES Data Access JASMES Data List

0. Introduction

Please use this tutorial as follows for your purposes.

If you want to convert JASMES MODIS data to GeoTiFF
 Execute the sample script according to "1. How to use sample script"

If you want to know what the sample script does
 See "2. Description of script processing"

If you want to know how to open GeoTiFF in QGIS for use
 See "3. How to open GeoTiFF with QGIS"

1. How to use sample script

1-1. Sample script download

These are sample scripts used in this tutorial. Please download it from the buttons bellow.
Multiple scripts are provided. Please refer to the list in "1-3. Target Data List" to determine which script to use.
This tutorial is an example of using script(1). Basically, the GeoTiFF conversion method is same except for reading part, and script usage is also the same.
For special instructions for each script, please refer to the "README_*.txt" file included with the downloaded script.

About Sample Scripts

The sample scripts use Python3, and the Python libraries are NumPy, ctypes, and osgeo (gdal and osr).
The tutorial shows an example of execution under Linux, but the sample scripts can also be used under Windows.

Sample scripts may be freely modified and redistributed.

Sample Script(1) (filename:'*_le') Download Sample Script(2) (filename:'*_8b') Download Sample Script(3) (multi band) Download Sample Script(4) (lst) Download Sample Script(5) (wf, wst) Download Sample Script(6) (rgb) Download

1-2. Execution enviroment

The tutorial shows an example of execution under Linux.
The sample scripts use Python3.

The following is the runtime environment and Python libraries used when testing the sample scripts.

Execution enviroment

Linux:Red Hat Enterprise Linux(8.4)
Python:Python 3.6.8
Python standard libraries:ctypes
Python external libraries:NumPy, osgeo(gdal, osr) *Installation required


1-3. Target data list

To get JASMES data, you need to register as a user here. Please refer to here for how to get data after user registration.

Products for which sample scripts can be used and the script number are listed below.
Please refer to the list of data provided by JASMES for details on the area, resolution, and statistical period (Daily, Monthly, etc.) of each product, if necessary.
No.Web pageSensorcategoryProductScriptNote
(1)(2)(3)(4)(5)(6)
1JASMESTerra・Aqua
/MODIS
Atmoshereaotatmosphere optical tickness-----
2JASMESTerra・Aqua
/MODIS
Atmoshereaerosolaerosol data-----multi band
3JASMESTerra・Aqua
/MODIS
AtmosherealphAngstrom exponent-----
4JASMESTerra・Aqua
/MODIS
AtmosherecfrCloud flag------Not applicable for HDF file.
5JASMESTerra・Aqua
/MODIS
AtmosheredparDirect PAR-----
6JASMESTerra・Aqua
/MODIS
AtmoshereparPhotosynthetically Available Radiation-----
7JASMESTerra・Aqua
/MODIS
AtmoshereptwPrecipitable Water-----
8JASMESTerra・Aqua
/MODIS
AtmosheretipTransmittance of Instantaneous PAR at noon----
9JASMESTerra・Aqua
/MODIS
Atmoshererparsurface Reflectance weighted by PAR wavelengths & solar irradiance-----
10JASMESTerra・Aqua
/MODIS
AtmoshereswrShortwave Radiation----
11JASMESTerra・Aqua
/MODIS
Atmoshereta1Aerosol optical thickness [WK= 412.46 nm]-----
12JASMESTerra・Aqua
/MODIS
AtmosheretauaAerosol abundance (Optical thickness)-----
13JASMESTerra・Aqua
/MODIS
AtmoshereuvaUV-A----
14JASMESTerra・Aqua
/MODIS
AtmoshereuvbUV-B----
15JASMESTerra・Aqua
/MODIS
LandlstLand Surface Temperature-----
16JASMESTerra・Aqua
/MODIS
LandndviActivity of Vegetation (NDVI)-----
17JASMESTerra・Aqua
/MODIS
LandwfWild fire-----No header in data.
18JASMESTerra・Aqua
/MODIS
LandwstPlant Water Stress Trend-----No header in data.
19JASMESTerra・Aqua
/MODIS
OceanchlaPhytoplankton abundance (Chlorophyll-a)-----
20JASMESTerra・Aqua
/MODIS
OceanolstOcean and Land Surface Temperature-----
21JASMESTerra・Aqua
/MODIS
OceansstSea Surface Temperature-----
22JASMESTerra・Aqua
/MODIS
OceanapgAbsorption Coefficient of Particles + CDOM-----
23JASMESTerra・Aqua
/MODIS
OceanbbpBackscattering Coefficient of Particles-----
24JASMESTerra・Aqua
/MODIS
CryosheresnwcfrLong-term Snow Cover Extent-----
25JASMESTerra・Aqua
/MODIS
-rgbRGB-----RGB
26JASMESTerra・Aqua
/MODIS
-multipar data including subparameters-----multi band

1-4. How to run the sample script

Execute the sample script with the input file path, output path and target area as arguments.
The usage of the script for the file name "*_le" is described. For special instructions for each script, please refer to the "README_*.txt" file included with the downloaded script.

$ ./MODIS_le_bin2geotiff.py <Input> <Output> <Area>

Argument 1 Input
 Specify the full path of binary file to be input.

Argument 2 Output
 Specify the name of the GeoTiFF file to be output.
 If only a file name is specified, the output will be in the current directory.

Argument 3 Area
 Specify the area corresponding to the file to be input.(Global, Japan and Thai)


An example of command execution is shown below. The output file name can be any arbitrary file name.
[DIR] : Data input/output directory

$ ./MODIS_le_bin2geotiff.py [DIR]/MDS02SSH_A20230101Av1_v811_7200_3601_CHLA_le [DIR]/MDS02SSH_A20230101Av1_v811_7200_3601_CHLA_le.tif Global

2. Description of script processing

From here, the various processes of the sample scripts are explained.

2-1. Reading binary data with Python

The header is specified according to the format of JASMES MODIS data shown in "1-3. Target Data List".
Since JASMES MODIS data is formatted to include necessary information such as pixel size in the header section, it is necessary to read the header.
Please note that this is specific to JASMES MODIS data.

# Header format
class headerFormat(c.Structure):
  _fields_ = [
    ("npixel" , c.c_char*6 ),
    ("nline"  , c.c_char*6 ),
    ("lon_min", c.c_char*8 ),
    ("lat_max", c.c_char*8 ),
    ("reso"   , c.c_char*8 ),
    ("slope"  , c.c_char*12),
    ("offset ", c.c_char*12)
  ]

arguments (input binary file path, output GeoTiFF file path, target area).

argvs   = sys.argv

# argument ERROR
if len(argvs) != 4:
  print("argument error: 1:input file, 2:output file, 3:area (Global / Japan / Thai)")
  sys.exit(9)
else:
  binfile = argvs[1]
  output  = argvs[2]
  area    = argvs[3]

Binary file reading is performed.
After reading the header information into format_data according to the file, the data portions is read into binarr, skipping the header portion.

# 1 line * 2byte
HEADER_SIZE = X_SIZE*2
format_data = headerFormat()

# Binary file open
with open(binfile, 'rb') as f:
  # Read header
  f.readinto(format_data)
  # Header skip
  f.seek(HEADER_SIZE)
  # Read binary data as unsiged-2byte integer
  binarr = np.fromfile(f, dtype=np.uint16)

The necessary values of the headers read in format_data are retrieved.
The values obtained are as follows.
・SLOPE, OFFSET are used for physical quantity convertion (DN * SLOPE + OFFSET).
・X_SIZE, Y_SIZE, UpperLeft_LON, UpperLeft_LAT, RESO are used for GeoTiFF output.

# Header value set
X_SIZE        = np.uint16(format_data.npixel)
Y_SIZE        = np.uint16(format_data.nline)
UpperLeft_LON = np.float32(format_data.lon_min)
UpperLeft_LAT = np.float32(format_data.lat_max)
RESO          = np.float32(format_data.reso)
SLOPE         = np.float32(format_data.slope)
OFFSET        = np.float32(format_data.offset)

# pixel center -> top left corner of the pixel
UpperLeft_LON = UpperLeft_LON - (RESO * 0.5)
UpperLeft_LAT = UpperLeft_LAT + (RESO * 0.5)

2-2. Convert to physical quantities using slope and offset values with Python

"DN * SLOPE + OFFSET" is converted to a physical quantity and stored in an array(data type is Float).
"65535" is "Error_DN", it is replaced by "nan".(In the case of "*_8b", "255" is "Error_DN".)

# Reshape pixel x line data
orgdat = binarr.reshape(Y_SIZE,X_SIZE).copy()
# value = DN * SLOPE + OFFSET
otemp  = orgdat * SLOPE + OFFSET
# convert error value to nan
otemp[orgdat==65535] = np.nan

2-3. Output GeoTiFF with Python (GDAL library)

The array is output in GeoTiFF format using Python's GDAL library.
Create a GDAL driver that creates GeoTiFF.
・driver.Create(output, cols, rows, band, data type)

# output GeoTiFF
driver = gdal.GetDriverByName('GTiff')

# outputfile, cols, rows, band num, data type
cols      = otemp.shape[1]
rows      = otemp.shape[0]
outRaster = driver.Create(output, cols, rows, 1, gdal.GDT_Float32)

SetGeoTransform with the coordinate values.
・outRaster.SetGeoTransform((upper left longitude, pixel size(x), rotate, upper left latitude, rotate, pixel size(y)))

# upper_left_longitude, pixel size(x), rotate, upper_left_latitude, rotate, pixel size(y)
dx = RESO
dy = RESO*-1
outRaster.SetGeoTransform((UpperLeft_LON, dx, 0, UpperLeft_LAT, 0, dy))

Specify the band.

# band
outband = outRaster.GetRasterBand(1)
outband.WriteArray(otemp)

The projection method is set to EPSG:4326.

# EPSG
outRasterSRS = osr.SpatialReference()
outRasterSRS.ImportFromEPSG(4326)
outRaster.SetProjection(outRasterSRS.ExportToWkt())

Export to file to output GeoTiFF.

outband.FlushCache()
outRaster = None

print("### END output : "+output+" ###")
sys.exit(0)

3. How to open GeoTiFF with QGIS

The GeoTiFF created in this tutorial can be opened directly in QGIS, a free GIS software, for viewing, editing, and analyzing data.
Please refer to the following QGIS usage instruction if necessary.

Imaging procedure for GCOM-C (SHIKISAI) products using QGIS (G-Portal)
Please refer to Step5 and later and "How convert color lamps" as the physical quantities and GeoTiFF conversion have already been done in this tutorial.
Imaging procedure for GCOM-C (SHIKISAI) products using QGIS (G-Portal)
Display of Chlorophyll-a Concentration (QGIS) (Shikisai Portal)
Please refer to the logarithmic scale (QGIS) if necessary, as the logarithmic scale may be easier to read in some cases, such as CHLA.
Display of Chlorophyll-a Concentration (QGIS) (Shikisai Portal)