# AQI location bound list of sensors limited?

**URL:** <https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343>\
**Category:** API\
**Created:** [January 20, 2023, 8:33pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343 "2023-01-20T20:33:27Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [January 20, 2023, 8:33pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/1 "2023-01-20T20:33:27Z")

</div>

Hi!

I’m trying to pull a list of sensors within a given lat/lon bounding box (Puget Sound, to be specific), and while the code (Python) runs fine and I’m getting a 200 response with data from the server, the list is suspiciously small.

There’s _no way_ that there are only 36 sensors within Puget Sound that have pm2.5 data. Is there any way I can get a complete list of `sensor_index` for the given lat/lon box? I’ve tested this both in the code below and in the [API documentation](https://api.purpleair.com/), and the result is the same (36 stations).

url string of the request: [https://api.purpleair.com/v1/sensors?fields=pm2.5&location\_type=0&nwlng=48.1162201&nwlat=-122.755863&selng=46.8555182&selat=-121.7631845](https://api.purpleair.com/v1/sensors?fields=pm2.5&location_type=0&nwlng=48.1162201&nwlat=-122.755863&selng=46.8555182&selat=-121.7631845)

code sample:

```auto
import requests
import json
import pandas as pd

with open('api_key.txt') as f:
    api = f.read()

headers= {'X-API-Key': api}

# get list of sensors within lat/long bounding box (defined by NW/SE corners)

# Port Townsend City Hall
NWlng = 48.1162201
NWlat = -122.755863

# Peak of Mt. Rainier
SElng = 46.8555182
SElat = -121.7631845

url = 'https://api.purpleair.com/v1/sensors?fields=pm2.5&location_type=0&nwlng=' + str(NWlng) + '&nwlat='+ str(NWlat) + '&selng=' + str(SElng) + '&selat=' + str(SElat)

response = requests.get(url, headers=headers)
print("Status Code: ", response.status_code)

content = json.loads(response.content)
data = content["data"]
columns = content["fields"]

df = pd.DataFrame(data, columns=columns)
print(df.shape)

```

output:

```auto
Status Code: 200
(36, 2)

```

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [January 20, 2023, 8:50pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/2 "2023-01-20T20:50:23Z")

</div>

Additional two points just discovered!

1 - apparently I needed to set `max_age=0` and `modified_since=0` to not filter out too many (now n=300)  
2 - The sensors I’m getting in this list don’t make any sense, as apparently I’m setting the bounding box incorrectly somehow? (This also happens in the API Docs tester).

See screenshot below that has both the lat/lon bounding box and the results. For example: “Downtown New Orleans” is certainly not located in Puget Sound.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/purpleair/original/2X/9/9b69a89ed88d0cb8fca148f246b5328da5ac6d27.png)

---

<div class="post-metadata">

**Author:** ![jeffgo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/jeffgo/32/1447_2.png) [@jeffgo](https://community.purpleair.com/u/jeffgo)\
**Post date:** [January 20, 2023, 10:05pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/3 "2023-01-20T22:05:51Z")

</div>

Well, I can say it’s not just you. I tried this with your coordinates as well as a smaller area (just a few square miles around my home in Kirkland, WA) with no better results.

If you look at the Purple Air map centered over the Puget Sound area, you’ll see that there are lots of available sensors. ([Real-Time Air Quality Map | PurpleAir](https://map.purpleair.com/1/a/l/m/i/mAQI/a0/p600/cC0?key=GX5HWOUCRRVR04YF#9.78/47.5863/-122.1309))

But what I noticed in the results from your call is that the latitude and longitude for all of the stations returned are null. With null coordinate values there’s no way to place them on a map.

It seems like this must be an issue with the API. It should be ignoring all stations with null latitude and/or longitude values, but it’s instead returning only stations with null coordinate values.

For my own use, I picked a bunch of stations near me using the map page ([Real-Time Air Quality Map | PurpleAir](https://map.purpleair.com/1/a/l/m/i/mAQI/a0/p600/cC0?key=GX5HWOUCRRVR04YF#13.22/47.66211/-122.19535)) to get the sensor\_index value. All of the stations I picked (like 34585 and 76973) have valid coordinate values - otherwise they wouldn’t be on the map. (As an aside, I created a group containing all of the sensors I wanted, and then I use the Get Member Data API call to get the data for those stations. This method, though, might not work for you if you’re looking for “all” of the stations in the Puget Sound area rather than picking them manually.)

I’ll leave it to you to contact Purple Air and report the issue with the coordinates search.

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [January 20, 2023, 10:37pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/4 "2023-01-20T22:37:15Z")

</div>

Thanks for confirming that I’m not crazy!

---

<div class="post-metadata">

**Author:** ![Andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/andrew/32/1211_2.png) [@Andrew](https://community.purpleair.com/u/Andrew)\
**Post date:** [January 23, 2023, 7:05pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/5 "2023-01-23T19:05:12Z")

</div>

In regards to the null values for latitude and longitude, @jeffgo is correct. These are, in fact, sensors that do not have a location set and are thus located in what we refer to as “No Man’s Land,” which you can see down near Antarctica on our map.

The reason your request isn’t returning data for the sensors you want is that your latitude and longitude are backwards. Flip those and you should be good to go!

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [January 23, 2023, 8:19pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/6 "2023-01-23T20:19:47Z")

</div>

🤦‍♂️

Well, that’s a fantastically dumb mistake. Thanks for the catch and not just pointing and laughing.

---

<div class="post-metadata">

**Author:** ![jeffgo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/jeffgo/32/1447_2.png) [@jeffgo](https://community.purpleair.com/u/jeffgo)\
**Post date:** [January 23, 2023, 9:50pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/7 "2023-01-23T21:50:38Z")

</div>

I now have a big red sore spot on my forehead from slapping it. At least I got the part about the null coordinate values right! 😵‍💫

---

<div class="post-metadata">

**Author:** ![Andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/andrew/32/1211_2.png) [@Andrew](https://community.purpleair.com/u/Andrew)\
**Post date:** [January 24, 2023, 8:52pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/8 "2023-01-24T20:52:17Z")

</div>

Actually, a very easy mistake to make, considering that we put longitude before latitude in our documentation, which is backwards for most people.

 ![Screenshot 2023-01-24 at 1.51.11 PM](https://us1.discourse-cdn.com/flex020/uploads/purpleair/original/2X/d/d1edac7e89e05f0b3d64e3b52a29417ae74db522.png)

---

<div class="post-metadata">

**Author:** ![Peter\_Fontana](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/peter_fontana/32/3198_2.png) [@Peter\_Fontana](https://community.purpleair.com/u/Peter_Fontana)\
**Post date:** [September 7, 2023, 5:12pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/9 "2023-09-07T17:12:10Z")

</div>

I’m attempting my first API call to get sensor\_index from a bounding box. However, the sample call returns no data (unlike the example screenshots in this thread which show data). I’m having the same problem when I put in R. Can someone point me in the right direction? Here’s my query from the sample call:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/purpleair/original/2X/e/eb2b01d4f55244830f6c0feb0fbd3b91ad49c330.png)

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [September 7, 2023, 5:28pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/10 "2023-09-07T17:28:44Z")

</div>

That’s a gigantic geographic area. Maybe test on a smaller square?

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [September 7, 2023, 5:36pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/11 "2023-09-07T17:36:35Z")

</div>

Another idea: it might be getting confused by you crossing 180 degrees of longitude. You want a square covering most of the pacific and N America, not one covering most of Eurasia and the Atlantic, right?

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [September 7, 2023, 5:38pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/13 "2023-09-07T17:38:51Z")

</div>

So a workaround would be to cut into two chunks, the part to the East of 180 degrees and the part to the West, then merge the data.

---

<div class="post-metadata">

**Author:** ![Peter\_Fontana](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/peter_fontana/32/3198_2.png) [@Peter\_Fontana](https://community.purpleair.com/u/Peter_Fontana)\
**Post date:** [September 7, 2023, 5:51pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/14 "2023-09-07T17:51:31Z")

</div>

> [@epcw](#):
>
> That’s a gigantic geographic area. Maybe test on a smaller square?

That did it! I think I just had the wrong nwlng to begin with. Thank you!

---

<div class="post-metadata">

**Author:** ![Md\_Zahidul\_Islam](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/md_zahidul_islam/32/4017_2.png) [@Md\_Zahidul\_Islam](https://community.purpleair.com/u/Md_Zahidul_Islam)\
**Post date:** [November 17, 2023, 6:03am UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/15 "2023-11-17T06:03:37Z")

</div>

the returned locations of the sensors are way different than the passed boundary locations. I tried nwlng=-121.75,nwlat= 37.42, selng= -114.52, selat=32.55. When I checked the locations of the returned sensors I got selected\_sensors[‘latitude’].max(), selected\_sensors[‘latitude’].min() = (62.34708, -40.87172). How is this possible? Can you please help?

---

<div class="post-metadata">

**Author:** ![Josh\_PurpleAir](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/josh_purpleair/32/2842_2.png) [@Josh\_PurpleAir](https://community.purpleair.com/u/Josh_PurpleAir)\
**Post date:** [November 17, 2023, 4:52pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/16 "2023-11-17T16:52:29Z")

</div>

We responded to your comment in [this thread](https://community.purpleair.com/t/finding-large-amounts-of-sensor-indexes-bounding-box-api-call/5688/2). Try providing us the URL you used for your API request and we can examine it.

---

<div class="post-metadata">

**Author:** ![epcw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.purpleair.com/epcw/32/1917_2.png) [@epcw](https://community.purpleair.com/u/epcw)\
**Post date:** [November 17, 2023, 5:08pm UTC](https://community.purpleair.com/t/aqi-location-bound-list-of-sensors-limited/3343/17 "2023-11-17T17:08:07Z")

</div>

What Josh\_PurpleAir said. I’d be happy to help, just need to see your query so I can unpack it.
