Skip to content

Instantly share code, notes, and snippets.

@AdrianoPereira
Created April 25, 2025 13:59
Show Gist options
  • Select an option

  • Save AdrianoPereira/0724011655602927750ea6767ec3d6f8 to your computer and use it in GitHub Desktop.

Select an option

Save AdrianoPereira/0724011655602927750ea6767ec3d6f8 to your computer and use it in GitHub Desktop.
Python script for tracking GOES-13 Infrared (B04) data in a specific interest area.
import gzip
import pyfortracc
import numpy as np
import xarray as xr
scale = 0.01
lon_min, lon_max = -100.0, -25.24
lat_min, lat_max = -56.0, 12.52
res_x, res_y = 0.04, 0.04
lons = np.arange(lon_min, lon_max+res_x, res_x)
lats = np.arange(lat_min, lat_max+res_y, res_y)
ncols = len(lons)
nrows = len(lats)
lon_grid, lat_grid = np.meshgrid(lons, lats)
clon_min = -74.97844303190824
clat_min = -11.99286774514141
clon_max = -41.02401555257619
clat_max = 7.978614856143793
def read_function(filename):
with gzip.open(filename, 'rb') as f:
data = np.frombuffer(f.read(), dtype=np.int16)
data = data.reshape((nrows, ncols))
data = data.astype(np.float32) * scale
# crop the image to the region of interest
lat_min_idx = np.abs(lats - clat_max).argmin() # max LAT corresponde ao menor índice
lat_max_idx = np.abs(lats - clat_min).argmin() # min LAT corresponde ao maior índice
lon_min_idx = np.abs(lons - clon_min).argmin()
lon_max_idx = np.abs(lons - clon_max).argmin()
# garante que os índices estão na ordem crescente
i0, i1 = sorted([lat_min_idx, lat_max_idx])
j0, j1 = sorted([lon_min_idx, lon_max_idx])
data_cropped = data[::-1, :][i0:i1, j0:j1][::-1, :]
return data_cropped
###################################
######## SET NAME_LIST ############
name_list = {}
name_list['input_path'] = '/storage/goes/goes13/B04/'
name_list['output_path'] = '/storage/tracks/goes13/'
#name_list['input_path'] = 'input/'
# name_list['output_path'] = 'output/'
name_list['thresholds'] = [235, 210]
name_list['min_cluster_size'] = [25, 9]
name_list['operator'] = '<='
name_list['timestamp_pattern'] = ['%Y%m%d%H%M'] #S10236964_201401011430.gz
name_list['pattern_position'] = [10,22]
name_list['delta_time'] = 30
name_list['cluster_method'] = 'ndimage'
name_list['edges'] = True
name_list['spl_correction'] = True
name_list['mrg_correction'] = True
name_list['inc_correction'] = True
name_list['opt_correction'] = True
name_list['elp_correction'] = True
name_list['opt_mtd'] = 'farneback'
name_list['validation'] = True
#name_list['validation_scores'] = True
name_list['lon_min'] = -74.97844303190824
name_list['lon_max'] = -41.02401555257619
name_list['lat_min'] = -11.99286774514141
name_list['lat_max'] = 7.978614856143793
name_list['n_jobs'] = 30
###################################
print(pyfortracc.__version__)
pyfortracc.features_extraction(name_list, read_function)
pyfortracc.spatial_operations(name_list, read_function)
pyfortracc.cluster_linking(name_list)
pyfortracc.concat(name_list, clean=False)
pyfortracc.post_processing.compute_duration(name_list, parallel=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment