Package: mixmasta
mixmastaA library for common scientific model transforms. This library enables fast and intuitive transforms including:Converting ageotiffto acsvConverting aNetCDFto acsvGeocodingcsv,xls, andxlsxdata that contains latitude and longitudeSetupSeedocs/docker.mdfor instructions on running Mixmasta in Docker (easiest!).Ensure you have a working installation ofGDALYou also need to ensure thatnumpyis installed prior tomixmastainstallation. This is an artifact of GDAL, which will build incorrectly ifnumpyis not already configured:pip install numpy==1.20.1
pip install mixmastaNote: if you had a prior installation of GDAL you may need to runpip install mixmasta --no-cache-dirin a clean environment.You must install the GADM2 and GADM3 data with:mixmasta downloadUsageExamples can be found in theinputdirectory.Convert a geotiff to a dataframe with:from mixmasta import mixmasta as mix
df = mix.raster2df('chirps-v2.0.2021.01.3.tif', feature_name='rainfall', band=1)Note that you should specify the data band of the geotiff to process if it is multi-band. You may also specify the name of the feature column to produce. You may optionally specify adateif the geotiff has an associated date. For example:Convert a NetCDF to a dataframe with:from mixmasta import mixmasta as mix
df = mix.netcdf2df('tos_O1_2001-2002.nc')Geocode a dataframe:from mixmasta import mixmasta as mix

# First, load in the geotiff as a dataframe
df = mix.raster2df('chirps-v2.0.2021.01.3.tif', feature_name='rainfall', band=1)

# next, we can geocode the dataframe to the admin-level desired (`admin2` or `admin3`)
# by specifying the names of the x and y columns
# in this case, we will geocode to admin2 where x,y are are 'longitude' and 'latitude', respectively.
df_g = mix.geocode("admin2", df, x='longitude', y='latitude')Running with CLIAfter cloning the repository and changing to themixmastadirectory, you can run mixmasta via the command line.Set-up:While you can pointmixmastato any file you would like to transform, the examples below assume your file is in theinputsfolder; the transformed.csvfile will be written to theoutputsfolder.Transform geotiff to geocoded csv:mixmasta mix --xform=geotiff --input_file=chirps-v2.0.2021.01.3.tif --output_file=geotiffTEST.csv --geo=admin2 --feature_name=rainfall --band=1 --date='5/4/2010' --x=longitude --y=latitudeTransform geotiff to csv:mixmasta mix --xform=geotiff --input_file=maxhop1.tif --output_file=maxhopOUT.csv --geo=admin2 --feature_name=probabilty --band=1 --x=longitude --y=latitudeTransform netcdf to geocoded csv:mixmasta mix --xform=netcdf --input_file=tos_O1_2001-2002.nc --output_file=netcdf.csv --geo=admin2 --x=lon --y=latTransform netcdf to csv:mixmasta mix --xform=netcdf --input_file=tos_O1_2001-2002.nc --output_file=netcdf.csv-geocode an existing csv file:mixmasta mix --xform=geocode --input_file=no_geo.csv --geo=admin3 --output_file=geoed_no_geo.csv --x=longitude --y=latitudeWorld Modelers Specific NormalizationFor the World Modelers program, it is necessary to convert arbitrarycsv,geotiff, andnetcdffiles into a CauseMos compliant format. This can be accomplished by leveraging amappingannotation file and thecausemosifycommand. The output is agzippedparquetfile. This may be invoked with:mixmasta causemosify --input_file=chirps-v2.0.2021.01.3.tif --mapper=mapper.json --geo=admin3 --output_file=causemosified_exampleThis will produce a file calledcausemosified_example.parquet.gzipwhich can be read using Pandas with:pd.read_parquet('causemosified_example.parquet.gzip')Other DocumentsDocker Instructions:docs/docker.mdGeo Entity Resolution Description:docs/geo-tentity-resolution.mdPackage Testing in SpaceTag Env:docs/spacetag-test.mdCreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.1.0 (2021-02-24)First release on PyPI.