-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Basic OmF/OmA Maps #108
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2575528
Start of OmF/OmA maps
CoryMartin-NOAA 2d5399f
Working OmF map; need to refine
CoryMartin-NOAA 9ff5a87
Change plot name to omf/oma
CoryMartin-NOAA 0b9a92e
Merge branch 'feature/LAMDA' into feature/omf_maps
CoryMartin-NOAA eec08df
Working OmF map
CoryMartin-NOAA 47cdad8
Merge branch 'feature/LAMDA' of https://github.com/noaa-emc/pygsi int…
CoryMartin-NOAA 7999bb5
Add round; double marker size
CoryMartin-NOAA 687ddab
Ensure rounding is done properly; keep edgecolors to None
CoryMartin-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import numpy as np | ||
import yaml | ||
import os | ||
from pathlib import Path | ||
import matplotlib.pyplot as plt | ||
import LAMDA.plot_features as features | ||
from LAMDA.no_data_plots import no_data_map | ||
from emcpy.plots.map_plots import MapScatter | ||
from emcpy.plots import CreateMap | ||
from emcpy.plots.map_tools import Domain, MapProjection | ||
from pyGSI.diags import Conventional, Radiance, Ozone | ||
|
||
|
||
def _create_map_departures(df, domain, projection, | ||
metadata, outdir): | ||
""" | ||
Create the map figure and plot data. | ||
""" | ||
# this for now puts all O-F/O-A together, might want to split by | ||
# monitored/rejected/assim later | ||
# grab variables for plotting | ||
lats = df['latitude'].to_numpy() | ||
lons = df['longitude'].to_numpy() | ||
omf = df['omf_adjusted'].to_numpy() | ||
|
||
plot_objects = [] | ||
|
||
# Create map object | ||
mymap = CreateMap(figsize=(12, 8), | ||
domain=Domain(domain), | ||
proj_obj=MapProjection(projection)) | ||
# Add coastlines and states | ||
mymap.add_features(['coastlines', 'states']) | ||
|
||
# determine vmin/vmax for colorbar and must be symmetric | ||
if len(lats) > 0: | ||
omfscatter = MapScatter(latitude=lats, | ||
longitude=lons, | ||
data=omf) | ||
omfscatter.markersize = 2 | ||
omfscatter.cmap = 'coolwarm' | ||
# determine min/max of values | ||
maxval = np.nanmax(omf) | ||
minval = np.nanmin(omf) | ||
vmax = max(abs(minval), maxval) | ||
omfscatter.vmin = vmax * -1 | ||
omfscatter.vmax = vmax | ||
# add data to plot objects | ||
plot_objects.append(omfscatter) | ||
# labels and annotations | ||
labels = features.get_labels(metadata) | ||
# draw data | ||
mymap.draw_data(plot_objects) | ||
# add labels | ||
mymap.add_colorbar(label=metadata['Diag Type'], | ||
label_fontsize=12, extend='neither') | ||
mymap.add_title(labels['title'], loc='left', fontsize=12) | ||
mymap.add_title(labels['date title'], loc='right', fontsize=12, | ||
fontweight='semibold') | ||
mymap.add_xlabel("Longitude", fontsize=12) | ||
mymap.add_ylabel("Latitude", fontsize=12) | ||
# add stats to figure | ||
stats_dict = { | ||
'nobs': len(lats), | ||
'min': np.round(minval, 4), | ||
'max': np.round(maxval, 4), | ||
} | ||
mymap.add_stats_dict(stats_dict=stats_dict) | ||
# save figure | ||
fig = mymap.return_figure() | ||
str_domain = domain.replace(" ", "_") | ||
plt.savefig(outdir + f"{labels['save file']}_{str_domain}.png", | ||
bbox_inches='tight', pad_inches=0.1) | ||
plt.close('all') | ||
|
||
else: | ||
# no data to plot | ||
fig = no_data_map(mymap, Domain(domain), metadata) | ||
|
||
|
||
def map_departures(config): | ||
""" | ||
Create map of departures (O-F and O-A) | ||
|
||
Args: | ||
config : (dict) configuration file that includes the | ||
appropriate inputs based on file type (i.e. | ||
conventional or radiance data) | ||
""" | ||
|
||
# Get filename to determing what the file type is | ||
filename = os.path.splitext(Path(config['diag file']).stem)[0] | ||
filetype = filename.split('_')[1] | ||
|
||
if filetype == 'conv': | ||
diag = Conventional(config['diag file']) | ||
df = diag.get_data(obsid=[config['observation id']], | ||
subtype=[config['observation subtype']], | ||
analysis_use=config['analysis use']) | ||
metadata = diag.metadata | ||
metadata['ObsID Name'] = features.get_obs_type([config['observation id']]) | ||
|
||
else: | ||
diag = Radiance(config['diag file']) | ||
df = diag.get_data(channel=[config['channel']], | ||
analysis_use=config['analysis use']) | ||
metadata = diag.metadata | ||
|
||
metadata['Diag Type'] = config['data type'] | ||
|
||
anl_use = config['analysis use'] | ||
if anl_use: | ||
for anl_type in df.keys(): | ||
metadata['Anl Use Type'] = anl_type | ||
_create_map_departures(df[anl_type], config['domain'], config['projection'], | ||
metadata, config['outdir']) | ||
else: | ||
metadata['Anl Use Type'] = None | ||
_create_map_departures(df, config['domain'], config['projection'], | ||
metadata, config['outdir']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to add the following kwarg?
omfscatter.linewidths=0.15
. I don't know API from which MapScatter is derived, but assuming it's from matplotlib and is based uponmatplotlib.pyplot.scatter
that should help the markers show up a little bit better. If it doesn't work right we made need to change the edgecolor kwarg.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is something we will have to add to EMCPy, as I don't think all **kwargs are inherited. We probably have to add it, what do you think @kevindougherty-noaa ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was just about to comment on this. Taking a look at MapScatter, I think it would be just as simple as adding
self.linewidths
as an additional argument.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs even more work in EMCPy, as I don't think the edge colors argument is passed properly, see NOAA-EMC/emcpy#80