Skip to content

Instantly share code, notes, and snippets.

@kokkytos
Created Oct 27, 2018
Embed
What would you like to do?
Batch convert daily viirs to geotiffs
# -*- coding: utf-8 -*-
from satpy import find_files_and_readers, Scene
from datetime import datetime
from pyresample import geometry
from satpy.utils import debug_on
import numpy as np
import glob,os
from pyresample import utils
debug_on()
### Greek_Grid area definition
area_id = 'greek_grid'
description = 'Greek Grid'
proj_id = 'greekgrid_2100'
x_size = 202 #3867
y_size = 203 #3918
area_extent = (379354, 4132181, 529440, 4283010)
projection = '+proj=tmerc +lat_0=0 +lon_0=24 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m'
area_def = utils.get_area_def(area_id, description, proj_id, projection, x_size, y_size, area_extent)
BASEDIR='~/daily_viirs/2017/3332700175/001'
os.chdir(BASEDIR)
swath_files = glob.glob('SVDNB_npp_d*.h5')
txt = open(os.path.join(BASEDIR,"errors.txt"), "a")
for file in swath_files:
try:
output_dir=os.path.join(BASEDIR, "geotiffs")
if not os.path.exists(output_dir):
os.makedirs(output_dir)
scene = Scene(filenames=[file], reader='viirs_sdr')
scene.load(["DNB"])
proj_scn = scene.resample(area_def)
proj_scn.save_datasets(writer='geotiff',
base_dir=output_dir,
file_pattern='{name}_{start_time:%Y%m%d_%H%M%S}_{end_time:%Y%m%d_%H%M%S}_so{start_orbit}_eo{end_orbit}_epsg2100.tif',
enhancement_config=False,
dtype=np.float32)
except Exception, e:
msg = "File:{},Error:{}\n".format(file, e)
txt.write(msg)
txt.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment