#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Sat Nov 23 09:35:24 EST 2024 if __name__ == '__main__': import sys,os try: from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) except: pass import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports wython = '/tigress/wenchang/wython' if wython not in sys.path: sys.path.append(wython); print('added to python path:', wython) #from misc import get_kws_from_argv import salem # if __name__ == '__main__': try: tt.check('end import') except: pass # #start from here: data and functions state = 'MD' ifile = 'VIIRS-Land_v001_JP113C1_NOAA-20_20241116_c20241118153011.nc' #read the data file ds = xr.open_dataset(ifile) da = ds.NDVI #get the data array #read the shape file of united states sh = salem.read_shapefile('cb_2016_us_state_5m/cb_2016_us_state_5m.shp') state_shape = sh[sh.STUSPS==state] #state shape #plot if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot fig, ax = plt.subplots() da.plot(cmap='BrBG', ax=ax, robust=True) mapplot(coastlines_color='none') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__01global.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) # state shape fig, ax = plt.subplots() state_shape.plot(ax=ax) mapplot(coastlines_color='none') ax.set_title(state, loc='left') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__02{state}shape.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) # state map fig, ax = plt.subplots(figsize=(7,3)) da.salem.subset(shape=state_shape, margin=1).plot(cmap='BrBG', ax=ax) mapplot(coastlines_color='none') state_shape.boundary.plot(ax=ax, color='C1') ax.set_title(state, loc='right') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__03{state}data.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) # state data masked fig, ax = plt.subplots(figsize=(7,3)) da.salem.subset(shape=state_shape, margin=1).salem.roi(shape=state_shape).plot(cmap='BrBG', ax=ax) mapplot(coastlines_color='none') state_shape.boundary.plot(ax=ax, color='C1') ax.set_title(state+ ' masked', loc='right') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__04{state}dataMasked.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show() try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()