diff --git a/mapies/mapies.py b/mapies/mapies.py index 17d9bac5a5e80acd002c62a406090c32c17b73aa..2129a03311e79e4d92c5f2a6d8458c75f42d4de1 100644 --- a/mapies/mapies.py +++ b/mapies/mapies.py @@ -355,12 +355,13 @@ class MAPIES: levels = np.linspace(unique_values.min(), unique_values.max(), unique_values.max()-unique_values.min()+1) # Use a discrete colormap - cmap = plt.cm.viridis - norm = mcolors.BoundaryNorm(np.arange(unique_values.min()-0.5, unique_values.max()+1, 1), cmap.N) + cmap = plt.cm.rainbow + norm = mcolors.Normalize(vmin=unique_values.min(), vmax=unique_values.max()) + # norm = mcolors.BoundaryNorm(np.arange(unique_values.min()-0.5, unique_values.max()+1, 1), cmap.N) # Create the plot and add features fig, ax = plt.subplots(subplot_kw={"projection": proj}, figsize=figsize) - ax.gridlines() + ax.gridlines(draw_labels=True) ax.coastlines(resolution="10m") # Scatter plot for the number of observations @@ -369,7 +370,7 @@ class MAPIES: ) # Add the discrete colorbar without arrow-like ends - cbar = fig.colorbar(im, ax=ax, orientation="vertical", ticks=levels) + cbar = fig.colorbar(im, ax=ax, orientation="vertical") cbar.set_label("Number of Observations") # cbar.ax.set_yticklabels([f"{level}" for level in range(unique_values)]) @@ -384,57 +385,5 @@ class MAPIES: plt.close(fig) print(f"Saved plot: {filepath}") - @timeit - def plot_2D_num_obs_custom_log_option( - self, lon_values=None, lat_values=None, num_obs=None, outdir="./", - title=None, filename=None, use_log_scale=False - ): - """ - General method for plotting the number of observations contributing to the final averages, - with an option to use a logarithmic scale for large observation counts. - """ - - # Set Basemap projection - figsize = (15, 10) - markersize = 2.5 - proj = ccrs.PlateCarree() - - # Handle log scale if needed - if use_log_scale: - num_obs = np.log10(num_obs + 1) # Avoid log(0) by adding 1 - label = "Log10(Number of Observations)" - else: - label = "Number of Observations" - - # Define discrete levels for the color bar - unique_values = np.unique(num_obs) - levels = np.linspace(unique_values.min(), unique_values.max(), 10) - - # Use a discrete colormap - cmap = plt.cm.rainbow - norm = mcolors.BoundaryNorm(levels, cmap.N) - # Create the plot and add features - fig, ax = plt.subplots(subplot_kw={"projection": proj}, figsize=figsize) - ax.gridlines(draw_labels=True) - ax.coastlines(resolution="10m") - - # Scatter plot for the number of observations - im = ax.scatter( - lon_values, lat_values, markersize, c=num_obs, cmap=cmap, norm=norm, transform=proj - ) - - # Add the colorbar - cbar = fig.colorbar(im, ax=ax, orientation="vertical", ticks=levels) - cbar.set_label(label) - - # Add title and save the plot - ax.set_title(title or "Number of Observations Plot") - - # Ensure the output directory exists - os.makedirs(outdir, exist_ok=True) - - filepath = os.path.join(outdir, filename or "num_observation_2D_plot.png") - plt.savefig(filepath, format="png") - plt.close(fig) - print(f"Saved plot: {filepath}") + diff --git a/mapies/viirs.py b/mapies/viirs.py index 88cc64ec038be9fb4bec03b80ddaaf13a78bea9d..2725ecb8e817d3ee6d14764d04f1c2fa67316b72 100644 --- a/mapies/viirs.py +++ b/mapies/viirs.py @@ -451,7 +451,7 @@ class VIIRS(MAPIES): continue # title = f"Observation 2D plot of {self.datatype.upper()} data from {self.start_date} to {self.end_date}" title = f"Observation 2D plot of month {m} from {self.start_date} to {self.end_date}" - filename = f"{outdir}/{self.datatype}_2D_obs_{m}_{self.year}_JANUARY_trial7.png" + filename = f"{outdir}/{self.datatype}_2D_obs_month{m}_{self.year}_.png" super().plot_2D_obs_custom( lon_values=lon_values, lat_values=lat_values, @@ -496,15 +496,14 @@ class VIIRS(MAPIES): continue # title = f"Observation 2D plot of {self.datatype.upper()} data from {self.start_date} to {self.end_date}" title = f"Plot of the number of valid observations for month {m} from {self.start_date} to {self.end_date}" - filename = f"{outdir}/{self.datatype}_2D_obs_count_{m}_{self.year}_JANUARY_trial7.png" - super().plot_2D_num_obs_custom_log_option( + filename = f"{outdir}/{self.datatype}_2D_obs_count_month{m}_{self.year}_trial4.png" + super().plot_2D_num_obs_custom( lon_values=lon_values, lat_values=lat_values, num_obs=cum_count, outdir=outdir, title=title, filename=filename, - use_log_scale=True, ) else: try: @@ -525,8 +524,7 @@ class VIIRS(MAPIES): filename=filename, ) - - + @timeit def process_data(self, monthly_avg=True, batch_size=100): """ Process the data for the specified year and months. diff --git a/run/run_viirs.py b/run/run_viirs.py index 3b3d13ba566997df624fe667f6ad9085ce877224..8685c6cd664b25428ba58eede0061c4727214bb4 100644 --- a/run/run_viirs.py +++ b/run/run_viirs.py @@ -5,15 +5,38 @@ import time if __name__ == "__main__": # Change these variables + # 00:30 to 02:36 from 2024-01-01 to 2024-01-03 + # start_date = "202401010030" + # end_date = "202401030236" + + # 00:30 to 03:36 of 2024-01-01 + # start_date = "202401010030" + # end_date = "202401010336" + + # ONE YEAR + # start_date = "202401300000" + # end_date = "202402022359" + + # ONE MONTH - JANUARY 2024 start_date = "202401010000" - end_date = "202401020000" - outdir="/esarchive/scratch/cmeikle/" - indir="/esarchive/obs/nasa/viirs_noaa20_aerdb_l2/original_files/VIIRS" - c = VIIRS(start_date, end_date, frequency="D", dest=outdir, indir=indir, apply_qa=True) + end_date = "202401312359" - # Monthly average plot (in 'month' variables specify the month) + # outdir="/home/cmeikle/Projects/data/" + # indir="/home/cmeikle/Projects/data/VIIRS/original_files/AERDB_L2_VIIRS_NOAA20" + outdir = "/home/cgile/Documents/mapies/figures" + # indir = "/home/cgile/bscearth000/esarchive/obs/nasa/viirs_noaa20_aerdb_l2/original_files/VIIRS" + indir = "/home/cgile/Documents/mapies/VIIRS" + + start_time = time.time() + + c = VIIRS(start_date, end_date, frequency="D", dest=outdir, indir=indir) c.read_nc() - c.process_data(monthly_avg=False, batch_size = 20) - #c.plot_2D_obs() - c.plot_2D_observations(months=[0], outdir=outdir) - #c.plot_2D_num_obs(months=[0], outdir=outdir) \ No newline at end of file + c.process_data(monthly_avg=True, batch_size = 100) + c.yearly_average() + c.plot_2D_observations(months=[1], outdir=outdir) + c.plot_2D_num_obs(months=[1], outdir=outdir) + end_time = time.time() + elapsed_time = end_time - start_time + print(f"Script executed in {elapsed_time:.2f} seconds.") + +