abby-baskind / seniorthesis

0 stars 2 forks source link

map of chen #22

Open abby-baskind opened 2 years ago

abby-baskind commented 2 years ago

hey @gmacgilchrist

here's the issue I've been having plotting a map of the PCO2 from chen. I tried it a few different ways

  1. This one is just the intuitive way plotting PCO2 with lon and lat
X = obs_fgco2.lon  # this is just the longitude from the Bushinsky observations because it's a 1 row array
Y = obs_fgco2.lat  # the coordinates from chen were many rows and hard to deal with 

Z = PCO2.sel(lev = 800)

im = ax.pcolormesh(X, Y, Z,cmap='viridis', transform = crs_source, shading = 'auto', vmin = 300, vmax = 600)

I get a fun little error, basically saying the shapes don't match up, and nothing gets plotted.

Screen Shot 2022-03-16 at 5 45 41 PM
  1. This time I tried swapping the axes on PCO2 to get the shape right
X = obs_fgco2.lon  # this is just the longitude from the Bushinsky observations because it's a 1 row array
Y = obs_fgco2.lat  # the coordinates from chen were many rows and hard to deal with 

Z = np.swapaxes(PCO2.sel(lev = 800),0,1)

im = ax.pcolormesh(X, Y, Z,cmap='viridis', transform = crs_source, shading = 'auto', vmin = 300, vmax = 600)
Screen Shot 2022-03-16 at 5 47 28 PM

It plots (yay!) but clearly the coordinates get screwed up. For example, there's a huge blank spot over by Australia that clearly should be where South America is.

  1. Then I tried transpose
X = obs_fgco2.lon  # this is just the longitude from the Bushinsky observations because it's a 1 row array
Y = obs_fgco2.lat  # the coordinates from chen were many rows and hard to deal with 

Z = PCO2.sel(lev = 800).transpose('y','x')

im = ax.pcolormesh(X, Y, Z,cmap='viridis', transform = crs_source, shading = 'auto', vmin = 300, vmax = 600)
Screen Shot 2022-03-16 at 5 47 28 PM

And it's the same issue as the last attempt. Any idea on the way around this?

jbusecke commented 2 years ago

Can you print the dataset? I suspect that there are no coordinates, but it just counts from 0-360. Id be able to say more when I see the dataset.

gmacgilchrist commented 2 years ago

Using the lat and lon from fgco2 to plot PCO2 doesn't make sense to me. As @jbusecke says, does PCO2 have lat and lon? If so, you should use them to plot that variable. There must be a mismatch between the coordinates for fgco2 and PCO2, which is what is muddling them when you try to use them together. You will see the mismatch in the coordinates if you plot them both independently just with pcolormesh i.e. not with cartopy, and you should see that the continents are not appearing in the same place.

If PCO2 does have coordinates, you can just use them to plot, and use the fgco2 coordinates to plot fgco2 - then they will both be mapped to the correct locations.

If not, and you need to use the fgco2 coordinates for PCO2, then you will need to "roll" PCO2 along the x-axis in order to match them up. You can do this with PCO2.roll(x=A), where x is the name of the x dimension, and A is the number of indices that you need to shift.