1212from __future__ import annotations
1313
1414import warnings
15+ import requests
1516from io import StringIO
1617from typing import TYPE_CHECKING
1718
@@ -90,7 +91,8 @@ def get_USGS_samples(
9091 pointLocationLongitude = None ,
9192 pointLocationWithinMiles = None ,
9293 projectIdentifier = None ,
93- recordIdentifierUserSupplied = None
94+ recordIdentifierUserSupplied = None ,
95+ mimeType = "text/csv"
9496):
9597 """Search Samples database for USGS water quality data.
9698 This is a wrapper function for the Samples database API. All potential
@@ -109,105 +111,118 @@ def get_USGS_samples(
109111
110112 Parameters
111113 ----------
112- service : string
114+ service : string
113115 One of the available Samples services: "results", "locations", "activities",
114116 "projects", or "organizations". Defaults to "results".
115- profile : string
116- One of the available profiles associated with a service. Options for each
117- service are:
118- "results" - "fullphyschem", "basicphyschem",
119- "fullbio", "basicbio", "narrow",
120- "resultdetectionquantitationlimit",
121- "labsampleprep", "count"
122- "locations" - "site", "count"
123- "activities" - "sampact", "actmetric",
124- "actgroup", "count"
125- "projects" - "project", "projectmonitoringlocationweight"
126- "organizations" - "organization", "count"
127- activityMediaName : string or list of strings, optional
128- Name or code indicating environmental medium sample was taken.
129- Example: "Water".
130- activityStartDateLower : string, optional
131- The start date if using a date range. Takes the format YYYY-MM-DD.
132- The logic is inclusive, i.e. it will also return results that
133- match the date.
134- activityStartDateUpper : string, optional
135- The end date if using a date range. Takes the format YYYY-MM-DD.
136- The logic is inclusive, i.e. it will also return results that
137- match the date. If left as None, will pull all data before
138- activityStartDateLower up to the most recent available results.
139- activityTypeCode : string or list of strings, optional
140- Text code that describes type of field activity performed.
141- Example: "Sample-Routine, regular".
142- characteristicGroup : string or list of strings, optional
143- Characteristic group is a broad category describing one or more
144- of results.
145- Example: "Organics, PFAS"
146- characteristc : string or list of strings, optional
147- Characteristic is a specific category describing one or more results.
148- Example: "Suspended Sediment Discharge"
149- characteristicUserSupplied : string or list of strings, optional
150- A user supplied characteristic name describing one or more results.
151- boundingBox: list of four floats, optional
152- Filters on the the associated monitoring location's point location
153- by checking if it is located within the specified geographic area.
154- The logic is inclusive, i.e. it will include locations that overlap
155- with the edge of the bounding box. Values are separated by commas,
156- expressed in decimal degrees, NAD83, and longitudes west of Greenwich
157- are negative.
158- The format is a string consisting of:
159- - Western-most longitude
160- - Southern-most latitude
161- - Eastern-most longitude
162- - Northern-most longitude
163- Example: [-92.8,44.2,-88.9,46.0]
164- countryFips : string or list of strings, optional
165- Example: "US" (United States)
166- stateFips : string or list of strings, optional
167- Check out the code service for FIPS codes:
168- https://api.waterdata.usgs.gov/samples-data/codeservice/docs#/
169- Example: "US:15" (United States: Hawaii)
170- countyFips : string or list of strings, optional
171- Check out the code service for FIPS codes:
172- https://api.waterdata.usgs.gov/samples-data/codeservice/docs#/
173- Example: "US:15:001" (United States: Hawaii, Hawaii County)
174- siteTypeCode : string or list of strings, optional
175- An abbreviation for a certain site type.
176- Example: "GW" (Groundwater site)
177- siteTypeName : string or list of strings, optional
178- A full name for a certain site type.
179- Example: "Well"
180- usgsPCode : string or list of strings, optional
181- 5-digit number used in the US Geological Survey computerized
182- data system, National Water Information System (NWIS), to
183- uniquely identify a specific constituent
184- Example: "00060" (Discharge, cubic feet per second)
185- hydrologicUnit : string or list of strings, optional
186- Max 12-digit number used to describe a hydrologic unit.
187- Example: "070900020502"
188- monitoringLocationIdentifier : string or list of strings, optional
189- A monitoring location identifier has two parts: the agency code
190- and the location number, separated by a dash (-).
191- Example: "USGS-040851385"
192- organizationIdentifier : string or list of strings, optional
193- Designator used to uniquely identify a specific organization.
194- Currently only accepting the organization "USGS".
195- pointLocationLatitude : float, optional
196- Latitude for a point/radius query (decimal degrees). Must be used
197- with pointLocationLongitude and pointLocationWithinMiles.
198- pointLocationLongitude : float, optional
199- Longitude for a point/radius query (decimal degrees). Must be used
200- with pointLocationLatitude and pointLocationWithinMiles.
201- pointLocationWithinMiles : float, optional
202- Radius for a point/radius query. Must be used with
203- pointLocationLatitude and pointLocationLongitude
204- projectIdentifier : string or list of strings, optional
205- Designator used to uniquely id a data collection project in
206- organization context.
207- recordIdentifierUserSupplied : string or list of strings, optional
208- Internal AQS record identifier that returns 1 entry. Only available
209- for the "results" service.
117+ profile : string
118+ One of the available profiles associated with a service. Options for each
119+ service are:
120+ "results" - "fullphyschem", "basicphyschem",
121+ "fullbio", "basicbio", "narrow",
122+ "resultdetectionquantitationlimit",
123+ "labsampleprep", "count"
124+ "locations" - "site", "count"
125+ "activities" - "sampact", "actmetric",
126+ "actgroup", "count"
127+ "projects" - "project", "projectmonitoringlocationweight"
128+ "organizations" - "organization", "count"
129+ activityMediaName : string or list of strings, optional
130+ Name or code indicating environmental medium sample was taken.
131+ Example: "Water".
132+ activityStartDateLower : string, optional
133+ The start date if using a date range. Takes the format YYYY-MM-DD.
134+ The logic is inclusive, i.e. it will also return results that
135+ match the date.
136+ activityStartDateUpper : string, optional
137+ The end date if using a date range. Takes the format YYYY-MM-DD.
138+ The logic is inclusive, i.e. it will also return results that
139+ match the date. If left as None, will pull all data before
140+ activityStartDateLower up to the most recent available results.
141+ activityTypeCode : string or list of strings, optional
142+ Text code that describes type of field activity performed.
143+ Example: "Sample-Routine, regular".
144+ characteristicGroup : string or list of strings, optional
145+ Characteristic group is a broad category describing one or more
146+ of results.
147+ Example: "Organics, PFAS"
148+ characteristc : string or list of strings, optional
149+ Characteristic is a specific category describing one or more results.
150+ Example: "Suspended Sediment Discharge"
151+ characteristicUserSupplied : string or list of strings, optional
152+ A user supplied characteristic name describing one or more results.
153+ boundingBox: list of four floats, optional
154+ Filters on the the associated monitoring location's point location
155+ by checking if it is located within the specified geographic area.
156+ The logic is inclusive, i.e. it will include locations that overlap
157+ with the edge of the bounding box. Values are separated by commas,
158+ expressed in decimal degrees, NAD83, and longitudes west of Greenwich
159+ are negative.
160+ The format is a string consisting of:
161+ - Western-most longitude
162+ - Southern-most latitude
163+ - Eastern-most longitude
164+ - Northern-most longitude
165+ Example: [-92.8,44.2,-88.9,46.0]
166+ countryFips : string or list of strings, optional
167+ Example: "US" (United States)
168+ stateFips : string or list of strings, optional
169+ Check out the code service for FIPS codes:
170+ https://api.waterdata.usgs.gov/samples-data/codeservice/docs#/
171+ Example: "US:15" (United States: Hawaii)
172+ countyFips : string or list of strings, optional
173+ Check out the code service for FIPS codes:
174+ https://api.waterdata.usgs.gov/samples-data/codeservice/docs#/
175+ Example: "US:15:001" (United States: Hawaii, Hawaii County)
176+ siteTypeCode : string or list of strings, optional
177+ An abbreviation for a certain site type.
178+ Example: "GW" (Groundwater site)
179+ siteTypeName : string or list of strings, optional
180+ A full name for a certain site type.
181+ Example: "Well"
182+ usgsPCode : string or list of strings, optional
183+ 5-digit number used in the US Geological Survey computerized
184+ data system, National Water Information System (NWIS), to
185+ uniquely identify a specific constituent
186+ Example: "00060" (Discharge, cubic feet per second)
187+ hydrologicUnit : string or list of strings, optional
188+ Max 12-digit number used to describe a hydrologic unit.
189+ Example: "070900020502"
190+ monitoringLocationIdentifier : string or list of strings, optional
191+ A monitoring location identifier has two parts: the agency code
192+ and the location number, separated by a dash (-).
193+ Example: "USGS-040851385"
194+ organizationIdentifier : string or list of strings, optional
195+ Designator used to uniquely identify a specific organization.
196+ Currently only accepting the organization "USGS".
197+ pointLocationLatitude : float, optional
198+ Latitude for a point/radius query (decimal degrees). Must be used
199+ with pointLocationLongitude and pointLocationWithinMiles.
200+ pointLocationLongitude : float, optional
201+ Longitude for a point/radius query (decimal degrees). Must be used
202+ with pointLocationLatitude and pointLocationWithinMiles.
203+ pointLocationWithinMiles : float, optional
204+ Radius for a point/radius query. Must be used with
205+ pointLocationLatitude and pointLocationLongitude
206+ projectIdentifier : string or list of strings, optional
207+ Designator used to uniquely id a data collection project in
208+ organization context.
209+ recordIdentifierUserSupplied : string or list of strings, optional
210+ Internal AQS record identifier that returns 1 entry. Only available
211+ for the "results" service.
212+ mimeType : string, optional
213+
214+
210215 """
211216 _check_profiles (service , profile )
212217
213-
218+ # Get all not-None inputs
219+ params = {key : value for key , value in locals ().items () if value is not None and key not in ['service' , 'profile' ]}
220+
221+ # Build URL with service and profile
222+ url = BASE_URL + service + "/" + profile
223+ # Make a GET request with the filtered parameters
224+ response = requests .get (url , params = params )
225+
226+ return response
227+
228+
0 commit comments