Skip to content

Commit

Permalink
Merge branch 'main' into sedafix
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime committed Jan 18, 2024
2 parents b2cdf4e + 4c8f016 commit da1e66d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
16 changes: 8 additions & 8 deletions geosnap/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ def seda(
"long",
"poolsub",
], "`pool` argument must be either 'pool', 'long', or 'poolsub'"
assert (
standardize
in [
"gcs",
"cs",
]
), "`standardize` argument must be either 'cs' for cohort-standardized or 'gcs' for grade-cohort-standardized"
fn = f"seda_{level}_{pooling}_{standardize}_4.1"
assert standardize in [
"gcs",
"cs",
], "`standardize` argument must be either 'cs' for cohort-standardized or 'gcs' for grade-cohort-standardized"
if pooling=='poolsub':
fn = f"seda_{level}_{pooling}_{standardize}_4.1_corrected"
else:
fn = f"seda_{level}_{pooling}_{standardize}_4.1"
local_path = pathlib.Path(self.data_dir, "seda", f"{fn}.parquet")
remote_path = f"https://stacks.stanford.edu/file/druid:xv742vh9296/{fn}.csv"
msg = (
Expand Down
11 changes: 6 additions & 5 deletions geosnap/harmonize/harmonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def harmonize(
if intensive_variables is not None:
for i in intensive_variables:
allcols.append(i)

with tqdm(total=len(times), desc=f"Converting {len(times)} time periods") as pbar:
for i in times:
pbar.set_description(f"Harmonizing {i}")
Expand All @@ -172,10 +172,10 @@ def harmonize(
allocate_total=allocate_total,
)
else:
# if there are NaNs, tobler will raise lots of warnings, that it's filling
# with implicit 0s. Those warnings are superfluous most of the time
# if there are NaNs, tobler will raise lots of warnings, that it's filling
# with implicit 0s. Those warnings are superfluous most of the time
with warnings.catch_warnings():
warnings.simplefilter("ignore")
warnings.simplefilter("ignore")
interpolation = area_interpolate(
source_df,
target_df.copy(),
Expand Down Expand Up @@ -225,7 +225,8 @@ def harmonize(
pbar.update(1)
pbar.set_description("Complete")
pbar.close()
interpolated_dfs.append(target_df[allcols].set_index(unit_index))
if target_year is not None:
interpolated_dfs.append(target_df[allcols].set_index(unit_index))

harmonized_df = gpd.GeoDataFrame(pd.concat(interpolated_dfs), crs=crs)

Expand Down
24 changes: 17 additions & 7 deletions geosnap/tests/test_harmonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
from geosnap.harmonize import harmonize
from geosnap.io import get_census

local_raster = os.path.join(os.getcwd(), "nlcd_2011.tif") # portability
if not os.path.exists(local_raster):
p = quilt3.Package.browse("rasters/nlcd", "s3://spatial-ucr")
p["nlcd_2011.tif"].fetch()


def test_harmonize_area():
la = get_census(county_fips="06037", datastore=DataStore())

Expand Down Expand Up @@ -49,11 +43,27 @@ def test_harmonize_area_weighted():
extensive_variables=["n_total_housing_units"],
intensive_variables=["p_vacant_housing_units"],
weights_method="dasymetric",
raster=local_raster,
raster='https://spatial-ucr.s3.amazonaws.com/nlcd/landcover/nlcd_landcover_2011.tif',
)
assert harmonized_nlcd_weighted.n_total_housing_units.sum().round(0) == 900620.0
assert_allclose(
harmonized_nlcd_weighted.p_vacant_housing_units.sum(),
8832.8796,
rtol=1e-03,
)

def test_harmonize_target_gdf():

balt = get_census(county_fips="24510", datastore=DataStore())
tgt_gdf = balt[balt.year==2000][['geometry']]
gdf = harmonize(balt,
target_gdf=tgt_gdf,
extensive_variables=["n_total_housing_units"],
intensive_variables=["p_vacant_housing_units"],
)
assert gdf.n_total_housing_units.sum().round(0) == 900620.0
assert_allclose(
gdf.p_vacant_housing_units.sum(),
8832.8796,
rtol=1e-03,
)
3 changes: 3 additions & 0 deletions geosnap/visualize/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ def plot_timeseries(
axs.format(suptitle=column)
else:
axs.format(suptitle=title)
else:
if title:
plt.suptitle(title)

if save_fig:
f.savefig(save_fig, dpi=dpi, bbox_inches="tight")
Expand Down

0 comments on commit da1e66d

Please sign in to comment.