Skip to content
Snippets Groups Projects
run_identify.py 2.34 KiB
Newer Older
# Usage Example
from enstools.feature.pipeline import FeaturePipeline
from enstools.feature.identification.african_easterly_waves import AEWIdentification
from enstools.feature.tracking.african_easterly_waves import AEWTracking
from datetime import timedelta
from enstools.feature.identification._proto_gen import african_easterly_waves_pb2
from os.path import expanduser, join
from enstools.feature.util.graph import DataGraph
Christoph.Fischer's avatar
Christoph.Fischer committed
from enstools.feature.identification.african_easterly_waves.plotting import plot_track_in_ts, plot_timesteps_from_desc, plot_tracks_from_desc
import enstools.feature.identification.african_easterly_waves.configuration as cfg
import sys
pipeline = FeaturePipeline(african_easterly_waves_pb2, processing_mode='2d')
Christoph.Fischer's avatar
Christoph.Fischer committed
data_dir = cfg.cv_data_dir
in_file = join(data_dir, '*.nc')
out_dir = cfg.out_dir
Christoph.Fischer's avatar
Christoph.Fischer committed
if len(sys.argv) > 1:
    proc_summer_of_year = int(sys.argv[1])
    if len(sys.argv) > 2:
        proc_month_of_year = int(sys.argv[2])
    
# init AEWIdentification strategy, can take different parameters
Christoph.Fischer's avatar
Christoph.Fischer committed
i_strat = AEWIdentification(wt_out_file=True, cv='cv', year_summer=proc_summer_of_year, month=proc_month_of_year)
t_strat = AEWTracking()

pipeline.set_identification_strategy(i_strat)
pipeline.set_tracking_strategy(t_strat) # None TODO
pipeline.set_data_path(in_file)
Christoph.Fischer's avatar
Christoph.Fischer committed
# generate the single tracks
pipeline.generate_tracks()
od = pipeline.get_object_desc() # just the identified objects and their connections in object_desc

# out_netcdf_path = data_path + '_streamers.nc'

Christoph.Fischer's avatar
Christoph.Fischer committed
if len(sys.argv) == 1:
    out_json_path = out_dir + 'aew_desc.json'
    out_dataset_path = out_dir + '05_wt.nc'
elif len(sys.argv) == 2:
    out_json_path = out_dir + 'aew_desc_' + str(proc_summer_of_year) + '.json'
    out_dataset_path = out_dir + '05_wt_' + str(proc_summer_of_year) + '.nc'
else:
    m_str = str(proc_month_of_year).zfill(2)
    out_json_path = out_dir + 'aew_desc_' + str(proc_summer_of_year) + '_' + m_str + '.json'
    out_dataset_path = out_dir + '05_wt_' + str(proc_summer_of_year) + '_' + m_str + '.nc'
    


pipeline.save_result(description_type='json', description_path=out_json_path, dataset_path=out_dataset_path) # dataset_path=out_dataset_path, 
# , description_path=out_json_path, graph_path=out_graph_path

# print("Plot.")
# plot_timesteps_from_desc(od, pipeline.get_data())
# plot_tracks_from_desc(od, None)