christianversloot Github contribution chart
christianversloot Github Stats
christianversloot Most Used Languages

Activity

21 Sep 2022

Issue Comment

Christianversloot

Are OpenAPI example objects possible with Sanic's OpenAPI extension?

Hi - I am creating this issue because I have not been able to find an answer to this question in any of the Sanic repositories nor using Sanic docs.

My setup is as follows:

  • Sanic based API
  • Sanic Extensions based OpenAPI documentation
  • Using dataclasses to represent response structure.

By specifying @openapi.response(...) decorators using my dataclasses, I am able to specify the response structure of my API. I am now trying to add example objects, too, which should illustrate a specific response example for a specific API route.

I have not been able to identify if this is possible using the decorator or in any other way. I do notice that it is possible to specify example objects per the OpenAPI 3 docs, and thus possibly via the advanced way of specifying Sanic OpenAPI - via the operation level YAML (https://sanic.dev/en/plugins/sanic-ext/openapi/autodoc.html#operation-level-yaml). However, this gets ugly quite soon as some of my JSONs are rather large.

I have looked at the code and see that the response decorator supports kwargs. Is there any way that such example objects can be specified through these keywords arguments, or in any other way, in such a way that I can just instantiate objects from my dataclasses and pass them to e.g. Sanic's OpenAPI decorators?

That would be really helpful!

Thanks a lot :)

Forked On 21 Sep 2022 at 11:34:42

Christianversloot

Thanks for your quick response!

As far as I can see, this addition makes possible defining the schema (and hence structure of e.g. your response) in a different way.

What I am looking for is the addition of example objects that serve as example responses based on the schema, i.e. https://redocly.com/docs/openapi-visual-reference/example/

image

Is this already possible with OpenAPI definitions?

If we are already talking about the same thing (which I think we're not), please let me know too!

Commented On 21 Sep 2022 at 11:34:42

Christianversloot

Personal experiments with the AWS Free Tier.

On 06 Aug 2022 at 03:11:32
Issue Comment

Christianversloot

Plotting Scene with Cartopy gives correct borders but red background

First things first: thanks for making such a well-supported library for satellite image processing.

Secondly: I'm aware that my question is Cartopy-oriented, but I'm opening an issue here because it is grounded in code one of Satpy's maintainers wrote in another issue (https://github.com/pytroll/satpy/issues/1714). More specifically: https://github.com/pytroll/satpy/issues/1714#issuecomment-854863471.

The problem: I am using Satpy to resample GOES-16 imagery using an area definition spanning the Texas/Oklahoma/New Mexico border area, using the true_color composite. I am trying to add borders with Cartopy. After resampling, I do get what I want:

no_cartopy

Then, when using the resampled Scene as a Cartopy CRS, I do see the borders - but the background is red:

example

I have tried to tinker a lot, using other examples as well, but I have no clue what I'm doing wrong. The code posted in the other issue (although slightly older than a year) seems to have worked, so why isn't mine :) What am I missing?

Thanks for your help!

import os
from satpy import Scene
from glob import glob
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pyresample import create_area_def

# Print channel files used
BASE_DIR = os.path.join(os.getcwd(), '23g16')
fn = glob(os.path.join(BASE_DIR, '*s20221432301174*.nc'))
for f in fn:
	print(f)

# Create scene and define composite
scn = Scene(filenames=fn, reader='abi_l1b')
composite = 'true_color'
scn.load([composite])

# Create area definition
ext = [-110.629439, 31.594328, -95.933875, 37.384890]
width = 3840
height = 2160
area_def = create_area_def('TX/OK/NM',
                           {'proj': 'longlat', 'datum': 'WGS84'},
                            area_extent=ext,
                            shape=(height, width),
                            units='degrees',
                            description='TX/OK/NM border')

# Resample to AreaDefinition
new_scn = scn.resample(area_def)
new_scn.load([composite])

# Save without Cartopy
new_scn.save_dataset(composite, filename='no_cartopy.png')

# Plot composite
CRS = new_scn[composite].attrs['area'].to_cartopy_crs()
fig = plt.figure(figsize=(30,25))
ax = fig.add_subplot(1, 1, 1, projection=CRS)
new_scn[composite].plot.imshow(rgb='bands', transform=CRS, origin='upper')
ax.add_feature(ccrs.cartopy.feature.STATES, linewidth=0.25)

# Save plot
plt.savefig('example.png') 

Forked On 03 Aug 2022 at 02:35:29

Christianversloot

I have it working now! For reference of anyone else running into this problem: ensure that your version of cartopy is up to date, which itself requires some hassle as it requires PROJ >8.0.0 but apt has ~6.3.7 as latest version. Building PROJ from source (https://stackoverflow.com/a/72442088) and then installing cartopy and then ensuring that the rest (satpy, pyresample,...) is up to date fixed it for me.

Thanks both for your help!

Commented On 03 Aug 2022 at 02:35:29
Issue Comment

Christianversloot

Plotting Scene with Cartopy gives correct borders but red background

First things first: thanks for making such a well-supported library for satellite image processing.

Secondly: I'm aware that my question is Cartopy-oriented, but I'm opening an issue here because it is grounded in code one of Satpy's maintainers wrote in another issue (https://github.com/pytroll/satpy/issues/1714). More specifically: https://github.com/pytroll/satpy/issues/1714#issuecomment-854863471.

The problem: I am using Satpy to resample GOES-16 imagery using an area definition spanning the Texas/Oklahoma/New Mexico border area, using the true_color composite. I am trying to add borders with Cartopy. After resampling, I do get what I want:

no_cartopy

Then, when using the resampled Scene as a Cartopy CRS, I do see the borders - but the background is red:

example

I have tried to tinker a lot, using other examples as well, but I have no clue what I'm doing wrong. The code posted in the other issue (although slightly older than a year) seems to have worked, so why isn't mine :) What am I missing?

Thanks for your help!

import os
from satpy import Scene
from glob import glob
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pyresample import create_area_def

# Print channel files used
BASE_DIR = os.path.join(os.getcwd(), '23g16')
fn = glob(os.path.join(BASE_DIR, '*s20221432301174*.nc'))
for f in fn:
	print(f)

# Create scene and define composite
scn = Scene(filenames=fn, reader='abi_l1b')
composite = 'true_color'
scn.load([composite])

# Create area definition
ext = [-110.629439, 31.594328, -95.933875, 37.384890]
width = 3840
height = 2160
area_def = create_area_def('TX/OK/NM',
                           {'proj': 'longlat', 'datum': 'WGS84'},
                            area_extent=ext,
                            shape=(height, width),
                            units='degrees',
                            description='TX/OK/NM border')

# Resample to AreaDefinition
new_scn = scn.resample(area_def)
new_scn.load([composite])

# Save without Cartopy
new_scn.save_dataset(composite, filename='no_cartopy.png')

# Plot composite
CRS = new_scn[composite].attrs['area'].to_cartopy_crs()
fig = plt.figure(figsize=(30,25))
ax = fig.add_subplot(1, 1, 1, projection=CRS)
new_scn[composite].plot.imshow(rgb='bands', transform=CRS, origin='upper')
ax.add_feature(ccrs.cartopy.feature.STATES, linewidth=0.25)

# Save plot
plt.savefig('example.png') 

Forked On 03 Aug 2022 at 12:27:12

Christianversloot

Thanks Martin! This gives me a gray image:

example2

import os
from satpy import Scene
from glob import glob
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pyresample import create_area_def
from satpy.writers import get_enhanced_image

# Print channel files used
BASE_DIR = os.path.join(os.getcwd(), '23g16')
fn = glob(os.path.join(BASE_DIR, '*s20221432301174*.nc'))
for f in fn:
	print(f)

# Create scene and define composite
scn = Scene(filenames=fn, reader='abi_l1b')
composite = 'true_color'
scn.load([composite])

# Create area definition
ext = [-110.629439, 31.594328, -95.933875, 37.384890]
width = 3840
height = 2160
area_def = create_area_def('TX/OK/NM',
                           {'proj': 'longlat', 'datum': 'WGS84'},
                            area_extent=ext,
                            shape=(height, width),
                            units='degrees',
                            description='TX/OK/NM border')

# Resample to AreaDefinition
new_scn = scn.resample(area_def)
new_scn.load([composite])

# Save without Cartopy
# new_scn.save_dataset(composite, filename='no_cartopy.png')

# Plot composite
CRS = new_scn[composite].attrs['area'].to_cartopy_crs()
fig = plt.figure(figsize=(30,25))
ax = fig.add_subplot(1, 1, 1, projection=CRS)
img = get_enhanced_image(new_scn[composite])
img.data.plot.imshow(rgb="bands", transform=CRS, origin="upper")
ax.add_feature(ccrs.cartopy.feature.STATES, linewidth=0.25)

# Save plot
plt.savefig('example2.png') 

Commented On 03 Aug 2022 at 12:27:12
Issue Comment

Christianversloot

Plotting Scene with Cartopy gives correct borders but red background

First things first: thanks for making such a well-supported library for satellite image processing.

Secondly: I'm aware that my question is Cartopy-oriented, but I'm opening an issue here because it is grounded in code one of Satpy's maintainers wrote in another issue (https://github.com/pytroll/satpy/issues/1714). More specifically: https://github.com/pytroll/satpy/issues/1714#issuecomment-854863471.

The problem: I am using Satpy to resample GOES-16 imagery using an area definition spanning the Texas/Oklahoma/New Mexico border area, using the true_color composite. I am trying to add borders with Cartopy. After resampling, I do get what I want:

no_cartopy

Then, when using the resampled Scene as a Cartopy CRS, I do see the borders - but the background is red:

example

I have tried to tinker a lot, using other examples as well, but I have no clue what I'm doing wrong. The code posted in the other issue (although slightly older than a year) seems to have worked, so why isn't mine :) What am I missing?

Thanks for your help!

import os
from satpy import Scene
from glob import glob
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pyresample import create_area_def

# Print channel files used
BASE_DIR = os.path.join(os.getcwd(), '23g16')
fn = glob(os.path.join(BASE_DIR, '*s20221432301174*.nc'))
for f in fn:
	print(f)

# Create scene and define composite
scn = Scene(filenames=fn, reader='abi_l1b')
composite = 'true_color'
scn.load([composite])

# Create area definition
ext = [-110.629439, 31.594328, -95.933875, 37.384890]
width = 3840
height = 2160
area_def = create_area_def('TX/OK/NM',
                           {'proj': 'longlat', 'datum': 'WGS84'},
                            area_extent=ext,
                            shape=(height, width),
                            units='degrees',
                            description='TX/OK/NM border')

# Resample to AreaDefinition
new_scn = scn.resample(area_def)
new_scn.load([composite])

# Save without Cartopy
new_scn.save_dataset(composite, filename='no_cartopy.png')

# Plot composite
CRS = new_scn[composite].attrs['area'].to_cartopy_crs()
fig = plt.figure(figsize=(30,25))
ax = fig.add_subplot(1, 1, 1, projection=CRS)
new_scn[composite].plot.imshow(rgb='bands', transform=CRS, origin='upper')
ax.add_feature(ccrs.cartopy.feature.STATES, linewidth=0.25)

# Save plot
plt.savefig('example.png') 

Forked On 03 Aug 2022 at 06:54:15

Christianversloot

Thanks for your quick response! Unfortunately:

new_scn[composite].plot.imshow(rgb='bands', ax=ax, transform=CRS, origin='upper')

example2

Commented On 03 Aug 2022 at 06:54:15

Christianversloot

Update index.md

Pushed On 08 Jul 2022 at 12:19:26

Christianversloot

Create CNAME

Pushed On 08 Jul 2022 at 12:02:48

Christianversloot

Thoughts about severe weather.

On 08 Jul 2022 at 12:00:51

Christianversloot

Thoughts about severe weather.

On 08 Jul 2022 at 12:00:44

Christianversloot

Delete CNAME

Pushed On 08 Jul 2022 at 11:53:54

Christianversloot

Create CNAME

Pushed On 08 Jul 2022 at 11:52:57

Christianversloot

Update index.md

Pushed On 08 Jul 2022 at 11:51:26
Create Branch

Christianversloot

Thoughts about severe weather ๐ŸŒชโšกโ„๐ŸŒง

On 08 Jul 2022 at 11:51:04

Christianversloot

Thoughts about severe weather ๐ŸŒชโšกโ„๐ŸŒง

On 08 Jul 2022 at 11:47:38