How to use the Basemap readshapefile method for tectonic boundaries - python

I'm not sure where I'm going wrong here so perhaps someone with experience with the readshapefile command in Basemap may be able to help. Below my code:
m.readshapefile('/Users/MyiMac/Desktop/ONGOING_PROJEKTS/MISC/PB2/PB2002_plates', name='PB2002_plates', drawbounds=True, color='orange')
I'd like to use the coordinates in a PB2002_plates.txt file to generate the tectonic plate boundaries in various maps. Using a .txt file which I retrieved didn't work. Error message below:
raise IOError('cannot locate %s.shx'%shapefile)
IOError: cannot locate /Users/MyiMac/Desktop/ONGOING_PROJEKTS/MISC/PB2/PB2002_plates.shx
The error mentions not being able to find a .shx file. On another site I located PB2002_plates.shp, PB2002_plates.sbn, and PB2002_plates.sbx. I put all these files in the same directory as my PB2002_plates.txt file. I don't know what the .shx file is or wehre to retrieve this from. These 3 "new" files are not in ASCII format. The PB2002_plates.txt contains coordinates and therefore in ASCII format.
I don't know where I am going wrong, but I suspect the type of file used is wrong. Or perhaps I need to use a different type of parameter for "name='PB2002_plates" in my code? Or is the directory wrong and need to go one directory higher as the "name" parameter is the file name? The literature I've found is so far sparse, with very few examples online to go by.

Problem solved. There must be 3 types of PB2002 files in the directory including the .shx file, in order for this to work.

Related

How to extract all files from a p7m file

I have a bunch of p7m files (used to digitally sign some files, usually pdf files) and I would like some help to find a way to extract the content. I know how to iterate a process over the files in a folder using Python, I need help just with the extraction part.
I tried with PyPDF2.PdfFileReader.decrypt() but I get a "EOF marker not found" error because apparently PyPDF2 cannot manage encrypted files.
I saw somebody used the mime library, but that is way above my level honestly.
Thank you

Create direct file object in python

I have images in 100 folders and the search results are slow, so I want to access those images, so maybe I wanna do it with python(if it is faster), in the way that when we select all the files, and drag and drop them in windows. then I realized that drag and drop in windows uses Component Object Model this source.
So I want to know is there any way in python to have COMs of the image files in those 100 folders in the same place (a specific folder)? or in other words can we create COMs of other files, (equivalent of shortcuts), cause I know shortcuts for my purpose won't work.
The question in general is about how to access direct handles or COMs of files of different folders in one folder? if it's possible, please tell me how? to be simpler I want to have similar function of file shortcuts but not 'shortcuts' existing in windows, because for my purpose 'shortcuts' won't work, so I think it can be done with COMs.
tkinter equivalent question:
let me ask my question in other way, lets think I want to make a windows file search application in python with some library like tkinter, so one background part of my code finds the file paths of desired search results, and other part in gui('gui part'): wants to show the result files with ability of opening files from that gui or drag files from gui to other folder or applications, so how should I do the 'gui part'?
this tutorial suggested by #Thingamabobs is about getting external files into window(gui) of app, but I want the opposite, I mean having file handles to open, something like windows explorer
My question maybe wrong in case of misunderstanding the concept of COMs, so please provide me more relevant sources of use case of mine. finally if the title seems to be unsuitable, feel free to change it.
Based on an interpretation of the question, the following is an initial summary approach to a solution.
"""
This module will enable easy access to files spread across 100 plus
directories. A file should be as easy to open as clicking on a link.
Analysis:
Will any files be duplicated in any other directory? Do not know.
Will any file name be the same as another file in a different directory? Do
not know.
Initial design in pseudocode:
> Capture absolute path to each file in each directory.
> Store files information in python data structure
> for instance a list of tuples <path>,<filename>
> Once a data structure is determined use Tkinter, ttk.treeview to open a
file as easy as clicking on a link in the tree.
"""

Save Abjad ouput pdfs

I'm using Abjad to create pdf's of lilypond files my python program has written.
When I use the abjad.show() method, I get the image that I want, but I can't figure out how to save it as a pdf somewhere my program can use.
The documentation mentions something about changing the abjad_output_directory in the config.py file, but there's no other mention of the config.py file. I can't figure out where the pdf's are being saved to on my Mac.
Is there an easy way to simply save the generated pdf as a file in the same directory as the program I'm in?
The documentation for abjad.system.AbjadConfiguration might be helpful:
It mentions where the abjad.cfg file is, in which you can hopefully define an output directory, and
It has a method for finding the abjad output directory: abjad_output_directory
I have not been able to test this myself, but hopefully it is enough for you.
you can set the following keywords in show():
abjad.show(notes, output_directory=r"C:\path\to\somewhere", should_open=False)
Answering in case anyone else searches this question as it was hard to figure out.

Detecting corrupt document files with python-docx

Can you please help me i figuring this out.
While reading a .docx file from python-docx (docx.Document(file_name)), how can I detect if the docx file is correct or corrupt.
I've got some cases where these input docx files are either empty or corrupt.
How can I flag these cases using this library
There is no such feature in python-docx. Part of the reason is that while a file could be determined to be valid or invalid according to the schema in the ISO specification, many small discrepancies are permitted by each client. What is permitted varies between clients; some things that LibreOffice will accept produce a repair error in Microsoft Word, for example.
The only reliable way to determine this is to attempt to open the file with the target client, perhaps using automation like VBA in the case of Microsoft Word.

Python UDF - import/read external files

I would like to import other python/csv files into my python udf to perform some operations.
Like,
Comparing the table data(which flows in as a stream, row by row) to an external .csv row.
When I try to read data of .csv file, it gives me an error
IOError: File /home/abc/xyz/myfile.csv does not exist
While the code works perfectly well when it is written as a regular python script (not like udf)
If I understood it right . You can try
ADD FILE [Your complete file path]
or
Add FILES [Your directory path].
Because before referring anything on cluster you must add it to the distribution cache so that code there can access that portion.
you can have a look at it.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli
Be careful about the syntax! It may cause many problems and unfortunately, query language interpreter is not able to show where the problem is coming from and it just shows some generic error report.
Look at kind of the same problem here that was caused by a syntax issue in addressing the file!
Accessing external file in Python UDF

Categories

Resources